Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bus-mapping/src/evm/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ mod stackonlyop;
mod stop;
mod swap;

mod error_code_store;
mod error_invalid_jump;
mod error_oog_call;
mod error_oog_exp;
Expand Down Expand Up @@ -71,6 +72,7 @@ use codecopy::Codecopy;
use codesize::Codesize;
use create::Create;
use dup::Dup;
use error_code_store::ErrorCodeStore;
use error_invalid_jump::InvalidJump;
use error_oog_call::OOGCall;
use error_oog_exp::OOGExp;
Expand All @@ -80,6 +82,7 @@ use error_oog_sload_sstore::OOGSloadSstore;
use error_return_data_outofbound::ErrorReturnDataOutOfBound;
use error_simple::ErrorSimple;
use error_write_protection::ErrorWriteProtection;

use exp::Exponentiation;
use extcodecopy::Extcodecopy;
use extcodehash::Extcodehash;
Expand Down Expand Up @@ -297,6 +300,8 @@ fn fn_gen_error_state_associated_ops(error: &ExecError) -> Option<FnGenAssociate
}
ExecError::WriteProtection => Some(ErrorWriteProtection::gen_associated_ops),
ExecError::ReturnDataOutOfBounds => Some(ErrorReturnDataOutOfBound::gen_associated_ops),
ExecError::CodeStoreOutOfGas => Some(ErrorCodeStore::gen_associated_ops),
ExecError::MaxCodeSizeExceeded => Some(ErrorCodeStore::gen_associated_ops),
// call, callcode, create & create2 can encounter DepthError error,
ExecError::Depth(DepthError::Call) => Some(CallOpcode::<7>::gen_associated_ops),
ExecError::Depth(DepthError::Create) => Some(Create::<false>::gen_associated_ops),
Expand Down
42 changes: 42 additions & 0 deletions bus-mapping/src/evm/opcodes/error_code_store.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use crate::{
circuit_input_builder::{CircuitInputStateRef, ExecStep},
error::ExecError,
evm::Opcode,
Error,
};
use eth_types::GethExecStep;

#[derive(Debug, Copy, Clone)]
pub struct ErrorCodeStore;

impl Opcode for ErrorCodeStore {
fn gen_associated_ops(
state: &mut CircuitInputStateRef,
geth_steps: &[GethExecStep],
) -> Result<Vec<ExecStep>, Error> {
let geth_step = &geth_steps[0];
let mut exec_step = state.new_step(geth_step)?;
let next_step = geth_steps.get(1);

exec_step.error = state.get_step_err(geth_step, next_step)?;

assert!(
exec_step.error == Some(ExecError::CodeStoreOutOfGas)
|| exec_step.error == Some(ExecError::MaxCodeSizeExceeded)
);

let offset = geth_step.stack.nth_last(0)?;
let length = geth_step.stack.nth_last(1)?;
state.stack_read(&mut exec_step, geth_step.stack.nth_last_filled(0), offset)?;
state.stack_read(&mut exec_step, geth_step.stack.nth_last_filled(1), length)?;

// in internal call context
let call = state.call()?;

// create context check
assert!(call.is_create());

state.handle_return(&mut exec_step, geth_steps, true)?;
Ok(vec![exec_step])
}
}
15 changes: 11 additions & 4 deletions zkevm-circuits/src/evm_circuit/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ mod dummy;
mod dup;
mod end_block;
mod end_tx;
mod error_code_store;
mod error_invalid_jump;
mod error_invalid_opcode;
mod error_oog_call;
Expand All @@ -76,6 +77,7 @@ mod error_oog_static_memory;
mod error_return_data_oo_bound;
mod error_stack;
mod error_write_protection;

mod exp;
mod extcodecopy;
mod extcodehash;
Expand Down Expand Up @@ -137,6 +139,7 @@ use dummy::DummyGadget;
use dup::DupGadget;
use end_block::EndBlockGadget;
use end_tx::EndTxGadget;
use error_code_store::ErrorCodeStoreGadget;
use error_invalid_jump::ErrorInvalidJumpGadget;
use error_invalid_opcode::ErrorInvalidOpcodeGadget;
use error_oog_call::ErrorOOGCallGadget;
Expand All @@ -148,6 +151,7 @@ use error_oog_sload_sstore::ErrorOOGSloadSstoreGadget;
use error_return_data_oo_bound::ErrorReturnDataOutOfBoundGadget;
use error_stack::ErrorStackGadget;
use error_write_protection::ErrorWriteProtectionGadget;

use exp::ExponentiationGadget;
use extcodecopy::ExtcodecopyGadget;
use extcodehash::ExtcodehashGadget;
Expand Down Expand Up @@ -305,7 +309,9 @@ pub struct ExecutionConfig<F> {
error_oog_create2: Box<DummyGadget<F, 0, 0, { ExecutionState::ErrorOutOfGasCREATE2 }>>,
error_oog_self_destruct:
Box<DummyGadget<F, 0, 0, { ExecutionState::ErrorOutOfGasSELFDESTRUCT }>>,
error_oog_code_store: Box<DummyGadget<F, 0, 0, { ExecutionState::ErrorOutOfGasCodeStore }>>,
error_code_store: Box<ErrorCodeStoreGadget<F>>,
error_insufficient_balance:
Box<DummyGadget<F, 0, 0, { ExecutionState::ErrorInsufficientBalance }>>,
error_invalid_jump: Box<ErrorInvalidJumpGadget<F>>,
error_invalid_opcode: Box<ErrorInvalidOpcodeGadget<F>>,
error_depth: Box<DummyGadget<F, 0, 0, { ExecutionState::ErrorDepth }>>,
Expand Down Expand Up @@ -567,7 +573,8 @@ impl<F: Field> ExecutionConfig<F> {
error_oog_exp: configure_gadget!(),
error_oog_create2: configure_gadget!(),
error_oog_self_destruct: configure_gadget!(),
error_oog_code_store: configure_gadget!(),
error_code_store: configure_gadget!(),
error_insufficient_balance: configure_gadget!(),
error_invalid_jump: configure_gadget!(),
error_invalid_opcode: configure_gadget!(),
error_write_protection: configure_gadget!(),
Expand Down Expand Up @@ -1276,8 +1283,8 @@ impl<F: Field> ExecutionConfig<F> {
assign_exec_step!(self.error_oog_self_destruct)
}

ExecutionState::ErrorOutOfGasCodeStore => {
assign_exec_step!(self.error_oog_code_store)
ExecutionState::ErrorCodeStore => {
assign_exec_step!(self.error_code_store)
}
ExecutionState::ErrorStack => {
assign_exec_step!(self.error_stack)
Expand Down
Loading