SafeBridge
Description¶
I've crafted what I believed to be an ultra-safe token bridge. Don't believe it?
nc 47.251.56.125 1337
Solution¶
-
This challenge is derived from Enterprise Blockchain in Paradigm CTF 2023. The
CrossDomainMessenger.sendMessage()function, which can be used for sending cross-chain messages, is still public available. The difference is that when finalizing a cross-chain token transfer, it will verify whether the initiator of the cross-chain message is the bridge on the corresponding chain. Thus, cross-chain token transfers are only possible viaL1ERC20Bridge.depositERC20() / L1ERC20Bridge.depositERC20To()andL2ERC20Bridge.withdraw() / L2ERC20Bridge.withdrawTo() -
To withdraw WETH from L1Bridge, we need to invoke the
L2ERC20Bridge.withdraw()function. In_initiateWithdrawal(),l1Tokenis read from_l2Token. Since the_l2Tokenprovided by users could be a custom token, then only the value ofL1ERC20Bridge.deposits[weth][_l2Token]should not be less than the amount to be transferred -
When initiating a transfer from L1 to L2, if
_l1Tokenisweth, the corresponding amount ofL2_WETHwill be minted inL2ERC20Bridge.finalizeDeposit(). However,_l2Tokenmay not beL2_WETH. If_l2Tokenis a custom token controlled by the player, not only can player obtainL2_WETH, butdeposits[weth][_l2Token]will also increase -
Since
deposits[weth][L2_WETH]already has a value, we can drain WETH in l1Bridge withL2_WETHand custom_l2Token
Exploitation¶
Flag¶
rwctf{yoU_draINED_BriD6E}