Skip to content

Commit

Permalink
tests: added profiling feature flag & breakpoints to e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akirillo committed Sep 6, 2023
1 parent ce10c52 commit cb82e4a
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 44 deletions.
70 changes: 46 additions & 24 deletions src/darkpool.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,16 @@ mod Darkpool {

let feature_flags = self.feature_flags.read();

if breakpoint == Breakpoint::PreMerkleInitialize {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::PreMerkleInitialize {
return;
}

// Initialize the Merkle tree
_get_merkle_tree(@self).initialize(height, feature_flags);

if breakpoint == Breakpoint::MerkleInitialize {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::MerkleInitialize {
return;
}

Expand Down Expand Up @@ -517,7 +519,8 @@ mod Darkpool {
// Inject witness
append_statement_commitments(@statement, ref witness_commitments);

if breakpoint == Breakpoint::AppendStatementCommitments {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::AppendStatementCommitments {
return;
}

Expand All @@ -531,7 +534,8 @@ mod Darkpool {
breakpoint,
);

if breakpoint == Breakpoint::QueueVerification {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::QueueVerification {
return;
}

Expand Down Expand Up @@ -566,7 +570,8 @@ mod Darkpool {
let verified = verifier
.step_verification(Circuit::ValidWalletCreate(()).into(), verification_job_id);

if breakpoint == Breakpoint::StepVerification {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::StepVerification {
return Option::Some(Result::Err('breakpoint reached'));
}

Expand All @@ -588,14 +593,16 @@ mod Darkpool {
hash_input.span(), self.feature_flags.read().use_base_field_poseidon
);

if breakpoint == Breakpoint::SharesCommitment {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::SharesCommitment {
return Option::Some(Result::Err('breakpoint reached'));
}

let merkle_tree = _get_merkle_tree(@self);
let new_root = merkle_tree.insert(total_shares_commitment);

if breakpoint == Breakpoint::MerkleInsert {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::MerkleInsert {
return Option::Some(Result::Err('breakpoint reached'));
}

Expand Down Expand Up @@ -644,7 +651,8 @@ mod Darkpool {
// now signing a new wallet with a new root key.
let statement_hash = hash_statement(@statement);

if breakpoint == Breakpoint::HashStatement {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::HashStatement {
return;
}

Expand All @@ -658,7 +666,7 @@ mod Darkpool {
'invalid statement signature'
);

if breakpoint == Breakpoint::CheckECDSA {
if self.feature_flags.read().enable_profiling && breakpoint == Breakpoint::CheckECDSA {
return;
}

Expand All @@ -668,7 +676,8 @@ mod Darkpool {
// Inject witness
append_statement_commitments(@statement, ref witness_commitments);

if breakpoint == Breakpoint::AppendStatementCommitments {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::AppendStatementCommitments {
return;
}

Expand All @@ -682,7 +691,8 @@ mod Darkpool {
breakpoint,
);

if breakpoint == Breakpoint::QueueVerification {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::QueueVerification {
return;
}

Expand Down Expand Up @@ -725,7 +735,8 @@ mod Darkpool {
let verified = verifier
.step_verification(Circuit::ValidWalletUpdate(()).into(), verification_job_id);

if breakpoint == Breakpoint::StepVerification {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::StepVerification {
return Option::Some(Result::Err('breakpoint reached'));
}

Expand All @@ -749,14 +760,16 @@ mod Darkpool {
hash_input.span(), self.feature_flags.read().use_base_field_poseidon
);

if breakpoint == Breakpoint::SharesCommitment {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::SharesCommitment {
return Option::Some(Result::Err('breakpoint reached'));
}

let merkle_tree = _get_merkle_tree(@self);
let new_root = merkle_tree.insert(total_shares_commitment);

if breakpoint == Breakpoint::MerkleInsert {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::MerkleInsert {
return Option::Some(Result::Err('breakpoint reached'));
}

Expand Down Expand Up @@ -837,7 +850,8 @@ mod Darkpool {

let verifier = _get_verifier(@self);

if breakpoint == Breakpoint::PreInjectAndQueue {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::PreInjectAndQueue {
return;
}

Expand All @@ -855,7 +869,8 @@ mod Darkpool {
breakpoint,
);

if breakpoint == Breakpoint::Party0ValidCommitments {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::Party0ValidCommitments {
return;
}

Expand All @@ -873,7 +888,8 @@ mod Darkpool {
breakpoint,
);

if breakpoint == Breakpoint::Party0ValidReblind {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::Party0ValidReblind {
return;
}

Expand All @@ -891,7 +907,8 @@ mod Darkpool {
breakpoint,
);

if breakpoint == Breakpoint::Party1ValidCommitments {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::Party1ValidCommitments {
return;
}

Expand All @@ -909,7 +926,8 @@ mod Darkpool {
breakpoint,
);

if breakpoint == Breakpoint::Party1ValidReblind {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::Party1ValidReblind {
return;
}

Expand All @@ -924,7 +942,8 @@ mod Darkpool {
breakpoint,
);

if breakpoint == Breakpoint::ValidMatchMpc {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::ValidMatchMpc {
return;
}

Expand All @@ -941,7 +960,7 @@ mod Darkpool {
breakpoint,
);

if breakpoint == Breakpoint::ValidSettle {
if self.feature_flags.read().enable_profiling && breakpoint == Breakpoint::ValidSettle {
return;
}

Expand Down Expand Up @@ -981,7 +1000,8 @@ mod Darkpool {
) -> Option<Result<Scalar, felt252>> {
let poll_result = _check_and_poll_process_match(@self, verification_job_id);

if breakpoint == Breakpoint::CheckAndPoll {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::CheckAndPoll {
return Option::Some(Result::Err('breakpoint reached'));
}

Expand Down Expand Up @@ -1206,15 +1226,17 @@ mod Darkpool {
party_1_hash_input.span(), use_base_field_poseidon
);

if breakpoint == Breakpoint::SharesCommitment {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::SharesCommitment {
return Option::Some(Result::Err('breakpoint reached'));
}

let merkle_tree = _get_merkle_tree(@self);
merkle_tree.insert(party_0_total_shares_commitment);
let new_root = merkle_tree.insert(party_1_total_shares_commitment);

if breakpoint == Breakpoint::MerkleInsert {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::MerkleInsert {
return Option::Some(Result::Err('breakpoint reached'));
}

Expand Down
2 changes: 2 additions & 0 deletions src/darkpool/types.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ struct FeatureFlags {
use_base_field_poseidon: bool,
/// Whether or not to verify proofs
disable_verification: bool,
/// Whether or not to enable profiling
enable_profiling: bool,
}

// --------------------------
Expand Down
17 changes: 13 additions & 4 deletions src/testing/tests/darkpool_tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ fn test_upgrade_verifier() {
let test_caller = contract_address_try_from_felt252(TEST_CALLER).unwrap();
set_contract_address(test_caller);
let mut darkpool = setup_darkpool_with_flags(
FeatureFlags { use_base_field_poseidon: true, disable_verification: false }
FeatureFlags {
use_base_field_poseidon: true, disable_verification: false, enable_profiling: false
}
);

darkpool.upgrade_verifier(DummyUpgradeTarget::TEST_CLASS_HASH.try_into().unwrap());
Expand Down Expand Up @@ -191,7 +193,9 @@ fn test_upgrade_verifier_access() {
let test_caller = contract_address_try_from_felt252(TEST_CALLER).unwrap();
set_contract_address(test_caller);
let mut darkpool = setup_darkpool_with_flags(
FeatureFlags { use_base_field_poseidon: true, disable_verification: false }
FeatureFlags {
use_base_field_poseidon: true, disable_verification: false, enable_profiling: false
}
);

let dummy_caller = contract_address_try_from_felt252(DUMMY_CALLER).unwrap();
Expand Down Expand Up @@ -227,7 +231,10 @@ fn test_initialize_twice() {
let mut calldata = ArrayTrait::new();
calldata.append(TEST_CALLER);
Serde::<FeatureFlags>::serialize(
@FeatureFlags { use_base_field_poseidon: false, disable_verification: false }, ref calldata
@FeatureFlags {
use_base_field_poseidon: false, disable_verification: false, enable_profiling: false
},
ref calldata
);

let (darkpool_address, _) = deploy_syscall(
Expand All @@ -249,7 +256,9 @@ fn setup_darkpool() -> IDarkpoolDispatcher {
// Default feature flags used disable the scalar field poseidon hash and the verifier, as these
// are generally not what is being tested here and disabling them speeds up tests.
setup_darkpool_with_flags(
FeatureFlags { use_base_field_poseidon: true, disable_verification: true }
FeatureFlags {
use_base_field_poseidon: true, disable_verification: true, enable_profiling: false
}
)
}

Expand Down
4 changes: 3 additions & 1 deletion src/testing/tests/merkle_tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ fn setup_merkle() -> ContractState {
merkle
.initialize(
TEST_MERKLE_HEIGHT,
FeatureFlags { use_base_field_poseidon: true, disable_verification: true }
FeatureFlags {
use_base_field_poseidon: true, disable_verification: true, enable_profiling: false
}
);
merkle
}
14 changes: 9 additions & 5 deletions src/verifier.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,15 @@ mod MultiVerifier {
let W_V = self.W_V.read(circuit_id).inner;
let c = self.c.read(circuit_id).inner;

if breakpoint == Breakpoint::ReadCircuitParams {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::ReadCircuitParams {
return;
}

// Prep `RemainingGenerators` structs for G and H generators
let (G_rem, H_rem) = prep_rem_gens(n_plus);

if breakpoint == Breakpoint::PrepRemGens {
if self.feature_flags.read().enable_profiling && breakpoint == Breakpoint::PrepRemGens {
return;
}

Expand All @@ -273,7 +274,8 @@ mod MultiVerifier {
@proof, witness_commitments.span(), m, n_plus
);

if breakpoint == Breakpoint::SqueezeChallengeScalars {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::SqueezeChallengeScalars {
return;
}

Expand All @@ -294,7 +296,8 @@ mod MultiVerifier {
y_inv, z, u, x, w, r, @proof, n, n_plus, @W_L, @W_R, @c,
);

if breakpoint == Breakpoint::PrepRemScalarPolys {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::PrepRemScalarPolys {
return;
}

Expand All @@ -304,7 +307,8 @@ mod MultiVerifier {
ref proof, ref witness_commitments, pedersen_generator, pedersen_generator,
);

if breakpoint == Breakpoint::PrepRemCommitments {
if self.feature_flags.read().enable_profiling
&& breakpoint == Breakpoint::PrepRemCommitments {
return;
}

Expand Down
Loading

0 comments on commit cb82e4a

Please sign in to comment.