-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
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.
Recommend reviewing and applying the feedback, but none of it is a blocker for DRAFT (maybe a blocker for Review).
### 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)`. | ||
|
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.
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.
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.
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.
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.
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. |
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.
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!)
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.
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?
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.
EIPs don't propose, they assert. Also recommend removing the Rationale at the end and keeping focused on the specification.
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. |
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.
I lied, there is one required change.
Co-authored-by: Micah Zoltu <micah@zoltu.net>
Co-authored-by: Micah Zoltu <micah@zoltu.net>
@MicahZoltu PTAL |
Changes the memory model for the EVM to use pagination.
No description provided.