Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EIP draft for paged memory #3336

Merged
merged 6 commits into from
Mar 6, 2021
Merged

Conversation

Arachnid
Copy link
Contributor

@Arachnid Arachnid commented Mar 6, 2021

No description provided.

Copy link
Contributor

@MicahZoltu MicahZoltu left a comment

Choose a reason for hiding this comment

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

Recommend reviewing and applying the feedback, but none of it is a blocker for DRAFT (maybe a blocker for Review).

Comment on lines +37 to +41
### Changes to memory expansion gas cost
Presently, the total cost to extend the memory to `a` words long is `Cmem(a) = 3 * a + floor(a ** 2 / 512)`. If the memory is already `b` words long, the incremental cost is `Cmem(a) - Cmem(b)`. `a` is the number of words required to cover the range from memory address 0 to the last word that has been read or written by the EVM.

Under this EIP, we define a new memory cost function, based on the number of allocated pages. This function is `Cmem'(p) = max(PAGE_BASE_COST * (p - 1) + floor(2 * (p - 1) ** 2), 0)`. As above, if the memory already contains `q` pages, the incremental cost is `Cmem'(p) - Cmem'(q)`.

Copy link
Contributor

Choose a reason for hiding this comment

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

This should mostly move to the Rationale section. The specification should just say what the gas cost is, not history or why it is what it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's important for anyone trying to understand the new cost function to know what the old one is. Removing this would make the standard harder to understand, IMO.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that it is very valuable information that should be present in the EIP. I just disagree that it is appropriate for the Specification section. The specification should focus purely on what one needs to implement in order to be compliant with this standard. Explaining what a previous iteration defined doesn't help them be compliant with this standard, it helps them be compliant with a previous standard (not the reader's goal).

Changes the memory model for the EVM to use pagination, which permits more flexible use of memory by compilers without unduly complicating implementations.

## Abstract
Presently, the EVM charges for memory as a linear array starting at address 0 and extending to the highest address that has been read from or written to. This suffices for simple uses, but means that compilers have to generate programs that use memory compactly, which leads to wasted gas with reallocation of memory elements, and makes some memory models such as separate heap and stack areas impractical. This EIP proposes changing to a page-based billing model, which adds minimal complexity to implementations, while providing for much more versatility in EVM programs.
Copy link
Contributor

Choose a reason for hiding this comment

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

The abstract should be a terse human readable version of the specification. Currently, this discusses history which is more appropriate for the Motivation section.

(normally I would try to provide an alternative abstract, but I don't think I grok the change well enough to do so... sorry!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
Presently, the EVM charges for memory as a linear array starting at address 0 and extending to the highest address that has been read from or written to. This suffices for simple uses, but means that compilers have to generate programs that use memory compactly, which leads to wasted gas with reallocation of memory elements, and makes some memory models such as separate heap and stack areas impractical. This EIP proposes changing to a page-based billing model, which adds minimal complexity to implementations, while providing for much more versatility in EVM programs.
This EIP proposes changing EVM memory to a page-based allocation and gas billing model by dividing the memory address space into 1 kilobyte (32 word) pages, and charging gas on the basis of the number of pages allocated, rather than the address of the highest word referenced in memory. This facilitates more flexible use of memory than is currently possible with a linear model.

How about this?

Copy link
Contributor

Choose a reason for hiding this comment

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

EIPs don't propose, they assert. Also recommend removing the Rationale at the end and keeping focused on the specification.

Suggested change
Presently, the EVM charges for memory as a linear array starting at address 0 and extending to the highest address that has been read from or written to. This suffices for simple uses, but means that compilers have to generate programs that use memory compactly, which leads to wasted gas with reallocation of memory elements, and makes some memory models such as separate heap and stack areas impractical. This EIP proposes changing to a page-based billing model, which adds minimal complexity to implementations, while providing for much more versatility in EVM programs.
Makes EVM memory a page-based allocation system and gas billing model by dividing the memory address space into 1 kilobyte (32 word) pages, and charging gas on the basis of the number of pages allocated, rather than the address of the highest word referenced in memory.

EIPS/eip-3336.md Outdated Show resolved Hide resolved
Copy link
Contributor

@MicahZoltu MicahZoltu left a comment

Choose a reason for hiding this comment

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

I lied, there is one required change.

EIPS/eip-3336.md Outdated Show resolved Hide resolved
Arachnid and others added 2 commits March 7, 2021 08:46
Co-authored-by: Micah Zoltu <micah@zoltu.net>
Co-authored-by: Micah Zoltu <micah@zoltu.net>
@Arachnid
Copy link
Contributor Author

Arachnid commented Mar 6, 2021

@MicahZoltu PTAL

@MicahZoltu MicahZoltu merged commit 575ea3a into ethereum:master Mar 6, 2021
phi-line pushed a commit to phi-line/EIPs that referenced this pull request Apr 29, 2021
Changes the memory model for the EVM to use pagination.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants