Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
073ee98
draft buss mapping for mcopy
DreamWuGit Apr 11, 2024
ec9ac3c
rename to mcopy.rs
DreamWuGit Apr 12, 2024
10e38fc
add mcopy.rs
DreamWuGit Apr 12, 2024
8f93795
add helper gen_copy_steps_for_memory_to_memory
DreamWuGit Apr 12, 2024
b11e5c1
add MCOPY in opcode_ids
DreamWuGit Apr 15, 2024
05cb697
handle opcode_id others as_u8, constant_gas etc.
DreamWuGit Apr 15, 2024
f3c280e
draft mcopy gadgets
DreamWuGit Apr 15, 2024
5151ac6
add gadget to execution config
DreamWuGit Apr 15, 2024
78a0847
remove unused fields
DreamWuGit Apr 16, 2024
b426e3d
update buss mapping test
DreamWuGit Apr 16, 2024
ae9c462
update gadget tests
DreamWuGit Apr 17, 2024
7d60b11
remove unnecessary testing stuff
DreamWuGit Apr 17, 2024
a2bdff3
Merge branch 'develop' into feat/mcopy
DreamWuGit Apr 22, 2024
f4fd6ff
update ExecutionState
DreamWuGit Apr 22, 2024
061550c
add cancun config
DreamWuGit Apr 23, 2024
514dd37
update buss mapping test
DreamWuGit Apr 23, 2024
5fce127
remove commented codes
DreamWuGit Apr 23, 2024
d69aa9d
enable multi copy case
DreamWuGit Apr 24, 2024
f05f3fa
fix buss mapping tests
DreamWuGit Apr 24, 2024
6d04d89
update gas cost
DreamWuGit Apr 24, 2024
36e9f00
remove tx id lookup
DreamWuGit Apr 24, 2024
745349a
fix memory_word_size
DreamWuGit Apr 25, 2024
c511e49
update word size if no copy happens
DreamWuGit Apr 25, 2024
cdd986f
add copy circuit test
DreamWuGit Apr 25, 2024
6156b26
merge to develop
DreamWuGit Apr 26, 2024
669dfd3
remove debug log
DreamWuGit Apr 26, 2024
d060715
fmt align
DreamWuGit Apr 26, 2024
5d84441
minor update
DreamWuGit Apr 26, 2024
28cdb4b
add OOGMemoryCopy test for mcopy
DreamWuGit Apr 26, 2024
7113054
make oog memorycopy include mcopy opcode
DreamWuGit Apr 26, 2024
3dc9957
revert temp debug changes
DreamWuGit Apr 26, 2024
4dc5d7a
add more test data
DreamWuGit Apr 26, 2024
137511a
minor updates
DreamWuGit Apr 28, 2024
c9566df
fmt adjust
DreamWuGit Apr 28, 2024
430125f
sycn with latest develop
DreamWuGit Apr 28, 2024
b74b81d
fix clippy
DreamWuGit Apr 28, 2024
40439ad
add testool
lispc Apr 28, 2024
7303a01
Merge branch 'feat/mcopy' of github.com:scroll-tech/zkevm-circuits in…
lispc Apr 28, 2024
ab66170
fix memory word
DreamWuGit Apr 28, 2024
e37db51
increase fix table rows detected by ci
DreamWuGit Apr 28, 2024
66e981c
Merge branch 'develop' into feat/mcopy
lispc Apr 28, 2024
b88b8c5
update testool
lispc Apr 28, 2024
d14863c
remove unused import
DreamWuGit Apr 29, 2024
cbbebab
clippy update
DreamWuGit Apr 29, 2024
b8c2c83
fix large dest memory addr
DreamWuGit Apr 29, 2024
c666aaf
refactor to use memory_expansion for dest_addr
DreamWuGit Apr 29, 2024
e68d5a1
handle dest_addr < src_addr
DreamWuGit Apr 30, 2024
bf2f0e1
Merge branch 'develop' into feat/mcopy
DreamWuGit Apr 30, 2024
d602765
update per cargo check
DreamWuGit Apr 30, 2024
7304bb3
intermediate clean up
DreamWuGit Apr 30, 2024
ad0a218
fix testool
lispc May 1, 2024
eb5f5bc
fix u64 overflow
DreamWuGit May 5, 2024
f4b3bc2
update oog memorycopy to cover src_offset overflow case
DreamWuGit May 6, 2024
dc111f3
Merge branch 'develop' into feat/mcopy
lispc May 6, 2024
de7e356
fix clippy; fix codehash.txt
lispc May 6, 2024
630e30d
remove debug codes
DreamWuGit May 7, 2024
4c16cda
Merge branch 'feat/mcopy' of https://github.com/scroll-tech/zkevm-cir…
DreamWuGit May 7, 2024
8a24ae7
fix clippy
DreamWuGit May 7, 2024
c5a01e9
reverted commented for testing
DreamWuGit May 7, 2024
a74d07a
remove outdated comment and todo for overlap case
DreamWuGit May 7, 2024
7f47a75
Merge branch 'develop' into feat/mcopy
DreamWuGit May 10, 2024
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
79 changes: 78 additions & 1 deletion bus-mapping/src/circuit_input_builder/input_state_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,7 @@ impl<'a> CircuitInputStateRef<'a> {
copy_length,
&bytecode.code,
&mut self.call_ctx_mut()?.memory,
false,
);

let copy_steps = CopyEventStepsBuilder::new()
Expand Down Expand Up @@ -2039,6 +2040,7 @@ impl<'a> CircuitInputStateRef<'a> {
copy_length,
result,
&mut self.caller_ctx_mut()?.memory,
false,
);

let read_slot_bytes = MemoryRef(result).read_chunk(src_range);
Expand Down Expand Up @@ -2096,6 +2098,7 @@ impl<'a> CircuitInputStateRef<'a> {
copy_length,
&call_ctx.call_data,
&mut call_ctx.memory,
false,
);

let copy_steps = CopyEventStepsBuilder::memory_range(range)
Expand Down Expand Up @@ -2144,6 +2147,7 @@ impl<'a> CircuitInputStateRef<'a> {
copy_length,
call_data,
&mut call_ctx.memory,
false,
);

let read_slot_bytes = self.caller_ctx()?.memory.read_chunk(src_range);
Expand Down Expand Up @@ -2205,6 +2209,7 @@ impl<'a> CircuitInputStateRef<'a> {
copy_length,
return_data,
&mut call_ctx.memory,
false,
);
let read_slot_bytes = self.call()?.last_callee_memory.read_chunk(src_range);

Expand Down Expand Up @@ -2247,6 +2252,71 @@ impl<'a> CircuitInputStateRef<'a> {
Ok((read_steps, write_steps, prev_bytes))
}

// generates copy steps for memory to memory case.
pub(crate) fn gen_copy_steps_for_memory_to_memory(
&mut self,
exec_step: &mut ExecStep,
src_addr: impl Into<MemoryAddress>,
dst_addr: impl Into<MemoryAddress>,
copy_length: impl Into<MemoryAddress>,
) -> Result<(CopyEventSteps, CopyEventSteps, Vec<u8>), Error> {
let copy_length = copy_length.into().0;
if copy_length == 0 {
return Ok((vec![], vec![], vec![]));
}

// current call's memory
let memory = self.call_ctx()?.memory.clone();
let call_ctx = self.call_ctx_mut()?;
let (src_range, dst_range, write_slot_bytes) = combine_copy_slot_bytes(
src_addr.into().0,
dst_addr.into().0,
copy_length,
&memory.0,
&mut call_ctx.memory,
true,
);
let read_slot_bytes = memory.read_chunk(src_range);

let read_steps = CopyEventStepsBuilder::memory_range(src_range)
.source(read_slot_bytes.as_slice())
.build();
let write_steps = CopyEventStepsBuilder::memory_range(dst_range)
.source(write_slot_bytes.as_slice())
.build();

let mut src_chunk_index = src_range.start_slot().0;
let mut dst_chunk_index = dst_range.start_slot().0;
let mut prev_bytes: Vec<u8> = vec![];
// memory word reads from source and writes to destination word
let call_id = self.call()?.call_id;
for (read_chunk, write_chunk) in read_slot_bytes.chunks(32).zip(write_slot_bytes.chunks(32))
{
self.push_op(
exec_step,
RW::READ,
MemoryOp::new(
call_id,
src_chunk_index.into(),
Word::from_big_endian(read_chunk),
),
)?;
trace!("read chunk: {call_id} {src_chunk_index} {read_chunk:?}");
src_chunk_index += 32;

self.write_chunk_for_copy_step(
exec_step,
write_chunk,
dst_chunk_index,
&mut prev_bytes,
)?;

dst_chunk_index += 32;
}

Ok((read_steps, write_steps, prev_bytes))
}

pub(crate) fn gen_copy_steps_for_log(
&mut self,
exec_step: &mut ExecStep,
Expand Down Expand Up @@ -2349,13 +2419,20 @@ fn combine_copy_slot_bytes(
copy_length: usize,
src_data: &[impl Into<u8> + Clone],
dst_memory: &mut Memory,
is_memory_copy: bool, // indicates memroy --> memory copy type.
) -> (MemoryWordRange, MemoryWordRange, Vec<u8>) {
let mut src_range = MemoryWordRange::align_range(src_addr, copy_length);
let mut dst_range = MemoryWordRange::align_range(dst_addr, copy_length);
src_range.ensure_equal_length(&mut dst_range);

// Extend call memory.
dst_memory.extend_for_range(dst_addr.into(), copy_length.into());
// if is_memory_copy=true, both dst_addr and src_addr are memory address
if is_memory_copy && dst_addr < src_addr {
dst_memory.extend_for_range(src_addr.into(), copy_length.into());
} else {
dst_memory.extend_for_range(dst_addr.into(), copy_length.into());
}

let dst_begin_slot = dst_range.start_slot().0;
let dst_end_slot = dst_range.end_slot().0;

Expand Down
1 change: 1 addition & 0 deletions bus-mapping/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ pub(crate) fn get_step_reported_error(op: &OpcodeId, error: GethExecError) -> Ex
OpcodeId::CALLDATACOPY
| OpcodeId::CODECOPY
| OpcodeId::EXTCODECOPY
| OpcodeId::MCOPY
| OpcodeId::RETURNDATACOPY => OogError::MemoryCopy,
OpcodeId::BALANCE | OpcodeId::EXTCODESIZE | OpcodeId::EXTCODEHASH => {
OogError::AccountAccess
Expand Down
4 changes: 4 additions & 0 deletions bus-mapping/src/evm/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ mod extcodesize;
mod gasprice;
mod jumpi;
mod logs;
mod mcopy;
mod mload;
mod mstore;
mod number;
Expand Down Expand Up @@ -116,6 +117,7 @@ use extcodehash::Extcodehash;
use extcodesize::Extcodesize;
use gasprice::GasPrice;
use logs::Log;
use mcopy::MCopy;
use mload::Mload;
use mstore::Mstore;
use origin::Origin;
Expand Down Expand Up @@ -235,6 +237,7 @@ fn fn_gen_associated_ops(opcode_id: &OpcodeId) -> FnGenAssociatedOps {
OpcodeId::SELFBALANCE => Selfbalance::gen_associated_ops,
OpcodeId::BASEFEE => GetBlockHeaderField::<{ OpcodeId::BASEFEE }>::gen_associated_ops,
OpcodeId::POP => StackPopOnlyOpcode::<1>::gen_associated_ops,
OpcodeId::MCOPY => MCopy::gen_associated_ops,
OpcodeId::MLOAD => Mload::gen_associated_ops,
OpcodeId::MSTORE => Mstore::<false>::gen_associated_ops,
OpcodeId::MSTORE8 => Mstore::<true>::gen_associated_ops,
Expand Down Expand Up @@ -477,6 +480,7 @@ pub fn gen_associated_ops(
} else {
None
};

if let Some(exec_error) = state.get_step_err(geth_step, next_step).unwrap() {
log::debug!(
"geth error {:?} occurred in {:?} at pc {:?}",
Expand Down
3 changes: 2 additions & 1 deletion bus-mapping/src/evm/opcodes/error_oog_memory_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ impl Opcode for OOGMemoryCopy {
OpcodeId::CALLDATACOPY,
OpcodeId::CODECOPY,
OpcodeId::EXTCODECOPY,
OpcodeId::RETURNDATACOPY
OpcodeId::RETURNDATACOPY,
OpcodeId::MCOPY,
]
.contains(&geth_step.op));

Expand Down
Loading