Skip to content

Commit

Permalink
sanitize precompile input
Browse files Browse the repository at this point in the history
  • Loading branch information
ralexstokes committed Jun 22, 2023
1 parent 5ef6bcd commit 613c665
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions EIPS/eip-4788.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ sstore(HISTORY_STORAGE_ADDRESS, root_index, parent_beacon_block_root)
Beginning at the execution timestamp `FORK_TIMESTAMP`, a "stateful" precompile is deployed at `HISTORY_STORAGE_ADDRESS`.

Callers of the precompile should provide the `timestamp` they are querying encoded as 32 bytes in big-endian format.
Clients **MUST** sanitize this input call data to the precompile.
If the input is _more_ than 32 bytes, the precompile only takes the first 32 bytes of the input buffer and ignores the rest.
If the input is _less_ than 32 bytes, the precompile should revert.

Given this input, the precompile reduces the `timestamp` in the same way during the write routine and first checks if
the `timestamp` recorded in the ring buffer matches the one supplied by the caller.
Expand All @@ -97,6 +100,10 @@ In pseudocode:

```python
timestamp = evm.calldata[:32]
if len(timestamp) != 32:
evm.revert()
return

timestamp_reduced = to_uint64_be(timestamp) % HISTORICAL_ROOTS_LENGTH
timestamp_index = to_uint256_be(timestamp_reduced)

Expand Down

0 comments on commit 613c665

Please sign in to comment.