@@ -22,7 +22,7 @@ use zkaleido::{PerformanceReport, ProofReceiptWithMetadata, ZkVmProgram, ZkVmPro
2222use zkaleido_sp1_groth16_verifier:: VK_HASH_PREFIX_LENGTH ;
2323use zkaleido_sp1_host:: SP1Host ;
2424
25- use crate :: programs:: { asm_stf :: asm_predicate_key , compute_sp1_predicate_key} ;
25+ use crate :: programs:: compute_sp1_predicate_key;
2626
2727static 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+
4973pub ( 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. clone ( ) ) ;
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 . clone ( ) ) ;
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