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-2935: bring up to date with sys contract impl #9144

Merged
merged 5 commits into from
Jan 9, 2025

Conversation

lightclient
Copy link
Member

This makes a few updates based on audits of system contract code here: https://github.com/lightclient/sys-asm/blob/main/src/execution_hash/main.eas

  • revert instead of return 0 when request is out of bounds
  • require get input to be 32 bytes
  • set history server window to 8191 instead of 8192 - rationale same as eip-4788

@lightclient lightclient requested a review from eth-bot as a code owner December 16, 2024 16:19
@github-actions github-actions bot added c-update Modifies an existing proposal s-review This EIP is in Review t-core labels Dec 16, 2024
@eth-bot
Copy link
Collaborator

eth-bot commented Dec 16, 2024

✅ All reviewers have approved.

@eth-bot eth-bot added the a-review Waiting on author to review label Dec 16, 2024
@eth-bot eth-bot changed the title 2935: bring up to date with sys contract impl Update EIP-2935: bring up to date with sys contract impl Dec 16, 2024
EIPS/eip-2935.md Outdated Show resolved Hide resolved
* If calldata is bigger than 2^64-1, revert.
* For any output outside the range of [block.number-`HISTORY_SERVE_WINDOW`, block.number-1] return 0.
* If calldata is not 32 bytes, revert.
* For any request outside the range of [block.number-`HISTORY_SERVE_WINDOW`, block.number-1], revert.
Copy link
Contributor

@g11tech g11tech Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not the current BLOCKHASH (with window 256) behavior so we are actually diverging from the behavior ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mentioned this elsewhere, but I think this divergence is okay because i) it matches other system contracts and ii) it is pretty straightforward to create an adapter around this system contract to mimic the BLOCKHASH behavior when it is used to back the actual op.

Copy link
Member

@gballet gballet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lightclient could you please share a link to the audit? We're especially interested in figuring out the REVERT on out-of-bounds part.

The behavior of returning 0 was initially intended, as there was no ring buffer in initial versions of the spec, and any request for a block hash before the fork was to be 0. The size of the ring buffer might be extended in the future (especially if the block time changes). Now, this is not a big deal per se, as executing the system contract's bytecode becomes "legacy" with eip-7709. Still, it'd be nice to know why an out-of-bounds read returning 0 is a security problem in this particular case.


// 0x57: set op - sstore the input to number-1 mod 8192
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason for removing the comments ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed all these comments because the assembled code comes from the command:

disease --code 0x$(geas src/consolidations/main.eas) | sed -E '/^[[:space:]]*$/d; s/^[[:space:]]*[0-9a-fA-F]+:[[:space:]]+//; s/[[:space:]]*# selector\(.*\)$//'

all the code info is in the sysasm: https://github.com/lightclient/sys-asm/blob/main/src/execution_hash/main.eas

I'd probably hold off on code comments in the eip until this is going to last call.

Copy link
Member

@gballet gballet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a round of discussions and while we consider it less than ideal to pick a buffer size for no direct reason than matching a design choice in another contract, we won't block Prague for that, since it has limited impact provided the justification is written in the eip.

// 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
push0
// Check if input is requesting a block hash greater than current block number
// minus 1.
push0

push2 0x1fff
dup2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
push2 0x1fff
dup2
// Check if the input is requesting a block hash before the earliest available
// hash currently. Since we've verified that input <= number - 1, we know
// there will be no overflow during the subtraction of number - input.
push2 0x1fff
dup2

jumpi

// mod 8192 and sload
push2 0x1fff
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
push2 0x1fff
// Load the hash.
push2 0x1fff


// 0x4b: return 0
jumpdest
push0
push0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
push0
// Load into memory and return.
push0

push0
mstore
push1 0x20
push0
return

// 0x53: revert
jumpdest
push0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
push0
// Reverts current execution with no return data.
push0

jumpdest
push0
push0
revert

// 0x57: set op - sstore the input to number-1 mod 8192
jumpdest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
jumpdest
// sstore block hash
jumpdest

@gballet
Copy link
Member

gballet commented Dec 30, 2024

But @lightclient please address the change requests before merging

@g11tech
Copy link
Contributor

g11tech commented Jan 8, 2025

@lightclient there are some merge conflicts here i guess

EIPS/eip-2935.md Outdated Show resolved Hide resolved
@eth-bot eth-bot enabled auto-merge (squash) January 9, 2025 14:18
Copy link
Collaborator

@eth-bot eth-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All Reviewers Have Approved; Performing Automatic Merge...

@eth-bot eth-bot merged commit 4c94526 into ethereum:master Jan 9, 2025
11 checks passed
@tersec tersec mentioned this pull request Jan 9, 2025
12 tasks
somnathb1 added a commit to erigontech/erigon that referenced this pull request Jan 10, 2025
gumb0 pushed a commit to ethereum/evmone that referenced this pull request Jan 15, 2025
The pectra-devnet-5 specs [1] includes an update to EIP-2935's system
contract and its address [2].

[1]: https://notes.ethereum.org/@ethpandaops/pectra-devnet-5
[2]: ethereum/EIPs#9144
chfast added a commit to ethereum/evmone that referenced this pull request Jan 20, 2025
The pectra-devnet-5 specs [1] includes an update to EIP-2935's system
contract and its address [2].

[1]: https://notes.ethereum.org/@ethpandaops/pectra-devnet-5
[2]: ethereum/EIPs#9144
chfast added a commit to ethereum/evmone that referenced this pull request Jan 20, 2025
The pectra-devnet-5 specs [1] includes an update to EIP-2935's system
contract and its address [2].

[1]: https://notes.ethereum.org/@ethpandaops/pectra-devnet-5
[2]: ethereum/EIPs#9144
chfast added a commit to ethereum/evmone that referenced this pull request Jan 20, 2025
The [pectra-devnet-5 specs] includes an [update to EIP-2935]'s system
contract and its address.

To pass blockchain tests the
#1094 is required, but we are
going to merge this change first.

[pectra-devnet-5 specs]:
https://notes.ethereum.org/@ethpandaops/pectra-devnet-5
[update to EIP-2935]: ethereum/EIPs#9144
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-review Waiting on author to review c-update Modifies an existing proposal s-review This EIP is in Review t-core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants