From 26e7e259dc2fbf1a78d945c5f3518aca89857ac5 Mon Sep 17 00:00:00 2001 From: mooreland Date: Tue, 1 Apr 2025 10:47:16 +0800 Subject: [PATCH 1/3] support bls381 --- .../{bls381adaptor => bls381adaptor.rs} | 2 - src/adaptor/mod.rs | 2 +- src/circuits/{bls => bls.rs} | 105 ++++++++---------- src/circuits/mod.rs | 2 +- src/proof.rs | 24 ++-- test_bls381.sh | 4 + 6 files changed, 63 insertions(+), 76 deletions(-) rename src/adaptor/{bls381adaptor => bls381adaptor.rs} (99%) rename src/circuits/{bls => bls.rs} (77%) create mode 100644 test_bls381.sh diff --git a/src/adaptor/bls381adaptor b/src/adaptor/bls381adaptor.rs similarity index 99% rename from src/adaptor/bls381adaptor rename to src/adaptor/bls381adaptor.rs index cdbd8f51..18411c25 100644 --- a/src/adaptor/bls381adaptor +++ b/src/adaptor/bls381adaptor.rs @@ -295,7 +295,6 @@ impl HostOpSelector for Bls381PairChip { arg_cells: &Vec>, layouter: &impl Layouter, ) -> Result<(), Error> { - self.range_chip.init_table(layouter)?; let a = arg_cells[0..9].to_vec(); let b = arg_cells[9..26].to_vec(); let ab = arg_cells[26..74].to_vec(); @@ -521,7 +520,6 @@ impl HostOpSelector for Bls381SumChip { arg_cells: &Vec>, layouter: &impl Layouter, ) -> Result<(), Error> { - self.range_chip.init_table(layouter)?; self.load_bls381_sum_circuit(&arg_cells, layouter)?; Ok(()) } diff --git a/src/adaptor/mod.rs b/src/adaptor/mod.rs index eb3043f9..89857169 100644 --- a/src/adaptor/mod.rs +++ b/src/adaptor/mod.rs @@ -4,7 +4,7 @@ use crate::utils::field_to_bn; use halo2_proofs::arithmetic::{BaseExt, FieldExt}; use num_bigint::BigUint; -// pub mod bls381adaptor; +pub mod bls381adaptor; pub mod bn256adaptor; pub mod hashadaptor; pub mod keccakadaptor; diff --git a/src/circuits/bls b/src/circuits/bls.rs similarity index 77% rename from src/circuits/bls rename to src/circuits/bls.rs index 0c46c05f..2a1bb40b 100644 --- a/src/circuits/bls +++ b/src/circuits/bls.rs @@ -25,8 +25,8 @@ pub const BLS381FQ_SIZE: usize = 8; pub const BLS381G1_SIZE: usize = 17; pub const BLS381G2_SIZE: usize = 33; -use halo2ecc_o::{NativeScalarEccConfig}; -use halo2ecc_o::context::{NativeScalarEccContext}; +use halo2ecc_o::{NativeScalarEccConfig,GeneralScalarEccConfig}; +use halo2ecc_o::context::{GeneralScalarEccContext}; use crate::utils::Limb; use num_bigint::BigUint; @@ -34,7 +34,7 @@ use std::ops::{AddAssign, Mul}; #[derive(Clone, Debug)] pub struct Bls381ChipConfig { - ecc_chip_config: NativeScalarEccConfig, + ecc_chip_config: GeneralScalarEccConfig, } pub struct Bls381PairChip { @@ -93,17 +93,16 @@ fn assigned_cells_to_bn381( fn get_scalar_from_cell( - ctx: &mut NativeScalarEccContext, + ctx: &mut GeneralScalarEccContext, a: &Vec>, -) -> AssignedInteger { +) -> AssignedInteger { let bn = assigned_cells_to_fr(a, 0); - //todo correct the fr type,refer old host - let fr = ctx.integer_context().assign_w(Some(bn)).unwrap(); + let fr = ctx.scalar_integer_context().assign_w(Some(bn)).unwrap(); fr } fn get_g1_from_cells( - ctx: &mut NativeScalarEccContext, + ctx: &mut GeneralScalarEccContext, a: &Vec>, //G1 (4 * 2 + 1) ) -> AssignedPoint { let x_bn = assigned_cells_to_bn381(a, 0); @@ -118,7 +117,7 @@ fn get_g1_from_cells( Fr::one() } else { Fr::zero() - })?.into(), + }).unwrap().into(), ) } @@ -130,19 +129,19 @@ fn get_g2_from_cells( let x2_bn = assigned_cells_to_bn381(b, 4); let y1_bn = assigned_cells_to_bn381(b, 8); let y2_bn = assigned_cells_to_bn381(b, 12); - let x1 = ctx.base_integer_chip().assign_w(&x1_bn); - let x2 = ctx.base_integer_chip().assign_w(&x2_bn); - let y1 = ctx.base_integer_chip().assign_w(&y1_bn); - let y2 = ctx.base_integer_chip().assign_w(&y2_bn); + let x1 = ctx.integer_context().assign_w(Some(x1_bn)).unwrap(); + let x2 = ctx.integer_context().assign_w(Some(x2_bn)).unwrap(); + let y1 = ctx.integer_context().assign_w(Some(y1_bn)).unwrap(); + let y2 = ctx.integer_context().assign_w(Some(y2_bn)).unwrap(); let is_identity = fr_to_bool(&b[16].value); AssignedG2Affine::new( (x1, x2), (y1, y2), - AssignedCondition(ctx.native_ctx.borrow_mut().assign(if is_identity { + ctx.plonk_region_context().assign(if is_identity { Fr::one() } else { Fr::zero() - })), + }).unwrap().into(), ) } @@ -154,9 +153,7 @@ fn enable_fr_permute( input: &Vec>, ) -> Result<(), Error> { for i in 0..3 { - let limb = fr.limbs_le[i].cell; - let limb_assigned = get_cell_of_ctx(cells, &limb); - region.constrain_equal(input[i].get_the_cell().cell(), limb_assigned.cell())?; + region.constrain_equal(input[i].get_the_cell().cell(), fr.limbs()[i].unwrap().cell())?; } Ok(()) } @@ -167,9 +164,7 @@ fn enable_fq_permute( input: &Vec>, ) -> Result<(), Error> { for i in 0..4 { - let limb = fq.limbs_le[i].cell; - let limb_assigned = get_cell_of_ctx(cells, &limb); - region.constrain_equal(input[i].get_the_cell().cell(), limb_assigned.cell())?; + region.constrain_equal(input[i].get_the_cell().cell(), fq.limbs()[i].unwrap().cell())?; } Ok(()) } @@ -182,9 +177,7 @@ fn enable_g1affine_permute( let mut inputs = input.chunks(4); enable_fq_permute(region, &point.x, &inputs.next().unwrap().to_vec())?; enable_fq_permute(region, &point.y, &inputs.next().unwrap().to_vec())?; - let z_limb0 = point.z.0.cell; - let z_limb0_assigned = get_cell_of_ctx(cells, &z_limb0); - region.constrain_equal(input[8].get_the_cell().cell(), z_limb0_assigned.cell())?; + region.constrain_equal(input[8].get_the_cell().cell(), point.z.cell())?; Ok(()) } @@ -198,9 +191,7 @@ fn enable_g2affine_permute( enable_fq_permute(region, &point.x.1, &inputs.next().unwrap().to_vec())?; enable_fq_permute(region, &point.y.0, &inputs.next().unwrap().to_vec())?; enable_fq_permute(region, &point.y.1, &inputs.next().unwrap().to_vec())?; - let z_limb0 = point.z.0.cell; - let z_limb0_assigned = get_cell_of_ctx(cells, &z_limb0); - region.constrain_equal(input[16].get_the_cell().cell(), z_limb0_assigned.cell())?; + region.constrain_equal(input[16].get_the_cell().cell(), point.z.cell())?; Ok(()) } @@ -283,7 +274,7 @@ impl Bls381PairChip { pub fn configure(cs: &mut ConstraintSystem) -> >::Config { Bls381ChipConfig { - ecc_chip_config: NativeScalarEccConfig::configure(cs), + ecc_chip_config: GeneralScalarEccConfig::configure::(cs), } } @@ -298,11 +289,13 @@ impl Bls381PairChip { || "base", |mut region| { let timer = start_timer!(|| "assign"); + let mut ctx = self.config.ecc_chip_config.to_context(region); + let a_g1 = get_g1_from_cells(&mut ctx, a); let b_g2 = get_g2_from_cells(&mut ctx, b); - let ab_fq12_raw = ctx.pairing(&[(&a_g1, &b_g2)]); - let ab_fq12 = ctx.fq12_reduce(&ab_fq12_raw); + let ab_fq12_raw = ctx.pairing(&[(&a_g1, &b_g2)]).unwrap(); + let ab_fq12 = ctx.fq12_reduce(&ab_fq12_raw).unwrap(); enable_g1affine_permute(&mut region, &a_g1, a)?; enable_g2affine_permute(&mut region, &b_g2, b)?; @@ -343,7 +336,7 @@ impl Bls381SumChip { pub fn configure(cs: &mut ConstraintSystem) -> >::Config { Bls381ChipConfig { - ecc_chip_config: NativeScalarEccConfig::configure(cs), + ecc_chip_config: GeneralScalarEccConfig::configure::(cs), } } @@ -356,10 +349,11 @@ impl Bls381SumChip { || "base", |mut region| { let timer = start_timer!(|| "assign"); + let mut ctx = self.config.ecc_chip_config.to_context(region); let mut ais = vec![]; let mut g1s = vec![]; let mut sums = vec![]; - let identity = ctx.assign_identity(); + let identity = ctx.assign_identity().unwrap(); let mut sum = identity.clone(); for group in ls.chunks_exact(22) { // using constraint to fix if to reset @@ -372,34 +366,10 @@ impl Bls381SumChip { ais.push(a.clone()); let g = get_g1_from_cells(&mut ctx, &group.get(4..13).unwrap().to_vec()); let rhs = ctx.ecc_mul(&g, a); - let sum_ret = ctx.ecc_add(&lhs, &rhs); - let sum_ret = ctx.ecc_reduce(&sum_ret); - ctx.native_ctx.borrow_mut().enable_permute(&sum_ret.z.0); - ctx.native_ctx - .borrow_mut() - .enable_permute(&sum_ret.x.limbs_le[0]); - ctx.native_ctx - .borrow_mut() - .enable_permute(&sum_ret.x.limbs_le[1]); - ctx.native_ctx - .borrow_mut() - .enable_permute(&sum_ret.x.limbs_le[2]); - ctx.native_ctx - .borrow_mut() - .enable_permute(&sum_ret.x.limbs_le[3]); - ctx.native_ctx - .borrow_mut() - .enable_permute(&sum_ret.y.limbs_le[0]); - ctx.native_ctx - .borrow_mut() - .enable_permute(&sum_ret.y.limbs_le[1]); - ctx.native_ctx - .borrow_mut() - .enable_permute(&sum_ret.y.limbs_le[2]); - ctx.native_ctx - .borrow_mut() - .enable_permute(&sum_ret.y.limbs_le[3]); - sum = ctx.to_point_with_curvature(sum_ret.clone()); + let sum_ret = ctx.ecc_add(&lhs, &rhs)?; + let sum_ret = ctx.ecc_reduce(&sum_ret)?; + + sum = sum_ret.clone(); g1s.push(g); sums.push(sum_ret); } @@ -426,6 +396,21 @@ impl Bls381SumChip { .unwrap() }); end_timer!(timer); + + let timer = start_timer!(|| "finalize int mul"); + ctx.integer_context().finalize_int_mul()?; + ctx.scalar_integer_context().finalize_int_mul()?; + end_timer!(timer); + + ctx.get_range_region_context().init()?; + ctx.get_scalar_range_region_context().init()?; + let timer = start_timer!(|| "finalize compact cells"); + ctx + .get_range_region_context() + .finalize_compact_cells()?; + ctx.get_scalar_range_region_context().finalize_compact_cells()?; + end_timer!(timer); + Ok(()) }, )?; diff --git a/src/circuits/mod.rs b/src/circuits/mod.rs index 4afa91f7..46b9a3a1 100644 --- a/src/circuits/mod.rs +++ b/src/circuits/mod.rs @@ -1,7 +1,7 @@ pub mod anemoi; pub mod babyjub; pub mod bits_arith; -// pub mod bls; +pub mod bls; pub mod bn256; pub mod host; pub mod keccak256; diff --git a/src/proof.rs b/src/proof.rs index b45590c6..fbf2668d 100644 --- a/src/proof.rs +++ b/src/proof.rs @@ -1,7 +1,7 @@ use crate::circuits::babyjub::AltJubChip; use crate::circuits::{ - // bls::Bls381PairChip, - // bls::Bls381SumChip, + bls::Bls381PairChip, + bls::Bls381SumChip, bn256::Bn256PairChip, bn256::Bn256SumChip, host::{HostOpChip, HostOpConfig, HostOpSelector}, @@ -35,8 +35,8 @@ struct ArgOpName { } #[derive(clap::ArgEnum, Clone, Debug, Serialize, Deserialize)] pub enum OpType { - // BLS381PAIR, - // BLS381SUM, + BLS381PAIR, + BLS381SUM, BN256PAIR, BN256SUM, POSEIDONHASH, @@ -190,14 +190,14 @@ pub fn exec_create_host_proof( } match opname { - // OpType::BLS381PAIR => { - // let circuit = build_host_circuit::>(&v, k, ()); - // gen_proof!(circuit); - // } - // OpType::BLS381SUM => { - // let circuit = build_host_circuit::>(&v, k, ()); - // gen_proof!(circuit); - // } + OpType::BLS381PAIR => { + let circuit = build_host_circuit::>(&v, k, ()); + gen_proof!(circuit); + } + OpType::BLS381SUM => { + let circuit = build_host_circuit::>(&v, k, ()); + gen_proof!(circuit); + } OpType::BN256PAIR => { let circuit = build_host_circuit::>(&v, k, ()); gen_proof!(circuit); diff --git a/test_bls381.sh b/test_bls381.sh new file mode 100644 index 00000000..350d7b6c --- /dev/null +++ b/test_bls381.sh @@ -0,0 +1,4 @@ +cargo test generate_bls_sum_input +cargo run --release --features cuda -- --input blssumtest.json --opname bls381sum --output output/ --param params/ +cargo test generate_bls_pair_input +cargo run --release --features cuda -- --input blspairtest.json --opname bls381pair --output output/ --param params/ From 592c8c6ef623507d6837f97715717259b0fe53f6 Mon Sep 17 00:00:00 2001 From: mooreland Date: Tue, 1 Apr 2025 22:19:00 +0800 Subject: [PATCH 2/3] fmt --- Cargo.lock | 18 ++++- Cargo.toml | 6 +- src/circuits/bls.rs | 180 +++++++++++++++++--------------------------- test_bls381.sh | 4 +- 4 files changed, 88 insertions(+), 120 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index afb5f966..d68de831 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1558,7 +1558,7 @@ dependencies = [ "blake2b_simd", "ff", "halo2_proofs 0.1.0-beta.1 (git+https://github.com/DelphinusLab/halo2-gpu-specific.git?tag=stable-logup-shuffle-v1.0.0)", - "halo2ecc-o", + "halo2ecc-o 0.1.0 (git+https://github.com/ooglayout/halo2ecc-o.git)", "lazy_static", "num-bigint", "num-integer", @@ -1572,6 +1572,20 @@ dependencies = [ "tera", ] +[[package]] +name = "halo2ecc-o" +version = "0.1.0" +source = "git+https://github.com/mooreland/halo2ecc-o.git?branch=support_bls381#0dcd5b77123e77c57f0af13545dfa7f3db53de50" +dependencies = [ + "ark-std", + "halo2_proofs 0.1.0-beta.1 (git+https://github.com/DelphinusLab/halo2-gpu-specific.git?tag=stable-logup-shuffle-v1.0.0)", + "lazy_static", + "num-bigint", + "num-integer", + "num-traits", + "rayon", +] + [[package]] name = "halo2ecc-o" version = "0.1.0" @@ -4000,7 +4014,7 @@ dependencies = [ "clap", "ff", "halo2_proofs 0.1.0-beta.1 (git+https://github.com/DelphinusLab/halo2-gpu-specific.git?tag=stable-logup-shuffle-v1.0.0)", - "halo2ecc-o", + "halo2ecc-o 0.1.0 (git+https://github.com/mooreland/halo2ecc-o.git?branch=support_bls381)", "hex", "itertools", "lazy_static", diff --git a/Cargo.toml b/Cargo.toml index d3ff8240..5d8daa27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ strum_macros = "0.24.1" ff = "0.12" cfg-if = "1.0.0" halo2_proofs = { git = "https://github.com/DelphinusLab/halo2-gpu-specific.git", tag="stable-logup-shuffle-v1.0.0",default-features = true } -halo2ecc-o = { git = "https://github.com/ooglayout/halo2ecc-o.git"} +halo2ecc-o = { git = "https://github.com/mooreland/halo2ecc-o.git",branch = "support_bls381"} itertools = "0.10.0" num-bigint = { version = "0.4", features = ["rand"] } poseidon = { git = "https://github.com/DelphinusLab/poseidon" } @@ -48,10 +48,10 @@ rocksdb = "0.21.0" tempfile = "3.18.0" [features] -default = ["mongo-tokio-sync"] +default = ["mongo-tokio-sync","cuda","perf","profile"] perf = ["circuits-batcher/perf"] mongo-std-sync = ["mongodb/sync"] mongo-tokio-sync = ["mongodb/tokio-sync"] cuda = ["halo2_proofs/cuda"] complex-leaf = [] -profile = ["ark-std/print-trace", "halo2_proofs/profile", "circuits-batcher/profile"] +profile = ["ark-std/print-trace", "halo2_proofs/profile", "circuits-batcher/profile"] \ No newline at end of file diff --git a/src/circuits/bls.rs b/src/circuits/bls.rs index 2a1bb40b..ab4fd781 100644 --- a/src/circuits/bls.rs +++ b/src/circuits/bls.rs @@ -3,30 +3,28 @@ use halo2_proofs::pairing::bls12_381::Fr as Scalar; use halo2_proofs::pairing::bn256::Fr; use halo2_proofs::{ arithmetic::{BaseExt, FieldExt}, - circuit::{AssignedCell, Chip, Layouter, Region}, + circuit::{Chip, Layouter, Region}, pairing::bls12_381::G1Affine, plonk::{ConstraintSystem, Error}, }; use halo2ecc_o::circuit::chips::pairing_chip::fq::Fq12ChipOps; -// use halo2ecc_s::circuit::integer_chip::IntegerChipOps; -// use halo2ecc_s::circuit::{base_chip::BaseChipOps, ecc_chip::EccChipScalarOps}; -use std::cell::RefCell; use std::marker::PhantomData; -use std::rc::Rc; use halo2_proofs::pairing::bls12_381::Fq as Bls381Fq; -use halo2ecc_o::circuit::assign::{AssignedCondition, AssignedFq, AssignedInteger}; +use halo2ecc_o::circuit::assign::{AssignedFq, AssignedInteger}; use halo2ecc_o::circuit::assign::{AssignedFq12, AssignedG2Affine, AssignedPoint}; -// use halo2ecc_o::circuit::chips::ecc_chip::EccBaseIntegerChipWrapper; -use halo2ecc_o::circuit::chips::{ecc_chip::EccChipBaseOps, pairing_chip::PairingChipOps,native_chip::NativeChipOps,msm_chip::EccChipMSMOps}; +use halo2ecc_o::circuit::chips::{ + ecc_chip::EccChipBaseOps, msm_chip::EccChipMSMOps, native_chip::NativeChipOps, + pairing_chip::PairingChipOps, +}; pub const BLS381FQ_SIZE: usize = 8; pub const BLS381G1_SIZE: usize = 17; pub const BLS381G2_SIZE: usize = 33; -use halo2ecc_o::{NativeScalarEccConfig,GeneralScalarEccConfig}; -use halo2ecc_o::context::{GeneralScalarEccContext}; +use halo2ecc_o::context::GeneralScalarEccContext; +use halo2ecc_o::GeneralScalarEccConfig; use crate::utils::Limb; use num_bigint::BigUint; @@ -91,18 +89,17 @@ fn assigned_cells_to_bn381( bn } - fn get_scalar_from_cell( - ctx: &mut GeneralScalarEccContext, + ctx: &mut GeneralScalarEccContext, a: &Vec>, -) -> AssignedInteger { +) -> AssignedInteger { let bn = assigned_cells_to_fr(a, 0); let fr = ctx.scalar_integer_context().assign_w(Some(bn)).unwrap(); fr } fn get_g1_from_cells( - ctx: &mut GeneralScalarEccContext, + ctx: &mut GeneralScalarEccContext, a: &Vec>, //G1 (4 * 2 + 1) ) -> AssignedPoint { let x_bn = assigned_cells_to_bn381(a, 0); @@ -113,11 +110,10 @@ fn get_g1_from_cells( AssignedPoint::new( x, y, - ctx.plonk_region_context().assign(if is_identity { - Fr::one() - } else { - Fr::zero() - }).unwrap().into(), + ctx.plonk_region_context() + .assign(if is_identity { Fr::one() } else { Fr::zero() }) + .unwrap() + .into(), ) } @@ -137,23 +133,23 @@ fn get_g2_from_cells( AssignedG2Affine::new( (x1, x2), (y1, y2), - ctx.plonk_region_context().assign(if is_identity { - Fr::one() - } else { - Fr::zero() - }).unwrap().into(), + ctx.plonk_region_context() + .assign(if is_identity { Fr::one() } else { Fr::zero() }) + .unwrap() + .into(), ) } - - fn enable_fr_permute( region: &Region<'_, Fr>, fr: &AssignedInteger, input: &Vec>, ) -> Result<(), Error> { for i in 0..3 { - region.constrain_equal(input[i].get_the_cell().cell(), fr.limbs()[i].unwrap().cell())?; + region.constrain_equal( + input[i].get_the_cell().cell(), + fr.limbs()[i].unwrap().cell(), + )?; } Ok(()) } @@ -164,7 +160,10 @@ fn enable_fq_permute( input: &Vec>, ) -> Result<(), Error> { for i in 0..4 { - region.constrain_equal(input[i].get_the_cell().cell(), fq.limbs()[i].unwrap().cell())?; + region.constrain_equal( + input[i].get_the_cell().cell(), + fq.limbs()[i].unwrap().cell(), + )?; } Ok(()) } @@ -175,8 +174,8 @@ fn enable_g1affine_permute( input: &Vec>, ) -> Result<(), Error> { let mut inputs = input.chunks(4); - enable_fq_permute(region, &point.x, &inputs.next().unwrap().to_vec())?; - enable_fq_permute(region, &point.y, &inputs.next().unwrap().to_vec())?; + enable_fq_permute(region, &point.x, &inputs.next().unwrap().to_vec())?; + enable_fq_permute(region, &point.y, &inputs.next().unwrap().to_vec())?; region.constrain_equal(input[8].get_the_cell().cell(), point.z.cell())?; Ok(()) } @@ -201,66 +200,18 @@ fn enable_fq12_permute( input: &Vec>, ) -> Result<(), Error> { let mut inputs = input.chunks(4); - enable_fq_permute( - region, - &fq12.0 .0 .0, - &inputs.next().unwrap().to_vec(), - )?; - enable_fq_permute( - region, - &fq12.0 .0 .1, - &inputs.next().unwrap().to_vec(), - )?; - enable_fq_permute( - region, - &fq12.0 .1 .0, - &inputs.next().unwrap().to_vec(), - )?; - enable_fq_permute( - region, - &fq12.0 .1 .1, - &inputs.next().unwrap().to_vec(), - )?; - enable_fq_permute( - region, - &fq12.0 .2 .0, - &inputs.next().unwrap().to_vec(), - )?; - enable_fq_permute( - region, - &fq12.0 .2 .1, - &inputs.next().unwrap().to_vec(), - )?; - enable_fq_permute( - region, - &fq12.1 .0 .0, - &inputs.next().unwrap().to_vec(), - )?; - enable_fq_permute( - region, - &fq12.1 .0 .1, - &inputs.next().unwrap().to_vec(), - )?; - enable_fq_permute( - region, - &fq12.1 .1 .0, - &inputs.next().unwrap().to_vec(), - )?; - enable_fq_permute( - region, - &fq12.1 .1 .1, - &inputs.next().unwrap().to_vec(), - )?; - enable_fq_permute( - region, - &fq12.1 .2 .0, - &inputs.next().unwrap().to_vec(), - )?; - enable_fq_permute( - region, - &fq12.1 .2 .1, - &inputs.next().unwrap().to_vec(), - )?; + enable_fq_permute(region, &fq12.0 .0 .0, &inputs.next().unwrap().to_vec())?; + enable_fq_permute(region, &fq12.0 .0 .1, &inputs.next().unwrap().to_vec())?; + enable_fq_permute(region, &fq12.0 .1 .0, &inputs.next().unwrap().to_vec())?; + enable_fq_permute(region, &fq12.0 .1 .1, &inputs.next().unwrap().to_vec())?; + enable_fq_permute(region, &fq12.0 .2 .0, &inputs.next().unwrap().to_vec())?; + enable_fq_permute(region, &fq12.0 .2 .1, &inputs.next().unwrap().to_vec())?; + enable_fq_permute(region, &fq12.1 .0 .0, &inputs.next().unwrap().to_vec())?; + enable_fq_permute(region, &fq12.1 .0 .1, &inputs.next().unwrap().to_vec())?; + enable_fq_permute(region, &fq12.1 .1 .0, &inputs.next().unwrap().to_vec())?; + enable_fq_permute(region, &fq12.1 .1 .1, &inputs.next().unwrap().to_vec())?; + enable_fq_permute(region, &fq12.1 .2 .0, &inputs.next().unwrap().to_vec())?; + enable_fq_permute(region, &fq12.1 .2 .1, &inputs.next().unwrap().to_vec())?; Ok(()) } @@ -274,7 +225,7 @@ impl Bls381PairChip { pub fn configure(cs: &mut ConstraintSystem) -> >::Config { Bls381ChipConfig { - ecc_chip_config: GeneralScalarEccConfig::configure::(cs), + ecc_chip_config: GeneralScalarEccConfig::configure::(cs), } } @@ -297,10 +248,24 @@ impl Bls381PairChip { let ab_fq12_raw = ctx.pairing(&[(&a_g1, &b_g2)]).unwrap(); let ab_fq12 = ctx.fq12_reduce(&ab_fq12_raw).unwrap(); - enable_g1affine_permute(&mut region, &a_g1, a)?; - enable_g2affine_permute(&mut region, &b_g2, b)?; - enable_fq12_permute(&mut region, &ab_fq12, ab)?; + enable_g1affine_permute(&mut region, &a_g1, a)?; + enable_g2affine_permute(&mut region, &b_g2, b)?; + enable_fq12_permute(&mut region, &ab_fq12, ab)?; + end_timer!(timer); + + let timer = start_timer!(|| "finalize int mul"); + ctx.integer_context().finalize_int_mul()?; + ctx.scalar_integer_context().finalize_int_mul()?; + end_timer!(timer); + + ctx.get_range_region_context().init()?; + ctx.get_scalar_range_region_context().init()?; + let timer = start_timer!(|| "finalize compact cells"); + ctx.get_range_region_context().finalize_compact_cells()?; + ctx.get_scalar_range_region_context() + .finalize_compact_cells()?; end_timer!(timer); + Ok(()) }, )?; @@ -336,7 +301,7 @@ impl Bls381SumChip { pub fn configure(cs: &mut ConstraintSystem) -> >::Config { Bls381ChipConfig { - ecc_chip_config: GeneralScalarEccConfig::configure::(cs), + ecc_chip_config: GeneralScalarEccConfig::configure::(cs), } } @@ -374,26 +339,16 @@ impl Bls381SumChip { sums.push(sum_ret); } - ais.iter().enumerate().for_each(|(i, x)| { - enable_fr_permute(&mut region, x, &ls[22 * i + 1..22 * i + 4].to_vec()) - .unwrap() + enable_fr_permute(&mut region, x, &ls[22 * i + 1..22 * i + 4].to_vec()).unwrap() }); g1s.iter().enumerate().for_each(|(i, x)| { - enable_g1affine_permute( - &mut region, - x, - &ls[22 * i + 4..22 * i + 13].to_vec(), - ) - .unwrap() + enable_g1affine_permute(&mut region, x, &ls[22 * i + 4..22 * i + 13].to_vec()) + .unwrap() }); sums.iter().enumerate().for_each(|(i, x)| { - enable_g1affine_permute( - &mut region, - x, - &ls[22 * i + 13..22 * i + 22].to_vec(), - ) - .unwrap() + enable_g1affine_permute(&mut region, x, &ls[22 * i + 13..22 * i + 22].to_vec()) + .unwrap() }); end_timer!(timer); @@ -405,10 +360,9 @@ impl Bls381SumChip { ctx.get_range_region_context().init()?; ctx.get_scalar_range_region_context().init()?; let timer = start_timer!(|| "finalize compact cells"); - ctx - .get_range_region_context() + ctx.get_range_region_context().finalize_compact_cells()?; + ctx.get_scalar_range_region_context() .finalize_compact_cells()?; - ctx.get_scalar_range_region_context().finalize_compact_cells()?; end_timer!(timer); Ok(()) diff --git a/test_bls381.sh b/test_bls381.sh index 350d7b6c..f173a7bf 100644 --- a/test_bls381.sh +++ b/test_bls381.sh @@ -1,4 +1,4 @@ cargo test generate_bls_sum_input cargo run --release --features cuda -- --input blssumtest.json --opname bls381sum --output output/ --param params/ -cargo test generate_bls_pair_input -cargo run --release --features cuda -- --input blspairtest.json --opname bls381pair --output output/ --param params/ +#cargo test generate_bls_pair_input +#cargo run --release --features cuda -- --input blspairtest.json --opname bls381pair --output output/ --param params/ From d1cbb3baa4a069a36bb7e14efb06a0bbde25ab21 Mon Sep 17 00:00:00 2001 From: mooreland Date: Tue, 1 Apr 2025 22:25:02 +0800 Subject: [PATCH 3/3] rm default feature --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5d8daa27..b20dcf38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,7 @@ rocksdb = "0.21.0" tempfile = "3.18.0" [features] -default = ["mongo-tokio-sync","cuda","perf","profile"] +default = ["mongo-tokio-sync"] perf = ["circuits-batcher/perf"] mongo-std-sync = ["mongodb/sync"] mongo-tokio-sync = ["mongodb/tokio-sync"]