diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 090eff68..79ae23db 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ env: jobs: style: - name: Check Style + name: Check style runs-on: ubuntu-latest strategy: fail-fast: true @@ -22,6 +22,29 @@ jobs: - name: fmt run: cargo fmt --all -- --check + check-benches: + name: Check benchmarks + runs-on: ubuntu-latest + env: + RUSTFLAGS: -Dwarnings + CARGO_TERM_COLOR: always + strategy: + fail-fast: true + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable + - uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-benches-cargo-${{ hashFiles('**/Cargo.lock') }} + + - name: Check + run: | + cargo bench --no-run + test-accumulators: name: Test (accumulators/) runs-on: ubuntu-latest diff --git a/api/benches/anon_xfr.rs b/api/benches/anon_xfr.rs index 3a34aa52..16dbcf0e 100644 --- a/api/benches/anon_xfr.rs +++ b/api/benches/anon_xfr.rs @@ -14,7 +14,7 @@ use noah::{ AnonAssetRecord, MTLeafInfo, MTNode, MTPath, OpenAnonAssetRecord, OpenAnonAssetRecordBuilder, }, - FEE_TYPE, TREE_DEPTH, + FEE_TYPE, }, keys::KeyPair, xfr::{ @@ -164,7 +164,7 @@ fn abar_to_abar( fn abar_to_ar(c: &mut Criterion) { let mut prng = test_rng(); let address_format = SECP256K1; - let params = ProverParams::gen_abar_to_ar(TREE_DEPTH, address_format).unwrap(); + let params = ProverParams::gen_abar_to_ar(address_format).unwrap(); let verify_params = VerifierParams::get_abar_to_ar(address_format).unwrap(); let sender = KeyPair::sample(&mut prng, address_format); @@ -226,7 +226,7 @@ fn abar_to_ar(c: &mut Criterion) { fn abar_to_bar(c: &mut Criterion) { let mut prng = test_rng(); let address_format = SECP256K1; - let params = ProverParams::gen_abar_to_bar(TREE_DEPTH, address_format).unwrap(); + let params = ProverParams::gen_abar_to_bar(address_format).unwrap(); let verify_params = VerifierParams::get_abar_to_bar(address_format).unwrap(); let sender = KeyPair::sample(&mut prng, address_format); diff --git a/api/src/parameters/params.rs b/api/src/parameters/params.rs index cbec6dc1..c6ba341d 100644 --- a/api/src/parameters/params.rs +++ b/api/src/parameters/params.rs @@ -235,10 +235,7 @@ impl ProverParams { } /// Obtain the parameters for anonymous to confidential. - pub fn gen_abar_to_bar( - tree_depth: usize, - address_format: AddressFormat, - ) -> Result { + pub fn gen_abar_to_bar(address_format: AddressFormat) -> Result { let label = match address_format { SECP256K1 => String::from("abar_to_bar_secp256k1"), ED25519 => String::from("abar_to_bar_ed25519"), @@ -287,7 +284,7 @@ impl ProverParams { uid: 0, amount: 0, asset_type: bls_zero, - path: MTPath::new(vec![node.clone(); tree_depth]), + path: MTPath::new(vec![node.clone(); TREE_DEPTH]), blind: bls_zero, }; @@ -320,13 +317,9 @@ impl ProverParams { let pcs = load_srs_params(cs_size)?; let lagrange_pcs = load_lagrange_params(cs_size); - let verifier_params = if tree_depth == TREE_DEPTH { - match VerifierParams::load_abar_to_bar(address_format).ok() { - Some(v) => Some(v.verifier_params), - None => None, - } - } else { - None + let verifier_params = match VerifierParams::load_abar_to_bar(address_format).ok() { + Some(v) => Some(v.verifier_params), + None => None, }; let prover_params = @@ -389,10 +382,7 @@ impl ProverParams { } /// Obtain the parameters for anonymous to transparent. - pub fn gen_abar_to_ar( - tree_depth: usize, - address_format: AddressFormat, - ) -> Result { + pub fn gen_abar_to_ar(address_format: AddressFormat) -> Result { let label = match address_format { SECP256K1 => String::from("abar_to_ar_secp256k1"), ED25519 => String::from("abar_to_ar_ed25519"), @@ -418,7 +408,7 @@ impl ProverParams { uid: 0, amount: 0, asset_type: bls_zero, - path: MTPath::new(vec![node.clone(); tree_depth]), + path: MTPath::new(vec![node.clone(); TREE_DEPTH]), blind: bls_zero, }; let (_, nullifier_trace) = nullify( @@ -446,13 +436,9 @@ impl ProverParams { let pcs = load_srs_params(cs_size)?; let lagrange_pcs = load_lagrange_params(cs_size); - let verifier_params = if tree_depth == TREE_DEPTH { - match VerifierParams::load_abar_to_ar(address_format).ok() { - Some(v) => Some(v.verifier_params), - None => None, - } - } else { - None + let verifier_params = match VerifierParams::load_abar_to_ar(address_format).ok() { + Some(v) => Some(v.verifier_params), + None => None, }; let prover_params = @@ -549,7 +535,7 @@ impl VerifierParams { match Self::load_abar_to_bar(address_format) { Ok(vk) => Ok(vk), _ => { - let prover_params = ProverParams::gen_abar_to_bar(TREE_DEPTH, address_format)?; + let prover_params = ProverParams::gen_abar_to_bar(address_format)?; Ok(VerifierParams::from(prover_params)) } } @@ -646,7 +632,7 @@ impl VerifierParams { match Self::load_abar_to_ar(address_format) { Ok(vk) => Ok(vk), _ => { - let prover_params = ProverParams::gen_abar_to_ar(TREE_DEPTH, address_format)?; + let prover_params = ProverParams::gen_abar_to_ar(address_format)?; Ok(VerifierParams::from(prover_params)) } } diff --git a/api/src/parameters/setup.rs b/api/src/parameters/setup.rs index ed3c75cd..e83e2607 100644 --- a/api/src/parameters/setup.rs +++ b/api/src/parameters/setup.rs @@ -196,7 +196,7 @@ fn gen_transfer_vk(directory: PathBuf, address_format: AddressFormat) { fn gen_abar_to_bar_vk(path: PathBuf) { println!("Generating the verifying key for ABAR TO BAR for secp256k1 ..."); let mut new_path = path.clone(); - let user_params = ProverParams::gen_abar_to_bar(TREE_DEPTH, SECP256K1).unwrap(); + let user_params = ProverParams::gen_abar_to_bar(SECP256K1).unwrap(); let node_params = VerifierParams::from(user_params); println!( "the size of the constraint system for ABAR TO BAR for secp256k1: {}", @@ -213,7 +213,7 @@ fn gen_abar_to_bar_vk(path: PathBuf) { println!("Generating the verifying key for ABAR TO BAR for ed25519 ..."); let mut new_path = path.clone(); - let user_params = ProverParams::gen_abar_to_bar(TREE_DEPTH, ED25519).unwrap(); + let user_params = ProverParams::gen_abar_to_bar(ED25519).unwrap(); let node_params = VerifierParams::from(user_params); println!( "the size of the constraint system for ABAR TO BAR for ed25519: {}", @@ -273,7 +273,7 @@ fn gen_ar_to_abar_vk(mut path: PathBuf) { fn gen_abar_to_ar_vk(path: PathBuf) { println!("Generating the verifying key for ABAR TO AR for secp256k1 ..."); let mut new_path = path.clone(); - let user_params = ProverParams::gen_abar_to_ar(TREE_DEPTH, SECP256K1).unwrap(); + let user_params = ProverParams::gen_abar_to_ar(SECP256K1).unwrap(); let node_params = VerifierParams::from(user_params); println!( "the size of the constraint system for ABAR TO AR for secp256k1: {}", @@ -290,7 +290,7 @@ fn gen_abar_to_ar_vk(path: PathBuf) { println!("Generating the verifying key for ABAR TO AR for ed25519 ..."); let mut new_path = path.clone(); - let user_params = ProverParams::gen_abar_to_ar(TREE_DEPTH, ED25519).unwrap(); + let user_params = ProverParams::gen_abar_to_ar(ED25519).unwrap(); let node_params = VerifierParams::from(user_params); println!( "the size of the constraint system for ABAR TO AR for ed25519: {}", diff --git a/smoke-tests/src/tests/smoke_axfr.rs b/smoke-tests/src/tests/smoke_axfr.rs index 6299cd7b..5a46fba8 100644 --- a/smoke-tests/src/tests/smoke_axfr.rs +++ b/smoke-tests/src/tests/smoke_axfr.rs @@ -16,7 +16,7 @@ mod smoke_axfr { AnonAssetRecord, MTLeafInfo, MTNode, MTPath, OpenAnonAssetRecord, OpenAnonAssetRecordBuilder, }, - FEE_TYPE, TREE_DEPTH, + FEE_TYPE, }, keys::{KeyPair, KeyType, PublicKey}, xfr::{ @@ -249,7 +249,7 @@ mod smoke_axfr { SecretKey::Secp256k1(_) => SECP256K1, }; - let params = ProverParams::gen_abar_to_ar(TREE_DEPTH, address_format).unwrap(); + let params = ProverParams::gen_abar_to_ar(address_format).unwrap(); let verify_params = VerifierParams::get_abar_to_ar(address_format).unwrap(); let fdb = MemoryDB::new(); @@ -362,7 +362,7 @@ mod smoke_axfr { SecretKey::Secp256k1(_) => SECP256K1, }; - let params = ProverParams::gen_abar_to_bar(TREE_DEPTH, address_format).unwrap(); + let params = ProverParams::gen_abar_to_bar(address_format).unwrap(); let verify_params = VerifierParams::get_abar_to_bar(address_format).unwrap(); let fdb = MemoryDB::new(); diff --git a/smoke-tests/src/tests/smoke_axfr_compatibility.rs b/smoke-tests/src/tests/smoke_axfr_compatibility.rs index 221f5899..b2ea25ea 100644 --- a/smoke-tests/src/tests/smoke_axfr_compatibility.rs +++ b/smoke-tests/src/tests/smoke_axfr_compatibility.rs @@ -25,7 +25,7 @@ mod smoke_axfr_compatibility { AnonAssetRecord, AxfrOwnerMemo, MTLeafInfo, MTNode, MTPath, OpenAnonAssetRecord, OpenAnonAssetRecordBuilder, }, - FEE_TYPE, TREE_DEPTH, + FEE_TYPE, }, keys::KeyPair, xfr::{ @@ -309,7 +309,7 @@ mod smoke_axfr_compatibility { }; let mut prng = test_rng(); - let params = ProverParams::gen_abar_to_ar(TREE_DEPTH, address_format).unwrap(); + let params = ProverParams::gen_abar_to_ar(address_format).unwrap(); let verify_params = VerifierParams::get_abar_to_ar(address_format).unwrap(); let receiver = if prng.gen() { KeyPair::sample(&mut prng, SECP256K1) @@ -456,7 +456,7 @@ mod smoke_axfr_compatibility { SecretKey::Secp256k1(_) => SECP256K1, }; - let params = ProverParams::gen_abar_to_bar(TREE_DEPTH, address_format).unwrap(); + let params = ProverParams::gen_abar_to_bar(address_format).unwrap(); let verify_params = VerifierParams::get_abar_to_bar(address_format).unwrap(); let receiver = if prng.gen() { KeyPair::sample(&mut prng, SECP256K1) diff --git a/smoke-tests/src/tests/smoke_axfr_secp256k1_address.rs b/smoke-tests/src/tests/smoke_axfr_secp256k1_address.rs index af814bd1..5ff654c6 100644 --- a/smoke-tests/src/tests/smoke_axfr_secp256k1_address.rs +++ b/smoke-tests/src/tests/smoke_axfr_secp256k1_address.rs @@ -14,7 +14,6 @@ mod smoke_axfr_secp256k1_address { AnonAssetRecord, MTLeafInfo, MTNode, MTPath, OpenAnonAssetRecord, OpenAnonAssetRecordBuilder, }, - TREE_DEPTH, }, keys::{KeyPair, PublicKey}, xfr::{ @@ -177,7 +176,7 @@ mod smoke_axfr_secp256k1_address { #[test] fn abar_to_address() { let mut prng = test_rng(); - let params = ProverParams::gen_abar_to_ar(TREE_DEPTH, SECP256K1).unwrap(); + let params = ProverParams::gen_abar_to_ar(SECP256K1).unwrap(); let verify_params = VerifierParams::get_abar_to_ar(SECP256K1).unwrap(); let sender = KeyPair::sample(&mut prng, SECP256K1); @@ -225,7 +224,7 @@ mod smoke_axfr_secp256k1_address { #[test] fn abar_to_secp256k1() { let mut prng = test_rng(); - let params = ProverParams::gen_abar_to_bar(TREE_DEPTH, SECP256K1).unwrap(); + let params = ProverParams::gen_abar_to_bar(SECP256K1).unwrap(); let verify_params = VerifierParams::get_abar_to_bar(SECP256K1).unwrap(); let sender = KeyPair::sample(&mut prng, SECP256K1); diff --git a/smoke-tests/src/tests/smoke_axfr_wasm.rs b/smoke-tests/src/tests/smoke_axfr_wasm.rs index 6fee56fa..1dca6985 100644 --- a/smoke-tests/src/tests/smoke_axfr_wasm.rs +++ b/smoke-tests/src/tests/smoke_axfr_wasm.rs @@ -15,7 +15,7 @@ mod smoke_axfr_wasm { AnonAssetRecord, MTLeafInfo, MTNode, MTPath, OpenAnonAssetRecord, OpenAnonAssetRecordBuilder, }, - FEE_TYPE, TREE_DEPTH, + FEE_TYPE, }, keys::{KeyPair, PublicKey}, xfr::{ @@ -189,7 +189,7 @@ mod smoke_axfr_wasm { fn abar_to_ar(sender: KeyPair, receiver: KeyPair) { let seed: [u8; 32] = [0u8; 32]; let mut prng = ChaChaRng::from_seed(seed); - let params = ProverParams::gen_abar_to_ar(TREE_DEPTH, SECP256K1).unwrap(); + let params = ProverParams::gen_abar_to_ar(SECP256K1).unwrap(); let verify_params = VerifierParams::get_abar_to_ar(SECP256K1).unwrap(); let mut mt = EphemeralMerkleTree::new().unwrap(); @@ -237,7 +237,7 @@ mod smoke_axfr_wasm { fn abar_to_bar(sender: KeyPair, receiver: KeyPair) { let seed: [u8; 32] = [0u8; 32]; let mut prng = ChaChaRng::from_seed(seed); - let params = ProverParams::gen_abar_to_bar(TREE_DEPTH, SECP256K1).unwrap(); + let params = ProverParams::gen_abar_to_bar(SECP256K1).unwrap(); let verify_params = VerifierParams::get_abar_to_bar(SECP256K1).unwrap(); let mut mt = EphemeralMerkleTree::new().unwrap();