When bridiging NFT from L1 to Starknet, user use the depositTokens function. This function is payable because starknet sequencer expect some fees to use as gas for calling the function annotated with #[l1_handler] on the starknet side. However the contract have no check in place to ensure that user sends enough msg.value to cover:
The registration of the hash of the message in the storage of ethereum.
since the L1HandlerTransaction
executed by the sequencer is not tied to any account (the message originates from L1), you must also ensure that you pay enough fees on L1 for your message to be deserialized and processed on L2.
Consider this scenario:
Alice want to bridge one or many nft to starknet, so she call depositTokens() on ethereum with the appropriate params.
Alice send the transaction with just enough msg.value worth of ETH to cover the storage of the message hash on ethereum .
The transaction suceed on L1 and when the sequencer try to call the #[l1_handler] transaction on starknet it runs out of gas and the NFT gets stuck inside the SnCore contract.
See the ref: https://book.cairo-lang.org/ch16-04-L1-L2-messaging.html
I have coded this PoC, just copy and paste it inside Bridge.t.sol and then run it using:
forge test --mt test_NFTStuckInBridge -vv
User NFT will get stuck inside the SnCore contract
Manual review
According to cairo-book: Use Snforge or Starkli to get an estimate of the cost of the message execution then enforce that users msg.value >= to the cost. The final cost will be the cost of the SnMessaging to store the hash on etehreum + The cost of the L1Handler tx on Starknet.
It's important to note that we have
{value: msg.value}
. In fact, the minimum value we've to send here is20k wei
, due to the fact that theStarknetMessaging
contract will register the hash of our message in the storage of Ethereum.In addition to those
20k wei
, since theL1HandlerTransaction
executed by the sequencer is not tied to any account (the message originates from L1), you must also ensure that you pay enough fees on L1 for your message to be deserialized and processed on L2.The fees of the
L1HandlerTransaction
are computed in a regular manner as it would be done for anInvoke
transaction. For this, you can profile the gas consumption usingstarkli
orsnforge
to estimate the cost of your message execution.
Impact: Medium/High. Need an admin to start a cancellation and wait for 5 days once done. DoS > 5 days. Likelyhood: Low. Everytime a wallet/or a user do not send enough gas
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.