Apply suggestions from code review

Co-authored-by: Robin Salen <30937548+Nashtare@users.noreply.github.com>
This commit is contained in:
Alonso González 2023-12-15 09:49:19 +01:00 committed by GitHub
parent 746e13448b
commit 2c5347c45f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 16 deletions

View File

@ -370,7 +370,6 @@ call_too_deep:
GET_CONTEXT GET_CONTEXT
// stack: ctx, code_size, retdest // stack: ctx, code_size, retdest
%validate_jumpdest_table %validate_jumpdest_table
PUSH 0 // jump dest PUSH 0 // jump dest
EXIT_KERNEL EXIT_KERNEL
// (Old context) stack: new_ctx // (Old context) stack: new_ctx

View File

@ -122,9 +122,9 @@ global is_jumpdest:
//stack: jumpdest, ctx, proof_prefix_addr, retdest //stack: jumpdest, ctx, proof_prefix_addr, retdest
SWAP2 DUP1 SWAP2 DUP1
// stack: proof_prefix_addr, proof_prefix_addr, ctx, jumpdest // stack: proof_prefix_addr, proof_prefix_addr, ctx, jumpdest
%eq_const(0) IS_ZERO
%jumpi(verify_path) %jumpi(verify_path)
//stack: proof_prefix_addr, ctx, jumpdest, retdest // stack: proof_prefix_addr, ctx, jumpdest, retdest
// If we are here we need to check that the next 32 bytes are less // If we are here we need to check that the next 32 bytes are less
// than JUMPXX for XX < 32 - i <=> opcode < 0x7f - i = 127 - i, 0 <= i < 32, // than JUMPXX for XX < 32 - i <=> opcode < 0x7f - i = 127 - i, 0 <= i < 32,
// or larger than 127 // or larger than 127
@ -141,7 +141,7 @@ global is_jumpdest:
%jump(verify_path) %jump(verify_path)
return_is_jumpdest: return_is_jumpdest:
//stack: proof_prefix_addr, jumpdest, ctx, retdest // stack: proof_prefix_addr, jumpdest, ctx, retdest
%pop3 %pop3
JUMP JUMP
@ -187,7 +187,7 @@ global validate_jumpdest_table:
// and the next prover input should contain a proof for address'. // and the next prover input should contain a proof for address'.
PROVER_INPUT(jumpdest_table::next_address) PROVER_INPUT(jumpdest_table::next_address)
DUP1 %jumpi(check_proof) DUP1 %jumpi(check_proof)
// If proof == 0 there are no more jump destionations to check // If proof == 0 there are no more jump destinations to check
POP POP
// This is just a hook used for avoiding verification of the jumpdest // This is just a hook used for avoiding verification of the jumpdest
// table in another contexts. It is useful during proof generation, // table in another contexts. It is useful during proof generation,
@ -196,7 +196,7 @@ global validate_jumpdest_table_end:
POP POP
JUMP JUMP
check_proof: check_proof:
%sub_const(1) %decrement
DUP2 DUP2 DUP2 DUP2
// stack: address, ctx, address, ctx // stack: address, ctx, address, ctx
// We read the proof // We read the proof

View File

@ -303,7 +303,7 @@ impl<'a> Interpreter<'a> {
) )
} }
fn incr(&mut self, n: usize) { const fn incr(&mut self, n: usize) {
self.generation_state.registers.program_counter += n; self.generation_state.registers.program_counter += n;
} }

View File

@ -293,7 +293,7 @@ fn simulate_cpu_between_labels_and_get_user_jumps<F: Field>(
state.registers.program_counter = KERNEL.global_labels[initial_label]; state.registers.program_counter = KERNEL.global_labels[initial_label];
let context = state.registers.context; let context = state.registers.context;
log::debug!("Simulating CPU for jumpdest analysis "); log::debug!("Simulating CPU for jumpdest analysis.");
loop { loop {
if state.registers.program_counter == KERNEL.global_labels["validate_jumpdest_table"] { if state.registers.program_counter == KERNEL.global_labels["validate_jumpdest_table"] {
@ -317,7 +317,7 @@ fn simulate_cpu_between_labels_and_get_user_jumps<F: Field>(
{ {
// TODO: hotfix for avoiding deeper calls to abort // TODO: hotfix for avoiding deeper calls to abort
let jumpdest = u256_to_usize(state.registers.stack_top) let jumpdest = u256_to_usize(state.registers.stack_top)
.map_err(|_| anyhow::Error::msg("Not a valid jump destination"))?; .map_err(|_| anyhow!("Not a valid jump destination"))?;
state.memory.set( state.memory.set(
MemoryAddress { MemoryAddress {
context: state.registers.context, context: state.registers.context,

View File

@ -274,7 +274,7 @@ impl<F: Field> GenerationState<F> {
} }
} }
/// Return the proof for the last jump adddress /// Returns the proof for the last jump address.
fn run_next_jumpdest_table_proof(&mut self) -> Result<U256, ProgramError> { fn run_next_jumpdest_table_proof(&mut self) -> Result<U256, ProgramError> {
let code = (0..self.last_jumpdest_address) let code = (0..self.last_jumpdest_address)
.map(|i| { .map(|i| {
@ -286,12 +286,12 @@ impl<F: Field> GenerationState<F> {
}) })
.collect::<Result<Vec<u8>, _>>()?; .collect::<Result<Vec<u8>, _>>()?;
// TODO: The proof searching algorithm is not very eficient. But luckyly it doesn't seem // TODO: The proof searching algorithm is not very efficient. But luckily it doesn't seem
// a problem as is done natively. // a problem as is done natively.
// Search the closest address to last_jumpdest_address for which none of // Search the closest address to `last_jumpdest_address` for which none of
// the previous 32 bytes in the code (including opcodes and pushed bytes) // the previous 32 bytes in the code (including opcodes and pushed bytes)
// are PUSHXX and the address is in its range // are PUSHXX and the address is in its range.
let proof = CodeIterator::until(&code, self.last_jumpdest_address + 1).fold( let proof = CodeIterator::until(&code, self.last_jumpdest_address + 1).fold(
0, 0,
@ -340,9 +340,9 @@ impl<F: Field> GenerationState<F> {
}) })
.collect::<Result<Vec<u8>, _>>()?; .collect::<Result<Vec<u8>, _>>()?;
// We need to set the the simulated jumpdest bits to one as otherwise // We need to set the simulated jumpdest bits to one as otherwise
// the simulation will fail // the simulation will fail.
let mut jumpdest_table = vec![]; let mut jumpdest_table = Vec::with_capacity(code.len());
for (pos, opcode) in CodeIterator::new(&code) { for (pos, opcode) in CodeIterator::new(&code) {
jumpdest_table.push((pos, opcode == get_opcode("JUMPDEST"))); jumpdest_table.push((pos, opcode == get_opcode("JUMPDEST")));
if opcode == get_opcode("JUMPDEST") { if opcode == get_opcode("JUMPDEST") {