-
Notifications
You must be signed in to change notification settings - Fork 6k
Add EIP: MLOAD8 and CALLDATALOAD8 Opcodes #11038
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
base: master
Are you sure you want to change the base?
Conversation
This EIP introduces new EVM opcodes for efficient single-byte memory and calldata loads, reducing gas costs and bytecode size.
Added details for MLOAD8 and CALLDATALOAD8 instructions, including stack inputs, outputs, gas costs, and exceptional conditions.
Clarified opcode references in the abstract and motivation sections.
Propose new opcodes for direct single-byte loading to reduce gas costs and bytecode size.
File
|
|
The commit 5e819b8 (as a parent of 61d002c) contains errors. |
EIPS/eip-9999.md
Outdated
| @@ -0,0 +1,103 @@ | |||
| --- | |||
| eip: 9999 | |||
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.
| eip: 9999 | |
| eip: 8120 |
Assigning next sequential EIP/ERC/RIP number.
Numbers are assigned by editors & associates.
Please also update the filename.
EIPS/eip-9999.md
Outdated
| title: MLOAD8 and CALLDATALOAD8 Opcodes | ||
| description: Adds EVM opcodes for efficient single-byte memory and calldata loads. | ||
| author: Helkomine (@Helkomine) | ||
| discussions-to: https://ethereum-magicians.org/t/eip-xxxx-mload8-and-calldataload8-opcodes/27396 |
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.
| discussions-to: https://ethereum-magicians.org/t/eip-xxxx-mload8-and-calldataload8-opcodes/27396 | |
| discussions-to: https://ethereum-magicians.org/t/eip-8120-mload8-and-calldataload8-opcodes/27396 |
Updated with assigned number. Recommend using the template for the discussions topic.
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.
Thank you for this proposal! The addition of MLOAD8 and CALLDATALOAD8 fills a clear gap in the EVM instruction set, offering symmetry with MSTORE8 and potential gas savings for byte-oriented processing. The draft is well-written and follows the standard structure.
The proposal is solid and ready for Draft status once the ambiguity regarding memory expansion size (1 byte vs 32 bytes) is resolved in the text.
|
|
||
| ## Specification | ||
|
|
||
| ### MLOAD8 (TBD) |
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.
While (TBD) is acceptable for an initial draft, consider proposing specific opcode values (e.g., from the 0x5X range if available) to facilitate early client prototyping and collision checking.
| - **Stack output**: `value` | ||
|
|
||
| Reads one byte from memory at position offset and pushes it onto the stack as a 32-byte word, with the byte placed in the least significant position. | ||
| If offset is greater than or equal to the current memory size, the returned value is 0. |
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 phrasing here could be interpreted as returning 0 without expanding memory. In the EVM, accessing memory beyond the current size typically triggers expansion (and the cost associated with it) first, and the value is 0 because the new memory is zero-initialized.
Consider clarifying that expansion happens first, or simply rely on the expansion rule definition.
|
|
||
| Reads one byte from memory at position offset and pushes it onto the stack as a 32-byte word, with the byte placed in the least significant position. | ||
| If offset is greater than or equal to the current memory size, the returned value is 0. | ||
| Memory expansion rules apply in the same way as for `MLOAD`. |
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 reference to MLOAD might be ambiguous regarding the size of the expansion. MLOAD reads 32 bytes, so it expands memory to cover offset + 32. MLOAD8 should presumably only expand to offset + 1 (like MSTORE8).
| Memory expansion rules apply in the same way as for `MLOAD`. | |
| Memory expansion rules apply in the same way as for `MSTORE8` (extending memory to at least `offset + 1` bytes). |
|
|
||
| ### Efficiency for Byte-Oriented Contracts | ||
|
|
||
| Instruction-based architectures, such as instruction-based routers used in decentralized exchange protocols, benefit from reduced gas usage and smaller bytecode size when parsing byte streams. |
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.
It would be valuable to include a concrete calculation of the savings here to strengthen the rationale.
For example: "Replacing CALLDATALOAD (3 gas) + PUSH (3 gas) + SHR (3 gas) with CALLDATALOAD8 (3 gas) saves 6 gas per byte read and reduces bytecode size by ~3 bytes."
This PR introduces a draft EIP proposing two new EVM opcodes,
MLOAD8andCALLDATALOAD8, which allow efficient single-byte access to memory and calldata.A discussion thread has been opened on Ethereum Magicians: https://ethereum-magicians.org/t/eip-xxxx-mload8-and-calldataload8-opcodes/27396