Address comments

This commit is contained in:
4l0n50 2024-01-10 17:26:34 +01:00
parent 92aaa404da
commit ae4a720a74
4 changed files with 17 additions and 13 deletions

View File

@ -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

View File

@ -379,7 +379,7 @@ fn simulate_cpu_between_labels_and_get_user_jumps<F: Field>(
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<F: Field>(
// 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<F: Field>(
}
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);

View File

@ -240,6 +240,7 @@ impl<F: Field> GenerationState<F> {
}
}
/// 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<U256, ProgramError> {
match input_fn.0[1].as_str() {
"next_address" => self.run_next_jumpdest_table_address(),
@ -293,6 +294,7 @@ impl<F: Field> GenerationState<F> {
}
impl<F: Field> GenerationState<F> {
/// 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<F: Field> GenerationState<F> {
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<usize, std::collections::BTreeSet<usize>>,

View File

@ -70,17 +70,17 @@ pub(crate) fn u256_to_u64<F: Field>(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<u8, ProgramError> {
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<usize, ProgramError> {
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<u8, ProgramError> {
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<bool, ProgramError> {
if u256 == U256::zero() {
Ok(false)