-
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
Precompile Execution Without Sufficient Gas In Kakarot #74
Comments
Severity: Invalid Comment: Kakarot paymaster can decide to not relay the tx. |
dmvt marked the issue as unsatisfactory: |
Hi @dmvt, Kakarot's implementation violates fundamental EVM gas accounting rules as defined in the Yellow Paper:
This specification has two critical requirements:
The current implementation violates both by executing first and attempting to charge gas after computation.
"In order to avoid issues of network abuse and to sidestep the inevitable questions stemming from Turing completeness, all programmable computation in Ethereum is subject to fees." The phrase "subject to fees" means gas checks and deductions must precede computation, not follow it. Kakarot execute precompiles before gas checks and deduction which represents a clear violation of the EVM specification. The only compliant implementation is to:
This matches both the letter and intent of the Yellow Paper's specification. I appreciate you having a second look at this 🙏. |
dmvt removed the grade |
dmvt changed the severity to QA (Quality Assurance) |
Point well taken. Adjusted to QA / low risk. |
dmvt marked the issue as grade-b |
ok for QA |
Lines of code
https://github.com/kkrt-labs/kakarot/blob/7411a5520e8a00be6f5243a50c160e66ad285563/src/kakarot/interpreter.cairo#L79-L100
Vulnerability details
Impact
Precompiles in Kakarot can execute computationally expensive operations before verifying sufficient gas is available, leading to:
The issue exists because while EVM gas would be charged preventing true "free" execution, the underlying Starknet Cairo program steps are executed during the precompile computation before the gas check. These computational costs are covered by the paymaster, not the EVM transaction sender.
Proof of Concept
Executing precompiles before verifying gas in Kakarot's:
Interpreter.cairo:L79
By contrast, Geth performs gas validation before execution in:
core/vm/contracts.go:L223
Flow:
Key differences:
Tools Used
Manual Review
Recommended Mitigation Steps
Add upfront gas validation before precompile execution by implementing a
check_precompile_gas
function that validates available gas. Only proceed with execution if sufficient gas exists, otherwise revert immediately with an out-of-gas error.Assessed type
Other
The text was updated successfully, but these errors were encountered: