Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.
Merged
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
51 changes: 37 additions & 14 deletions bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use crate::state_db::{self, CodeDB, StateDB};
use crate::Error;
use core::fmt::Debug;
use eth_types::evm_types::{Gas, GasCost, MemoryAddress, OpcodeId, ProgramCounter, StackAddress};
use eth_types::{self, Address, GethExecStep, GethExecTrace, Hash, ToAddress, ToBigEndian, Word};
use eth_types::{
self, Address, GethExecStep, GethExecTrace, Hash, ToAddress, ToBigEndian, Word, U256,
};
use ethers_core::utils::{get_contract_address, get_create2_address};
use std::collections::{hash_map::Entry, BTreeMap, HashMap, HashSet};

Expand Down Expand Up @@ -139,22 +141,43 @@ impl ExecState {
}
}

/// Auxiliary data for CopyToMemory internal state.
#[derive(Clone, Copy, Debug)]
pub struct CopyToMemoryAuxData {
/// Source start address
pub src_addr: u64,
/// Destination address
pub dst_addr: u64,
/// Bytes left
pub bytes_left: u64,
/// Source end address
pub src_addr_end: u64,
/// Indicate if copy from transaction call data
pub from_tx: bool,
}

/// Auxiliary data for CopyCodeToMemory internal state.
#[derive(Clone, Copy, Debug)]
pub struct CopyCodeToMemoryAuxData {
/// Source start address
pub src_addr: u64,
/// Destination address
pub dst_addr: u64,
/// Bytes left
pub bytes_left: u64,
/// Source end address
pub src_addr_end: u64,
/// Hash of the bytecode to be copied
pub code_source: U256,
}

/// Auxiliary data of Execution step
#[derive(Clone, Debug)]
#[derive(Clone, Copy, Debug)]
pub enum StepAuxiliaryData {
/// Auxiliary data of Copy To Memory
CopyToMemory {
/// Source start address
src_addr: u64,
/// Destination address
dst_addr: u64,
/// Bytes left
bytes_left: u64,
/// Source end address
src_addr_end: u64,
/// Indicate if copy from transaction call data
from_tx: bool,
},
CopyToMemory(CopyToMemoryAuxData),
/// Auxiliary data of Copy Code To Memory
CopyCodeToMemory(CopyCodeToMemoryAuxData),
}

/// An execution step of the EVM.
Expand Down
8 changes: 5 additions & 3 deletions bus-mapping/src/evm/opcodes/calldatacopy.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use super::Opcode;
use crate::circuit_input_builder::{CircuitInputStateRef, ExecState, ExecStep, StepAuxiliaryData};
use crate::circuit_input_builder::{
CircuitInputStateRef, CopyToMemoryAuxData, ExecState, ExecStep, StepAuxiliaryData,
};
use crate::operation::{CallContextField, CallContextOp, RW};
use crate::Error;
use eth_types::GethExecStep;
Expand Down Expand Up @@ -108,13 +110,13 @@ fn gen_memory_copy_step(
state.push_memory_op(exec_step, RW::WRITE, (idx + dst_addr as usize).into(), byte)?;
}

exec_step.aux_data = Some(StepAuxiliaryData::CopyToMemory {
exec_step.aux_data = Some(StepAuxiliaryData::CopyToMemory(CopyToMemoryAuxData {
src_addr,
dst_addr,
bytes_left: bytes_left as u64,
src_addr_end,
from_tx: is_root,
});
}));

Ok(())
}
Expand Down
Loading