From 90484032f5ed46c1f76497f8dc685960b0ea9a54 Mon Sep 17 00:00:00 2001 From: Andrew Kirillov <20803092+akirillo@users.noreply.github.com> Date: Thu, 7 Sep 2023 18:47:03 -0700 Subject: [PATCH] wip: profiling circuit parameterization & new_wallet --- .gitignore | 1 + Cargo.lock | 13 ++-- Cargo.toml | 3 +- src/verifier.cairo | 2 +- tests/Cargo.toml | 4 +- tests/src/darkpool/utils.rs | 1 + tests/src/profiling/utils.rs | 110 +++++++--------------------- tests/src/utils.rs | 27 +++++-- tests/tests/darkpool.rs | 36 ++++----- tests/tests/merkle.rs | 10 +-- tests/tests/nullifier_set.rs | 4 +- tests/tests/poseidon.rs | 2 +- tests/tests/profiling.rs | 130 +++++++++++++++++++++++++++++---- tests/tests/statement_serde.rs | 20 ++--- tests/tests/transcript.rs | 4 +- tests/tests/verifier.rs | 4 +- tests/tests/verifier_utils.rs | 8 +- 17 files changed, 215 insertions(+), 164 deletions(-) diff --git a/.gitignore b/.gitignore index 355d0860..1b98cee0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /cairo_project.toml /.vscode /.gitattributes +/*.log diff --git a/Cargo.lock b/Cargo.lock index 26d91713..91ae018b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -599,6 +599,7 @@ dependencies = [ [[package]] name = "blockifier" version = "0.1.0-rc0" +source = "git+https://github.com/renegade-fi/blockifier.git?branch=renegade-testing#9f4375853d40ea7f2a1a840cb5c5feb017bb1b03" dependencies = [ "ark-ff", "ark-secp256k1", @@ -2112,7 +2113,7 @@ checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" [[package]] name = "dojo-lang" version = "0.1.0" -source = "git+https://github.com/dojoengine/dojo.git?rev=954dbb3#954dbb32e1454cbd1491991ad16feeadbc78d6de" +source = "git+https://github.com/renegade-fi/dojo.git?branch=renegade-testing#114412e193ede743772d5ce1d94a74e52b19220c" dependencies = [ "anyhow", "assert_fs", @@ -2152,7 +2153,7 @@ dependencies = [ [[package]] name = "dojo-test-utils" version = "0.1.0" -source = "git+https://github.com/dojoengine/dojo.git?rev=954dbb3#954dbb32e1454cbd1491991ad16feeadbc78d6de" +source = "git+https://github.com/renegade-fi/dojo.git?branch=renegade-testing#114412e193ede743772d5ce1d94a74e52b19220c" dependencies = [ "anyhow", "assert_fs", @@ -2182,7 +2183,7 @@ dependencies = [ [[package]] name = "dojo-types" version = "0.1.0" -source = "git+https://github.com/dojoengine/dojo.git?rev=954dbb3#954dbb32e1454cbd1491991ad16feeadbc78d6de" +source = "git+https://github.com/renegade-fi/dojo.git?branch=renegade-testing#114412e193ede743772d5ce1d94a74e52b19220c" dependencies = [ "serde", "starknet", @@ -2191,7 +2192,7 @@ dependencies = [ [[package]] name = "dojo-world" version = "0.1.0" -source = "git+https://github.com/dojoengine/dojo.git?rev=954dbb3#954dbb32e1454cbd1491991ad16feeadbc78d6de" +source = "git+https://github.com/renegade-fi/dojo.git?branch=renegade-testing#114412e193ede743772d5ce1d94a74e52b19220c" dependencies = [ "anyhow", "async-trait", @@ -4093,7 +4094,7 @@ dependencies = [ [[package]] name = "katana-core" version = "0.1.0" -source = "git+https://github.com/dojoengine/dojo.git?rev=954dbb3#954dbb32e1454cbd1491991ad16feeadbc78d6de" +source = "git+https://github.com/renegade-fi/dojo.git?branch=renegade-testing#114412e193ede743772d5ce1d94a74e52b19220c" dependencies = [ "anyhow", "async-trait", @@ -4121,7 +4122,7 @@ dependencies = [ [[package]] name = "katana-rpc" version = "0.1.0" -source = "git+https://github.com/dojoengine/dojo.git?rev=954dbb3#954dbb32e1454cbd1491991ad16feeadbc78d6de" +source = "git+https://github.com/renegade-fi/dojo.git?branch=renegade-testing#114412e193ede743772d5ce1d94a74e52b19220c" dependencies = [ "anyhow", "blockifier", diff --git a/Cargo.toml b/Cargo.toml index acca1bac..bcfacd72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,7 @@ starknet = "0.5.0" mpc-stark = "0.2" [patch."https://github.com/starkware-libs/blockifier"] -# blockifier = { git = "https://github.com/renegade-fi/blockifier.git", rev = "9c9bbe1" } -blockifier = { path = "../blockifier/crates/blockifier" } +blockifier = { git = "https://github.com/renegade-fi/blockifier.git", branch = "renegade-testing" } [patch.crates-io] cairo-felt = { git = "https://github.com/dojoengine/cairo-rs.git", rev = "262b7eb4b11ab165a2a936a5f914e78aa732d4a2" } diff --git a/src/verifier.cairo b/src/verifier.cairo index dfabc076..f390f38c 100644 --- a/src/verifier.cairo +++ b/src/verifier.cairo @@ -264,7 +264,7 @@ mod MultiVerifier { // Assert weight matrix has `q` rows assert(w_v.len() == self.q.read(circuit_id), 'W_V has wrong number of rows'); // Assert weight matrix has correct max number of columns - w_v.assert_width(self.n.read(circuit_id)); + w_v.assert_width(self.m.read(circuit_id)); self.W_V.write(circuit_id, StoreSerdeWrapper { inner: w_v }); diff --git a/tests/Cargo.toml b/tests/Cargo.toml index a6399f1a..0d71252d 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -25,8 +25,8 @@ num-bigint = { version = "0.4.3", features = ["rand"] } byteorder = "1.4.3" starknet = { workspace = true } -katana-core = { git = "https://github.com/dojoengine/dojo.git", rev = "954dbb3" } -dojo-test-utils = { git = "https://github.com/dojoengine/dojo.git", rev = "954dbb3" } +katana-core = { git = "https://github.com/renegade-fi/dojo.git", branch = "renegade-testing" } +dojo-test-utils = { git = "https://github.com/renegade-fi/dojo.git", branch = "renegade-testing" } mpc-stark = { workspace = true } mpc-bulletproof = { git = "https://github.com/renegade-fi/mpc-bulletproof.git", features = ["integration_test"] } merlin = { git = "https://github.com/renegade-fi/merlin.git" } diff --git a/tests/src/darkpool/utils.rs b/tests/src/darkpool/utils.rs index 3c03bc39..5f4d0ca0 100644 --- a/tests/src/darkpool/utils.rs +++ b/tests/src/darkpool/utils.rs @@ -315,6 +315,7 @@ pub async fn is_nullifier_available(account: &ScriptAccount, nullifier: Scalar) } pub async fn new_wallet(account: &ScriptAccount, args: &NewWalletArgs) -> Result { + debug!("Running new_wallet until {:?}", args.breakpoint); let calldata = args.to_calldata(); invoke_contract( diff --git a/tests/src/profiling/utils.rs b/tests/src/profiling/utils.rs index 07461399..fa13e118 100644 --- a/tests/src/profiling/utils.rs +++ b/tests/src/profiling/utils.rs @@ -24,10 +24,9 @@ use circuits::zk_circuits::{ }; use dojo_test_utils::sequencer::TestSequencer; use eyre::{eyre, Result}; -use lazy_static::lazy_static; use merlin::HashChainTranscript; use mpc_bulletproof::{ - r1cs::{Prover, R1CSProof, Verifier}, + r1cs::{R1CSProof, Verifier}, BulletproofGens, PedersenGens, }; use mpc_stark::algebra::scalar::Scalar; @@ -44,10 +43,9 @@ use crate::{ darkpool::utils::{initialize_darkpool, DARKPOOL_ADDRESS}, merkle::utils::TEST_MERKLE_HEIGHT, utils::{ - fully_parameterize_circuit, get_circuit_params, get_contract_address_from_artifact, - global_setup, random_felt, Breakpoint, CalldataSerializable, Circuit, MatchPayload, - NewWalletArgs, ProcessMatchArgs, UpdateWalletArgs, ARTIFACTS_PATH_ENV_VAR, SK_ROOT, - TRANSCRIPT_SEED, + get_contract_address_from_artifact, global_setup, random_felt, singleprover_prove, + Breakpoint, CalldataSerializable, Circuit, MatchPayload, NewWalletArgs, ProcessMatchArgs, + UpdateWalletArgs, ARTIFACTS_PATH_ENV_VAR, SK_ROOT, TRANSCRIPT_SEED, }, }; @@ -58,25 +56,14 @@ pub type SizedValidCommitments = ValidCommitments; pub type SizedValidSettle = ValidSettle; -// Mirrors pre-allocated BP generators from relayer repo -lazy_static! { - /// The maximum number of generators that may be needed for any of the circuits - /// so that the generators may be pre-allocated and re-used between proofs - static ref MAX_GENERATORS: usize = vec![ - SizedValidWalletCreate::BP_GENS_CAPACITY, - SizedValidWalletUpdate::BP_GENS_CAPACITY, - SizedValidReblind::BP_GENS_CAPACITY, - SizedValidCommitments::BP_GENS_CAPACITY, - ValidMatchMpcSingleProver::BP_GENS_CAPACITY, - SizedValidSettle::BP_GENS_CAPACITY, - ] - .into_iter() - .max() - .unwrap(); - - /// The pre-allocated bulletproof generators for the circuits - static ref PRE_ALLOCATED_GENS: BulletproofGens = BulletproofGens::new(*MAX_GENERATORS, 1 /* party_capacity */); -} +pub type TestParamsCircuit = Circuit< + SizedValidWalletCreate, + SizedValidWalletUpdate, + SizedValidCommitments, + SizedValidReblind, + ValidMatchMpcSingleProver, + SizedValidSettle, +>; // --------------------- // | META TEST HELPERS | @@ -116,36 +103,6 @@ pub async fn init_profiling_test_state() -> Result { ) .await?; - for circuit in [ - Circuit::ValidWalletCreate(SizedValidWalletCreate {}), - Circuit::ValidWalletUpdate(SizedValidWalletUpdate {}), - Circuit::ValidCommitments(SizedValidCommitments {}), - Circuit::ValidReblind(SizedValidReblind {}), - Circuit::ValidMatchMpc(ValidMatchMpcSingleProver {}), - Circuit::ValidSettle(SizedValidSettle {}), - ] - .into_iter() - { - debug!("Parameterizing circuit {circuit}"); - - let circuit_params = match circuit { - Circuit::ValidWalletCreate(_) => get_circuit_params::(), - Circuit::ValidWalletUpdate(_) => get_circuit_params::(), - Circuit::ValidCommitments(_) => get_circuit_params::(), - Circuit::ValidReblind(_) => get_circuit_params::(), - Circuit::ValidMatchMpc(_) => get_circuit_params::(), - Circuit::ValidSettle(_) => get_circuit_params::(), - }; - - fully_parameterize_circuit( - &account, - darkpool_address, - circuit.to_calldata()[0], - circuit_params, - ) - .await?; - } - Ok(sequencer) } @@ -179,21 +136,8 @@ pub fn init_profiling_test_statics(account: &ScriptAccount) -> Result<()> { // | MISC HELPERS | // ---------------- -/// Mirrors `singleprover_prove` from the relayer repo, but uses our pre-allocated BP gens -pub fn singleprover_prove_prealloc( - witness: C::Witness, - statement: C::Statement, -) -> Result<(::CommitmentType, R1CSProof)> { - let mut transcript = HashChainTranscript::new(TRANSCRIPT_SEED.as_bytes()); - let pc_gens = PedersenGens::default(); - let prover = Prover::new(&pc_gens, &mut transcript); - - C::prove(witness, statement, &PRE_ALLOCATED_GENS, prover) - .map_err(|e| eyre!("Error proving circuit: {}", e)) -} - /// Mirrors `verify_singleprover_proof` from the relayer repo, but uses our pre-allocated BP gens -pub fn verify_singleprover_proof_prealloc( +pub fn verify_singleprover_proof( statement: C::Statement, witness_commitment: ::CommitmentType, proof: R1CSProof, @@ -203,14 +147,10 @@ pub fn verify_singleprover_proof_prealloc( let pc_gens = PedersenGens::default(); let verifier = Verifier::new(&pc_gens, &mut verifier_transcript); - C::verify( - witness_commitment, - statement, - proof, - &PRE_ALLOCATED_GENS, - verifier, - ) - .map_err(|e| eyre!("Error verifying proof: {}", e)) + let bp_gens = BulletproofGens::new(C::BP_GENS_CAPACITY, 1); + + C::verify(witness_commitment, statement, proof, &bp_gens, verifier) + .map_err(|e| eyre!("Error verifying proof: {}", e)) } pub fn get_new_wallet_args(breakpoint: Breakpoint) -> Result { @@ -218,9 +158,9 @@ pub fn get_new_wallet_args(breakpoint: Breakpoint) -> Result { let (witness, statement) = valid_wallet_create_witness_statement(); let wallet_blinder_share = statement.public_wallet_shares.blinder; let (witness_commitment, proof) = - singleprover_prove_prealloc::(witness, statement.clone())?; + singleprover_prove::(witness, statement.clone())?; - verify_singleprover_proof_prealloc::( + verify_singleprover_proof::( statement.clone(), witness_commitment.clone(), proof.clone(), @@ -258,9 +198,9 @@ pub fn get_update_wallet_args( let statement_signature = sign_scalar_message(&statement.to_scalars(), &SK_ROOT); let (witness_commitment, proof) = - singleprover_prove_prealloc::(witness, statement.clone())?; + singleprover_prove::(witness, statement.clone())?; - verify_singleprover_proof_prealloc::( + verify_singleprover_proof::( statement.clone(), witness_commitment.clone(), proof.clone(), @@ -296,9 +236,9 @@ pub async fn get_process_match_args( .await .0?; let (valid_match_mpc_witness_commitment, valid_match_mpc_proof) = - singleprover_prove_prealloc::(valid_match_mpc_witness, ())?; + singleprover_prove::(valid_match_mpc_witness, ())?; - verify_singleprover_proof_prealloc::( + verify_singleprover_proof::( (), valid_match_mpc_witness_commitment.clone(), valid_match_mpc_proof.clone(), @@ -307,12 +247,12 @@ pub async fn get_process_match_args( let (valid_settle_witness, valid_settle_statement) = valid_settle_witness_statement(party0_wallet.clone(), party1_wallet.clone(), match_res); let (valid_settle_witness_commitment, valid_settle_proof) = - singleprover_prove_prealloc::( + singleprover_prove::( valid_settle_witness, valid_settle_statement.clone(), )?; - verify_singleprover_proof_prealloc::( + verify_singleprover_proof::( valid_settle_statement.clone(), valid_settle_witness_commitment.clone(), valid_settle_proof.clone(), diff --git a/tests/src/utils.rs b/tests/src/utils.rs index abd46539..34fcbb7a 100644 --- a/tests/src/utils.rs +++ b/tests/src/utils.rs @@ -80,8 +80,8 @@ use crate::{ nullifier_set::utils::{init_nullifier_set_test_state, init_nullifier_set_test_statics}, poseidon::utils::{init_poseidon_test_state, init_poseidon_test_statics}, profiling::utils::{ - init_profiling_test_state, init_profiling_test_statics, singleprover_prove_prealloc, - verify_singleprover_proof_prealloc, SizedValidCommitments, SizedValidReblind, + init_profiling_test_state, init_profiling_test_statics, verify_singleprover_proof, + SizedValidCommitments, SizedValidReblind, }, statement_serde::utils::{init_statement_serde_test_state, init_statement_serde_test_statics}, transcript::utils::{init_transcript_test_state, init_transcript_test_statics}, @@ -188,7 +188,7 @@ pub async fn global_setup(init_state: Option) -> TestSequence TRACING_INIT.call_once(|| { fmt() .with_env_filter(EnvFilter::from_default_env()) - // .with_ansi(false) + .with_ansi(false) .init(); }); @@ -201,7 +201,16 @@ pub async fn global_setup(init_state: Option) -> TestSequence .await } -pub fn global_teardown(sequencer: TestSequencer) { +pub async fn global_teardown(test_config: TestConfig, sequencer: TestSequencer, force_dump: bool) { + if force_dump { + let (state_dumped_lock, state_separator) = get_state_lock_and_separator(&test_config); + let mut state_dumped = state_dumped_lock.lock().await; + // Dump the state + debug!("Dumping state..."); + dump_state(&sequencer, state_separator).await.unwrap(); + // Mark the state as dumped + *state_dumped = true; + } debug!("Stopping test sequencer..."); sequencer.stop().unwrap(); } @@ -359,6 +368,7 @@ pub async fn invoke_contract( selector: get_selector_from_name(entry_point)?, calldata, }]) + .max_fee(FieldElement::ZERO) .send() .await .map_err(|e| eyre!("Error invoking {}: {}", entry_point, e)) @@ -556,24 +566,24 @@ impl MatchPayload { valid_reblind_statement.merkle_root = merkle_root; let (valid_commitments_witness_commitment, valid_commitments_proof) = - singleprover_prove_prealloc::( + singleprover_prove::( valid_commitments_witness, valid_commitments_statement.clone(), )?; - verify_singleprover_proof_prealloc::( + verify_singleprover_proof::( valid_commitments_statement.clone(), valid_commitments_witness_commitment.clone(), valid_commitments_proof.clone(), )?; let (valid_reblind_witness_commitment, valid_reblind_proof) = - singleprover_prove_prealloc::( + singleprover_prove::( valid_reblind_witness, valid_reblind_statement.clone(), )?; - verify_singleprover_proof_prealloc::( + verify_singleprover_proof::( valid_reblind_statement.clone(), valid_reblind_witness_commitment.clone(), valid_reblind_proof.clone(), @@ -689,6 +699,7 @@ pub struct ProcessMatchArgs { pub breakpoint: Breakpoint, } +#[derive(Debug)] pub enum Breakpoint { None, ReadCircuitParams, diff --git a/tests/tests/darkpool.rs b/tests/tests/darkpool.rs index c1094189..ce015963 100644 --- a/tests/tests/darkpool.rs +++ b/tests/tests/darkpool.rs @@ -24,7 +24,7 @@ use tests::{ }, utils::{ assert_roots_equal, get_root, global_teardown, insert_scalar_to_ark_merkle_tree, - DUMMY_WALLET, + TestConfig, DUMMY_WALLET, }, }; @@ -44,7 +44,7 @@ async fn test_initialization_root() -> Result<()> { ) .await?; - global_teardown(sequencer); + global_teardown(TestConfig::Darkpool, sequencer, false).await; Ok(()) } @@ -66,7 +66,7 @@ async fn test_new_wallet_root() -> Result<()> { assert_roots_equal(&account, *DARKPOOL_ADDRESS.get().unwrap(), &ark_merkle_tree).await?; - global_teardown(sequencer); + global_teardown(TestConfig::Darkpool, sequencer, false).await; Ok(()) } @@ -94,7 +94,7 @@ async fn test_update_wallet_root() -> Result<()> { assert_roots_equal(&account, *DARKPOOL_ADDRESS.get().unwrap(), &ark_merkle_tree).await?; - global_teardown(sequencer); + global_teardown(TestConfig::Darkpool, sequencer, false).await; Ok(()) } @@ -118,7 +118,7 @@ async fn test_update_wallet_invalid_statement_root() -> Result<()> { // a valid historical root assert!(update_wallet(&account, &args).await.is_err()); - global_teardown(sequencer); + global_teardown(TestConfig::Darkpool, sequencer, false).await; Ok(()) } @@ -155,7 +155,7 @@ async fn test_process_match_root() -> Result<()> { assert_roots_equal(&account, *DARKPOOL_ADDRESS.get().unwrap(), &ark_merkle_tree).await?; - global_teardown(sequencer); + global_teardown(TestConfig::Darkpool, sequencer, false).await; Ok(()) } @@ -174,7 +174,7 @@ async fn test_process_match_invalid_statement_root() -> Result<()> { // The random root in the dummy `MatchPayload`s should not be a valid historical root assert!(process_match(&account, &args).await.is_err()); - global_teardown(sequencer); + global_teardown(TestConfig::Darkpool, sequencer, false).await; Ok(()) } @@ -196,7 +196,7 @@ async fn test_new_wallet_last_modified() -> Result<()> { assert_eq!(tx_hash, last_modified_tx); - global_teardown(sequencer); + global_teardown(TestConfig::Darkpool, sequencer, false).await; Ok(()) } @@ -220,7 +220,7 @@ async fn test_update_wallet_last_modified() -> Result<()> { assert_eq!(tx_hash, last_modified_tx); - global_teardown(sequencer); + global_teardown(TestConfig::Darkpool, sequencer, false).await; Ok(()) } @@ -249,7 +249,7 @@ async fn test_process_match_last_modified() -> Result<()> { assert_eq!(tx_hash, party_0_last_modified_tx); assert_eq!(tx_hash, party_1_last_modified_tx); - global_teardown(sequencer); + global_teardown(TestConfig::Darkpool, sequencer, false).await; Ok(()) } @@ -277,7 +277,7 @@ async fn test_update_wallet_nullifiers() -> Result<()> { assert!(!is_nullifier_available(&account, args.statement.old_shares_nullifier).await?); - global_teardown(sequencer); + global_teardown(TestConfig::Darkpool, sequencer, false).await; Ok(()) } @@ -335,7 +335,7 @@ async fn test_process_match_nullifiers() -> Result<()> { .await? ); - global_teardown(sequencer); + global_teardown(TestConfig::Darkpool, sequencer, false).await; Ok(()) } @@ -357,7 +357,7 @@ async fn test_double_update_wallet() -> Result<()> { // should already be marked as in progress assert!(update_wallet(&account, &args).await.is_err()); - global_teardown(sequencer); + global_teardown(TestConfig::Darkpool, sequencer, false).await; Ok(()) } @@ -380,7 +380,7 @@ async fn test_double_process_match() -> Result<()> { // should already be marked as in progress assert!(process_match(&account, &args).await.is_err()); - global_teardown(sequencer); + global_teardown(TestConfig::Darkpool, sequencer, false).await; Ok(()) } @@ -435,7 +435,7 @@ async fn test_update_wallet_deposit() -> Result<()> { (INIT_BALANCE + TRANSFER_AMOUNT) as u128 ); - global_teardown(sequencer); + global_teardown(TestConfig::Darkpool, sequencer, false).await; Ok(()) } @@ -481,7 +481,7 @@ async fn test_update_wallet_withdrawal() -> Result<()> { (INIT_BALANCE - TRANSFER_AMOUNT) as u128 ); - global_teardown(sequencer); + global_teardown(TestConfig::Darkpool, sequencer, false).await; Ok(()) } @@ -521,7 +521,7 @@ async fn test_upgrade_darkpool_storage() -> Result<()> { assert_eq!(pre_upgrade_root, post_upgrade_root); assert!(old_shares_nullifier_used); - global_teardown(sequencer); + global_teardown(TestConfig::Darkpool, sequencer, false).await; Ok(()) } @@ -543,7 +543,7 @@ async fn test_update_wallet_invalid_signature() -> Result<()> { assert!(update_wallet(&account, &args).await.is_err()); - global_teardown(sequencer); + global_teardown(TestConfig::Darkpool, sequencer, false).await; Ok(()) } diff --git a/tests/tests/merkle.rs b/tests/tests/merkle.rs index 48ff6f8b..21db480f 100644 --- a/tests/tests/merkle.rs +++ b/tests/tests/merkle.rs @@ -6,7 +6,7 @@ use tests::{ insert, insert_random_val_to_trees, setup_merkle_test, MERKLE_ADDRESS, MULTI_INSERT_ROUNDS, TEST_MERKLE_HEIGHT, }, - utils::{assert_roots_equal, global_teardown}, + utils::{assert_roots_equal, global_teardown, TestConfig}, }; #[tokio::test] @@ -20,7 +20,7 @@ async fn test_initialization_root() -> Result<()> { ) .await?; - global_teardown(sequencer); + global_teardown(TestConfig::Merkle, sequencer, false).await; Ok(()) } @@ -34,7 +34,7 @@ async fn test_single_insert_root() -> Result<()> { assert_roots_equal(&account, *MERKLE_ADDRESS.get().unwrap(), &ark_merkle_tree).await?; - global_teardown(sequencer); + global_teardown(TestConfig::Merkle, sequencer, false).await; Ok(()) } @@ -50,7 +50,7 @@ async fn test_multi_insert_root() -> Result<()> { assert_roots_equal(&account, *MERKLE_ADDRESS.get().unwrap(), &ark_merkle_tree).await?; - global_teardown(sequencer); + global_teardown(TestConfig::Merkle, sequencer, false).await; Ok(()) } @@ -68,7 +68,7 @@ async fn test_full_insert() -> Result<()> { .await .is_err()); - global_teardown(sequencer); + global_teardown(TestConfig::Merkle, sequencer, false).await; Ok(()) } diff --git a/tests/tests/nullifier_set.rs b/tests/tests/nullifier_set.rs index 880a7b56..731e36be 100644 --- a/tests/tests/nullifier_set.rs +++ b/tests/tests/nullifier_set.rs @@ -25,7 +25,7 @@ async fn test_nullifier_set_fuzz() -> Result<()> { ); } - global_teardown(sequencer); + global_teardown(TestConfig::NullifierSet, sequencer, false).await; Ok(()) } @@ -47,7 +47,7 @@ async fn test_in_use_nullifier_set_fuzz() -> Result<()> { ); } - global_teardown(sequencer); + global_teardown(TestConfig::NullifierSet, sequencer, false).await; Ok(()) } diff --git a/tests/tests/poseidon.rs b/tests/tests/poseidon.rs index 85b1e28a..c126eda2 100644 --- a/tests/tests/poseidon.rs +++ b/tests/tests/poseidon.rs @@ -14,7 +14,7 @@ async fn test_poseidon_fuzz() -> Result<()> { assert!(contract_hash == ark_hash); } - global_teardown(sequencer); + global_teardown(TestConfig::Poseidon, sequencer, false).await; Ok(()) } diff --git a/tests/tests/profiling.rs b/tests/tests/profiling.rs index 64517fae..de05ec59 100644 --- a/tests/tests/profiling.rs +++ b/tests/tests/profiling.rs @@ -2,21 +2,121 @@ #![feature(generic_const_exprs)] use circuit_types::{order::Order, transfers::ExternalTransfer}; +use circuits::zk_circuits::valid_match_mpc::ValidMatchMpcSingleProver; use eyre::Result; use tests::{ darkpool::utils::{ new_wallet, poll_new_wallet_to_completion, poll_update_wallet_to_completion, update_wallet, DARKPOOL_ADDRESS, }, - profiling::utils::{get_new_wallet_args, get_update_wallet_args}, - utils::{get_root, global_teardown, setup_sequencer, Breakpoint, TestConfig, DUMMY_WALLET}, + profiling::utils::{ + get_new_wallet_args, get_update_wallet_args, SizedValidCommitments, SizedValidReblind, + SizedValidSettle, SizedValidWalletCreate, SizedValidWalletUpdate, TestParamsCircuit, + }, + utils::{ + fully_parameterize_circuit, get_circuit_params, get_root, global_teardown, setup_sequencer, + Breakpoint, CalldataSerializable, TestConfig, DUMMY_WALLET, + }, }; #[tokio::test] -async fn profile_parameterize_circuit() -> Result<()> { +async fn profile_parameterize_valid_wallet_create() -> Result<()> { + let sequencer = setup_sequencer(TestConfig::Profiling).await?; + + fully_parameterize_circuit( + &sequencer.account(), + *DARKPOOL_ADDRESS.get().unwrap(), + TestParamsCircuit::ValidWalletCreate(SizedValidWalletCreate {}).to_calldata()[0], + get_circuit_params::(), + ) + .await?; + + global_teardown(TestConfig::Profiling, sequencer, true).await; + + Ok(()) +} + +#[tokio::test] +async fn profile_parameterize_valid_wallet_update() -> Result<()> { + let sequencer = setup_sequencer(TestConfig::Profiling).await?; + + fully_parameterize_circuit( + &sequencer.account(), + *DARKPOOL_ADDRESS.get().unwrap(), + TestParamsCircuit::ValidWalletUpdate(SizedValidWalletUpdate {}).to_calldata()[0], + get_circuit_params::(), + ) + .await?; + + global_teardown(TestConfig::Profiling, sequencer, true).await; + + Ok(()) +} + +#[tokio::test] +async fn profile_parameterize_valid_commitments() -> Result<()> { + let sequencer = setup_sequencer(TestConfig::Profiling).await?; + + fully_parameterize_circuit( + &sequencer.account(), + *DARKPOOL_ADDRESS.get().unwrap(), + TestParamsCircuit::ValidCommitments(SizedValidCommitments {}).to_calldata()[0], + get_circuit_params::(), + ) + .await?; + + global_teardown(TestConfig::Profiling, sequencer, true).await; + + Ok(()) +} + +#[tokio::test] +async fn profile_parameterize_valid_reblind() -> Result<()> { let sequencer = setup_sequencer(TestConfig::Profiling).await?; - global_teardown(sequencer); + fully_parameterize_circuit( + &sequencer.account(), + *DARKPOOL_ADDRESS.get().unwrap(), + TestParamsCircuit::ValidReblind(SizedValidReblind {}).to_calldata()[0], + get_circuit_params::(), + ) + .await?; + + global_teardown(TestConfig::Profiling, sequencer, true).await; + + Ok(()) +} + +#[tokio::test] +async fn profile_parameterize_valid_match_mpc() -> Result<()> { + let sequencer = setup_sequencer(TestConfig::Profiling).await?; + + fully_parameterize_circuit( + &sequencer.account(), + *DARKPOOL_ADDRESS.get().unwrap(), + TestParamsCircuit::ValidMatchMpc(ValidMatchMpcSingleProver {}).to_calldata()[0], + get_circuit_params::(), + ) + .await?; + + global_teardown(TestConfig::Profiling, sequencer, true).await; + + Ok(()) +} + +#[tokio::test] +async fn profile_parameterize_valid_settle() -> Result<()> { + let sequencer = setup_sequencer(TestConfig::Profiling).await?; + + fully_parameterize_circuit( + &sequencer.account(), + *DARKPOOL_ADDRESS.get().unwrap(), + TestParamsCircuit::ValidSettle(SizedValidSettle {}).to_calldata()[0], + get_circuit_params::(), + ) + .await?; + + global_teardown(TestConfig::Profiling, sequencer, true).await; Ok(()) } @@ -26,16 +126,14 @@ async fn profile_new_wallet() -> Result<()> { let sequencer = setup_sequencer(TestConfig::Profiling).await?; let account = sequencer.account(); - for breakpoint in [ - Breakpoint::AppendStatement, - Breakpoint::QueueVerification, - Breakpoint::None, - ] { - let new_wallet_args = get_new_wallet_args(breakpoint)?; - new_wallet(&account, &new_wallet_args).await?; - } + // Breakpoints: + // Breakpoint::AppendStatement (done) + // Breakpoint::QueueVerification + // Breakpoint::None + let new_wallet_args = get_new_wallet_args(Breakpoint::None)?; + new_wallet(&account, &new_wallet_args).await?; - global_teardown(sequencer); + global_teardown(TestConfig::Profiling, sequencer, false).await; Ok(()) } @@ -47,7 +145,7 @@ async fn profile_poll_new_wallet() -> Result<()> { let new_wallet_args = get_new_wallet_args(Breakpoint::None)?; poll_new_wallet_to_completion(&sequencer.account(), &new_wallet_args).await?; - global_teardown(sequencer); + global_teardown(TestConfig::Profiling, sequencer, false).await; Ok(()) } @@ -78,7 +176,7 @@ async fn profile_update_wallet() -> Result<()> { update_wallet(&account, &update_wallet_args).await?; } - global_teardown(sequencer); + global_teardown(TestConfig::Profiling, sequencer, false).await; Ok(()) } @@ -103,7 +201,7 @@ async fn profile_poll_update_wallet() -> Result<()> { )?; poll_update_wallet_to_completion(&account, &update_wallet_args).await?; - global_teardown(sequencer); + global_teardown(TestConfig::Profiling, sequencer, false).await; Ok(()) } diff --git a/tests/tests/statement_serde.rs b/tests/tests/statement_serde.rs index 2dcf4894..5e758128 100644 --- a/tests/tests/statement_serde.rs +++ b/tests/tests/statement_serde.rs @@ -16,7 +16,7 @@ async fn test_valid_wallet_create_statement_serde() -> Result<()> { assert_valid_wallet_create_statement(&sequencer.account()).await?; - global_teardown(sequencer); + global_teardown(TestConfig::StatementSerde, sequencer, false).await; Ok(()) } @@ -27,7 +27,7 @@ async fn test_valid_wallet_update_statement_serde() -> Result<()> { assert_valid_wallet_update_statement(&sequencer.account()).await?; - global_teardown(sequencer); + global_teardown(TestConfig::StatementSerde, sequencer, false).await; Ok(()) } @@ -38,7 +38,7 @@ async fn test_valid_reblind_statement_serde() -> Result<()> { assert_valid_reblind_statement(&sequencer.account()).await?; - global_teardown(sequencer); + global_teardown(TestConfig::StatementSerde, sequencer, false).await; Ok(()) } @@ -49,7 +49,7 @@ async fn test_valid_commitments_statement_serde() -> Result<()> { assert_valid_commitments_statement(&sequencer.account()).await?; - global_teardown(sequencer); + global_teardown(TestConfig::StatementSerde, sequencer, false).await; Ok(()) } @@ -60,7 +60,7 @@ async fn test_valid_settle_statement_serde() -> Result<()> { assert_valid_settle_statement(&sequencer.account()).await?; - global_teardown(sequencer); + global_teardown(TestConfig::StatementSerde, sequencer, false).await; Ok(()) } @@ -71,7 +71,7 @@ async fn test_valid_wallet_create_statement_to_scalars() -> Result<()> { assert_valid_wallet_create_statement_to_scalars(&sequencer.account()).await?; - global_teardown(sequencer); + global_teardown(TestConfig::StatementSerde, sequencer, false).await; Ok(()) } @@ -82,7 +82,7 @@ async fn test_valid_wallet_update_statement_to_scalars() -> Result<()> { assert_valid_wallet_update_statement_to_scalars(&sequencer.account()).await?; - global_teardown(sequencer); + global_teardown(TestConfig::StatementSerde, sequencer, false).await; Ok(()) } @@ -93,7 +93,7 @@ async fn test_valid_reblind_statement_to_scalars() -> Result<()> { assert_valid_reblind_statement_to_scalars(&sequencer.account()).await?; - global_teardown(sequencer); + global_teardown(TestConfig::StatementSerde, sequencer, false).await; Ok(()) } @@ -104,7 +104,7 @@ async fn test_valid_commitments_statement_to_scalars() -> Result<()> { assert_valid_commitments_statement_to_scalars(&sequencer.account()).await?; - global_teardown(sequencer); + global_teardown(TestConfig::StatementSerde, sequencer, false).await; Ok(()) } @@ -115,7 +115,7 @@ async fn test_valid_settle_statement_to_scalars() -> Result<()> { assert_valid_settle_statement_to_scalars(&sequencer.account()).await?; - global_teardown(sequencer); + global_teardown(TestConfig::StatementSerde, sequencer, false).await; Ok(()) } diff --git a/tests/tests/transcript.rs b/tests/tests/transcript.rs index 9412df27..9f0a6c3e 100644 --- a/tests/tests/transcript.rs +++ b/tests/tests/transcript.rs @@ -8,7 +8,7 @@ use tests::{ innerproduct_domain_sep, r1cs_1phase_domain_sep, r1cs_domain_sep, rangeproof_domain_sep, setup_transcript_test, validate_and_append_point, FUZZ_ROUNDS, }, - utils::global_teardown, + utils::{global_teardown, TestConfig}, }; #[tokio::test] @@ -56,7 +56,7 @@ async fn test_transcript_fuzz() -> Result<()> { assert!(challenge_scalar == expected_challenge_scalar); } - global_teardown(sequencer); + global_teardown(TestConfig::Transcript, sequencer, false).await; Ok(()) } diff --git a/tests/tests/verifier.rs b/tests/tests/verifier.rs index 2388d485..f820cce4 100644 --- a/tests/tests/verifier.rs +++ b/tests/tests/verifier.rs @@ -44,7 +44,7 @@ async fn test_full_verification_fuzz() -> Result<()> { .unwrap()); } - global_teardown(sequencer); + global_teardown(TestConfig::Verifier, sequencer, false).await; Ok(()) } @@ -78,6 +78,6 @@ async fn test_full_verification_invalid_proof() -> Result<()> { .await? .unwrap()); - global_teardown(sequencer); + global_teardown(TestConfig::Verifier, sequencer, false).await; Ok(()) } diff --git a/tests/tests/verifier_utils.rs b/tests/tests/verifier_utils.rs index 700e2f68..4b73bc34 100644 --- a/tests/tests/verifier_utils.rs +++ b/tests/tests/verifier_utils.rs @@ -6,7 +6,7 @@ use mpc_bulletproof::{ PedersenGens, }; use tests::{ - utils::{global_teardown, TRANSCRIPT_SEED}, + utils::{global_teardown, TestConfig, TRANSCRIPT_SEED}, verifier::utils::DUMMY_CIRCUIT_N, verifier_utils::utils::{ calc_delta, get_expected_dummy_circuit_delta, get_expected_dummy_circuit_s, get_s_elem, @@ -37,7 +37,7 @@ async fn test_squeeze_challenge_scalars_dummy_circuit() -> Result<()> { assert_eq!(challenge_scalars, expected_challenge_scalars); assert_eq!(u, expected_u); - global_teardown(sequencer); + global_teardown(TestConfig::VerifierUtils, sequencer, false).await; Ok(()) } @@ -66,7 +66,7 @@ async fn test_get_s_elem() -> Result<()> { assert_eq!(&s_elem, expected_s_elem); } - global_teardown(sequencer); + global_teardown(TestConfig::VerifierUtils, sequencer, false).await; Ok(()) } @@ -106,7 +106,7 @@ async fn test_calc_delta() -> Result<()> { assert_eq!(delta, expected_delta); - global_teardown(sequencer); + global_teardown(TestConfig::VerifierUtils, sequencer, false).await; Ok(()) }