Skip to content

Commit

Permalink
Improve benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve committed May 7, 2024
1 parent 560dc1d commit 5f0875e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 29 deletions.
14 changes: 7 additions & 7 deletions crypto/fcmps/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,9 +747,9 @@ where

// Escape to the raw weights to form a GBP with
assert!(c1_circuit.muls() <= 256);
assert!(c2_circuit.muls() <= 256);
dbg!(c1_circuit.muls());
dbg!(c2_circuit.muls());
assert!(c2_circuit.muls() <= 128);
// dbg!(c1_circuit.muls());
// dbg!(c2_circuit.muls());

// TODO: unwrap -> Result
let (c1_statement, c1_witness) = c1_circuit
Expand Down Expand Up @@ -787,7 +787,7 @@ where
verifier_2: &mut BatchVerifier<C2>,
params: &FcmpParams<T, C1, C2>,
tree: TreeRoot<C1, C2>,
layer_lens: Vec<usize>,
layer_lens: &[usize],
input: Input<C1::F>,
) where
OC::G: DivisorCurve<FieldElement = C1::F>,
Expand Down Expand Up @@ -966,9 +966,9 @@ where

// Escape to the raw weights to form a GBP with
assert!(c1_circuit.muls() <= 256);
assert!(c2_circuit.muls() <= 256);
dbg!(c1_circuit.muls());
dbg!(c2_circuit.muls());
assert!(c2_circuit.muls() <= 128);
// dbg!(c1_circuit.muls());
// dbg!(c2_circuit.muls());

// TODO: unwrap -> Result
let (c1_statement, _witness) = c1_circuit
Expand Down
53 changes: 31 additions & 22 deletions crypto/fcmps/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,41 @@ fn random_output() -> Output<Ed25519> {

#[inline(never)]
fn verify_fn(
iters: usize,
batch: usize,
proof: Fcmp<Selene, Helios>,
params: &FcmpParams<RecommendedTranscript, Selene, Helios>,
root: TreeRoot<Selene, Helios>,
layer_lens: Vec<usize>,
layer_lens: &[usize],
input: Input<<Selene as Ciphersuite>::F>,
) {
let instant = std::time::Instant::now();

let mut verifier_1 = params.curve_1_generators.batch_verifier();
let mut verifier_2 = params.curve_2_generators.batch_verifier();

for _ in 0 .. 10 {
proof.clone().verify::<_, _, Ed25519>(
&mut OsRng,
&mut RecommendedTranscript::new(b"FCMP Test"),
&mut verifier_1,
&mut verifier_2,
params,
root,
layer_lens.clone(),
input,
);
}
let mut times = vec![];
for _ in 0 .. iters {
let instant = std::time::Instant::now();

let mut verifier_1 = params.curve_1_generators.batch_verifier();
let mut verifier_2 = params.curve_2_generators.batch_verifier();

for _ in 0 .. batch {
proof.clone().verify::<_, _, Ed25519>(
&mut OsRng,
&mut RecommendedTranscript::new(b"FCMP Test"),
&mut verifier_1,
&mut verifier_2,
params,
root,
layer_lens,
input,
);
}

assert!(params.curve_1_generators.verify(verifier_1));
assert!(params.curve_2_generators.verify(verifier_2));
assert!(params.curve_1_generators.verify(verifier_1));
assert!(params.curve_2_generators.verify(verifier_2));

dbg!((std::time::Instant::now() - instant).as_millis());
times.push((std::time::Instant::now() - instant).as_millis());
}
times.sort();
dbg!((batch, times[times.len() / 2]));
}

#[test]
Expand Down Expand Up @@ -182,5 +189,7 @@ fn test() {
branches,
);

verify_fn(proof, &params, root, layer_lens, input);
verify_fn(100, 1, proof.clone(), &params, root, &layer_lens, input);
verify_fn(100, 10, proof.clone(), &params, root, &layer_lens, input);
verify_fn(100, 100, proof.clone(), &params, root, &layer_lens, input);
}

0 comments on commit 5f0875e

Please sign in to comment.