Summary:
Insufficient Access Control in L1 Handler Function
Vulnerability Details:
The withdraw_auto_from_l1
function in the bridge.cairo
contract is marked as an #[l1_handler]
, allowing it to be called directly from L1. However, the function lacks proper access control to ensure that only the authorized L1 bridge contract can initiate this call. The current implementation only checks that the from_address
matches the stored bridge_l1_address
, which is insufficient to guarantee the authenticity of the L1 message.
This vulnerability allows an attacker to potentially bypass the L1 bridge contract entirely and directly call the withdraw_auto_from_l1
function with crafted data, compromising the integrity of the bridging process.
Concrete Example of Exploiting the Vulnerability:
Step 1: Setup
Legitimate L1 Bridge Address: 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707
Attacker's L1 Address: 0x1337C0D3R00000000000000000000000BADAC70R
Attacker's L2 Address: 0x000069696969696969696969696969696969696969696969696969696969BEEF
Valuable NFT Collection L1 Address: 0x9A38deC0590aBc8c883D72e52391090e948Ddf12 (Everai)
Corresponding NFT Collection L2 Address: 0x02acee8c430f62333cf0e0e7a94b2347b5513b4c25f699461dd8d7b23c072478
Step 2: Attacker Deploys Malicious L1 Contract
The attacker deploys a contract on Ethereum that can send messages to Starknet:
Step 3: Craft Malicious Payload
The attacker constructs a payload that mimics a legitimate withdrawal request:
Step 4: Send Malicious Message
The attacker calls their malicious contract to send the crafted message:
Step 5: L2 Bridge Processes the Message
On Starknet, the withdraw_auto_from_l1
function is triggered with:
from_address
: 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 (legitimate bridge address)
req
: The deserialized payload
The function performs these key steps:
Checks if the bridge is enabled (passes)
Asserts the from_address
matches self.bridge_l1_address
(passes due to the vulnerability)
Processes the request:
Verifies the collection addresses (passes)
For each token ID (42 and 69):
If the token is in escrow, transfers it to the attacker's L2 address
If not in escrow, mints a new token to the attacker's L2 address
Step 6: Attacker Gains Control of NFTs
The attacker now owns Everai NFTs with IDs 42 and 69 on Starknet, without having locked or burned any tokens on Ethereum.
Impact:
The impact of this vulnerability is severe. An attacker could:
Initiate unauthorized withdrawals of NFTs from L2 to L1.
Manipulate the bridging process to mint tokens on L2 without the corresponding lock or burn on L1.
Potentially drain or redirect NFTs held in escrow by the bridge contract.
This vulnerability undermines the entire security model of the cross-chain NFT bridge, potentially leading to significant financial losses for users and a complete breakdown of trust in the bridging mechanism.
Tools Used:
Manual code review
Static analysis of the Cairo smart contract
Recommendations:
Implement a robust message verification mechanism that cryptographically verifies the authenticity of L1 messages. This should leverage Starknet's built-in L1-to-L2 message verification system.
Add a nonce system to prevent replay attacks and ensure each message can only be processed once.
Implement a two-step verification process where the L1 message triggers a state change, and a separate function (callable only by authorized parties) completes the withdrawal after additional checks.
Consider implementing a time-lock mechanism for large or suspicious withdrawals, allowing for manual review if necessary.
By implementing these recommendations, the security of the L1-to-L2 messaging in the bridge contract will be significantly enhanced, mitigating the risk of unauthorized withdrawals and maintaining the integrity of the cross-chain NFT bridging process.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.