@@ -9,17 +9,19 @@ use core::cmp::Ordering;
99use std:: collections:: { BTreeSet , HashMap } ;
1010
1111use anyhow:: anyhow;
12- use ethereum_types:: { BigEndianHash , U256 } ;
12+ use ethereum_types:: { BigEndianHash , U256 , H256 } ;
1313use log:: Level ;
1414use mpt_trie:: partial_trie:: PartialTrie ;
1515use plonky2:: field:: types:: Field ;
16+ //use alloy::primitives::Address;
1617
1718use crate :: byte_packing:: byte_packing_stark:: BytePackingOp ;
1819use crate :: cpu:: columns:: CpuColumnsView ;
1920use crate :: cpu:: kernel:: aggregator:: KERNEL ;
2021use crate :: cpu:: kernel:: constants:: global_metadata:: GlobalMetadata ;
2122use crate :: generation:: debug_inputs;
2223use crate :: generation:: mpt:: load_all_mpts;
24+ use crate :: generation:: prover_input:: { get_proofs_and_jumpdests, JumpDestTableProcessed , JumpDestTableRaw } ;
2325use crate :: generation:: rlp:: all_rlp_prover_inputs_reversed;
2426use crate :: generation:: state:: {
2527 all_withdrawals_prover_inputs_reversed, GenerationState , GenerationStateCheckpoint ,
@@ -62,10 +64,12 @@ pub(crate) struct Interpreter<F: Field> {
6264
6365/// Simulates the CPU execution from `state` until the program counter reaches
6466/// `final_label` in the current context.
67+ /// TODO: main fun
68+ #[ deprecated( note = "use rpc to get jumpdests instead" ) ]
6569pub ( crate ) fn simulate_cpu_and_get_user_jumps < F : Field > (
6670 final_label : & str ,
6771 state : & GenerationState < F > ,
68- ) -> Option < HashMap < usize , Vec < usize > > > {
72+ ) -> Option < HashMap < usize , Vec < usize > > > {
6973 match state. jumpdest_table {
7074 Some ( _) => None ,
7175 None => {
@@ -90,6 +94,58 @@ pub(crate) fn simulate_cpu_and_get_user_jumps<F: Field>(
9094 }
9195}
9296
97+ // todo: remove. for easy comparison only
98+ #[ deprecated( note = "use rpc to get jumpdests instead" ) ]
99+ pub ( crate ) fn simulate_cpu_and_get_user_jumps_rpc < F : Field > (
100+ final_label : & str ,
101+ state : & GenerationState < F > ,
102+ ) -> Option < JumpDestTableProcessed > {
103+ match state. jumpdest_table {
104+ Some ( _) => None ,
105+ None => {
106+ let halt_pc = KERNEL . global_labels [ final_label] ;
107+ let initial_context = state. registers . context ;
108+ let mut interpreter =
109+ Interpreter :: new_with_state_and_halt_condition ( state, halt_pc, initial_context) ;
110+
111+ log:: debug!( "Simulating CPU for jumpdest analysis." ) ;
112+
113+ let _ = interpreter. run ( ) ;
114+
115+ log:: trace!( "jumpdest table = {:?}" , interpreter. jumpdest_table) ;
116+
117+ //debug_assert_eq!(&interpreter.jumpdest_table, &state.inputs.jumpdest_table);
118+ let jumpdest_table = set_jumpdest_analysis_inputs_rpc ( & state. inputs . jumpdest_table , & state. inputs . contract_code ) ;
119+
120+ Some ( jumpdest_table)
121+ }
122+ }
123+ }
124+
125+ /// Given a HashMap containing the contexts and the jumpdest addresses, compute
126+ /// their respective proofs, by calling `get_proofs_and_jumpdests`
127+ pub ( crate ) fn set_jumpdest_analysis_inputs_rpc (
128+ jumpdest_table_rpc : & JumpDestTableRaw ,
129+ codes : & HashMap < H256 , Vec < u8 > > ,
130+ ) -> JumpDestTableProcessed {
131+ JumpDestTableProcessed ( jumpdest_table_rpc. 0 . iter ( ) . flat_map ( |( code_address, ctx_table) | {
132+ ctx_table. 0 . iter ( ) . map ( |( & ctx, jumpdest_table) | {
133+ let code = & codes[ code_address] ;
134+ if let Some ( & largest_address) = jumpdest_table. last ( ) {
135+ // maybe just serialize it as BTreeSet and avoid conversion
136+ // this is consistent with:
137+ // https://doc.rust-lang.org/std/collections/struct.BTreeSet.html#method.last
138+ // let jdt: BTreeSet<usize> = jumpdest_table.into_iter().collect();
139+ let proofs = get_proofs_and_jumpdests ( code, largest_address, jumpdest_table. clone ( ) ) ;
140+ ( ctx, proofs)
141+ } else {
142+ ( ctx, vec ! [ ] )
143+ }
144+ } ) . collect :: < HashMap < usize , Vec < _ > > > ( )
145+ } ) . collect ( ) )
146+ }
147+
148+
93149impl < F : Field > Interpreter < F > {
94150 /// Returns an instance of `Interpreter` given `GenerationInputs`, and
95151 /// assuming we are initializing with the `KERNEL` code.
@@ -350,6 +406,7 @@ impl<F: Field> Interpreter<F> {
350406 }
351407
352408 pub ( crate ) fn add_jumpdest_offset ( & mut self , offset : usize ) {
409+ println ! ( "SIM: ({:?}, {:?})" , & self . generation_state. registers. context, offset) ;
353410 if let Some ( jumpdest_table) = self
354411 . jumpdest_table
355412 . get_mut ( & self . generation_state . registers . context )
@@ -506,7 +563,7 @@ impl<F: Field> State<F> for Interpreter<F> {
506563 let registers = self . generation_state . registers ;
507564 let ( mut row, opcode) = self . base_row ( ) ;
508565
509- let op = decode ( registers, opcode) ?;
566+ let op: Operation = decode ( registers, opcode) ?;
510567
511568 fill_op_flag ( op, & mut row) ;
512569
0 commit comments