From 936f2c9c053e26a07b1300dea3de32abb16e07b6 Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Tue, 5 Dec 2023 15:31:42 +0100 Subject: [PATCH] Update EIP-7480: implicit zero-padding on out-of-bounds access Merged by EIP-Bot. --- EIPS/eip-7480.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/EIPS/eip-7480.md b/EIPS/eip-7480.md index 6d3a483da39bcb..b2a2d5750428b9 100644 --- a/EIPS/eip-7480.md +++ b/EIPS/eip-7480.md @@ -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` @@ -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 @@ -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