Skip to content

Commit

Permalink
bus-mapping: Implement OutOfGas(Constant) (privacy-scaling-exploratio…
Browse files Browse the repository at this point in the history
  • Loading branch information
pinkiebell authored Feb 8, 2023
1 parent a75c9aa commit 38b4fd4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions bus-mapping/src/evm/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ mod swap;

mod error_invalid_jump;
mod error_oog_call;
mod error_stack_oog_constant;

#[cfg(test)]
mod memory_expansion_test;
Expand All @@ -73,6 +74,7 @@ use create::DummyCreate;
use dup::Dup;
use error_invalid_jump::ErrorInvalidJump;
use error_oog_call::OOGCall;
use error_stack_oog_constant::ErrorStackOogConstant;
use exp::Exponentiation;
use extcodecopy::Extcodecopy;
use extcodehash::Extcodehash;
Expand Down Expand Up @@ -257,6 +259,9 @@ fn fn_gen_error_state_associated_ops(error: &ExecError) -> Option<FnGenAssociate
match error {
ExecError::InvalidJump => Some(ErrorInvalidJump::gen_associated_ops),
ExecError::OutOfGas(OogError::Call) => Some(OOGCall::gen_associated_ops),
ExecError::OutOfGas(OogError::Constant) => Some(ErrorStackOogConstant::gen_associated_ops),
ExecError::StackOverflow => Some(ErrorStackOogConstant::gen_associated_ops),
ExecError::StackUnderflow => Some(ErrorStackOogConstant::gen_associated_ops),
// call & callcode can encounter InsufficientBalance error, Use pop-7 generic CallOpcode
ExecError::InsufficientBalance => Some(CallOpcode::<7>::gen_associated_ops),
// more future errors place here
Expand Down
25 changes: 25 additions & 0 deletions bus-mapping/src/evm/opcodes/error_stack_oog_constant.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use crate::circuit_input_builder::{CircuitInputStateRef, ExecStep};
use crate::evm::Opcode;
use crate::Error;
use eth_types::GethExecStep;

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

impl Opcode for ErrorStackOogConstant {
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).unwrap();

// handles all required steps
state.gen_restore_context_ops(&mut exec_step, geth_steps)?;
state.handle_return(geth_step)?;

Ok(vec![exec_step])
}
}

0 comments on commit 38b4fd4

Please sign in to comment.