-
Notifications
You must be signed in to change notification settings - Fork 10
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
EIP-2935 get() fails to revert on out-of-bounds input #34
Comments
Although not directly related to this issue, it's worth noting that the Patch: daejunpark@a6af555 |
The EIP says to return zero outside the range. https://eips.ethereum.org/EIPS/eip-2935#block-hash-history-contract
It seems @lightclient changed this in the code but didn't update the EIP. |
I agree with your point, but please note that this issue is a different thing. The current implementation neither returns zero nor reverts for the specific out-of-range input, (Additionally, this is unrelated to the edge case of |
This was fixed in 6cae17b |
Thanks for fixing it! Could you please also check the ring buffer size (#34 (comment))? It's set to 8191 in the code, while it's 8192 in the eip spec. Which one is correct? |
@lightclient ^^ |
It seems he is busy and has forgotten about us 😢 But a recent PR against the EIP clarifies things: ethereum/EIPs#9144. Ring buffer size of 8191 is the correct one, and the PR proposes to change the EIP based on the code here. The size of 8191 was chosen because it is prime, see https://eips.ethereum.org/EIPS/eip-4788#size-of-ring-buffers. |
@fjl, chatted with @lightclient out of band, and for EIP-2935 using a prime number isn't required. For 4788 makes sense since the value that is taking the modulo is After our chat, the argument used now for 8191 is mainly using the same size in a similar construction (4788). The rationale was updated with this argument removing the prime one. |
Thanks. That's actually a good point about it not using timestamp! |
Problem
According to the EIP-2935 spec, the valid input range for the get() operation is
[block.number - HISTORY_SERVE_WINDOW, block.number - 1]
. Additionally, as per #19, the get() operation should revert if the input falls outside this valid range.However, when get() is called with an input of
block.number - HISTORY_SERVE_WINDOW - 1
, which is outside the valid range, it currently does NOT revert; instead it returns the blockhash ofblock.number - 1
, which I believe is incorrect behavior.How to reproduce
The issue can be reproduced by adding the following test to
test/ExecutionHash.t.sol.in
:Test output:
(Note that the returned
data
is0x88e96d4537bea4d9c05d12549907b32561d3bf31f45aae734cdc119f13406cb6
, which is the blockhash set earlier for the last block.)Suggested fix
The root cause of this issue is the following line:
sys-asm/src/execution_hash/main.eas
Line 70 in b5b9f33
This issue can be fixed by changing it to
push BUFLEN
(removing+1
).Once this issue is fixed, the existing
testHistoricalReads()
test will also need to be adjusted, e.g., by addingvm.roll(buflen);
before the secondfor
loop.Patch: daejunpark@2a11c29
The text was updated successfully, but these errors were encountered: