Skip to content

Commit

Permalink
Update EIP-7480: implicit zero-padding on out-of-bounds access
Browse files Browse the repository at this point in the history
Merged by EIP-Bot.
  • Loading branch information
gumb0 authored Dec 5, 2023
1 parent 45301a2 commit 936f2c9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions EIPS/eip-7480.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ If the code is valid EOF1, the following execution rules apply:
### `DATALOAD`

1. Pops one value, `offset`, from the stack.
2. If `offset + 32` is greater than the data section size of the active container, execution results in exceptional halt.
3. Reads `[offset:offset+32]` segment from the data section and pushes it as 32-byte value to the stack.
2. Reads `[offset:offset+32]` segment from the data section and pushes it as 32-byte value to the stack.
3. If `offset + 32` is greater than the data section size, bytes after the end of data section are set to 0.
4. Deducts 4 gas.

### `DATALOADN`
Expand All @@ -63,8 +63,8 @@ If the code is valid EOF1, the following execution rules apply:
1. Pops three values from the stack: `mem_offset`, `offset`, `size`.
2. Performs memory expansion to `mem_offset + size` and deducts memory expansion cost.
3. Deducts `3 * ((size + 31) // 32)` gas for copying.
3. If `offset + size` is greater than data section size of the active container, execution results in exceptional halt.
4. Reads `[offset:offset+size]` segment from the data section and writes it to memory starting at offset `mem_offset`.
5. If `offset + size` is greater than data section size, 0 bytes will be copied for bytes after the end of the data section.


### Code Validation
Expand All @@ -77,7 +77,11 @@ We extend code section validation rules (as defined in [EIP-3670](./eip-3670.md)

## Rationale

TBA
### Zero-padding on out of bounds access

Existing instructions for reading other kinds of data implicitly pad with zeroes on out of bounds access, with the only exception of return data copying.

It is benefitial to avoid exceptional failures, because compilers can employ optimizations like removing a code that copies data, but never accesses this copy afterwards, but such optimization is possible only if instruction never has other side effects like exceptional abort.

## Backwards Compatibility

Expand Down

0 comments on commit 936f2c9

Please sign in to comment.