Skip to content
This repository was archived by the owner on Apr 18, 2025. 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
7 changes: 7 additions & 0 deletions Cargo.lock

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

15 changes: 4 additions & 11 deletions bus-mapping/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,10 @@ pub enum OogError {
Sload,
/// Out of Gas for SSTORE
Sstore,
/// Out of Gas for CALL
/// Out of Gas for CALL, CALLCODE, DELEGATECALL and STATICCALL
Call,
/// Out of Gas for CALLCODE
CallCode,
/// Out of Gas for DELEGATECALL
DelegateCall,
/// Out of Gas for CREATE2
Create2,
/// Out of Gas for STATICCALL
StaticCall,
/// Out of Gas for SELFDESTRUCT
SelfDestruct,
}
Expand Down Expand Up @@ -166,11 +160,10 @@ pub(crate) fn get_step_reported_error(op: &OpcodeId, error: &str) -> ExecError {
OpcodeId::EXTCODECOPY => OogError::ExtCodeCopy,
OpcodeId::SLOAD => OogError::Sload,
OpcodeId::SSTORE => OogError::Sstore,
OpcodeId::CALL => OogError::Call,
OpcodeId::CALLCODE => OogError::CallCode,
OpcodeId::DELEGATECALL => OogError::DelegateCall,
OpcodeId::CALL | OpcodeId::CALLCODE | OpcodeId::DELEGATECALL | OpcodeId::STATICCALL => {
OogError::Call
}
OpcodeId::CREATE2 => OogError::Create2,
OpcodeId::STATICCALL => OogError::StaticCall,
OpcodeId::SELFDESTRUCT => OogError::SelfDestruct,
_ => OogError::Constant,
};
Expand Down
34 changes: 21 additions & 13 deletions bus-mapping/src/evm/opcodes/error_oog_call.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use super::Opcode;
use crate::{
circuit_input_builder::{CircuitInputStateRef, ExecStep},
operation::{AccountField, CallContextField, TxAccessListAccountOp, RW},
Error,
};
use crate::circuit_input_builder::{CircuitInputStateRef, ExecStep};
use crate::operation::{AccountField, CallContextField, TxAccessListAccountOp, RW};
use crate::Error;
use eth_types::evm_types::OpcodeId;
use eth_types::{GethExecStep, ToAddress, ToWord, Word};

/// Placeholder structure used to implement [`Opcode`] trait over it
/// corresponding to the `OpcodeId::CALL` `OpcodeId`.
/// corresponding to the out of gas errors for [`OpcodeId::CALL`],
/// [`OpcodeId::CALLCODE`], [`OpcodeId::DELEGATECALL`] and
/// [`OpcodeId::STATICCALL`].
#[derive(Debug, Copy, Clone)]
pub(crate) struct OOGCall;

Expand All @@ -17,6 +18,12 @@ impl Opcode for OOGCall {
geth_steps: &[GethExecStep],
) -> Result<Vec<ExecStep>, Error> {
let geth_step = &geth_steps[0];
let stack_input_num = match geth_step.op {
OpcodeId::CALL | OpcodeId::CALLCODE => 7,
OpcodeId::DELEGATECALL | OpcodeId::STATICCALL => 6,
op => unreachable!("{op} should not happen in OOGCall"),
};

let mut exec_step = state.new_step(geth_step)?;
let next_step = if geth_steps.len() > 1 {
Some(&geth_steps[1])
Expand All @@ -25,10 +32,10 @@ impl Opcode for OOGCall {
};
exec_step.error = state.get_step_err(geth_step, next_step).unwrap();

let args_offset = geth_step.stack.nth_last(3)?.as_usize();
let args_length = geth_step.stack.nth_last(4)?.as_usize();
let ret_offset = geth_step.stack.nth_last(5)?.as_usize();
let ret_length = geth_step.stack.nth_last(6)?.as_usize();
let args_offset = geth_step.stack.nth_last(stack_input_num - 4)?.as_usize();
let args_length = geth_step.stack.nth_last(stack_input_num - 3)?.as_usize();
let ret_offset = geth_step.stack.nth_last(stack_input_num - 2)?.as_usize();
let ret_length = geth_step.stack.nth_last(stack_input_num - 1)?.as_usize();

state.call_expand_memory(args_offset, args_length, ret_offset, ret_length)?;

Expand All @@ -46,7 +53,7 @@ impl Opcode for OOGCall {
state.call_context_read(&mut exec_step, current_call.call_id, field, value);
}

for i in 0..7 {
for i in 0..stack_input_num {
state.stack_read(
&mut exec_step,
geth_step.stack.nth_last_filled(i),
Expand All @@ -56,8 +63,9 @@ impl Opcode for OOGCall {

state.stack_write(
&mut exec_step,
geth_step.stack.nth_last_filled(6),
(0u64).into(), // must fail
geth_step.stack.nth_last_filled(stack_input_num - 1),
// Must fail.
(0_u64).into(),
)?;

let (_, callee_account) = state.sdb.get_account(&call_address);
Expand Down
6 changes: 3 additions & 3 deletions circuit-benchmarks/src/bytecode_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ mod tests {
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;
use std::env::var;
use zkevm_circuits::bytecode_circuit::bytecode_unroller::{
unroll, BytecodeCircuit, UnrolledBytecode,
};
use zkevm_circuits::bytecode_circuit::bytecode_unroller::{unroll, UnrolledBytecode};

use zkevm_circuits::bytecode_circuit::circuit::BytecodeCircuit;

#[cfg_attr(not(feature = "benches"), ignore)]
#[test]
Expand Down
16 changes: 14 additions & 2 deletions circuit-benchmarks/src/super_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#[cfg(test)]
mod tests {
use ark_std::{end_timer, start_timer};
use bus_mapping::circuit_input_builder::CircuitsParams;
use eth_types::geth_types::GethData;
use eth_types::{address, bytecode, Word};
use ethers_signers::LocalWallet;
Expand Down Expand Up @@ -71,7 +72,18 @@ mod tests {

block.sign(&wallets);

let (_, circuit, instance, _) = SuperCircuit::<_, 1, 32, 512, 512>::build(block).unwrap();
const MAX_TXS: usize = 1;
const MAX_CALLDATA: usize = 32;
let circuits_params = CircuitsParams {
max_txs: MAX_TXS,
max_calldata: MAX_CALLDATA,
max_rws: 256,
max_copy_rows: 256,
max_bytecode: 512,
keccak_padding: None,
};
let (_, circuit, instance, _) =
SuperCircuit::<_, MAX_TXS, MAX_CALLDATA, 0x100>::build(block, circuits_params).unwrap();
let instance_refs: Vec<&[Fr]> = instance.iter().map(|v| &v[..]).collect();

// Bench setup generation
Expand All @@ -96,7 +108,7 @@ mod tests {
Challenge255<G1Affine>,
ChaChaRng,
Blake2bWrite<Vec<u8>, G1Affine, Challenge255<G1Affine>>,
SuperCircuit<Fr, 1, 32, 512, 512>,
SuperCircuit<Fr, MAX_TXS, MAX_CALLDATA, 0x100>,
>(
&general_params,
&pk,
Expand Down
Loading