-
Notifications
You must be signed in to change notification settings - Fork 840
Extend memory gadgets to handle dynamic offset and length #279
Extend memory gadgets to handle dynamic offset and length #279
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some questions and nits.
Amazing job as always @han0110 👍
zkevm-circuits/src/evm_circuit/execution/error_oog_pure_memory.rs
Outdated
Show resolved
Hide resolved
zkevm-circuits/src/evm_circuit/execution/error_oog_pure_memory.rs
Outdated
Show resolved
Hide resolved
8b8a7ac
to
cc66d5c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
3909ef6
to
c617ddc
Compare
/// to integer. It handles the "no expansion" feature when length is zero. | ||
#[derive(Clone, Debug)] | ||
pub(crate) struct MemoryAddressGadget<F> { | ||
memory_offset: Cell<F>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
memory_offset
is starting point of address for expansion ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, more precisely, the starting point of address for call_data
or return_data
specified by caller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding of this gadget is that it aims to provide the max used address after a memory access by an opcode that takes offset
and length
like CALLDATACOPY
, CODECOPY
, EXTCODECOPY
, RETURNDATACOPY
. And I think this max address would then be used in the MemoryExpansionGadget
to calculate the gas_cost
of the possible expansion.
And MemoryAddressGadget
returns max_address = 0
when the length = 0
so that no memory expansion is performed in such case, even if the offset is past the current max used address.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, thanks for explanation!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This PR is part of #278, which extends memory gadgets to add/extend
MemoryAddressGadget
- To handle dynamic offset and length expansion. It's also useful for memory expansion opcode likeCALLDATACOPY
.MemoryExpansionGadget
- To support multiple expansion size. It's useful for*CALL*
which assign 2 memory chunks as expansion targets.It also refactors some frequently used constant and methods. For main changes, please refer to
memory_gadget.rs