@@ -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,11 @@ 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
6568pub ( crate ) fn simulate_cpu_and_get_user_jumps < F : Field > (
6669 final_label : & str ,
6770 state : & GenerationState < F > ,
68- ) -> Option < HashMap < usize , Vec < usize > > > {
71+ ) -> Option < HashMap < usize , Vec < usize > > > {
6972 match state. jumpdest_table {
7073 Some ( _) => None ,
7174 None => {
@@ -90,6 +93,58 @@ pub(crate) fn simulate_cpu_and_get_user_jumps<F: Field>(
9093 }
9194}
9295
96+ // todo: remove. for easy comparison only
97+ #[ deprecated( note = "use rpc to get jumpdests instead" ) ]
98+ pub ( crate ) fn simulate_cpu_and_get_user_jumps_rpc < F : Field > (
99+ final_label : & str ,
100+ state : & GenerationState < F > ,
101+ ) -> Option < JumpDestTableProcessed > {
102+ match state. jumpdest_table {
103+ Some ( _) => None ,
104+ None => {
105+ let halt_pc = KERNEL . global_labels [ final_label] ;
106+ let initial_context = state. registers . context ;
107+ let mut interpreter =
108+ Interpreter :: new_with_state_and_halt_condition ( state, halt_pc, initial_context) ;
109+
110+ log:: debug!( "Simulating CPU for jumpdest analysis." ) ;
111+
112+ let _ = interpreter. run ( ) ;
113+
114+ log:: trace!( "jumpdest table = {:?}" , interpreter. jumpdest_table) ;
115+
116+ //debug_assert_eq!(&interpreter.jumpdest_table, &state.inputs.jumpdest_table);
117+ let jumpdest_table = set_jumpdest_analysis_inputs_rpc ( & state. inputs . jumpdest_table , & state. inputs . contract_code ) ;
118+
119+ Some ( jumpdest_table)
120+ }
121+ }
122+ }
123+
124+ /// Given a HashMap containing the contexts and the jumpdest addresses, compute
125+ /// their respective proofs, by calling `get_proofs_and_jumpdests`
126+ pub ( crate ) fn set_jumpdest_analysis_inputs_rpc (
127+ jumpdest_table_rpc : & JumpDestTableRaw ,
128+ codes : & HashMap < H256 , Vec < u8 > > ,
129+ ) -> JumpDestTableProcessed {
130+ JumpDestTableProcessed ( jumpdest_table_rpc. 0 . iter ( ) . flat_map ( |( code_address, ctx_table) | {
131+ ctx_table. 0 . iter ( ) . map ( |( & ctx, jumpdest_table) | {
132+ let code = & codes[ code_address] ;
133+ if let Some ( & largest_address) = jumpdest_table. last ( ) {
134+ // maybe just serialize it as BTreeSet and avoid conversion
135+ // this is consistent with:
136+ // https://doc.rust-lang.org/std/collections/struct.BTreeSet.html#method.last
137+ // let jdt: BTreeSet<usize> = jumpdest_table.into_iter().collect();
138+ let proofs = get_proofs_and_jumpdests ( code, largest_address, jumpdest_table. clone ( ) ) ;
139+ ( ctx, proofs)
140+ } else {
141+ ( ctx, vec ! [ ] )
142+ }
143+ } ) . collect :: < HashMap < usize , Vec < _ > > > ( )
144+ } ) . collect ( ) )
145+ }
146+
147+
93148impl < F : Field > Interpreter < F > {
94149 /// Returns an instance of `Interpreter` given `GenerationInputs`, and
95150 /// assuming we are initializing with the `KERNEL` code.
@@ -350,6 +405,7 @@ impl<F: Field> Interpreter<F> {
350405 }
351406
352407 pub ( crate ) fn add_jumpdest_offset ( & mut self , offset : usize ) {
408+ println ! ( "SIM: ({:?}, {:?})" , & self . generation_state. registers. context, offset) ;
353409 if let Some ( jumpdest_table) = self
354410 . jumpdest_table
355411 . get_mut ( & self . generation_state . registers . context )
@@ -506,7 +562,7 @@ impl<F: Field> State<F> for Interpreter<F> {
506562 let registers = self . generation_state . registers ;
507563 let ( mut row, opcode) = self . base_row ( ) ;
508564
509- let op = decode ( registers, opcode) ?;
565+ let op: Operation = decode ( registers, opcode) ?;
510566
511567 fill_op_flag ( op, & mut row) ;
512568
0 commit comments