Skip to content

Commit 038cd36

Browse files
committed
fix: use right program id for the saved proof
1 parent c1acf25 commit 038cd36

File tree

9 files changed

+49
-25
lines changed

9 files changed

+49
-25
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ borsh = { version = "1.5.0", features = ["derive"] }
152152
clap = { version = "4.5.20", features = ["cargo", "derive", "env"] }
153153
corepc-node = { version = "0.10.0", features = ["29_0"] }
154154
futures = "0.3.31"
155+
hex = "0.4"
155156
hex-literal = "1.1"
156157
jsonrpsee = "0.26.0"
157158
k256 = "0.13.4"

bin/prover-perf/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ strata-predicate.workspace = true
2626

2727
anyhow.workspace = true
2828
clap.workspace = true
29+
hex.workspace = true
2930
num-format = "0.4.4"
3031
reqwest = { version = "0.12.28", default-features = false, features = [
3132
"blocking",
-419 Bytes
Binary file not shown.

bin/prover-perf/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ fn main() -> Result<()> {
2323

2424
if args.generate_proof {
2525
let sp1_proofs = programs::gen_sp1_proof(&programs);
26-
for (program, proof) in programs.iter().zip(sp1_proofs) {
26+
for (program, (program_id, proof)) in programs.iter().zip(sp1_proofs) {
2727
proof
28-
.save(program.as_str())
28+
.save(format!("{}_{}", program.as_str(), program_id))
2929
.unwrap_or_else(|e| panic!("failed to save proof for {}: {e}", program.as_str()));
3030
}
3131
return Ok(());

bin/prover-perf/src/programs/asm_stf.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static ASM_HOST: LazyLock<SP1Host> = LazyLock::new(|| {
2626
pub(crate) fn create_runtime_input() -> RuntimeInput {
2727
let step_input = create_asm_step_input();
2828
let inner_pre_state = create_deterministic_genesis_anchor_state(step_input.block());
29-
let moho_pre_state = create_moho_state(&inner_pre_state, asm_predicate_key());
29+
let moho_pre_state = create_moho_state(&inner_pre_state, compute_asm_predicate_key());
3030
RuntimeInput::new(
3131
moho_pre_state,
3232
inner_pre_state.as_ssz_bytes(),
@@ -40,12 +40,13 @@ pub(crate) fn gen_perf_report() -> PerformanceReport {
4040
.expect("failed to generate performance report")
4141
}
4242

43-
pub(crate) fn gen_proof() -> ProofReceiptWithMetadata {
43+
pub(crate) fn gen_proof() -> (String, ProofReceiptWithMetadata) {
4444
let input = create_runtime_input();
45-
AsmStfProofProgram::prove(&input, &*ASM_HOST).expect("failed to generate proof")
45+
let proof = AsmStfProofProgram::prove(&input, &*ASM_HOST).expect("failed to generate proof");
46+
(ASM_HOST.proving_key.vk.bytes32(), proof)
4647
}
4748

48-
pub(crate) fn asm_predicate_key() -> PredicateKey {
49+
pub(crate) fn compute_asm_predicate_key() -> PredicateKey {
4950
let vk = ASM_HOST.proving_key.vk.bytes32_raw();
5051
compute_sp1_predicate_key(vk)
5152
}

bin/prover-perf/src/programs/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub(crate) fn gen_sp1_perf_report(programs: &[GuestProgram]) -> Vec<PerformanceR
4848
}
4949

5050
/// Runs SP1 programs to generate reports.
51-
pub(crate) fn gen_sp1_proof(programs: &[GuestProgram]) -> Vec<ProofReceiptWithMetadata> {
51+
pub(crate) fn gen_sp1_proof(programs: &[GuestProgram]) -> Vec<(String, ProofReceiptWithMetadata)> {
5252
programs
5353
.iter()
5454
.map(|program| match program {

bin/prover-perf/src/programs/moho.rs

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use zkaleido::{PerformanceReport, ProofReceiptWithMetadata, ZkVmProgram, ZkVmPro
2222
use zkaleido_sp1_groth16_verifier::VK_HASH_PREFIX_LENGTH;
2323
use zkaleido_sp1_host::SP1Host;
2424

25-
use crate::programs::{asm_stf::asm_predicate_key, compute_sp1_predicate_key};
25+
use crate::programs::asm_stf::compute_sp1_predicate_key;
2626

2727
static MOHO_HOST: LazyLock<SP1Host> = LazyLock::new(|| {
2828
let elf = fs::read(MOHO_ELF_PATH)
@@ -36,20 +36,46 @@ pub(crate) fn gen_perf_report() -> PerformanceReport {
3636
.expect("failed to generate performance report")
3737
}
3838

39-
pub(crate) fn gen_proof() -> ProofReceiptWithMetadata {
39+
pub(crate) fn gen_proof() -> (String, ProofReceiptWithMetadata) {
4040
let input = create_moho_recursive_input();
41-
MohoRecursiveProgram::prove(&input, &*MOHO_HOST).expect("failed to generate performance report")
41+
let proof = MohoRecursiveProgram::prove(&input, &*MOHO_HOST)
42+
.expect("failed to generate performance report");
43+
(MOHO_HOST.proving_key.vk.bytes32(), proof)
4244
}
4345

44-
pub(crate) fn moho_predicate_key() -> PredicateKey {
46+
pub(crate) fn compute_moho_predicate_key() -> PredicateKey {
4547
let vk = MOHO_HOST.proving_key.vk.bytes32_raw();
4648
compute_sp1_predicate_key(vk)
4749
}
4850

51+
pub(crate) fn load_asm_stf_predicate_and_proof() -> (PredicateKey, MohoTransitionWithProof) {
52+
const ASM_PROGRAM_ID_STR: &str =
53+
"00d0c2a2a163035da6766fd1fdb1cd044425e8b26faa69282fc8d8851452e6fc";
54+
let asm_program_id: [u8; 32] = hex::decode(ASM_PROGRAM_ID_STR).unwrap().try_into().unwrap();
55+
let asm_predicate = compute_sp1_predicate_key(asm_program_id);
56+
57+
let proof_path = Path::new(env!("CARGO_MANIFEST_DIR")).join(format!(
58+
"asm-stf_0x{}_SP1_v5.0.0.proof.bin",
59+
ASM_PROGRAM_ID_STR
60+
));
61+
let asm_stf_proof = ProofReceiptWithMetadata::load(proof_path).expect("failed to open proof");
62+
let proven_moho_transition =
63+
MohoStateTransition::from_ssz_bytes(asm_stf_proof.receipt().public_values().as_bytes())
64+
.unwrap();
65+
66+
let proof = &asm_stf_proof.receipt().proof().as_bytes()[VK_HASH_PREFIX_LENGTH..];
67+
let incremental_step_proof =
68+
MohoTransitionWithProof::new(proven_moho_transition, proof.to_vec());
69+
70+
(asm_predicate, incremental_step_proof)
71+
}
72+
4973
pub(crate) fn create_moho_recursive_input() -> MohoRecursiveInput {
5074
let input = create_asm_step_input();
5175
let asm_pre_state = create_deterministic_genesis_anchor_state(input.block());
52-
let moho_pre_state = create_moho_state(&asm_pre_state, asm_predicate_key());
76+
let (asm_predicate, incremental_step_proof) = load_asm_stf_predicate_and_proof();
77+
78+
let moho_pre_state = create_moho_state(&asm_pre_state, asm_predicate);
5379

5480
let moho_pre_state_ref = StateRefAttestation::new(
5581
AsmStfProgram::extract_prev_reference(&input),
@@ -66,7 +92,7 @@ pub(crate) fn create_moho_recursive_input() -> MohoRecursiveInput {
6692
.unwrap()
6793
.state;
6894

69-
let moho_post_state = create_moho_state(&asm_post_state, asm_predicate_key());
95+
let moho_post_state = create_moho_state(&asm_post_state, asm_predicate);
7096

7197
let moho_post_state_ref = StateRefAttestation::new(
7298
AsmStfProgram::compute_input_reference(&input),
@@ -76,24 +102,18 @@ pub(crate) fn create_moho_recursive_input() -> MohoRecursiveInput {
76102
let expected_moho_transition =
77103
MohoStateTransition::new(moho_pre_state_ref, moho_post_state_ref);
78104

79-
let proof_path = Path::new(env!("CARGO_MANIFEST_DIR")).join("asm-stf_SP1_v5.0.0.proof.bin");
80-
let asm_stf_proof = ProofReceiptWithMetadata::load(proof_path).expect("failed to open proof");
81-
let proven_moho_transition =
82-
MohoStateTransition::from_ssz_bytes(asm_stf_proof.receipt().public_values().as_bytes())
83-
.unwrap();
84-
assert_eq!(expected_moho_transition, proven_moho_transition);
85-
86-
let proof = &asm_stf_proof.receipt().proof().as_bytes()[VK_HASH_PREFIX_LENGTH..];
87-
let incremental_step_proof =
88-
MohoTransitionWithProof::new(expected_moho_transition, proof.to_vec());
105+
assert_eq!(
106+
&expected_moho_transition,
107+
incremental_step_proof.transition()
108+
);
89109

90110
let step_predicate_merkle_proof = create_predicate_inclusion_proof(&moho_pre_state);
91111

92112
MohoRecursiveInput::new(
93-
moho_predicate_key(),
113+
compute_moho_predicate_key(),
94114
None,
95115
incremental_step_proof,
96-
asm_predicate_key(),
116+
asm_predicate,
97117
step_predicate_merkle_proof,
98118
)
99119
}

0 commit comments

Comments
 (0)