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

BLOCKHASH Opcode does not comply with Kakarot spec #130

Open
howlbot-integration bot opened this issue Oct 28, 2024 · 4 comments
Open

BLOCKHASH Opcode does not comply with Kakarot spec #130

howlbot-integration bot opened this issue Oct 28, 2024 · 4 comments
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-5 edited-by-warden grade-b Q-01 QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 🤖_21_group AI based duplicate group recommendation satisfactory satisfies C4 submission criteria; eligible for awards sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") sufficient quality report This report is of sufficient quality

Comments

@howlbot-integration
Copy link

Lines of code

https://github.com/kkrt-labs/kakarot/blob/697100af34444b3931c18596cec56c454caf28ed/src/kakarot/instructions/block_information.cairo#L167-L172

Vulnerability details

Proof of Concept

blockhash function in the Internals namespace does not align with the Kakarot protocol's hint for the BLOCKHASH opcode. According to the Kakarot's doc, the BLOCKHASH opcode should return 0 for the last 10 blocks, but this is not followed.

https://github.com/kkrt-labs/kakarot/blob/697100af34444b3931c18596cec56c454caf28ed/src/kakarot/instructions/block_information.cairo#L167-L172

let lower_bound = Helpers.saturated_sub(evm.message.env.block_number, 256);
let in_range = is_in_range(block_number.low, lower_bound, evm.message.env.block_number);

if (in_range == FALSE) {
    Stack.push_uint256(Uint256(0, 0));
    return ();
}

This allows access to block hashes for all blocks within the last 256 blocks, including the most recent ones. It does not implement the Kakarot-specific behavior of returning 0 for the last 10 blocks.

Reference to Kakarot's doc:

Item Ethereum Kakarot
BLOCKHASH Get the hash of one of the 256 most recent complete blocks The last 10 blocks are not available, and 0 is returned instead

This could cause issues for contracts expecting Kakarot's specified BLOCKHASH behavior.

Recommended Mitigation Steps

Modify the blockhash function to comply with Kakarot's specification:

  let lower_bound = Helpers.saturated_sub(evm.message.env.block_number, 256);
-    let in_range = is_in_range(block_number.low, lower_bound, evm.message.env.block_number);
+    let upper_bound = evm.message.env.block_number - 10;
+    let in_range = is_in_range(block_number.low, lower_bound, upper_bound);

     if (in_range == FALSE) {
         Stack.push_uint256(Uint256(0, 0));
         return ();
     }

Assessed type

Other

@howlbot-integration howlbot-integration bot added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value 🤖_21_group AI based duplicate group recommendation bug Something isn't working duplicate-37 edited-by-warden sufficient quality report This report is of sufficient quality labels Oct 28, 2024
howlbot-integration bot added a commit that referenced this issue Oct 28, 2024
@ClementWalter
Copy link

Severity: Low

Comment: SEE issue 3 for comment dup 130, 5, 3, 37

@ClementWalter ClementWalter added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Nov 4, 2024
@c4-judge
Copy link
Contributor

c4-judge commented Nov 7, 2024

dmvt marked the issue as satisfactory

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Nov 7, 2024
@c4-judge
Copy link
Contributor

dmvt changed the severity to QA (Quality Assurance)

@c4-judge c4-judge added downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Nov 16, 2024
@c4-judge
Copy link
Contributor

dmvt marked the issue as grade-b

@C4-Staff C4-Staff reopened this Nov 18, 2024
@C4-Staff C4-Staff added the Q-01 label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-5 edited-by-warden grade-b Q-01 QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 🤖_21_group AI based duplicate group recommendation satisfactory satisfies C4 submission criteria; eligible for awards sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") sufficient quality report This report is of sufficient quality
Projects
None yet
Development

No branches or pull requests

3 participants