withdrawTokens function of the L1 bridge contract processes data from the L2 message payload before verifying its authenticity through the StarkNet messaging system. This violates the security model outlined in the Cairo/Starknet documentation and could lead to processing of unverified, potentially malicious data.
The withdrawTokens function in the L1 bridge contract is designed to handle withdrawal requests from the StarkNet L2 network.
The vulnerability stems from an incorrect order of operations in the withdrawTokens function. This function currently extracts the header from the request payload before verifying the message's authenticity through the _consumeMessageStarknet function. This order of operations poses a security risk because unverified data is used before cryptographic validation, violating the principles outlined in the StarkNet documentation.
According to the StarkNet documentation, messages from L2->L1 must be consumed and verified before their contents are used. The correct sequence, as implied by the documentation, is:
Consume and verify the message using consumeMessageFromL2.
Extract and use the payload data.
This is the code example provided in the cairo-book::L1<>L2Messaging:
You can see that the payload is used here only after the message has been verified by StarknetMessaging i.e. after a call to consumeMessageFromL2 function.
By processing the header before message verification, the contract assumes the integrity of data before it has been cryptographically verified by the StarkNet system. This violates the StarkNet L2->L1 messaging security model.
This could potentially open up unforeseen attack vectors for e.g. it could enable attacker to manipulate withdrawal logic, leading to unauthorized token withdrawals or the deployment of malicious contracts on L1
Manual Review, Cairo Book
Request payload must only be processed after message verification:
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.