From 36a6af71921e876265b7a2298a3febf485f8e419 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Sat, 18 May 2024 12:03:52 -0400 Subject: [PATCH 01/35] eip/initial-draft --- EIPS/eip-7703.md | 137 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 EIPS/eip-7703.md diff --git a/EIPS/eip-7703.md b/EIPS/eip-7703.md new file mode 100644 index 00000000000000..7e8316f377a4a3 --- /dev/null +++ b/EIPS/eip-7703.md @@ -0,0 +1,137 @@ +--- +eip: 7703 +title: Adjust the `BLOCKHASH` (0x40) to read from storage, and update gas cost for Verkle +description: Serve the `BLOCKHASH (0x40)` opcode from the system contract storage from EIP-2935 to allow for stateless execution. Also adjust its gas cost to reflect storage access. +author: Vitalik Buterin (@vbuterin), Tomasz Stanczak (@tkstanczak), Guillaume Ballet (@gballet), Gajinder Singh (@g11tech), Tanishq Jasoria (@tanishqjasoria), Ignacio Hagopian (@jsign), Jochem Brouwer (@jochem-brouwer), Gabriel Rocheleau (@gabrocheleau) +discussions-to: https://ethereum-magicians.org/t/eip-2935-save-historical-block-hashes-in-state/4565 +status: Draft +type: Standards Track +category: Core +created: 2024-05-18 +--- + +## Abstract + +Update the `BLOCKHASH (0x40)` opcode to read and serve from the system contract storage to allow for stateless execution. Update the `BLOCKHASH (0x40)` opcode gas cost to reflect storage access cost, and include storage accesses in the Verkle block witness. + +## Motivation + +The `BLOCKHASH (0x40)` opcode currently assumes that the client has knowledge of the previous blocks, which in Verkle, would prevent stateless execution. This EIP assumes that [EIP-2935](./eip-2935.md) has been implemented, and that blockhashes can be retrieved from the systems contract storage. By updating the behavior of `BLOCKHASH (0x40)` to directly read and serve from state through the system contract storage, we allow Verkle blocks to include a storage access witness, which will allow stateless execution. + +The motivation behind the updated gas cost is to match the real cost of the operation, which is equivalent to an `SLOAD`. + +## Specification + +| Parameter | Value | +| ------------------------- | -------------------------------------------- | +| `FORK_TIMESTAMP` | TBD | +| `HISTORY_STORAGE_ADDRESS` | `0x25a219378dad9b3503c8268c9ca836a52427a4fb` | +| `BLOCKHASH_SERVE_WINDOW` | `256` | + +The `BLOCKHASH` opcode semantics remains the same as before. From the `fork_block` (first block where `block.timestamp >= FORK_TIMESTAMP`), the `BLOCKHASH` instruction should be updated to retrieve the requested blockhash from the contract storage. + +### Contract Implementation + +Exact evm assembly that can be used for the contract to resolve `BLOCKHASH` + +``` +// check if input > 8 byte value and revert if this isn't the case +// the check is performed by comparing the biggest 8 byte number with +// the call data, which is a right-padded 32 byte number. +push8 0xffffffffffffffff +push0 +calldataload +gt +push1 0x39 +jumpi + +// check if input > blocknumber-1 then return 0 +push1 0x1 +number +sub +push0 +calldataload +gt +push1 0x31 +jumpi + +// check if blocknumber > input + 8192 then return 0, no overflow expected for input of 8 bytes +push0 +calldataload +push2 0x2000 +add +number +gt +push1 0x31 +jumpi + +// mod 8192 and sload +push2 0x1FFF +push0 +calldataload +and +sload + +// load into mem and return 32 bytes +push0 +mstore +push1 0x20 +push0 +return + +// return 0 +jumpdest +push0 +push0 +mstore +push1 0x20 +push0 +return + +// revert +jumpdest +push0 +push0 +revert + +stop +``` + +Note that the input contract read `32` bytes input as `calldataload`. Users and clients doing EVM call to this contract should left pad the `arg` correctly. + + + +Corresponding bytecode: +`60203611603157600143035f35116029575f356120000143116029576120005f3506545f5260205ff35b5f5f5260205ff35b5f5ffd00` + +#### Deployment + +For the verkle_block (blocks where `block.timestamp >= FORK_TIMESTAMP`), we consider that the fork (`FORK_TIMESTAMP`) is already in effect for at least `HISTORY_SERVE_WINDOW` blocks (or from genesis if `fork_block < HISTORY_SERVE_WINDOW`). The following changes take effect: + +- `BLOCKHASH` MUST retrieve blockhashes from the system contract storage +- The gas cost of the `BLOCKHASH` opcode is updated as per specification +- The storage access is provided in the verkle execution witness. + +### [EIP-158](./eip-158.md) handling + +### Gas costs + +At FORK_TIMESTAMP, the corresponding storage access witness for the blockhash `SLOAD` lookups must also included in the execution witness, along with their access gas charges. + +## Rationale + +## Backwards Compatibility + +This EIP introduces a significant increase in the cost of `BLOCKHASH`, which could break use-cases that rely on the previous gas cost. + +## Test Cases + +TBD + +## Security Considerations + +Having contracts (system or otherwise) with hot update paths (branches) poses a risk of "branch" poisoning attacks where attacker could sprinkle trivial amounts of eth around these hot paths (branches). But it has been deemed that cost of attack would escalate significantly to cause any meaningful slow down of state root updates. + +## Copyright + +Copyright and related rights waived via [CC0](../LICENSE.md). From df5dbc3c4142b80fac048b8e0b5c8eac30ac1e6b Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Sat, 18 May 2024 12:04:41 -0400 Subject: [PATCH 02/35] adjust title --- EIPS/eip-7703.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-7703.md b/EIPS/eip-7703.md index 7e8316f377a4a3..a6a04e9e168b31 100644 --- a/EIPS/eip-7703.md +++ b/EIPS/eip-7703.md @@ -1,6 +1,6 @@ --- eip: 7703 -title: Adjust the `BLOCKHASH` (0x40) to read from storage, and update gas cost for Verkle +title: Adjust the BLOCKHASH opcode to read from storage and update its gas cost description: Serve the `BLOCKHASH (0x40)` opcode from the system contract storage from EIP-2935 to allow for stateless execution. Also adjust its gas cost to reflect storage access. author: Vitalik Buterin (@vbuterin), Tomasz Stanczak (@tkstanczak), Guillaume Ballet (@gballet), Gajinder Singh (@g11tech), Tanishq Jasoria (@tanishqjasoria), Ignacio Hagopian (@jsign), Jochem Brouwer (@jochem-brouwer), Gabriel Rocheleau (@gabrocheleau) discussions-to: https://ethereum-magicians.org/t/eip-2935-save-historical-block-hashes-in-state/4565 From 026d2643e5804a7fe1bb1ef66d712758886791d5 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Sat, 18 May 2024 12:06:05 -0400 Subject: [PATCH 03/35] adjust number --- EIPS/{eip-7703.md => eip-7704.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename EIPS/{eip-7703.md => eip-7704.md} (99%) diff --git a/EIPS/eip-7703.md b/EIPS/eip-7704.md similarity index 99% rename from EIPS/eip-7703.md rename to EIPS/eip-7704.md index a6a04e9e168b31..61a766fe882459 100644 --- a/EIPS/eip-7703.md +++ b/EIPS/eip-7704.md @@ -1,5 +1,5 @@ --- -eip: 7703 +eip: 7704 title: Adjust the BLOCKHASH opcode to read from storage and update its gas cost description: Serve the `BLOCKHASH (0x40)` opcode from the system contract storage from EIP-2935 to allow for stateless execution. Also adjust its gas cost to reflect storage access. author: Vitalik Buterin (@vbuterin), Tomasz Stanczak (@tkstanczak), Guillaume Ballet (@gballet), Gajinder Singh (@g11tech), Tanishq Jasoria (@tanishqjasoria), Ignacio Hagopian (@jsign), Jochem Brouwer (@jochem-brouwer), Gabriel Rocheleau (@gabrocheleau) From 38d94e29b54ad952b11508ebbe97eaf8b25a77c5 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Mon, 20 May 2024 00:49:47 -0400 Subject: [PATCH 04/35] adjust EIP number --- EIPS/{eip-7704.md => eip-7709.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename EIPS/{eip-7704.md => eip-7709.md} (99%) diff --git a/EIPS/eip-7704.md b/EIPS/eip-7709.md similarity index 99% rename from EIPS/eip-7704.md rename to EIPS/eip-7709.md index 61a766fe882459..a4f0251b9a329b 100644 --- a/EIPS/eip-7704.md +++ b/EIPS/eip-7709.md @@ -1,5 +1,5 @@ --- -eip: 7704 +eip: 7709 title: Adjust the BLOCKHASH opcode to read from storage and update its gas cost description: Serve the `BLOCKHASH (0x40)` opcode from the system contract storage from EIP-2935 to allow for stateless execution. Also adjust its gas cost to reflect storage access. author: Vitalik Buterin (@vbuterin), Tomasz Stanczak (@tkstanczak), Guillaume Ballet (@gballet), Gajinder Singh (@g11tech), Tanishq Jasoria (@tanishqjasoria), Ignacio Hagopian (@jsign), Jochem Brouwer (@jochem-brouwer), Gabriel Rocheleau (@gabrocheleau) From 1a453323dd9ed5957d6355afb4bc27510823883b Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Mon, 20 May 2024 01:41:41 -0400 Subject: [PATCH 05/35] chore: update link to eth magicians --- EIPS/eip-7709.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index a4f0251b9a329b..9ec5ee2895aae1 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -3,7 +3,7 @@ eip: 7709 title: Adjust the BLOCKHASH opcode to read from storage and update its gas cost description: Serve the `BLOCKHASH (0x40)` opcode from the system contract storage from EIP-2935 to allow for stateless execution. Also adjust its gas cost to reflect storage access. author: Vitalik Buterin (@vbuterin), Tomasz Stanczak (@tkstanczak), Guillaume Ballet (@gballet), Gajinder Singh (@g11tech), Tanishq Jasoria (@tanishqjasoria), Ignacio Hagopian (@jsign), Jochem Brouwer (@jochem-brouwer), Gabriel Rocheleau (@gabrocheleau) -discussions-to: https://ethereum-magicians.org/t/eip-2935-save-historical-block-hashes-in-state/4565 +discussions-to: https://ethereum-magicians.org/t/eip-7709-read-blockhash-opcode-from-storage-and-adjust-gas-cost/20052 status: Draft type: Standards Track category: Core From 5879ff86fcc26debb60bc54ec9327c10bfe88c81 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Mon, 20 May 2024 01:47:41 -0400 Subject: [PATCH 06/35] chore: add require and minor adjustments --- EIPS/eip-7709.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index 9ec5ee2895aae1..d0567dc8c03376 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -1,11 +1,12 @@ --- eip: 7709 -title: Adjust the BLOCKHASH opcode to read from storage and update its gas cost -description: Serve the `BLOCKHASH (0x40)` opcode from the system contract storage from EIP-2935 to allow for stateless execution. Also adjust its gas cost to reflect storage access. +title: Read BLOCKHASH from storage and update gas cost +description: Read the `BLOCKHASH (0x40)` opcode from the EIP-2935 system contract storage and adjust its gas cost to reflect storage access. author: Vitalik Buterin (@vbuterin), Tomasz Stanczak (@tkstanczak), Guillaume Ballet (@gballet), Gajinder Singh (@g11tech), Tanishq Jasoria (@tanishqjasoria), Ignacio Hagopian (@jsign), Jochem Brouwer (@jochem-brouwer), Gabriel Rocheleau (@gabrocheleau) discussions-to: https://ethereum-magicians.org/t/eip-7709-read-blockhash-opcode-from-storage-and-adjust-gas-cost/20052 status: Draft type: Standards Track +requires: 2935 category: Core created: 2024-05-18 --- From 14a872ccff94f156c7b4791ffda6ede675419325 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Mon, 20 May 2024 01:56:14 -0400 Subject: [PATCH 07/35] chore: adjust should/must for retrieving from storage and execution witness --- EIPS/eip-7709.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index d0567dc8c03376..db571549a3012d 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -6,7 +6,7 @@ author: Vitalik Buterin (@vbuterin), Tomasz Stanczak (@tkstanczak), Guillaume Ba discussions-to: https://ethereum-magicians.org/t/eip-7709-read-blockhash-opcode-from-storage-and-adjust-gas-cost/20052 status: Draft type: Standards Track -requires: 2935 +requires: 2935, 6800 category: Core created: 2024-05-18 --- @@ -109,9 +109,8 @@ Corresponding bytecode: For the verkle_block (blocks where `block.timestamp >= FORK_TIMESTAMP`), we consider that the fork (`FORK_TIMESTAMP`) is already in effect for at least `HISTORY_SERVE_WINDOW` blocks (or from genesis if `fork_block < HISTORY_SERVE_WINDOW`). The following changes take effect: -- `BLOCKHASH` MUST retrieve blockhashes from the system contract storage +- `BLOCKHASH` SHOULD retrieve blockhashes from the system contract storage and MUST provide the storage access in the Verkle execution witness - The gas cost of the `BLOCKHASH` opcode is updated as per specification -- The storage access is provided in the verkle execution witness. ### [EIP-158](./eip-158.md) handling From c3168f01c199639d521ecba6e17b33d6bf5c7fcb Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Mon, 20 May 2024 01:59:42 -0400 Subject: [PATCH 08/35] chore: adjust formatting --- EIPS/eip-7709.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index db571549a3012d..020b957ea6e220 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -1,14 +1,14 @@ --- eip: 7709 -title: Read BLOCKHASH from storage and update gas cost +title: Read BLOCKHASH from storage and update cost description: Read the `BLOCKHASH (0x40)` opcode from the EIP-2935 system contract storage and adjust its gas cost to reflect storage access. author: Vitalik Buterin (@vbuterin), Tomasz Stanczak (@tkstanczak), Guillaume Ballet (@gballet), Gajinder Singh (@g11tech), Tanishq Jasoria (@tanishqjasoria), Ignacio Hagopian (@jsign), Jochem Brouwer (@jochem-brouwer), Gabriel Rocheleau (@gabrocheleau) discussions-to: https://ethereum-magicians.org/t/eip-7709-read-blockhash-opcode-from-storage-and-adjust-gas-cost/20052 status: Draft type: Standards Track -requires: 2935, 6800 category: Core created: 2024-05-18 +requires: 2935, 6800 --- ## Abstract @@ -100,7 +100,7 @@ stop Note that the input contract read `32` bytes input as `calldataload`. Users and clients doing EVM call to this contract should left pad the `arg` correctly. - + Corresponding bytecode: `60203611603157600143035f35116029575f356120000143116029576120005f3506545f5260205ff35b5f5f5260205ff35b5f5ffd00` From e800e870469842417ca168b729c569a638eefb43 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Mon, 20 May 2024 03:36:49 -0400 Subject: [PATCH 09/35] chore: add history serve window constant and adjust verkle fork block naming to fork block --- EIPS/eip-7709.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index 020b957ea6e220..0deeaa0baf3316 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -28,6 +28,7 @@ The motivation behind the updated gas cost is to match the real cost of the oper | `FORK_TIMESTAMP` | TBD | | `HISTORY_STORAGE_ADDRESS` | `0x25a219378dad9b3503c8268c9ca836a52427a4fb` | | `BLOCKHASH_SERVE_WINDOW` | `256` | +| `HISTORY_SERVE_WINDOW` | `8192` | The `BLOCKHASH` opcode semantics remains the same as before. From the `fork_block` (first block where `block.timestamp >= FORK_TIMESTAMP`), the `BLOCKHASH` instruction should be updated to retrieve the requested blockhash from the contract storage. @@ -107,7 +108,7 @@ Corresponding bytecode: #### Deployment -For the verkle_block (blocks where `block.timestamp >= FORK_TIMESTAMP`), we consider that the fork (`FORK_TIMESTAMP`) is already in effect for at least `HISTORY_SERVE_WINDOW` blocks (or from genesis if `fork_block < HISTORY_SERVE_WINDOW`). The following changes take effect: +For the fork_block (blocks where `block.timestamp >= FORK_TIMESTAMP`), we consider that the fork (`FORK_TIMESTAMP`) is already in effect for at least `HISTORY_SERVE_WINDOW` blocks (or from genesis if `fork_block < HISTORY_SERVE_WINDOW`). The following changes take effect: - `BLOCKHASH` SHOULD retrieve blockhashes from the system contract storage and MUST provide the storage access in the Verkle execution witness - The gas cost of the `BLOCKHASH` opcode is updated as per specification From 72ff8860ad9cee5baf76cda9d807aec96ae30485 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Tue, 21 May 2024 10:29:09 -0400 Subject: [PATCH 10/35] eip 7709: add warm storage slot for newly inserted blockhash --- EIPS/eip-7709.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index 0deeaa0baf3316..c633aef5021955 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -113,11 +113,9 @@ For the fork_block (blocks where `block.timestamp >= FORK_TIMESTAMP`), we consid - `BLOCKHASH` SHOULD retrieve blockhashes from the system contract storage and MUST provide the storage access in the Verkle execution witness - The gas cost of the `BLOCKHASH` opcode is updated as per specification -### [EIP-158](./eip-158.md) handling - ### Gas costs -At FORK_TIMESTAMP, the corresponding storage access witness for the blockhash `SLOAD` lookups must also included in the execution witness, along with their access gas charges. +At FORK_TIMESTAMP, the corresponding storage access witness for the blockhash `SLOAD` lookups must also included in the execution witness, along with their access gas charges. The blockhash that has been inserted at the beginning of the block processing (the parent block hash) is considered warm. ## Rationale From 9a4c1419f82ec59c3fb1be0fc5dc881776dbdeff Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Wed, 22 May 2024 04:03:45 -0400 Subject: [PATCH 11/35] make history storage address tbd --- EIPS/eip-7709.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index c633aef5021955..04cf3dd8aed6dc 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -23,12 +23,12 @@ The motivation behind the updated gas cost is to match the real cost of the oper ## Specification -| Parameter | Value | -| ------------------------- | -------------------------------------------- | -| `FORK_TIMESTAMP` | TBD | -| `HISTORY_STORAGE_ADDRESS` | `0x25a219378dad9b3503c8268c9ca836a52427a4fb` | -| `BLOCKHASH_SERVE_WINDOW` | `256` | -| `HISTORY_SERVE_WINDOW` | `8192` | +| Parameter | Value | +| ------------------------- | ------ | +| `FORK_TIMESTAMP` | TBD | +| `HISTORY_STORAGE_ADDRESS` | TBD | +| `BLOCKHASH_SERVE_WINDOW` | `256` | +| `HISTORY_SERVE_WINDOW` | `8192` | The `BLOCKHASH` opcode semantics remains the same as before. From the `fork_block` (first block where `block.timestamp >= FORK_TIMESTAMP`), the `BLOCKHASH` instruction should be updated to retrieve the requested blockhash from the contract storage. From f3fb509c7ea729c0b444740f09fea6ee7c94fd83 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Wed, 22 May 2024 05:03:23 -0400 Subject: [PATCH 12/35] update as per comments --- EIPS/eip-7709.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index 04cf3dd8aed6dc..a65cde983ceab7 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -8,7 +8,7 @@ status: Draft type: Standards Track category: Core created: 2024-05-18 -requires: 2935, 6800 +requires: 2935, 4762, 6800 --- ## Abstract @@ -17,7 +17,7 @@ Update the `BLOCKHASH (0x40)` opcode to read and serve from the system contract ## Motivation -The `BLOCKHASH (0x40)` opcode currently assumes that the client has knowledge of the previous blocks, which in Verkle, would prevent stateless execution. This EIP assumes that [EIP-2935](./eip-2935.md) has been implemented, and that blockhashes can be retrieved from the systems contract storage. By updating the behavior of `BLOCKHASH (0x40)` to directly read and serve from state through the system contract storage, we allow Verkle blocks to include a storage access witness, which will allow stateless execution. +The `BLOCKHASH (0x40)` opcode currently assumes that the client has knowledge of the previous blocks, which in Verkle, would prevent stateless execution. This EIP assumes that [EIP-2935](./eip-2935.md) has been implemented, and that blockhashes can be retrieved from the systems contract storage. This EIP also assumes that the Verkle [EIP-6800](./eip-6800.md) is being implemented in the same hard fork. By updating the behavior of `BLOCKHASH (0x40)` to directly read and serve from state through the system contract storage, we allow Verkle blocks to include a storage access witness, which will allow stateless execution. The motivation behind the updated gas cost is to match the real cost of the operation, which is equivalent to an `SLOAD`. @@ -121,11 +121,13 @@ At FORK_TIMESTAMP, the corresponding storage access witness for the blockhash `S ## Backwards Compatibility -This EIP introduces a significant increase in the cost of `BLOCKHASH`, which could break use-cases that rely on the previous gas cost. +This EIP introduces a significant increase in the cost of `BLOCKHASH`, which could break use-cases that rely on the previous gas cost. Also, this EIP introduces a breaking change in the case where less than `BLOCKHASH_SERVE_WINDOW` elapse between the [EIP-2935](./eip-2935.md) fork and this EIP's fork. Otherwise, the blockhashes for the block preceding the `EIP-2935` fork block's parent would return `0`, as they will not have been saved to the system contract storage. ## Test Cases -TBD +- If BLOCKHASH is not called within the block, there MUST be no witness related to the storage contract, except the storage slot witness for the parent blockhash just added to the storage contract. +- If BLOCKHASH is called, there MUST be a storage access witness for each corresponding storage slot. There corresponding account access witnesses MUST NOT be included unless the contract has been accessed explicitly (i.e. not through `BLOCKHASH`). The gas cost for each BLOCKHASH operation should still be charged, in addition to the `SLOAD` cost of each lookup (initially cold, unless it is the parent blockhash, in which case it is initially warm). +- If the storage contract is accessed directly (i.e. not through `BLOCKHASH`), then the witness and gas costs remain consistent with other contract storage accesses, as per [EIP-4762](./eip-4762.md). ## Security Considerations From 9ee85fe6631115c109fcfd41458e28c3413f4239 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Sun, 26 May 2024 08:13:43 -0400 Subject: [PATCH 13/35] Update EIPS/eip-7709.md Co-authored-by: g11tech --- EIPS/eip-7709.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index a65cde983ceab7..d11d1643780c82 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -17,7 +17,9 @@ Update the `BLOCKHASH (0x40)` opcode to read and serve from the system contract ## Motivation -The `BLOCKHASH (0x40)` opcode currently assumes that the client has knowledge of the previous blocks, which in Verkle, would prevent stateless execution. This EIP assumes that [EIP-2935](./eip-2935.md) has been implemented, and that blockhashes can be retrieved from the systems contract storage. This EIP also assumes that the Verkle [EIP-6800](./eip-6800.md) is being implemented in the same hard fork. By updating the behavior of `BLOCKHASH (0x40)` to directly read and serve from state through the system contract storage, we allow Verkle blocks to include a storage access witness, which will allow stateless execution. +The `BLOCKHASH (0x40)` opcode currently assumes that the client has knowledge of the previous blocks, which in Verkle [EIP-6800](./eip-6800.md) would prevent stateless execution. However with [EIP-2935](./eip-2935.md) blockhashes can be retrieved and served from its system contract storage which allows Verkle blocks to include a storage access witness for stateless execution. + +This EIP specifies the transition to the new logic on the Verkle hardfork assuming that [EIP-2935](./eip-2935.md) has been activated sufficiently ahead of Verkle(>= `BLOCKHASH_SERVE_WINDOW` or at genesis for testnets/devnets) The motivation behind the updated gas cost is to match the real cost of the operation, which is equivalent to an `SLOAD`. From e925fbac150ff0022271835c664215a44ba77641 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Sun, 26 May 2024 08:16:19 -0400 Subject: [PATCH 14/35] eip-7709: address review --- EIPS/eip-7709.md | 78 ++---------------------------------------------- 1 file changed, 3 insertions(+), 75 deletions(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index a65cde983ceab7..687c18d1db9ccd 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -19,8 +19,6 @@ Update the `BLOCKHASH (0x40)` opcode to read and serve from the system contract The `BLOCKHASH (0x40)` opcode currently assumes that the client has knowledge of the previous blocks, which in Verkle, would prevent stateless execution. This EIP assumes that [EIP-2935](./eip-2935.md) has been implemented, and that blockhashes can be retrieved from the systems contract storage. This EIP also assumes that the Verkle [EIP-6800](./eip-6800.md) is being implemented in the same hard fork. By updating the behavior of `BLOCKHASH (0x40)` to directly read and serve from state through the system contract storage, we allow Verkle blocks to include a storage access witness, which will allow stateless execution. -The motivation behind the updated gas cost is to match the real cost of the operation, which is equivalent to an `SLOAD`. - ## Specification | Parameter | Value | @@ -32,79 +30,7 @@ The motivation behind the updated gas cost is to match the real cost of the oper The `BLOCKHASH` opcode semantics remains the same as before. From the `fork_block` (first block where `block.timestamp >= FORK_TIMESTAMP`), the `BLOCKHASH` instruction should be updated to retrieve the requested blockhash from the contract storage. -### Contract Implementation - -Exact evm assembly that can be used for the contract to resolve `BLOCKHASH` - -``` -// check if input > 8 byte value and revert if this isn't the case -// the check is performed by comparing the biggest 8 byte number with -// the call data, which is a right-padded 32 byte number. -push8 0xffffffffffffffff -push0 -calldataload -gt -push1 0x39 -jumpi - -// check if input > blocknumber-1 then return 0 -push1 0x1 -number -sub -push0 -calldataload -gt -push1 0x31 -jumpi - -// check if blocknumber > input + 8192 then return 0, no overflow expected for input of 8 bytes -push0 -calldataload -push2 0x2000 -add -number -gt -push1 0x31 -jumpi - -// mod 8192 and sload -push2 0x1FFF -push0 -calldataload -and -sload - -// load into mem and return 32 bytes -push0 -mstore -push1 0x20 -push0 -return - -// return 0 -jumpdest -push0 -push0 -mstore -push1 0x20 -push0 -return - -// revert -jumpdest -push0 -push0 -revert - -stop -``` - -Note that the input contract read `32` bytes input as `calldataload`. Users and clients doing EVM call to this contract should left pad the `arg` correctly. - - - -Corresponding bytecode: -`60203611603157600143035f35116029575f356120000143116029576120005f3506545f5260205ff35b5f5f5260205ff35b5f5ffd00` +Additional gas costs need to be applied for the corresponding SLOAD operation and the corresponding access witness added to the execution witnesses #### Deployment @@ -119,6 +45,8 @@ At FORK_TIMESTAMP, the corresponding storage access witness for the blockhash `S ## Rationale +The reason behind the updated gas cost is to match the real cost of the operation, which is equivalent to an SLOAD. + ## Backwards Compatibility This EIP introduces a significant increase in the cost of `BLOCKHASH`, which could break use-cases that rely on the previous gas cost. Also, this EIP introduces a breaking change in the case where less than `BLOCKHASH_SERVE_WINDOW` elapse between the [EIP-2935](./eip-2935.md) fork and this EIP's fork. Otherwise, the blockhashes for the block preceding the `EIP-2935` fork block's parent would return `0`, as they will not have been saved to the system contract storage. From a7e97d44a4f0e692643665193e59bc0ce344863a Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Sun, 26 May 2024 08:18:27 -0400 Subject: [PATCH 15/35] eip-7709: linting error --- EIPS/eip-7709.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index f26b4b6d9b9763..58e26b2b098a71 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -17,7 +17,7 @@ Update the `BLOCKHASH (0x40)` opcode to read and serve from the system contract ## Motivation -The `BLOCKHASH (0x40)` opcode currently assumes that the client has knowledge of the previous blocks, which in Verkle [EIP-6800](./eip-6800.md) would prevent stateless execution. However with [EIP-2935](./eip-2935.md) blockhashes can be retrieved and served from its system contract storage which allows Verkle blocks to include a storage access witness for stateless execution. +The `BLOCKHASH (0x40)` opcode currently assumes that the client has knowledge of the previous blocks, which in Verkle [EIP-6800](./eip-6800.md) would prevent stateless execution. However with [EIP-2935](./eip-2935.md) blockhashes can be retrieved and served from its system contract storage which allows Verkle blocks to include a storage access witness for stateless execution. This EIP specifies the transition to the new logic on the Verkle hardfork assuming that [EIP-2935](./eip-2935.md) has been activated sufficiently ahead of Verkle(>= `BLOCKHASH_SERVE_WINDOW` or at genesis for testnets/devnets) @@ -34,7 +34,7 @@ The `BLOCKHASH` opcode semantics remains the same as before. From the `fork_bloc Additional gas costs need to be applied for the corresponding SLOAD operation and the corresponding access witness added to the execution witnesses -#### Deployment +### Deployment For the fork_block (blocks where `block.timestamp >= FORK_TIMESTAMP`), we consider that the fork (`FORK_TIMESTAMP`) is already in effect for at least `HISTORY_SERVE_WINDOW` blocks (or from genesis if `fork_block < HISTORY_SERVE_WINDOW`). The following changes take effect: From 100a05e91f822a220752a21dfd183571f8cda6ee Mon Sep 17 00:00:00 2001 From: gajinder Date: Mon, 27 May 2024 19:23:43 +0530 Subject: [PATCH 16/35] refactor the eip --- EIPS/eip-7709.md | 61 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index 58e26b2b098a71..a1ee33edd66ef1 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -8,19 +8,17 @@ status: Draft type: Standards Track category: Core created: 2024-05-18 -requires: 2935, 4762, 6800 +requires: 2935 --- ## Abstract -Update the `BLOCKHASH (0x40)` opcode to read and serve from the system contract storage to allow for stateless execution. Update the `BLOCKHASH (0x40)` opcode gas cost to reflect storage access cost, and include storage accesses in the Verkle block witness. +Update the `BLOCKHASH (0x40)` opcode to read and serve from the system contract storage to allow for stateless execution and charge the **additional** (cold or warm) gas on the lines of `SLOAD` for the corresponding slot. ## Motivation The `BLOCKHASH (0x40)` opcode currently assumes that the client has knowledge of the previous blocks, which in Verkle [EIP-6800](./eip-6800.md) would prevent stateless execution. However with [EIP-2935](./eip-2935.md) blockhashes can be retrieved and served from its system contract storage which allows Verkle blocks to include a storage access witness for stateless execution. -This EIP specifies the transition to the new logic on the Verkle hardfork assuming that [EIP-2935](./eip-2935.md) has been activated sufficiently ahead of Verkle(>= `BLOCKHASH_SERVE_WINDOW` or at genesis for testnets/devnets) - ## Specification | Parameter | Value | @@ -28,40 +26,67 @@ This EIP specifies the transition to the new logic on the Verkle hardfork assumi | `FORK_TIMESTAMP` | TBD | | `HISTORY_STORAGE_ADDRESS` | TBD | | `BLOCKHASH_SERVE_WINDOW` | `256` | -| `HISTORY_SERVE_WINDOW` | `8192` | -The `BLOCKHASH` opcode semantics remains the same as before. From the `fork_block` (first block where `block.timestamp >= FORK_TIMESTAMP`), the `BLOCKHASH` instruction should be updated to retrieve the requested blockhash from the contract storage. +The `BLOCKHASH` opcode semantics remains the same as before. From the `fork_block` (first block where `block.timestamp >= FORK_TIMESTAMP`), the `BLOCKHASH` instruction should be updated to resolve block hash in the following manner: + +```python +def resolve_blockhash(block: Block, state: State, arg: uint64): + # note that outside the BLOCKHASH_SERVE_WINDOW we continue to return 0 + # despite the 2935 history contract being able to serve more hashes + if arg >= block.number or (arg + BLOCKHASH_SERVE_WINDOW) < block.number + return 0 + + # performs an sload on arg % HISTORY_SERVE_WINDOW including gas charges, + # warming effects as well as execution accesses + # + # note that the `BLOCKHASH_SERVE_WINDOW` and the 2935 ring buffer window + # `HISTORY_SERVE_WINDOW` for slot calculation are different + return state.load_slot(HISTORY_STORAGE_ADDRESS, arg % HISTORY_SERVE_WINDOW) +``` + +ONLY if the `arg` is within the correct `BLOCKHASH` window, clients can choose to either -Additional gas costs need to be applied for the corresponding SLOAD operation and the corresponding access witness added to the execution witnesses +* do a direct `SLOAD` from state, or +* do a system call to [EIP-2935](./eip-2935.md) contract `get` or +* serve from memory or as per current designs if maintaining requisite history (full clients for e.g.) -### Deployment +However the entire semantics and after effects of the `SLOAD` operation needs to be applied as per the current fork if the `arg` is within the correct `BLOCKHASH` window: -For the fork_block (blocks where `block.timestamp >= FORK_TIMESTAMP`), we consider that the fork (`FORK_TIMESTAMP`) is already in effect for at least `HISTORY_SERVE_WINDOW` blocks (or from genesis if `fork_block < HISTORY_SERVE_WINDOW`). The following changes take effect: +* `SLOAD` gas costs (cold or warm) for the `arg % HISTORY_SERVE_WINDOW` slot. +* `SLOAD` after effects on the slot (warming the slot) +* `SLOAD` accesses added to execution witnesses if Verkle ([EIP-6800](./eip-6800.md) and [EIP-4762](./eip-4762.md)) is activated -- `BLOCKHASH` SHOULD retrieve blockhashes from the system contract storage and MUST provide the storage access in the Verkle execution witness -- The gas cost of the `BLOCKHASH` opcode is updated as per specification +### Activation + +This EIP specifies the transition to the new logic on the Verkle hardfork assuming that [EIP-2935](./eip-2935.md) has been activated sufficiently ahead of Verkle(>= `BLOCKHASH_SERVE_WINDOW` or at genesis for testnets/devnets). ### Gas costs -At FORK_TIMESTAMP, the corresponding storage access witness for the blockhash `SLOAD` lookups must also included in the execution witness, along with their access gas charges. The blockhash that has been inserted at the beginning of the block processing (the parent block hash) is considered warm. +As described above, if the `arg` to be resolved is within the correct window, the corresponding `SLOAD` charges and accesses are to be applied for the slot `arg % HISTORY_SERVE_WINDOW`. Note that the `HISTORY_SERVE_WINDOW` and `BLOCKHASH_SERVE_WINDOW` are different. + +### System contract + +Even if the clients choose to resolve `BLOCKHASH` through system call to [EIP-2935](./eip-2935.md) contract, the gas cost for the system code execution (and also the code witnesses if Verkle activated) is not applied. Only the effect of `SLOAD` is applied as described above. ## Rationale -The reason behind the updated gas cost is to match the real cost of the operation, which is equivalent to an SLOAD. +* The reason behind the updated gas cost is to match the real operation, which is equivalent to an `SLOAD`. + +* The [EIP-2935](./eip-2935.md) system contract execution charges (and accesses) are not applied to keep the gas low and to keep things simple for clients which don't choose to resolve `BLOCKHASH` in other ways (directly or though memory/maintained history) ## Backwards Compatibility -This EIP introduces a significant increase in the cost of `BLOCKHASH`, which could break use-cases that rely on the previous gas cost. Also, this EIP introduces a breaking change in the case where less than `BLOCKHASH_SERVE_WINDOW` elapse between the [EIP-2935](./eip-2935.md) fork and this EIP's fork. Otherwise, the blockhashes for the block preceding the `EIP-2935` fork block's parent would return `0`, as they will not have been saved to the system contract storage. +This EIP introduces a significant increase in the cost of `BLOCKHASH`, which could break use-cases that rely on the previous gas cost. Also, this EIP introduces a breaking change in the case where less than `BLOCKHASH_SERVE_WINDOW` elapse between the [EIP-2935](./eip-2935.md) fork and this EIP's fork as the [EIP-2935](./eip-2935.md) would not have saved the requisite history. ## Test Cases -- If BLOCKHASH is not called within the block, there MUST be no witness related to the storage contract, except the storage slot witness for the parent blockhash just added to the storage contract. -- If BLOCKHASH is called, there MUST be a storage access witness for each corresponding storage slot. There corresponding account access witnesses MUST NOT be included unless the contract has been accessed explicitly (i.e. not through `BLOCKHASH`). The gas cost for each BLOCKHASH operation should still be charged, in addition to the `SLOAD` cost of each lookup (initially cold, unless it is the parent blockhash, in which case it is initially warm). -- If the storage contract is accessed directly (i.e. not through `BLOCKHASH`), then the witness and gas costs remain consistent with other contract storage accesses, as per [EIP-4762](./eip-4762.md). +- If BLOCKHASH is called, there MUST be a storage access gas charge ( and witness if Verkle activated) for the corresponding storage slot ONLY if the `BLOCKHASH` query is for the last `BLOCKHASH_SERVE_WINDOW` ancestors irrespective of how the client chooses to resolve the `BLOCKHASH` (directly, via system contract or via memory) +- The gas cost for each `BLOCKHASH` operation should still be charged, in addition to the `SLOAD` cost of each lookup +- If the storage contract is accessed directly (i.e. not through `BLOCKHASH`), then the witness and gas costs remain consistent as per normal contract execution by the EVM as per the current fork/activated EIPs. ## Security Considerations -Having contracts (system or otherwise) with hot update paths (branches) poses a risk of "branch" poisoning attacks where attacker could sprinkle trivial amounts of eth around these hot paths (branches). But it has been deemed that cost of attack would escalate significantly to cause any meaningful slow down of state root updates. +No Security considerations other than the [EIP-2935](./eip-2935.md) are determined as of now. ## Copyright From 2fb7c0e84e4c1406a7d363c357318dca9c4511e3 Mon Sep 17 00:00:00 2001 From: gajinder Date: Mon, 27 May 2024 19:28:59 +0530 Subject: [PATCH 17/35] lint --- EIPS/eip-7709.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index a1ee33edd66ef1..ed650e6fa623de 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -80,9 +80,9 @@ This EIP introduces a significant increase in the cost of `BLOCKHASH`, which cou ## Test Cases -- If BLOCKHASH is called, there MUST be a storage access gas charge ( and witness if Verkle activated) for the corresponding storage slot ONLY if the `BLOCKHASH` query is for the last `BLOCKHASH_SERVE_WINDOW` ancestors irrespective of how the client chooses to resolve the `BLOCKHASH` (directly, via system contract or via memory) -- The gas cost for each `BLOCKHASH` operation should still be charged, in addition to the `SLOAD` cost of each lookup -- If the storage contract is accessed directly (i.e. not through `BLOCKHASH`), then the witness and gas costs remain consistent as per normal contract execution by the EVM as per the current fork/activated EIPs. +* If BLOCKHASH is called, there MUST be a storage access gas charge ( and witness if Verkle activated) for the corresponding storage slot ONLY if the `BLOCKHASH` query is for the last `BLOCKHASH_SERVE_WINDOW` ancestors irrespective of how the client chooses to resolve the `BLOCKHASH` (directly, via system contract or via memory) +* The gas cost for each `BLOCKHASH` operation should still be charged, in addition to the `SLOAD` cost of each lookup +* If the storage contract is accessed directly (i.e. not through `BLOCKHASH`), then the witness and gas costs remain consistent as per normal contract execution by the EVM as per the current fork/activated EIPs. ## Security Considerations From c730a3a5bfd7d5652a9cd55411745fbe74ff2ff5 Mon Sep 17 00:00:00 2001 From: gajinder Date: Mon, 27 May 2024 19:37:47 +0530 Subject: [PATCH 18/35] some more clarity in test cases --- EIPS/eip-7709.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index ed650e6fa623de..83ae440aa4d3ad 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -80,9 +80,10 @@ This EIP introduces a significant increase in the cost of `BLOCKHASH`, which cou ## Test Cases -* If BLOCKHASH is called, there MUST be a storage access gas charge ( and witness if Verkle activated) for the corresponding storage slot ONLY if the `BLOCKHASH` query is for the last `BLOCKHASH_SERVE_WINDOW` ancestors irrespective of how the client chooses to resolve the `BLOCKHASH` (directly, via system contract or via memory) -* The gas cost for each `BLOCKHASH` operation should still be charged, in addition to the `SLOAD` cost of each lookup -* If the storage contract is accessed directly (i.e. not through `BLOCKHASH`), then the witness and gas costs remain consistent as per normal contract execution by the EVM as per the current fork/activated EIPs. +* if `BLOCKHASH` is not called or there is no [EIP-2935](./eip-2935.md) contract call by an transaction, only the [EIP-2935](./eip-2935.md) system update of the parent hash show up in witnesses if Verkle is activated. +* If `BLOCKHASH` is called, there MUST be a storage access gas charge ( and correspending access witness if Verkle activated) for the storage slot but ONLY if the `BLOCKHASH` query is for the last `BLOCKHASH_SERVE_WINDOW` ancestors. This is irrespective of how the client chooses to resolve the `BLOCKHASH` (directly, via system contract or via memory) +* The gas cost for each `BLOCKHASH` operation should still be charged, in addition to the `SLOAD` cost of each lookup (if performed) +* If the [EIP-2935](./eip-2935.md) contract is called directly (i.e. not through `BLOCKHASH`), then the witness and gas costs remain consistent as per normal contract execution by the EVM as per the current fork/activated EIPs. ## Security Considerations From e29aae455c423a3499067fd2e73c8111693f468f Mon Sep 17 00:00:00 2001 From: gajinder Date: Mon, 27 May 2024 19:42:00 +0530 Subject: [PATCH 19/35] some more testcase clarity --- EIPS/eip-7709.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index 83ae440aa4d3ad..c7cc8e66703fa9 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -80,10 +80,11 @@ This EIP introduces a significant increase in the cost of `BLOCKHASH`, which cou ## Test Cases -* if `BLOCKHASH` is not called or there is no [EIP-2935](./eip-2935.md) contract call by an transaction, only the [EIP-2935](./eip-2935.md) system update of the parent hash show up in witnesses if Verkle is activated. +* If `BLOCKHASH` is not called or there is no [EIP-2935](./eip-2935.md) contract call by an transaction, only the [EIP-2935](./eip-2935.md) system update of the parent hash show up in witnesses if Verkle is activated. * If `BLOCKHASH` is called, there MUST be a storage access gas charge ( and correspending access witness if Verkle activated) for the storage slot but ONLY if the `BLOCKHASH` query is for the last `BLOCKHASH_SERVE_WINDOW` ancestors. This is irrespective of how the client chooses to resolve the `BLOCKHASH` (directly, via system contract or via memory) * The gas cost for each `BLOCKHASH` operation should still be charged, in addition to the `SLOAD` cost of each lookup (if performed) * If the [EIP-2935](./eip-2935.md) contract is called directly (i.e. not through `BLOCKHASH`), then the witness and gas costs remain consistent as per normal contract execution by the EVM as per the current fork/activated EIPs. +* `BLOCKHASH` should be consistently resolved if this eip is activated correctly `>= BLOCKHASH_SERVE_WINDOW` after [EIP-2935](./eip-2935.md) ## Security Considerations From 6c56f5fa6d51f28830bb2dbf01e23c57b8e9b152 Mon Sep 17 00:00:00 2001 From: gajinder Date: Mon, 27 May 2024 19:46:40 +0530 Subject: [PATCH 20/35] typo --- EIPS/eip-7709.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index c7cc8e66703fa9..64c33f825f5287 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -72,7 +72,7 @@ Even if the clients choose to resolve `BLOCKHASH` through system call to [EIP-29 * The reason behind the updated gas cost is to match the real operation, which is equivalent to an `SLOAD`. -* The [EIP-2935](./eip-2935.md) system contract execution charges (and accesses) are not applied to keep the gas low and to keep things simple for clients which don't choose to resolve `BLOCKHASH` in other ways (directly or though memory/maintained history) +* The [EIP-2935](./eip-2935.md) system contract execution charges (and accesses) are not applied to keep the gas low and to keep things simple for clients which choose to resolve `BLOCKHASH` in other ways (directly or though memory/maintained history) ## Backwards Compatibility From 17af00997a65a61bc3a56dac4edb9f6bd91a3f75 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Mon, 27 May 2024 12:32:28 -0400 Subject: [PATCH 21/35] Update EIPS/eip-7709.md --- EIPS/eip-7709.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index 64c33f825f5287..07a8df00df5be6 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -58,7 +58,7 @@ However the entire semantics and after effects of the `SLOAD` operation needs to ### Activation -This EIP specifies the transition to the new logic on the Verkle hardfork assuming that [EIP-2935](./eip-2935.md) has been activated sufficiently ahead of Verkle(>= `BLOCKHASH_SERVE_WINDOW` or at genesis for testnets/devnets). +This EIP specifies the transition to the new logic on the Verkle hardfork assuming that [EIP-2935](./eip-2935.md) has been activated sufficiently ahead of Verkle (>= `BLOCKHASH_SERVE_WINDOW` or at genesis for testnets/devnets). ### Gas costs From ffb76d1e830f07a176ed88b3c0dd073c01b1829b Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Mon, 27 May 2024 12:33:43 -0400 Subject: [PATCH 22/35] Update EIPS/eip-7709.md --- EIPS/eip-7709.md | 1 - 1 file changed, 1 deletion(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index 07a8df00df5be6..07ef46b94428c7 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -71,7 +71,6 @@ Even if the clients choose to resolve `BLOCKHASH` through system call to [EIP-29 ## Rationale * The reason behind the updated gas cost is to match the real operation, which is equivalent to an `SLOAD`. - * The [EIP-2935](./eip-2935.md) system contract execution charges (and accesses) are not applied to keep the gas low and to keep things simple for clients which choose to resolve `BLOCKHASH` in other ways (directly or though memory/maintained history) ## Backwards Compatibility From 571f14908fc5030789f26061192887c66e3c4e09 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Mon, 27 May 2024 12:34:26 -0400 Subject: [PATCH 23/35] Update EIPS/eip-7709.md --- EIPS/eip-7709.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index 07ef46b94428c7..21f15b38fb3353 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -79,7 +79,7 @@ This EIP introduces a significant increase in the cost of `BLOCKHASH`, which cou ## Test Cases -* If `BLOCKHASH` is not called or there is no [EIP-2935](./eip-2935.md) contract call by an transaction, only the [EIP-2935](./eip-2935.md) system update of the parent hash show up in witnesses if Verkle is activated. +* If `BLOCKHASH` is not called or there is no [EIP-2935](./eip-2935.md) contract call by any transaction, only the [EIP-2935](./eip-2935.md) system update of the parent hash show up in witnesses if Verkle is activated. * If `BLOCKHASH` is called, there MUST be a storage access gas charge ( and correspending access witness if Verkle activated) for the storage slot but ONLY if the `BLOCKHASH` query is for the last `BLOCKHASH_SERVE_WINDOW` ancestors. This is irrespective of how the client chooses to resolve the `BLOCKHASH` (directly, via system contract or via memory) * The gas cost for each `BLOCKHASH` operation should still be charged, in addition to the `SLOAD` cost of each lookup (if performed) * If the [EIP-2935](./eip-2935.md) contract is called directly (i.e. not through `BLOCKHASH`), then the witness and gas costs remain consistent as per normal contract execution by the EVM as per the current fork/activated EIPs. From 8cd03d70a47f6aab048bd0c748077c96366edb62 Mon Sep 17 00:00:00 2001 From: g11tech Date: Mon, 27 May 2024 22:04:53 +0530 Subject: [PATCH 24/35] Update EIPS/eip-7709.md Co-authored-by: Gabriel Rocheleau --- EIPS/eip-7709.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index 21f15b38fb3353..6d516180e64979 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -13,7 +13,7 @@ requires: 2935 ## Abstract -Update the `BLOCKHASH (0x40)` opcode to read and serve from the system contract storage to allow for stateless execution and charge the **additional** (cold or warm) gas on the lines of `SLOAD` for the corresponding slot. +Update the `BLOCKHASH (0x40)` opcode to read and serve from the system contract storage and charge the **additional** (cold or warm) gas on the lines of `SLOAD` for the corresponding slot. ## Motivation From 066be6798d0d02af6de5c05f4926b308ddbf417e Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Mon, 27 May 2024 12:35:46 -0400 Subject: [PATCH 25/35] Update EIPS/eip-7709.md --- EIPS/eip-7709.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index 6d516180e64979..75157cee81f5d4 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -75,7 +75,7 @@ Even if the clients choose to resolve `BLOCKHASH` through system call to [EIP-29 ## Backwards Compatibility -This EIP introduces a significant increase in the cost of `BLOCKHASH`, which could break use-cases that rely on the previous gas cost. Also, this EIP introduces a breaking change in the case where less than `BLOCKHASH_SERVE_WINDOW` elapse between the [EIP-2935](./eip-2935.md) fork and this EIP's fork as the [EIP-2935](./eip-2935.md) would not have saved the requisite history. +This EIP introduces a significant increase in the cost of `BLOCKHASH`, which could break use-cases that rely on the previous gas cost. Also, this EIP introduces a breaking change in the case where less than `BLOCKHASH_SERVE_WINDOW` elapse between the [EIP-2935](./eip-2935.md) fork and this EIP's fork as the [EIP-2935](./eip-2935.md) system contract would not have saved the required history. ## Test Cases From dfc2b6951cc933f46cb8f5bc355d6fece40b5d61 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Mon, 27 May 2024 12:36:39 -0400 Subject: [PATCH 26/35] Update EIPS/eip-7709.md --- EIPS/eip-7709.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index 75157cee81f5d4..abb688c61f23a4 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -79,7 +79,7 @@ This EIP introduces a significant increase in the cost of `BLOCKHASH`, which cou ## Test Cases -* If `BLOCKHASH` is not called or there is no [EIP-2935](./eip-2935.md) contract call by any transaction, only the [EIP-2935](./eip-2935.md) system update of the parent hash show up in witnesses if Verkle is activated. +* If `BLOCKHASH` is not called or there is no [EIP-2935](./eip-2935.md) contract call by any transaction, only the [EIP-2935](./eip-2935.md) system update of the parent hash shows up in witnesses if Verkle is activated. * If `BLOCKHASH` is called, there MUST be a storage access gas charge ( and correspending access witness if Verkle activated) for the storage slot but ONLY if the `BLOCKHASH` query is for the last `BLOCKHASH_SERVE_WINDOW` ancestors. This is irrespective of how the client chooses to resolve the `BLOCKHASH` (directly, via system contract or via memory) * The gas cost for each `BLOCKHASH` operation should still be charged, in addition to the `SLOAD` cost of each lookup (if performed) * If the [EIP-2935](./eip-2935.md) contract is called directly (i.e. not through `BLOCKHASH`), then the witness and gas costs remain consistent as per normal contract execution by the EVM as per the current fork/activated EIPs. From 1bafa493c53b498be10ba79fe2260c997236fc64 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Mon, 27 May 2024 12:37:16 -0400 Subject: [PATCH 27/35] Update EIPS/eip-7709.md --- EIPS/eip-7709.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index abb688c61f23a4..5cc99fec541e78 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -80,7 +80,7 @@ This EIP introduces a significant increase in the cost of `BLOCKHASH`, which cou ## Test Cases * If `BLOCKHASH` is not called or there is no [EIP-2935](./eip-2935.md) contract call by any transaction, only the [EIP-2935](./eip-2935.md) system update of the parent hash shows up in witnesses if Verkle is activated. -* If `BLOCKHASH` is called, there MUST be a storage access gas charge ( and correspending access witness if Verkle activated) for the storage slot but ONLY if the `BLOCKHASH` query is for the last `BLOCKHASH_SERVE_WINDOW` ancestors. This is irrespective of how the client chooses to resolve the `BLOCKHASH` (directly, via system contract or via memory) +* If `BLOCKHASH` is called, there MUST be a storage access gas charge (and corresponding access witness if Verkle is activated) for the storage slot but ONLY if the `BLOCKHASH` query is for the last `BLOCKHASH_SERVE_WINDOW` ancestors. This is irrespective of how the client chooses to resolve the `BLOCKHASH` (directly, via system contract or via memory) * The gas cost for each `BLOCKHASH` operation should still be charged, in addition to the `SLOAD` cost of each lookup (if performed) * If the [EIP-2935](./eip-2935.md) contract is called directly (i.e. not through `BLOCKHASH`), then the witness and gas costs remain consistent as per normal contract execution by the EVM as per the current fork/activated EIPs. * `BLOCKHASH` should be consistently resolved if this eip is activated correctly `>= BLOCKHASH_SERVE_WINDOW` after [EIP-2935](./eip-2935.md) From dc246c415810083c45b2ca85992b757202605779 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Mon, 27 May 2024 12:38:00 -0400 Subject: [PATCH 28/35] Update EIPS/eip-7709.md --- EIPS/eip-7709.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index 5cc99fec541e78..84bea83f7276bc 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -83,7 +83,7 @@ This EIP introduces a significant increase in the cost of `BLOCKHASH`, which cou * If `BLOCKHASH` is called, there MUST be a storage access gas charge (and corresponding access witness if Verkle is activated) for the storage slot but ONLY if the `BLOCKHASH` query is for the last `BLOCKHASH_SERVE_WINDOW` ancestors. This is irrespective of how the client chooses to resolve the `BLOCKHASH` (directly, via system contract or via memory) * The gas cost for each `BLOCKHASH` operation should still be charged, in addition to the `SLOAD` cost of each lookup (if performed) * If the [EIP-2935](./eip-2935.md) contract is called directly (i.e. not through `BLOCKHASH`), then the witness and gas costs remain consistent as per normal contract execution by the EVM as per the current fork/activated EIPs. -* `BLOCKHASH` should be consistently resolved if this eip is activated correctly `>= BLOCKHASH_SERVE_WINDOW` after [EIP-2935](./eip-2935.md) +* `BLOCKHASH` should be consistently resolved if this EIP is activated correctly `>= BLOCKHASH_SERVE_WINDOW` after [EIP-2935](./eip-2935.md) ## Security Considerations From 21e0c291572087da2128443374cc99fc2f5c8b2b Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Mon, 27 May 2024 12:38:23 -0400 Subject: [PATCH 29/35] Update EIPS/eip-7709.md --- EIPS/eip-7709.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index 84bea83f7276bc..b5d178bfa294a0 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -87,7 +87,7 @@ This EIP introduces a significant increase in the cost of `BLOCKHASH`, which cou ## Security Considerations -No Security considerations other than the [EIP-2935](./eip-2935.md) are determined as of now. +No security considerations other than the ones contained in [EIP-2935](./eip-2935.md) are determined as of now. ## Copyright From 9ae6d5c378a1d354c985432303d759f99fceb627 Mon Sep 17 00:00:00 2001 From: gajinder Date: Mon, 27 May 2024 22:18:15 +0530 Subject: [PATCH 30/35] clarify activation --- EIPS/eip-7709.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index b5d178bfa294a0..4137b3cdae3a62 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -58,7 +58,12 @@ However the entire semantics and after effects of the `SLOAD` operation needs to ### Activation -This EIP specifies the transition to the new logic on the Verkle hardfork assuming that [EIP-2935](./eip-2935.md) has been activated sufficiently ahead of Verkle (>= `BLOCKHASH_SERVE_WINDOW` or at genesis for testnets/devnets). +This EIP specifies the transition to the new logic assuming that [EIP-2935](./eip-2935.md) has been activated: + +* sufficiently ahead of thie EIP's activation (>= `BLOCKHASH_SERVE_WINDOW`) or +* at genesis for testnets/devnets where this EIP could also be activated at genesis + +The current proposal is to activate this EIP with Verkle to allow for stateless execution of the block. ### Gas costs From 37a83cbba5037694569180a43ba655cf18c58f2b Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Mon, 27 May 2024 13:08:29 -0400 Subject: [PATCH 31/35] Update EIPS/eip-7709.md --- EIPS/eip-7709.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index 4137b3cdae3a62..bfa844fa3c7218 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -60,7 +60,7 @@ However the entire semantics and after effects of the `SLOAD` operation needs to This EIP specifies the transition to the new logic assuming that [EIP-2935](./eip-2935.md) has been activated: -* sufficiently ahead of thie EIP's activation (>= `BLOCKHASH_SERVE_WINDOW`) or +* sufficiently ahead of this EIP's activation (>= `BLOCKHASH_SERVE_WINDOW`) or * at genesis for testnets/devnets where this EIP could also be activated at genesis The current proposal is to activate this EIP with Verkle to allow for stateless execution of the block. From 87f3ba03405d32489211c98b02fdc1898bea883e Mon Sep 17 00:00:00 2001 From: g11tech Date: Wed, 29 May 2024 01:50:20 +0530 Subject: [PATCH 32/35] Update EIPS/eip-7709.md Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com> --- EIPS/eip-7709.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index bfa844fa3c7218..6d9171eac5a381 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -27,7 +27,7 @@ The `BLOCKHASH (0x40)` opcode currently assumes that the client has knowledge of | `HISTORY_STORAGE_ADDRESS` | TBD | | `BLOCKHASH_SERVE_WINDOW` | `256` | -The `BLOCKHASH` opcode semantics remains the same as before. From the `fork_block` (first block where `block.timestamp >= FORK_TIMESTAMP`), the `BLOCKHASH` instruction should be updated to resolve block hash in the following manner: +The `BLOCKHASH` opcode semantics remains the same as before. From the `fork_block` (defined as `fork_block.timestamp >= FORK_TIMESTAMP and fork_block.parent.timestamp < FORK_TIMESTAMP`), the `BLOCKHASH` instruction should be updated to resolve block hash in the following manner: ```python def resolve_blockhash(block: Block, state: State, arg: uint64): From 5420e021b28be641cfcb3f866b24121a6343273e Mon Sep 17 00:00:00 2001 From: g11tech Date: Wed, 29 May 2024 01:54:30 +0530 Subject: [PATCH 33/35] Update EIPS/eip-7709.md --- EIPS/eip-7709.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index 6d9171eac5a381..d2e0489b7ffbf4 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -47,7 +47,7 @@ def resolve_blockhash(block: Block, state: State, arg: uint64): ONLY if the `arg` is within the correct `BLOCKHASH` window, clients can choose to either * do a direct `SLOAD` from state, or -* do a system call to [EIP-2935](./eip-2935.md) contract `get` or +* do a system call to [EIP-2935](./eip-2935.md) contract via its `get` mechanism (caller other than `SYSTEM_ADDRESS`) or * serve from memory or as per current designs if maintaining requisite history (full clients for e.g.) However the entire semantics and after effects of the `SLOAD` operation needs to be applied as per the current fork if the `arg` is within the correct `BLOCKHASH` window: From e4f8c11971877601e8b2367a648be0e6f8490da7 Mon Sep 17 00:00:00 2001 From: g11tech Date: Wed, 29 May 2024 01:57:19 +0530 Subject: [PATCH 34/35] Update EIPS/eip-7709.md --- EIPS/eip-7709.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index d2e0489b7ffbf4..84d4b749f3fd2e 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -80,7 +80,7 @@ Even if the clients choose to resolve `BLOCKHASH` through system call to [EIP-29 ## Backwards Compatibility -This EIP introduces a significant increase in the cost of `BLOCKHASH`, which could break use-cases that rely on the previous gas cost. Also, this EIP introduces a breaking change in the case where less than `BLOCKHASH_SERVE_WINDOW` elapse between the [EIP-2935](./eip-2935.md) fork and this EIP's fork as the [EIP-2935](./eip-2935.md) system contract would not have saved the required history. +This EIP introduces a significant increase in the cost of `BLOCKHASH`, which could break use-cases that rely on the previous gas cost. Also, this EIP introduces a breaking change in the case where less than `BLOCKHASH_SERVE_WINDOW` elapse between the [EIP-2935](./eip-2935.md) fork and this EIP's fork (unless [EIP-2935](./eip-2935.md) is activated in genesis for e.g. in testnets/devnets) as the [EIP-2935](./eip-2935.md) system contract would not have saved the required history. ## Test Cases From 8110463307d65debe9033210971dd918fa4236ec Mon Sep 17 00:00:00 2001 From: gajinder Date: Wed, 29 May 2024 17:21:53 +0530 Subject: [PATCH 35/35] feedback --- EIPS/eip-7709.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/EIPS/eip-7709.md b/EIPS/eip-7709.md index 84d4b749f3fd2e..6f69c9abd491bc 100644 --- a/EIPS/eip-7709.md +++ b/EIPS/eip-7709.md @@ -13,7 +13,7 @@ requires: 2935 ## Abstract -Update the `BLOCKHASH (0x40)` opcode to read and serve from the system contract storage and charge the **additional** (cold or warm) gas on the lines of `SLOAD` for the corresponding slot. +Update the `BLOCKHASH (0x40)` opcode to read and serve from the system contract storage and charge the **additional** (cold or warm) storage costs. ## Motivation @@ -69,7 +69,7 @@ The current proposal is to activate this EIP with Verkle to allow for stateless As described above, if the `arg` to be resolved is within the correct window, the corresponding `SLOAD` charges and accesses are to be applied for the slot `arg % HISTORY_SERVE_WINDOW`. Note that the `HISTORY_SERVE_WINDOW` and `BLOCKHASH_SERVE_WINDOW` are different. -### System contract +### Reading from the System contract Even if the clients choose to resolve `BLOCKHASH` through system call to [EIP-2935](./eip-2935.md) contract, the gas cost for the system code execution (and also the code witnesses if Verkle activated) is not applied. Only the effect of `SLOAD` is applied as described above. @@ -78,6 +78,8 @@ Even if the clients choose to resolve `BLOCKHASH` through system call to [EIP-29 * The reason behind the updated gas cost is to match the real operation, which is equivalent to an `SLOAD`. * The [EIP-2935](./eip-2935.md) system contract execution charges (and accesses) are not applied to keep the gas low and to keep things simple for clients which choose to resolve `BLOCKHASH` in other ways (directly or though memory/maintained history) +Note that `BLOCKHASH` opcode only serves a limited `BLOCKHASH_SERVE_WINDOW` to be backward compatible (and to not extend the above exemptions). For deeper accesses one will need to directly call [EIP-2935](./eip-2935.md) system contract which will lead to a normal contract execution (as well as charges and accesses) + ## Backwards Compatibility This EIP introduces a significant increase in the cost of `BLOCKHASH`, which could break use-cases that rely on the previous gas cost. Also, this EIP introduces a breaking change in the case where less than `BLOCKHASH_SERVE_WINDOW` elapse between the [EIP-2935](./eip-2935.md) fork and this EIP's fork (unless [EIP-2935](./eip-2935.md) is activated in genesis for e.g. in testnets/devnets) as the [EIP-2935](./eip-2935.md) system contract would not have saved the required history. @@ -87,7 +89,7 @@ This EIP introduces a significant increase in the cost of `BLOCKHASH`, which cou * If `BLOCKHASH` is not called or there is no [EIP-2935](./eip-2935.md) contract call by any transaction, only the [EIP-2935](./eip-2935.md) system update of the parent hash shows up in witnesses if Verkle is activated. * If `BLOCKHASH` is called, there MUST be a storage access gas charge (and corresponding access witness if Verkle is activated) for the storage slot but ONLY if the `BLOCKHASH` query is for the last `BLOCKHASH_SERVE_WINDOW` ancestors. This is irrespective of how the client chooses to resolve the `BLOCKHASH` (directly, via system contract or via memory) * The gas cost for each `BLOCKHASH` operation should still be charged, in addition to the `SLOAD` cost of each lookup (if performed) -* If the [EIP-2935](./eip-2935.md) contract is called directly (i.e. not through `BLOCKHASH`), then the witness and gas costs remain consistent as per normal contract execution by the EVM as per the current fork/activated EIPs. +* If the [EIP-2935](./eip-2935.md) contract is called directly (i.e. not through `BLOCKHASH`), then the witness and gas costs (including those related to contract code) are applied as per normal contract execution of the current fork. * `BLOCKHASH` should be consistently resolved if this EIP is activated correctly `>= BLOCKHASH_SERVE_WINDOW` after [EIP-2935](./eip-2935.md) ## Security Considerations