Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.

Extend memory gadgets to handle dynamic offset and length #279

Merged

Conversation

han0110
Copy link
Contributor

@han0110 han0110 commented Jan 14, 2022

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 like CALLDATACOPY.
  • 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

@github-actions github-actions bot added crate-bus-mapping Issues related to the bus-mapping workspace member T-opcode Type: opcode-related and focused PR/Issue labels Jan 14, 2022
@han0110 han0110 requested a review from scroll-dev January 14, 2022 05:54
@han0110 han0110 mentioned this pull request Jan 14, 2022
6 tasks
Copy link
Contributor

@CPerezz CPerezz left a 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 👍

@han0110 han0110 force-pushed the feature/extend-memory-gadget branch from 8b8a7ac to cc66d5c Compare January 15, 2022 05:39
Copy link
Contributor

@CPerezz CPerezz left a comment

Choose a reason for hiding this comment

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

LGTM

@han0110 han0110 force-pushed the feature/extend-memory-gadget branch from 3909ef6 to c617ddc Compare January 19, 2022 10:00
/// to integer. It handles the "no expansion" feature when length is zero.
#[derive(Clone, Debug)]
pub(crate) struct MemoryAddressGadget<F> {
memory_offset: Cell<F>,
Copy link
Collaborator

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 ?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly, thanks for explanation!

Copy link
Member

@ed255 ed255 left a comment

Choose a reason for hiding this comment

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

LGTM!

@han0110 han0110 merged commit fa41416 into privacy-scaling-explorations:main Jan 19, 2022
@han0110 han0110 deleted the feature/extend-memory-gadget branch January 19, 2022 14:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
crate-bus-mapping Issues related to the bus-mapping workspace member T-opcode Type: opcode-related and focused PR/Issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants