Unauthorized calls to Cairo precompiles cause system panic, providing attack opportunities #8
Labels
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
grade-b
primary issue
Highest quality submission among a set of duplicates
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
🤖_14_group
AI based duplicate group recommendation
sponsor disputed
Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/kkrt-labs/kakarot/blob/7411a5520e8a00be6f5243a50c160e66ad285563/src/kakarot/interpreter.cairo#L1008
Vulnerability details
Impact
When calling Cairo precompiles from an unauthorized address, it causes the system to panic. On Ethereum, this isn't possible if a call encounters an issue, it just uses up all the gas and returns false instead of causing a full system crash. The difference in behavior between Kakarot and Ethereum opens up various attack opportunities, especially on projects like bridges, cross-chain systems, relayers, and more.
Proof of Concept
The Cairo precompiles exist at specific addresses
0x75001
and0x75002
.https://github.com/kkrt-labs/kakarot/blob/7411a5520e8a00be6f5243a50c160e66ad285563/src/kakarot/precompiles/precompiles_helpers.cairo#L7-L8
When calling these addresses, the function
exec_precompile
would be called where it jumps to the destinationkakarot_precompile
. If the caller is not whitelisted/authorized, it jumps to the destinationunauthorized_call
where it invokes the functionunauthorized_precompile
.https://github.com/kkrt-labs/kakarot/blob/7411a5520e8a00be6f5243a50c160e66ad285563/src/kakarot/precompiles/precompiles.cairo#L41
In the function
unauthorized_precompile
, it reverts with errorEXCEPTIONAL_HALT
which has value2
.https://github.com/kkrt-labs/kakarot/blob/7411a5520e8a00be6f5243a50c160e66ad285563/src/kakarot/precompiles/precompiles.cairo#L169
https://github.com/kkrt-labs/kakarot/blob/7411a5520e8a00be6f5243a50c160e66ad285563/src/kakarot/errors.cairo#L10
Returning to the function
exec_opcode
, it stops the EVM.https://github.com/kkrt-labs/kakarot/blob/7411a5520e8a00be6f5243a50c160e66ad285563/src/kakarot/interpreter.cairo#L91
Returning to the function
run
, due to theEXCEPTIONAL_HALT
, all the gas would be consumed.https://github.com/kkrt-labs/kakarot/blob/7411a5520e8a00be6f5243a50c160e66ad285563/src/kakarot/interpreter.cairo#L739
Finally, returning to the function
execute
, it reverts with errorEVM tx reverted, reverting SN tx because of previous calls to cairo precompiles
.https://github.com/kkrt-labs/kakarot/blob/7411a5520e8a00be6f5243a50c160e66ad285563/src/kakarot/interpreter.cairo#L1008
The issue is that calling these two contracts will lead to failure
An ASSERT_EQ instruction failed: 0 != 1.
Even a low-level call, staticcall, w/wo limited forwarded gas will lead to Panic.On Ethereum, however, if an issue arises, the system does not stop. Instead, the call consumes all the forwarded gas and returns false, without halting the EVM. This is a critical difference that can lead to attacks on systems by misusing Cairo precompiles.
This issue can severely impact projects using Kakarot, such as:
Bridges that process multiple messages could be disrupted. For example, if a bridge sends 10 messages to Kakarot and one of them tries to call a precompile address, the entire process stops. Even if the project is designed to handle delivery failures, it could still be attacked this way.
Many cross-chain systems rely on callbacks to notify the source when a message has been delivered. If a precompile address is called on the destination (Kakarot), the system will panic and prevent the callback from being sent, leaving the source system pending.
Relayers, which handle meta-transactions, could also be affected, causing disruptions in how they process transactions.
PoC
In the following tests, simply two cairo precompile addresses are called. The output log shows the panic.
To run the end-to-end tests correctly, the
make test-end-to-end6
command should be used, as defined in theMakefile
.The output log is:
Tools Used
Recommended Mitigation Steps
To address this problem, the precompile logic should be updated to align more closely with Ethereum’s behavior. Specifically, the system should avoid halting entirely when an unauthorized address attempts to call a precompile.
Assessed type
Context
The text was updated successfully, but these errors were encountered: