Skip to content

Commit

Permalink
Merge pull request #237 from a16z/feat/sha2-chain-bench-alone
Browse files Browse the repository at this point in the history
feat: Sha2 Chain Bench
  • Loading branch information
sragss authored Mar 29, 2024
2 parents 4694ef8 + 55190f2 commit c768a93
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions jolt-core/src/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub enum BenchType {
Fibonacci,
Sha2,
Sha3,
Sha2Chain,
}

#[allow(unreachable_patterns)] // good errors on new BenchTypes
Expand All @@ -41,6 +42,7 @@ pub fn benchmarks(
BenchType::InstructionLookups => prove_instruction_lookups(num_cycles),
BenchType::Sha2 => sha2(),
BenchType::Sha3 => sha3(),
BenchType::Sha2Chain => sha2chain(),
BenchType::Fibonacci => fibonacci(),
_ => panic!("BenchType does not have a mapping"),
}
Expand Down Expand Up @@ -260,3 +262,44 @@ fn prove_example<T: Serialize>(

tasks
}

fn sha2chain() -> Vec<(tracing::Span, Box<dyn FnOnce()>)> {
let mut tasks = Vec::new();
let mut program = host::Program::new("sha2-chain-guest");
program.set_input(&[5u8; 32]);
program.set_input(&1024u32);

let task = move || {
let bytecode = program.decode();
let (io_device, bytecode_trace, instruction_trace, memory_trace, circuit_flags) =
program.trace();

let preprocessing: crate::jolt::vm::JoltPreprocessing<
ark_ff::Fp<ark_ff::MontBackend<ark_bn254::FrConfig, 4>, 4>,
ark_ec::short_weierstrass::Projective<ark_bn254::g1::Config>,
> = RV32IJoltVM::preprocess(bytecode.clone(), 1 << 20, 1 << 20, 1 << 22);

let (jolt_proof, jolt_commitments) = <RV32IJoltVM as Jolt<_, G1Projective, C, M>>::prove(
io_device,
bytecode,
bytecode_trace,
memory_trace,
instruction_trace,
circuit_flags,
preprocessing.clone(),
);
let verification_result = RV32IJoltVM::verify(preprocessing, jolt_proof, jolt_commitments);
assert!(
verification_result.is_ok(),
"Verification failed with error: {:?}",
verification_result.err()
);
};

tasks.push((
tracing::info_span!("Example_E2E"),
Box::new(task) as Box<dyn FnOnce()>,
));

tasks
}

0 comments on commit c768a93

Please sign in to comment.