Skip to content

Commit

Permalink
fix: merge some errors to StackOnlyOpcode in bus-mapping (scroll-te…
Browse files Browse the repository at this point in the history
…ch#431)

* Merge some errors to `StackOnlyOpcode` in bus-mapping.

* Fix lint.
  • Loading branch information
silathdiir authored Mar 27, 2023
1 parent 8e5c529 commit bd58553
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 161 deletions.
30 changes: 14 additions & 16 deletions bus-mapping/src/evm/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,11 @@ mod error_invalid_creation_code;
mod error_invalid_jump;
mod error_oog_call;
mod error_oog_dynamic_memory;
mod error_oog_exp;
mod error_oog_log;
mod error_oog_memory_copy;
mod error_oog_sha3;
mod error_oog_sload_sstore;
mod error_oog_static_memory;
mod error_precompile_failed;
mod error_return_data_outofbound;
mod error_simple;
mod error_write_protection;

#[cfg(test)]
Expand All @@ -96,15 +92,11 @@ use error_invalid_creation_code::ErrorCreationCode;
use error_invalid_jump::InvalidJump;
use error_oog_call::OOGCall;
use error_oog_dynamic_memory::OOGDynamicMemory;
use error_oog_exp::OOGExp;
use error_oog_log::ErrorOOGLog;
use error_oog_memory_copy::OOGMemoryCopy;
use error_oog_sha3::OOGSha3;
use error_oog_sload_sstore::OOGSloadSstore;
use error_oog_static_memory::OOGStaticMemory;
use error_precompile_failed::PrecompileFailed;
use error_return_data_outofbound::ErrorReturnDataOutOfBound;
use error_simple::ErrorSimple;
use error_write_protection::ErrorWriteProtection;
use exp::Exponentiation;
use extcodecopy::Extcodecopy;
Expand Down Expand Up @@ -287,28 +279,34 @@ fn fn_gen_error_state_associated_ops(
) -> Option<FnGenAssociatedOps> {
match error {
ExecError::InvalidJump => Some(InvalidJump::gen_associated_ops),
ExecError::InvalidOpcode => Some(ErrorSimple::gen_associated_ops),
ExecError::InvalidOpcode => Some(StackOnlyOpcode::<0, 0, true>::gen_associated_ops),
ExecError::Depth => {
let op = geth_step.op;
assert!(op.is_call());
Some(fn_gen_associated_ops(&op))
}
ExecError::OutOfGas(OogError::Call) => Some(OOGCall::gen_associated_ops),
ExecError::OutOfGas(OogError::Constant) => Some(ErrorSimple::gen_associated_ops),
ExecError::OutOfGas(OogError::Constant) => {
Some(StackOnlyOpcode::<0, 0, true>::gen_associated_ops)
}
ExecError::OutOfGas(OogError::Log) => Some(ErrorOOGLog::gen_associated_ops),
ExecError::OutOfGas(OogError::DynamicMemoryExpansion) => {
Some(OOGDynamicMemory::gen_associated_ops)
}
ExecError::OutOfGas(OogError::StaticMemoryExpansion) => {
Some(OOGStaticMemory::gen_associated_ops)
Some(StackOnlyOpcode::<1, 0, true>::gen_associated_ops)
}
ExecError::OutOfGas(OogError::Exp) => {
Some(StackOnlyOpcode::<2, 0, true>::gen_associated_ops)
}
ExecError::OutOfGas(OogError::Exp) => Some(OOGExp::gen_associated_ops),
ExecError::OutOfGas(OogError::MemoryCopy) => Some(OOGMemoryCopy::gen_associated_ops),
ExecError::OutOfGas(OogError::Sha3) => Some(OOGSha3::gen_associated_ops),
ExecError::OutOfGas(OogError::Sha3) => {
Some(StackOnlyOpcode::<2, 0, true>::gen_associated_ops)
}
ExecError::OutOfGas(OogError::SloadSstore) => Some(OOGSloadSstore::gen_associated_ops),
// ExecError::
ExecError::StackOverflow => Some(ErrorSimple::gen_associated_ops),
ExecError::StackUnderflow => Some(ErrorSimple::gen_associated_ops),
ExecError::StackOverflow => Some(StackOnlyOpcode::<0, 0, true>::gen_associated_ops),
ExecError::StackUnderflow => Some(StackOnlyOpcode::<0, 0, true>::gen_associated_ops),
ExecError::CodeStoreOutOfGas => Some(ErrorCodeStore::gen_associated_ops),
ExecError::MaxCodeSizeExceeded => Some(ErrorCodeStore::gen_associated_ops),
// call & callcode can encounter InsufficientBalance error, Use pop-7 generic CallOpcode
Expand All @@ -331,7 +329,7 @@ fn fn_gen_error_state_associated_ops(
OpcodeId::CREATE2 => Some(StackOnlyOpcode::<4, 1>::gen_associated_ops),
_ => unreachable!(),
},
ExecError::GasUintOverflow => Some(ErrorSimple::gen_associated_ops),
ExecError::GasUintOverflow => Some(StackOnlyOpcode::<0, 0, true>::gen_associated_ops),
ExecError::InvalidCreationCode => Some(ErrorCreationCode::gen_associated_ops),
// more future errors place here
_ => {
Expand Down
38 changes: 0 additions & 38 deletions bus-mapping/src/evm/opcodes/error_oog_exp.rs

This file was deleted.

38 changes: 0 additions & 38 deletions bus-mapping/src/evm/opcodes/error_oog_sha3.rs

This file was deleted.

36 changes: 0 additions & 36 deletions bus-mapping/src/evm/opcodes/error_oog_static_memory.rs

This file was deleted.

31 changes: 0 additions & 31 deletions bus-mapping/src/evm/opcodes/error_simple.rs

This file was deleted.

18 changes: 16 additions & 2 deletions bus-mapping/src/evm/opcodes/stackonlyop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ use eth_types::GethExecStep;
/// - N = 2: BinaryOpcode
/// - N = 3: TernaryOpcode
#[derive(Debug, Copy, Clone)]
pub(crate) struct StackOnlyOpcode<const N_POP: usize, const N_PUSH: usize>;
pub(crate) struct StackOnlyOpcode<
const N_POP: usize,
const N_PUSH: usize,
const IS_ERR: bool = { false },
>;

impl<const N_POP: usize, const N_PUSH: usize> Opcode for StackOnlyOpcode<N_POP, N_PUSH> {
impl<const N_POP: usize, const N_PUSH: usize, const IS_ERR: bool> Opcode
for StackOnlyOpcode<N_POP, N_PUSH, IS_ERR>
{
fn gen_associated_ops(
state: &mut CircuitInputStateRef,
geth_steps: &[GethExecStep],
Expand All @@ -39,6 +45,14 @@ impl<const N_POP: usize, const N_PUSH: usize> Opcode for StackOnlyOpcode<N_POP,
)?;
}

if IS_ERR {
let next_step = geth_steps.get(1);
exec_step.error = state.get_step_err(geth_step, next_step).unwrap();

state.gen_restore_context_ops(&mut exec_step, geth_steps)?;
state.handle_return(geth_step)?;
}

Ok(vec![exec_step])
}
}
Expand Down

0 comments on commit bd58553

Please sign in to comment.