diff --git a/evm/src/cpu/kernel/asm/core/jumpdest_analysis.asm b/evm/src/cpu/kernel/asm/core/jumpdest_analysis.asm index aed6c186..c197fb6a 100644 --- a/evm/src/cpu/kernel/asm/core/jumpdest_analysis.asm +++ b/evm/src/cpu/kernel/asm/core/jumpdest_analysis.asm @@ -2,7 +2,7 @@ // for the given context's code. // Pre stack: init_pos, ctx, final_pos, retdest // Post stack: (empty) -global verify_path_and_write_table: +global verify_path_and_write_jumpdest_table: loop: // stack: i, ctx, final_pos, retdest DUP3 DUP2 EQ // i == final_pos @@ -10,7 +10,7 @@ loop: DUP3 DUP2 GT // i > final_pos %jumpi(proof_not_ok) - // stack: i, ctx, code_len, retdest + // stack: i, ctx, final_pos, retdest %stack (i, ctx) -> (ctx, i, i, ctx) ADD // combine context and offset to make an address (SEGMENT_CODE == 0) MLOAD_GENERAL @@ -124,7 +124,7 @@ global write_table_if_jumpdest: SWAP2 DUP1 // stack: proof_prefix_addr, proof_prefix_addr, ctx, jumpdest ISZERO - %jumpi(verify_path_and_write_table) + %jumpi(verify_path_and_write_jumpdest_table) // stack: proof_prefix_addr, ctx, jumpdest, retdest @@ -266,7 +266,7 @@ global write_table_if_jumpdest: %add_const(32) // check the remaining path - %jump(verify_path_and_write_table) + %jump(verify_path_and_write_jumpdest_table) return: // stack: proof_prefix_addr, jumpdest, ctx, retdest %pop3 diff --git a/evm/src/generation/mod.rs b/evm/src/generation/mod.rs index 238011d8..e14de9b9 100644 --- a/evm/src/generation/mod.rs +++ b/evm/src/generation/mod.rs @@ -379,7 +379,7 @@ fn simulate_cpu_between_labels_and_get_user_jumps( state.registers.program_counter, ))) else { log::debug!( - "Simulated CPU halted after {} cycles", + "Simulated CPU for jumpdest analysis halted after {} cycles", state.traces.clock() - initial_clock ); return Some(jumpdest_addresses); @@ -395,7 +395,7 @@ fn simulate_cpu_between_labels_and_get_user_jumps( // Avoid deeper calls to abort let Ok(jumpdest) = u256_to_usize(state.registers.stack_top) else { log::debug!( - "Simulated CPU halted after {} cycles", + "Simulated CPU for jumpdest analysis halted after {} cycles", state.traces.clock() - initial_clock ); return Some(jumpdest_addresses); @@ -416,7 +416,7 @@ fn simulate_cpu_between_labels_and_get_user_jumps( } if halt || transition(state).is_err() { log::debug!( - "Simulated CPU halted after {} cycles", + "Simulated CPU for jumpdest analysis halted after {} cycles", state.traces.clock() - initial_clock ); return Some(jumpdest_addresses); diff --git a/evm/src/generation/prover_input.rs b/evm/src/generation/prover_input.rs index 97177a8c..ccec9c45 100644 --- a/evm/src/generation/prover_input.rs +++ b/evm/src/generation/prover_input.rs @@ -240,6 +240,7 @@ impl GenerationState { } } + /// Generate the either the next used jump address or the the proof for the last jump address. fn run_jumpdest_table(&mut self, input_fn: &ProverInputFn) -> Result { match input_fn.0[1].as_str() { "next_address" => self.run_next_jumpdest_table_address(), @@ -293,6 +294,7 @@ impl GenerationState { } impl GenerationState { + /// Simulate the user's code and store all the jump addresses with their respective contexts. fn generate_jumpdest_proofs(&mut self) -> Result<(), ProgramError> { let checkpoint = self.checkpoint(); let memory = self.memory.clone(); @@ -322,6 +324,8 @@ impl GenerationState { Ok(()) } + /// Given a HashMap containing the contexts and the jumpdest addresses, compute their respective proofs, + /// by calling `get_proofs_and_jumpdests` pub(crate) fn set_proofs_and_jumpdests( &mut self, jumpdest_table: HashMap>, diff --git a/evm/src/util.rs b/evm/src/util.rs index ee2d9607..f4d80859 100644 --- a/evm/src/util.rs +++ b/evm/src/util.rs @@ -70,17 +70,17 @@ pub(crate) fn u256_to_u64(u256: U256) -> Result<(F, F), ProgramError> )) } -/// Safe conversion from U256 to u8, which errors in case of overflow instead of panicking. -pub(crate) fn u256_to_u8(u256: U256) -> Result { - u256.try_into().map_err(|_| ProgramError::IntegerTooLarge) -} - /// Safe alternative to `U256::as_usize()`, which errors in case of overflow instead of panicking. pub(crate) fn u256_to_usize(u256: U256) -> Result { u256.try_into().map_err(|_| ProgramError::IntegerTooLarge) } -/// Converts a `U256` to a `bool`, erroring in case of overlow instead of panicking. +/// Converts a `U256` to a `u8`, erroring in case of overflow instead of panicking. +pub(crate) fn u256_to_u8(u256: U256) -> Result { + u256.try_into().map_err(|_| ProgramError::IntegerTooLarge) +} + +/// Converts a `U256` to a `bool`, erroring in case of overflow instead of panicking. pub(crate) fn u256_to_bool(u256: U256) -> Result { if u256 == U256::zero() { Ok(false)