-
Notifications
You must be signed in to change notification settings - Fork 0
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
Blockhash revert issue in last 10 blocks #5
Comments
dmvt marked the issue as selected for report |
This fits as a medium issue in my opinion. Though, as mentioned in the comment on #3, there are no loss of funds, there is an impact to the availability of the protocol given that transactions revert unexpectedly. |
To summarize
Because there is no way to implement the spec, we think that is not a vulnerabiliy but a documented limitation. We agree on the low as we need to fix the doc (or update the code to push 0). |
Agree with the sponsor. This is low and a documentation issue. |
dmvt changed the severity to QA (Quality Assurance) |
dmvt marked the issue as not selected for report |
Lines of code
https://github.com/kkrt-labs/kakarot/blob/7411a5520e8a00be6f5243a50c160e66ad285563/src/kakarot/instructions/block_information.cairo#L158
Vulnerability details
Impact
The blockhash of the last 10 blocks is supposed to be zero since they are unavailable based on the documentation and protocol rules. However, trying to get the blockhash of these blocks causes an unexpected revert, breaking the protocol rules.
Proof of Concept
According to the documentation, "the last 10 blocks are not available, and 0 is returned instead."
https://docs.kakarot.org/differences/#evm-opcodes
https://github.com/kkrt-labs/kakarot-ssj/blob/935c2238ac0b42c910afd3efeb96f003c1742edf/crates/evm/src/instructions/block_information.cairo#L26-L27
The issue occurs when trying to get the blockhash for
block.blocknumber - 1
toblock.blocknumber - 9
, which causes a revert instead of returning 0 as expected by the protocol.When the
blockhash
opcode is executed, the following function is called:https://github.com/kkrt-labs/kakarot/blob/7411a5520e8a00be6f5243a50c160e66ad285563/src/kakarot/instructions/block_information.cairo#L55
https://github.com/kkrt-labs/kakarot/blob/7411a5520e8a00be6f5243a50c160e66ad285563/src/kakarot/instructions/block_information.cairo#L158
The
is_in_range
function checks if the block number is betweenblocknumber - 256
andblocknumber
, but this is incorrect. It should check betweenblocknumber - 256
andblocknumber - 10
.https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/cairo/common/math_cmp.cairo#L65
PoC
In the following PoC, there are three tests to retrieve the blockhash for block numbers
block.blocknumber - 10
,block.blocknumber - 9
, andblock.blocknumber - 1
. The first test,test_blockhash_10_block_before
, completes successfully, but the second and third tests,test_blockhash_9_block_before
andtest_blockhash_1_block_before
, fail due to aBlock number out of range
error.To run the end-to-end tests correctly, the
make test-end-to-end12
command should be used, as defined in theMakefile
.The output shows that the first test, "test_blockhash_10_block_before", passed, but the second and third tests failed.
Tools Used
Recommended Mitigation Steps
The code below should be modified:
https://github.com/kkrt-labs/kakarot/blob/7411a5520e8a00be6f5243a50c160e66ad285563/src/kakarot/instructions/block_information.cairo#L168
Assessed type
Context
The text was updated successfully, but these errors were encountered: