# Unauthorized contracts can bypass precompile authorization via delegatecall in Kakarot zkEVM

Kakarot's precompile whitelist checked caller code address, so any contract could delegatecall a whitelisted contract to invoke privileged precompiles.

- Payout: Audit contest
- Severity: high
- Program: Kakarot
- Found by: 0xastronatey
- Disclosed: 2024-12-10
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2024-09-kakarot-findings/issues/124
- Library page: https://bugbountylibrary.com/r/c4%3A2024-09-kakarot%3AH-01
- Tags: area:web3 domain:web3 impact:funds-loss impact:integrity kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:chained technique:source-review vuln:access-control vuln:auth-bypass

**Target:** Kakarot zkEVM exec_precompile authorization (Cairo)
**Root cause:** exec_precompile authorizes using caller_code_address (the code being executed) rather than caller_address, so a delegatecall into a whitelisted contract inherits its code address and passes the whitelist check.
**Steps:**
1. Identify exec_precompile gating on KakarotPrecompiles.is_caller_whitelisted(caller_code_address).
2. Deploy unauthorized contract A.
3. Have A delegatecall a whitelisted contract B (or trigger a callback into A from a whitelisted DEX).
4. Inside the delegatecall context, call the privileged precompile at 0x75001; caller_code_address is B's code, so the whitelist check passes.
5. Execute privileged precompile operations as if whitelisted.
**How found:** Code review of exec_precompile noticed authorization keyed on caller_code_address while ignoring caller_address, then reasoned that delegatecall preserves code address, breaking the whitelist assumption.
**Exploitation:** Attacker contract delegatecalls a whitelisted contract (e.g. a DEX supporting callbacks) so the precompile sees the whitelisted code address and authorizes the call, letting the attacker run privileged precompile functions and manipulate Starknet tokens without explicit approvals.
**Escalation:** Chained via whitelisted contracts that allow arbitrary external calls/callbacks, letting a malicious contract be invoked in the whitelisted contract's delegatecall context.
**Insight:** When an allowlist keys on code address rather than execution address, delegatecall from any contract inherits the trusted identity; audit whitelisted contracts for callback/arbitrary-call surfaces that let attackers enter that delegatecall context.

