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

Update EIP-7069: Padding oob behavior of RETURNDATA* #8617

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions EIPS/eip-7069.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
type: Standards Track
category: Core
created: 2023-05-05
requires: 150, 211, 214, 2929
requires: 150, 211, 214, 2929, 3540
---

## Abstract

Introduce three new call instructions, `EXTCALL`, `EXTDELEGATECALL` and `EXTSTATICCALL`, with simplified semantics. Introduce another instruction, `RETURNDATALOAD` for loading a word from return data into stack. The existing call instructions remain unchanged.
Introduce three new call instructions, `EXTCALL`, `EXTDELEGATECALL` and `EXTSTATICCALL`, with simplified semantics. Introduce another instruction, `RETURNDATALOAD` for loading a word from return data into stack. Modify the behavior of `RETURNDATACOPY` instruction executed within EOF formatted code (as defined by [EIP-3540](./eip-3540.md)). The existing `*CALL` instructions remain unchanged.

The new instructions do not allow specifying a gas limit, but rather rely on the "63/64th rule" ([EIP-150](./eip-150.md)) to limit gas. An important improvement is the rules around the "stipend" are simplified, and callers do not need to perform special calculation whether the value is sent or not.

Expand Down Expand Up @@ -86,10 +86,18 @@

1. Charge `G_verylow` (3) gas
2. Pop 1 item from the stack, to be referred to as `offset`
3. If `offset + 32 > len(returndata buffer)`, halt with exceptional failure.
4. Push 1 item onto the stack, the 32-byte word read from the returndata buffer starting at `offset`.
3. Push 1 item onto the stack, the 32-byte word read from the returndata buffer starting at `offset`.
4. If `offset + 32 > len(returndata buffer)`, the result is zero-padded.

In case this EIP is included as part of the greater EOF upgrade, execution semantics of `RETURNDATACOPY` in EOF formatted code ([EIP-3540](./eip-3540.md)) is modified as follows:

1. Assume the 3 arguments popped from stack are `destOffset`, `offset` and `size`.
2. If `offset + size > len(returndata buffer)` **do not** halt with exceptional failure, but instead set the `offset + size - len(returndata buffer)` memory bytes after the copied ones to zero.
3. Gas charged for memory copying remains `3 * num_words(size)`, regardless of the number of bytes actually copied or set to zero.

Execution of `RETURNDATACOPY` which is not in EOF formatted code (i.e. is in legacy code) is not changed.

<!-- *TODO:* Clarify which side (caller/callee) is gas deducted from and where an error originates from. -->

Check warning on line 100 in EIPS/eip-7069.md

View workflow job for this annotation

GitHub Actions / EIP Walidator

HTML comments are only allowed while `status` is one of: `Draft`, `Withdrawn`

warning[markdown-html-comments]: HTML comments are only allowed while `status` is one of: `Draft`, `Withdrawn` --> EIPS/eip-7069.md | 100 | <!-- *TODO:* Clarify which side (caller/callee) is gas deducted from and where an error originates from. --> | ::: EIPS/eip-7069.md | 102 | <!-- *TODO:* Mention gas refunds? --> | ::: EIPS/eip-7069.md | 104 | <!-- *TODO:* Consider option where non-calldata value transfer is not allowed, but there's a specific `TRANSFER`/`PAY` function for that. Would simplify the logic greatly. --> | = help: see https://ethereum.github.io/eipw/markdown-html-comments/

Check warning on line 100 in EIPS/eip-7069.md

View workflow job for this annotation

GitHub Actions / EIP Walidator

HTML comments are only allowed while `status` is one of: `Draft`, `Withdrawn`

warning[markdown-html-comments]: HTML comments are only allowed while `status` is one of: `Draft`, `Withdrawn` --> EIPS/eip-7069.md | 100 | <!-- *TODO:* Clarify which side (caller/callee) is gas deducted from and where an error originates from. --> | ::: EIPS/eip-7069.md | 102 | <!-- *TODO:* Mention gas refunds? --> | ::: EIPS/eip-7069.md | 104 | <!-- *TODO:* Consider option where non-calldata value transfer is not allowed, but there's a specific `TRANSFER`/`PAY` function for that. Would simplify the logic greatly. --> | = help: see https://ethereum.github.io/eipw/markdown-html-comments/

Check warning on line 100 in EIPS/eip-7069.md

View workflow job for this annotation

GitHub Actions / EIP Walidator

HTML comments are only allowed while `status` is one of: `Draft`, `Withdrawn`

warning[markdown-html-comments]: HTML comments are only allowed while `status` is one of: `Draft`, `Withdrawn` --> EIPS/eip-7069.md | 100 | <!-- *TODO:* Clarify which side (caller/callee) is gas deducted from and where an error originates from. --> | ::: EIPS/eip-7069.md | 102 | <!-- *TODO:* Mention gas refunds? --> | ::: EIPS/eip-7069.md | 104 | <!-- *TODO:* Consider option where non-calldata value transfer is not allowed, but there's a specific `TRANSFER`/`PAY` function for that. Would simplify the logic greatly. --> | = help: see https://ethereum.github.io/eipw/markdown-html-comments/

<!-- *TODO:* Mention gas refunds? -->

Expand Down Expand Up @@ -186,6 +194,14 @@

There is an alternative scenario where, in case this EIP is included as part of the greater EOF upgrade, the four new instructions are **additionally** available in legacy EVM. There is, however, a preference to limit changes to legacy EVM in the fork where EOF is included as well as in subsequent ones.

### `RETURNDATALOAD` and `RETURNDATACOPY` padding behavior

This EIP initially proposed keeping the halt-on-OOB behavior of legacy `RETURNDATACOPY`. This makes compilers optimizations harder, because unnecessary `RETURNDATA*` instructions cannot be optimized out without change to code semantics.

It could be that only `RETURNDATALOAD` is given the padding behavior, but that would make it confusingly inconsistent with the closely related `RETURNDATACOPY` instruction.

There also was the alternative to have `RETURNDATACOPY2` introduced with the padding behavior, available in EOF only, at the same time banning `RETURNDATACOPY` in EOF. This has been rejected in order to avoid multiplying opcodes, and also as suboptimal from the point of view of compiler implementation.

## Backwards Compatibility

No existing instructions are changed and so we do not think any backwards compatibility issues can occur.
Expand Down
Loading