Skip to content

Commit

Permalink
better err log: (1) return err for copy circuit overflow (2) log::war… (
Browse files Browse the repository at this point in the history
#1409)

* better err log: (1) return err for copy circuit overflow (2) log::warn for state root mismatch

* update poseidon-base
  • Loading branch information
lispc authored Aug 29, 2024
1 parent 41f0c6d commit e319bee
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 25 deletions.
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions bus-mapping/src/circuit_input_builder/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,17 @@ impl Blocks {

impl Blocks {
/// Push a copy event to the block.
pub fn add_copy_event(&mut self, event: CopyEvent) {
pub fn add_copy_event(&mut self, event: CopyEvent) -> Result<(), Error> {
self.copy_counter += event.full_length() as usize;
self.copy_events.push(event);
// Each byte needs 2 rows
// TODO: magic num

if self.copy_counter > 500_000 && cfg!(feature = "strict-ccc") {
log::error!("copy event len overflow {}", self.copy_counter);
panic!("copy event len overflow");
return Err(Error::InvalidGethExecTrace("copy event len overflow"));
}
Ok(())
}
fn copy_event_total_len(&self) -> usize {
self.copy_events
Expand Down
8 changes: 6 additions & 2 deletions bus-mapping/src/circuit_input_builder/input_state_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1629,9 +1629,13 @@ impl<'a> CircuitInputStateRef<'a> {
}

/// Push a copy event to the state.
pub fn push_copy(&mut self, step: &mut ExecStep, event: CopyEvent) {
pub fn push_copy(&mut self, step: &mut ExecStep, event: CopyEvent) -> Result<(), Error> {
step.copy_rw_counter_delta += event.rw_counter_delta();
self.block.add_copy_event(event);
let result = self.block.add_copy_event(event);
if result.is_err() {
log::error!("push_copy failed {result:?}, step {step:?}");
}
result
}

/// Push a exponentiation event to the state.
Expand Down
8 changes: 4 additions & 4 deletions bus-mapping/src/evm/opcodes/begin_end_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ pub fn gen_begin_tx_steps(state: &mut CircuitInputStateRef) -> Result<Vec<ExecSt
copy_bytes: CopyBytes::new(bytes, None, None),
access_list: vec![],
},
);
)?;
}

let mut precompile_step = None;
Expand Down Expand Up @@ -466,7 +466,7 @@ pub fn gen_begin_tx_steps(state: &mut CircuitInputStateRef) -> Result<Vec<ExecSt
copy_bytes: CopyBytes::new(copy_steps, None, None),
access_list: vec![],
},
);
)?;

let call_success = call.is_success;
// modexp's oog error is handled in ModExpGadget
Expand Down Expand Up @@ -908,7 +908,7 @@ fn add_access_list_address_copy_event(
log_id: None,
};

state.push_copy(exec_step, copy_event);
state.push_copy(exec_step, copy_event)?;

Ok(())
}
Expand Down Expand Up @@ -993,7 +993,7 @@ fn add_access_list_storage_key_copy_event(
log_id: None,
};

state.push_copy(exec_step, copy_event);
state.push_copy(exec_step, copy_event)?;

Ok(())
}
2 changes: 1 addition & 1 deletion bus-mapping/src/evm/opcodes/calldatacopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Opcode for Calldatacopy {
};

let copy_event = gen_copy_event(state, memory_offset, data_offset, length, &mut exec_step)?;
state.push_copy(&mut exec_step, copy_event);
state.push_copy(&mut exec_step, copy_event)?;
Ok(vec![exec_step])
}
}
Expand Down
6 changes: 3 additions & 3 deletions bus-mapping/src/evm/opcodes/callop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ impl<const N_ARGS: usize> Opcode for CallOpcode<N_ARGS> {
copy_bytes: CopyBytes::new(copy_steps, None, None),
access_list: vec![],
},
);
)?;
Some(input_bytes)
} else {
None
Expand Down Expand Up @@ -446,7 +446,7 @@ impl<const N_ARGS: usize> Opcode for CallOpcode<N_ARGS> {
copy_bytes: CopyBytes::new(copy_steps, None, Some(prev_bytes)),
access_list: vec![],
},
);
)?;
Some(output_bytes)
} else {
None
Expand Down Expand Up @@ -486,7 +486,7 @@ impl<const N_ARGS: usize> Opcode for CallOpcode<N_ARGS> {
),
access_list: vec![],
},
);
)?;
Some(returned_bytes)
} else {
None
Expand Down
2 changes: 1 addition & 1 deletion bus-mapping/src/evm/opcodes/codecopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Opcode for Codecopy {
length.as_u64(),
&mut exec_step,
)?;
state.push_copy(&mut exec_step, copy_event);
state.push_copy(&mut exec_step, copy_event)?;
Ok(vec![exec_step])
}
}
Expand Down
2 changes: 1 addition & 1 deletion bus-mapping/src/evm/opcodes/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ fn handle_copy(
copy_bytes: CopyBytes::new(copy_steps, None, None),
access_list: vec![],
},
);
)?;

Ok((initcode, keccak_code_hash, code_hash))
}
Expand Down
2 changes: 1 addition & 1 deletion bus-mapping/src/evm/opcodes/extcodecopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl Opcode for Extcodecopy {
length,
&mut exec_step,
)?;
state.push_copy(&mut exec_step, copy_event);
state.push_copy(&mut exec_step, copy_event)?;
Ok(vec![exec_step])
}
}
Expand Down
2 changes: 1 addition & 1 deletion bus-mapping/src/evm/opcodes/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Opcode for Log {
// https://github.com/ethereum/go-ethereum/blob/b80f05bde2c4e93ae64bb3813b6d67266b5fc0e6/core/vm/instructions.go#L850
let copy_event =
gen_copy_event(state, mstart.low_u64(), msize.low_u64(), &mut exec_step)?;
state.push_copy(&mut exec_step, copy_event);
state.push_copy(&mut exec_step, copy_event)?;
state.tx_ctx.log_id += 1;
}

Expand Down
2 changes: 1 addition & 1 deletion bus-mapping/src/evm/opcodes/mcopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Opcode for MCopy {
length.as_u64(),
&mut exec_step,
)?;
state.push_copy(&mut exec_step, copy_event);
state.push_copy(&mut exec_step, copy_event)?;
Ok(vec![exec_step])
}
}
Expand Down
4 changes: 2 additions & 2 deletions bus-mapping/src/evm/opcodes/return_revert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ fn handle_copy(
copy_bytes: CopyBytes::new(read_steps, Some(write_steps), Some(dst_data_prev)),
access_list: vec![],
},
);
)?;

Ok(())
}
Expand Down Expand Up @@ -363,7 +363,7 @@ fn handle_create(
copy_bytes: CopyBytes::new(copy_steps, None, None),
access_list: vec![],
},
);
)?;

Ok(AccountCodeInfo {
keccak_hash,
Expand Down
2 changes: 1 addition & 1 deletion bus-mapping/src/evm/opcodes/returndatacopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Opcode for Returndatacopy {
}

let copy_event = gen_copy_event(state, memory_offset, data_offset, length, &mut exec_step)?;
state.push_copy(&mut exec_step, copy_event);
state.push_copy(&mut exec_step, copy_event)?;
Ok(vec![exec_step])
}
}
Expand Down
2 changes: 1 addition & 1 deletion bus-mapping/src/evm/opcodes/sha3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Opcode for Sha3 {
copy_bytes: CopyBytes::new(copy_steps, None, None),
access_list: vec![],
},
);
)?;

Ok(vec![exec_step])
}
Expand Down
3 changes: 2 additions & 1 deletion zkevm-circuits/src/witness/mpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,14 @@ impl MptUpdates {

let root_pair2 = (self.old_root, self.new_root);
if root_pair2 != root_pair {
log::error!(
log::warn!(
"roots non consistent ({:#x},{:#x}) vs ({:#x},{:#x})",
root_pair.0,
root_pair.1,
root_pair2.0,
root_pair2.1
);
#[cfg(debug_assertions)]
wit_gen.dump(
self.updates
.iter()
Expand Down

0 comments on commit e319bee

Please sign in to comment.