"retrySettlement" could be reentered by poisonous underlying token when clearing tokens #295
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-492
satisfactory
satisfies C4 submission criteria; eligible for awards
Lines of code
https://github.com/code-423n4/2023-05-maia/blob/54a45beb1428d85999da3f721f923cbf36ee3d35/src/ulysses-omnichain/RootBridgeAgent.sol#L244
https://github.com/code-423n4/2023-05-maia/blob/54a45beb1428d85999da3f721f923cbf36ee3d35/src/ulysses-omnichain/ArbitrumBranchPort.sol#L76-L84
Vulnerability details
Impact
When clearing tokens,
_underlyingAddress.safeTransfer
is called; however, thelock
is missing onretrySettlement
, making reentrancy possible.Proof of Concept
All essential entry points of ulysses omnichain are modified with
lock
to prevent reentrancy. However, thelock
is missing onretrySettlement
at RootBridgeAgent.When clearing tokens, an external call to
_underlyingAddress
is made. However,_underlyingAddress
may be an arbitary contract since token is permissionlessly added, which means it could reenterretrySettlement
to receive token multiple times.Below are the steps of the attack, starting with 1 BNB on BNB Chain:
addLocalToken
for XIN at ArbitrumCoreBranchRouter.callOutSignedAndBridge
(on Arbitrum) with_dParams = {hToken: arb-hXIN, token: XIN, amount: 1, deposit: 1}
and receive 1 arb-hXIN at virtual account.callOutSignedAndBridge
(on BNB Chain) with_dParams = {hToken: bnb-hBNB, token: BNB, amount: 1, deposit: 1}
and receive 1 arb-hBNB at virtual account.callOut
withparams = abi.encode(0x03, [{target: XIN, calldata: abi.encode(selector("initiate()")}], {recipient: attacker, outputTokens: [arb-hXIN, arb-hBNB], amountsOut: [1, 1], depositsOut: [1, 0]}, Arb)
,initiate()
will be called by the virtual account to changesafeTransfer
into reentrancy mode.retrySettlement
is reentered 100 times and attacker receives 101 arb-hBNB.Tools Used
Manual Review
Recommended Mitigation Steps
Add
lock
forretrySettlement
.Assessed type
Reentrancy
The text was updated successfully, but these errors were encountered: