Depositors could lose all their deposited tokens (including the hTokens) if their address is blacklisted in one of all the deposited underlyingTokens
The redeemDeposit function sends all deposited tokens back to the original depositor's address, and if that address is blacklisted in any one of the underlying tokens, the entire redemption reverts. As a result, all other deposited tokens, including hTokens, become permanently stuck in the BranchPort.
0xStalin Follow with Bauchibred
Originally disclosed on Code4rena
Submitted by 0xStalin, also found by Bauchibred
All user deposited assets, both, hTokens and underlyingTokens are at risk of getting stuck in a BranchPort if the address of the depositor gets blacklisted in one of all the deposited underlyingTokens.
Proof of Concept
The problem is caused by the fact that the redemption process works by sending back all the tokens that were deposited and that tokens can only be sent back to the same address from where they were deposited.
Users can deposit/bridgeOut multiple tokens at once (underlyingTokens and hTokens) from a Branch to Root. The system has a mechanism to prevent users from losing their tokens in case something fails with the execution of the crosschain message in the Root environment.
If something fails with the execution in Root, the users can retry the deposit, and as a last resource, they can retrieve and redeem their deposit from Root and get their tokens back in the Branch where they were deposited.
When redeeming deposits, the redemption is made atomically, in the sense that it redeems all the tokens that were deposited at once, it doesn’t redeem one or two specific tokens; it redeems all of them.
The problem is that the function to redeem the tokens sets the recipient address to be the caller (msg.sender), and the caller is enforced to be only the owner of the depositor (i.e. the account from where the tokens were taken from). The fact that the depositor’s address gets blacklisted in one of the underlyingTokens should not cause that all the rest of the tokens to get stuck in the BranchPort.
function redeemDeposit(uint32 _depositNonce) external override lock {
//@audit-info => Loads the deposit's information based on the _depositNonce
// Get storage reference
Deposit storage deposit = getDeposit[_depositNonce];
// Check Deposit
if (deposit.status == STATUS_SUCCESS) revert DepositRedeemUnavailable();
if (deposit.owner == address(0)) revert DepositRedeemUnavailable();
if (deposit.owner != msg.sender) revert NotDepositOwner();
// Zero out owner
deposit.owner = address(0);
//@audit-issue => Sending back tokens to the deposit.owner. Depositors can't specify the address where they'd like to receive their tokens
// Transfer token to depositor / user
for (uint256 i = 0; i < deposit.tokens.length;) {
_clearToken(msg.sender, deposit.hTokens[i], deposit.tokens[i], deposit.amounts[i], deposit.deposits[i]);
unchecked {
++i;
}
}
Coded PoC
I coded a PoC to demonstrate the problem I’m reporting, using the RootForkTest.t.sol test file as the base to reproduce this PoC:
Make sure to import the below Mock a Blacklisted token under the test/ulysses-omnichain/helpers/ folder. Also, add the global variables and the 3 below functions in the RootForkTest file:
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol";
contract BlacklistedToken is MockERC20 {
mapping (address => bool) public blacklistedUsers;
constructor(
string memory _name,
string memory _symbol,
uint8 _decimals
) MockERC20(_name, _symbol, _decimals) {}
function blacklistAddress(address _user) external returns (bool) {
blacklistedUsers[_user] = true;
}
function transfer(address to, uint256 amount) public override returns (bool) {
if(blacklistedUsers[to]) revert("Blacklisted User");
super.transfer(to,amount);
return true;
}
function mint(address to, uint256 value) public override {
super._mint(to, value);
}
function burn(address from, uint256 value) public override {
super._burn(from, value);
}
}
...
+//@audit-info => Blacklisted Token
+import "./helpers/BlacklistedToken.sol";
...
contract RootForkTest is LzForkTest {
...
// ERC20s from different chains.
address avaxMockAssethToken;
MockERC20 avaxMockAssetToken;
//@audit-info => underlyingTokens for PoC
+ MockERC20 underToken0;
+ MockERC20 underToken1;
//@audit-info => Create a new token using a contract that allows to Blacklist users!
+ BlacklistedToken underBlacklistToken;
...
function _deployUnderlyingTokensAndMocks() internal {
//Switch Chain and Execute Incoming Packets
switchToLzChain(avaxChainId);
vm.prank(address(1));
// avaxMockAssethToken = new MockERC20("hTOKEN-AVAX", "LOCAL hTOKEN FOR TOKEN IN AVAX", 18);
avaxMockAssetToken = new MockERC20("underlying token", "UNDER", 18);
//@audit-info => Deploying underlyingTokens for PoC
+ underToken0 = new MockERC20("u0 token", "U0", 18);
+ underToken1 = new MockERC20("u0 token", "U0", 18);
+ underBlacklistToken = new BlacklistedToken("u2 BlaclistedToken", "U2", 18);
...
}
...
//@audit => Variables required for the PoC
+ address[] public hTokens;
+ address[] public tokens;
+ uint256[] public amounts;
+ uint256[] public deposits;
+
+ address public localTokenUnder0;
+ address public localTokenUnder1;
+ address public localBlacklistedToken;
+
+ address public globalTokenUnder0;
+ address public globalTokenUnder1;
+ address public globalBlacklistedToken;
+
+ address public _recipient;
//@audit-info => First function required for the PoC, will create a Deposit in a Branch that will fail its execution in Root
function testDepositBlocklistedTokenWithNotEnoughGasForRootFallbackModePoC() public {
//Switch Chain and Execute Incoming Packets
switchToLzChain(avaxChainId);
vm.deal(address(this), 10 ether);
avaxCoreRouter.addLocalToken{value: 1 ether}(address(underToken0), GasParams(2_000_000, 0));
avaxCoreRouter.addLocalToken{value: 1 ether}(address(underToken1), GasParams(2_000_000, 0));
avaxCoreRouter.addLocalToken{value: 1 ether}(address(underBlacklistToken), GasParams(2_000_000, 0));
//Switch Chain and Execute Incoming Packets
switchToLzChain(rootChainId);
//Switch Chain and Execute Incoming Packets
switchToLzChain(avaxChainId);
//Switch Chain and Execute Incoming Packets
switchToLzChain(rootChainId);
prevNonceRoot = multicallRootBridgeAgent.settlementNonce();
localTokenUnder0 = rootPort.getLocalTokenFromUnderlying(address(underToken0), avaxChainId);
localTokenUnder1 = rootPort.getLocalTokenFromUnderlying(address(underToken1), avaxChainId);
localBlacklistedToken = rootPort.getLocalTokenFromUnderlying(address(underBlacklistToken), avaxChainId);
switchToLzChain(avaxChainId);
prevNonceBranch = avaxMulticallBridgeAgent.depositNonce();
vm.deal(address(this), 50 ether);
uint256 _amount0 = 1 ether;
uint256 _amount1 = 1 ether;
uint256 _amount2 = 1 ether;
uint256 _deposit0 = 1 ether;
uint256 _deposit1 = 1 ether;
uint256 _deposit2 = 1 ether;
//GasParams
GasParams memory gasParams = GasParams(100_000 , 0 ether);
_recipient = address(this);
vm.startPrank(address(avaxPort));
ERC20hTokenBranch(localTokenUnder0).mint(_recipient, _amount0 - _deposit0);
ERC20hTokenBranch(localTokenUnder1).mint(_recipient, _amount1 - _deposit1);
ERC20hTokenBranch(localBlacklistedToken).mint(_recipient, _amount2 - _deposit2);
underToken0.mint(_recipient, _deposit0);
underToken1.mint(_recipient, _deposit1);
underBlacklistToken.mint(_recipient, _deposit2);
vm.stopPrank();
// Cast to Dynamic
hTokens.push(address(localTokenUnder0));
hTokens.push(address(localTokenUnder1));
hTokens.push(address(localBlacklistedToken));
tokens.push(address(underToken0));
tokens.push(address(underToken1));
tokens.push(address(underBlacklistToken));
amounts.push(_amount0);
amounts.push(_amount1);
amounts.push(_amount2);
deposits.push(_deposit0);
deposits.push(_deposit1);
deposits.push(_deposit2);
//@audit-info => Prepare deposit info
DepositMultipleInput memory depositInput =
DepositMultipleInput({hTokens: hTokens, tokens: tokens, amounts: amounts, deposits: deposits});
// Approve AvaxPort to spend
MockERC20(hTokens[0]).approve(address(avaxPort), amounts[0] - deposits[0]);
MockERC20(tokens[0]).approve(address(avaxPort), deposits[0]);
MockERC20(hTokens[1]).approve(address(avaxPort), amounts[1] - deposits[1]);
MockERC20(tokens[1]).approve(address(avaxPort), deposits[1]);
MockERC20(hTokens[2]).approve(address(avaxPort), amounts[2] - deposits[2]);
BlacklistedToken(tokens[2]).approve(address(avaxPort), deposits[2]);
//@audit-info => deposit multiple assets from Avax branch to Root
//@audit-info => Attempting to deposit two hTokens and two underlyingTokens
avaxMulticallBridgeAgent.callOutSignedAndBridgeMultiple{value: 1 ether}(
payable(address(this)),bytes(""), depositInput, gasParams, true
);
require(prevNonceBranch == avaxMulticallBridgeAgent.depositNonce() - 1, "Branch should be updated");
// avaxMulticallRouter.callOutAndBridgeMultiple{value: 1 ether}(bytes(""), depositInput, gasParams);
console2.log("GOING ROOT AFTER BRIDGE REQUEST FROM AVAX");
//Switch Chain and Execute Incoming Packets
switchToLzChain(rootChainId);
require(prevNonceRoot == multicallRootBridgeAgent.settlementNonce(), "Root should not be updated");
}
//@audit-info => Calls the function above and retrieves the deposit in the Branch
function testRetrieveDepositPoC() public {
//Set up
testDepositBlocklistedTokenWithNotEnoughGasForRootFallbackModePoC();
switchToLzChain(avaxChainId);
//Get some ether.
vm.deal(address(this), 10 ether);
//Call Deposit function
console2.log("retrieving");
avaxMulticallBridgeAgent.retrieveDeposit{value: 10 ether}(prevNonceRoot, GasParams(1_000_000, 0.01 ether));
require(
avaxMulticallBridgeAgent.getDepositEntry(prevNonceRoot).status == 0, "Deposit status should be success."
);
console2.log("Going ROOT to retrieve Deposit");
switchToLzChain(rootChainId);
console2.log("Triggered Fallback");
console2.log("Returning to Avax");
switchToLzChain(avaxChainId);
console2.log("Done ROOT");
require(
avaxMulticallBridgeAgent.getDepositEntry(prevNonceRoot).status == 1,
"Deposit status should be ready for redemption."
);
}
//@audit-info => The _recipient/depositor of the Deposit is blacklisted before redeeming the deposit from the Branch
function testRedeemBlocklistedTokenPoC() public {
//Set up
testRetrieveDepositPoC();
//Get some ether.
vm.deal(address(this), 10 ether);
uint256 balanceBeforeUnderToken0 = underToken0.balanceOf(_recipient);
uint256 balanceBeforeUnderToken1 = underToken1.balanceOf(_recipient);
uint256 balanceBeforeBlaclistedToken = underBlacklistToken.balanceOf(_recipient);
uint256 balanceBeforeUnderToken0BranchPort = underToken0.balanceOf(address(avaxPort));
uint256 balanceBeforeUnderToken1BranchPort = underToken1.balanceOf(address(avaxPort));
uint256 balanceBeforeBlaclistedTokenBranchPort = underBlacklistToken.balanceOf(address(avaxPort));
//@audit-info => receiver get's blacklisted before redeeming its deposit
underBlacklistToken.blacklistAddress(_recipient);
//Call Deposit function
console2.log("redeeming");
vm.expectRevert();
avaxMulticallBridgeAgent.redeemDeposit(prevNonceRoot);
assertFalse(
avaxMulticallBridgeAgent.getDepositEntry(prevNonceRoot).owner == address(0),
"Deposit status should not have deleted because the redemption can't be executed"
);
assertFalse(underToken0.balanceOf(_recipient) == balanceBeforeUnderToken0 + 1 ether, "Balance should not be increased because tokens can't be redeemed");
assertFalse(underToken1.balanceOf(_recipient) == balanceBeforeUnderToken1 + 1 ether, "Balance should not be increased because tokens can't be redeemed");
assertFalse(underBlacklistToken.balanceOf(_recipient) == balanceBeforeBlaclistedToken + 1 ether, "Balance should not be increased because tokens can't be redeemed");
}
Now everything is ready to run the test and analyze the output:
forge test --mc RootForkTest --match-test testRedeemBlocklistedTokenPoC -vvvv
As we can see in the Output, the depositor can’t redeem its deposit because the address was blacklisted in one of the 3 deposited underlyingTokens.
As a consequence, the depositor’s tokens are stuck in the BranchPort:
├─ [0] console::log(redeeming) [staticcall]
│ └─ ← ()
├─ [0] VM::expectRevert()
│ └─ ← ()
├─ [45957] BranchBridgeAgent::redeemDeposit(1)
│ ├─ [19384] BranchPort::withdraw(RootForkTest: [0xBb2180ebd78ce97360503434eD37fcf4a1Df61c3], MockERC20: [0x32Fa025409e66A35F3C95B04a195b4517f479dCF], 1000000000000000000 [1e18])
│ │ ├─ [18308] MockERC20::transfer(RootForkTest: [0xBb2180ebd78ce97360503434eD37fcf4a1Df61c3], 1000000000000000000 [1e18])
│ │ │ ├─ emit Transfer(from: BranchPort: [0x369Ff55AD83475B07d7FF2F893128A93da9bC79d], to: RootForkTest: [0xBb2180ebd78ce97360503434eD37fcf4a1Df61c3], amount: 1000000000000000000 [1e18])
│ │ │ └─ ← true
│ │ └─ ← ()
│ ├─ [19384] BranchPort::withdraw(RootForkTest: [0xBb2180ebd78ce97360503434eD37fcf4a1Df61c3], MockERC20: [0x541dC483Eb43cf8F9969baF71BF783193e5C5B1A], 1000000000000000000 [1e18])
│ │ ├─ [18308] MockERC20::transfer(RootForkTest: [0xBb2180ebd78ce97360503434eD37fcf4a1Df61c3], 1000000000000000000 [1e18])
│ │ │ ├─ emit Transfer(from: BranchPort: [0x369Ff55AD83475B07d7FF2F893128A93da9bC79d], to: RootForkTest: [0xBb2180ebd78ce97360503434eD37fcf4a1Df61c3], amount: 1000000000000000000 [1e18])
│ │ │ └─ ← true
│ │ └─ ← ()
│ ├─ [1874] BranchPort::withdraw(RootForkTest: [0xBb2180ebd78ce97360503434eD37fcf4a1Df61c3], BlacklistedToken: [0x56723b40D167976C402fBfe901cDD81fA5584dc4], 1000000000000000000 [1e18])
│ │ ├─ [660] BlacklistedToken::transfer(RootForkTest: [0xBb2180ebd78ce97360503434eD37fcf4a1Df61c3], 1000000000000000000 [1e18])
│ │ │ └─ ← "Blacklisted User"
│ │ └─ ← 0x90b8ec18
│ └─ ← 0x90b8ec18
├─ [6276] BranchBridgeAgent::getDepositEntry(1) [staticcall]
│ └─ ← (1, 0xBb2180ebd78ce97360503434eD37fcf4a1Df61c3, [0xabb4Cf532dC72dFDe5a18c67AF3fD3359Cb87055, 0x2B8A2bb23C66976322B20B6ceD182b1157B92862, 0x6079330AaAC5ca228ade7a78CF588F67a23Fe815], [0x32Fa025409e66A35F3C95B04a195b4517f479dCF, 0x541dC483Eb43cf8F9969baF71BF783193e5C5B1A, 0x56723b40D167976C402fBfe901cDD81fA5584dc4], [1000000000000000000 [1e18], 1000000000000000000 [1e18], 1000000000000000000 [1e18]], [1000000000000000000 [1e18], 1000000000000000000 [1e18], 1000000000000000000 [1e18]])
├─ [542] MockERC20::balanceOf(RootForkTest: [0xBb2180ebd78ce97360503434eD37fcf4a1Df61c3]) [staticcall]
│ └─ ← 0
├─ [542] MockERC20::balanceOf(RootForkTest: [0xBb2180ebd78ce97360503434eD37fcf4a1Df61c3]) [staticcall]
│ └─ ← 0
├─ [542] BlacklistedToken::balanceOf(RootForkTest: [0xBb2180ebd78ce97360503434eD37fcf4a1Df61c3]) [staticcall]
│ └─ ← 0
├─ [542] MockERC20::balanceOf(BranchPort: [0x369Ff55AD83475B07d7FF2F893128A93da9bC79d]) [staticcall]
│ └─ ← 1000000000000000000 [1e18]
├─ [542] MockERC20::balanceOf(BranchPort: [0x369Ff55AD83475B07d7FF2F893128A93da9bC79d]) [staticcall]
│ └─ ← 1000000000000000000 [1e18]
├─ [542] BlacklistedToken::balanceOf(BranchPort: [0x369Ff55AD83475B07d7FF2F893128A93da9bC79d]) [staticcall]
│ └─ ← 1000000000000000000 [1e18]
└─ ← ()
Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 3.58s
Recommended Mitigation Steps
When redeeming the failed deposits, the easiest and most straightforward solution is to allow the depositor to pass an address where it would like to receive all the deposited tokens.
- function redeemDeposit(uint32 _depositNonce) external override lock {
+ function redeemDeposit(uint32 _depositNonce, address _receiver) external override lock {
...
// Transfer token to depositor / user
for (uint256 i = 0; i < deposit.tokens.length;) {
- _clearToken(msg.sender, deposit.hTokens[i], deposit.tokens[i], deposit.amounts[i], deposit.deposits[i]);
+ _clearToken(_receiver, deposit.hTokens[i], deposit.tokens[i], deposit.amounts[i], deposit.deposits[i]);
unchecked {
++i;
}
}
...
}
Assessed type
Token-Transfer
Addressed here.
Note: For full discussion, see here.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The redemption function hardcodes the recipient as the original depositor and processes all tokens atomically, so a single token transfer failure blocks the entire redemption.
Impact
All deposited tokens, including hTokens, could be permanently locked in the BranchPort if the depositor is blacklisted in any one of the underlying tokens.
What the attacker needed
Deposit multiple tokens including a blacklistable one; depositor's address gets blacklisted in one token
The fix
The redeemDeposit function should allow the depositor to specify a different receiver address for the returned tokens.
How it was found
- Deposit multiple tokens (including a blacklistable token) from a Branch to Root.
- Make the Root execution fail so the deposit can be retrieved.
- Retrieve the deposit from Root back to the Branch.
- Blacklist the depositor's address in one of the deposited tokens.
- Attempt to redeem the deposit; the transaction reverts and all tokens remain stuck.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you deposit several different tokens, the system tries to return them all at once to your original address. If one of those tokens has a blacklist feature and your address is on it, the whole return fails. Then none of your tokens can be withdrawn, even the ones that are not blacklisted.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.