Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Fix copy_rwc_inc calculation as bus-mapping #573

Merged
merged 1 commit into from
Jun 29, 2023
Merged
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
11 changes: 6 additions & 5 deletions zkevm-circuits/src/evm_circuit/execution/return_revert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,19 +333,20 @@ impl<F: Field> ExecutionGadget<F> for ReturnRevertGadget<F> {
}

let shift = memory_offset.low_u64() % 32;
let memory_start_slot = memory_offset.low_u64() - shift;
let memory_end = memory_offset.low_u64() + length.low_u64();
let memory_end_slot = memory_end - memory_end % 32;
let valid_length = if call.is_root || (call.is_create && call.is_success) {
length.as_u64()
} else {
std::cmp::min(call.return_data_length, length.as_u64())
call.return_data_length.min(length.as_u64())
};

let copy_rwc_inc = if valid_length == 0 {
0
} else {
(memory_end_slot - memory_start_slot) / 32 + 1
let begin_slot = memory_offset.low_u64() - shift;
let end = memory_offset.low_u64() + valid_length;
let end_slot = end - end % 32;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be incorrect when end % 32 == 0. You could use the function align_range from here. Although it is not merged yet.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, an alternative formula is end = begin + length - 1. This is the index of the last byte (not the length).

let end = memory_offset.low_u64() + valid_length - 1;


(end_slot - begin_slot) / 32 + 1
};

if call.is_create && call.is_success {
Expand Down