The addGlobalToken function allows multiple concurrent requests to create local tokens for the same global token on a destination chain. Because the final check uses the newly generated local address instead of the global token, a later request can overwrite the earlier local token mapping, potentially causing users to lose deposited tokens if they bridge during the window between the two confirmations.
3.2 rootPort.setLocalAddress (globalGlobal, new Local token, fmtChainId)
Call sequence [root]->[branch]->[root], with asynchronous calls via layerzero. Since it is asynchronous, in the case of concurrency, the check in step 1.2 is invalid because step 3.2 is executed after a certain amount of time.
Consider the following scenarios:
Alice executes addGlobalToken(ftm) through Steps 1 and 2, and generates alice_LocalTokenAddress = 0x01.
Bob executes addGlobalToken(ftm) through Steps 1 and 1, and generates bob_LocalTokenAddress = 0x02 at the same time.
After a while, layerzero executes Alice’s request and will pass step 3.1, because alice_LocalTokenAddress is new.
After a while, layerzero executes Bob’s request and will pass step 3.1, because bob_LocalTokenAddress is new.
So bob_LocalTokenAddress will override alice_LocalTokenAddress.
The main problem here, is that the check in step 3.1 is wrong because the local token is a regenerated address, so isLocalToken() is always false. It should be checking isGlobalToken(_globalAddress, _dstChainId)).
function _setLocalToken(address _globalAddress, address _localAddress, uint16 _dstChainId) internal {
// Verify if the token already added
@> if (IPort(rootPortAddress).isLocalToken(_localAddress, _dstChainId)) revert TokenAlreadyAdded();
// Set the global token's new branch chain address
IPort(rootPortAddress).setLocalAddress(_globalAddress, _localAddress, _dstChainId);
}
Impact
In the case of concurrency, the second local token will overwrite the first local token. Before overwriting, the first local token is still valid. If someone exchanges the first local token and waits until after overwriting, then the first local token will be invalidated and the user will lose the corresponding token.
Proof of Concept
The following code demonstrates that with layerzero asynchronous and due to _setLocalToken() error checking, it may cause the second localToken to overwrite the first localToken; the layerzero call is simplified.
Add to CoreRootBridgeAgentTest.t.sol
function testAddGlobalTokenOverride() public {
//1. new global token
GasParams memory gasParams = GasParams(0, 0);
arbitrumCoreRouter.addLocalToken(address(arbAssetToken), gasParams);
newGlobalAddress = RootPort(rootPort).getLocalTokenFromUnderlying(address(arbAssetToken), rootChainId);
console2.log("New Global Token Address: ", newGlobalAddress);
//2.1 new first local token
gasParams = GasParams(1 ether, 1 ether);
GasParams[] memory remoteGas = new GasParams[](2);
remoteGas[0] = GasParams(0.0001 ether, 0.00005 ether);
remoteGas[1] = GasParams(0.0001 ether, 0.00005 ether);
bytes memory data = abi.encode(ftmCoreBridgeAgentAddress, newGlobalAddress, ftmChainId,remoteGas);
bytes memory packedData = abi.encodePacked(bytes1(0x01), data);
encodeCallNoDeposit(
payable(ftmCoreBridgeAgentAddress),
payable(address(coreBridgeAgent)),
chainNonce[ftmChainId]++,
packedData,
gasParams,
ftmChainId
);
//2.2 new second local token
data = abi.encode(ftmCoreBridgeAgentAddress, newGlobalAddress, ftmChainId,remoteGas);
packedData = abi.encodePacked(bytes1(0x01), data);
encodeCallNoDeposit(
payable(ftmCoreBridgeAgentAddress),
payable(address(coreBridgeAgent)),
chainNonce[ftmChainId]++,
packedData,
gasParams,
ftmChainId
);
//3.1 wait some time ,lz execute first local token
address newLocalToken = address(0xFA111111);
data = abi.encode(newGlobalAddress, newLocalToken, "UnderLocal Coin", "UL");
packedData = abi.encodePacked(bytes1(0x03), data);
encodeSystemCall(
payable(ftmCoreBridgeAgentAddress),
payable(address(coreBridgeAgent)),
chainNonce[ftmChainId]++,
packedData,
gasParams,
ftmChainId
);
//3.1.1 show first local token address
address ftmLocalToken = RootPort(rootPort).getLocalTokenFromGlobal(newGlobalAddress,ftmChainId);
console2.log("loal Token Address(first): ", ftmLocalToken);
//3.2 wait some time ,lz execute second local token
gasParams = GasParams(0.0001 ether, 0.00005 ether);
newLocalToken = address(0xFA222222);
data = abi.encode(newGlobalAddress, newLocalToken, "UnderLocal Coin", "UL");
packedData = abi.encodePacked(bytes1(0x03), data);
encodeSystemCall(
payable(ftmCoreBridgeAgentAddress),
payable(address(coreBridgeAgent)),
chainNonce[ftmChainId]++,
packedData,
gasParams,
ftmChainId
);
//3.2.1 show second local token address
ftmLocalToken = RootPort(rootPort).getLocalTokenFromGlobal(newGlobalAddress,ftmChainId);
console2.log("loal Token Address(override): ", ftmLocalToken);
}
$ forge test -vvv --match-contract CoreRootBridgeAgentTest --match-test testAddGlobalTokenOverride
[PASS] testAddGlobalTokenOverride() (gas: 1846078)
Logs:
New Global Token Address: 0x12Cd3f6571aF11e01137d294866C5fFd1369Bbe9
loal Token Address(first): 0x00000000000000000000000000000000Fa111111
loal Token Address(override): 0x00000000000000000000000000000000fA222222
Recommended Mitigation
Check isGlobalToken() should replace check isLocalToken().
function _setLocalToken(address _globalAddress, address _localAddress, uint16 _dstChainId) internal {
// Verify if the token already added
- if (IPort(rootPortAddress).isLocalToken(_localAddress, _dstChainId)) revert TokenAlreadyAdded();
+ if (IPort(rootPortAddress).isGlobalToken(_globalAddress, _dstChainId)) {
+ revert TokenAlreadyAdded();
+ }
// Set the global token's new branch chain address
IPort(rootPortAddress).setLocalAddress(_globalAddress, _localAddress, _dstChainId);
}
As a rule, you should validate the arguments in internal functions, that when those arguments change state in the same function, some values of those arguments could break the logic represented by that state.
[What the submission] is saying has no impact on users in any way, since there is no way to acquire the asset on the origin branch before token addition execution is confirmed on root; it would simply revert and the user would be able to redeem the deposited assets. In addition, the issue seems to revolve around the misuse of this function IPort(rootPortAddress).isLocalToken(_localAddress, _dstChainId) in _setLocalToken - but this is intended so as to prevent overwriting this mapping after it already being added.
Furthermore, the suggested funciton IPort(rootPortAddress).isGlobalToken(_globalAddress, _dstChainId) is always updated in tandem with the one currently being used, so it’s the same thing as doing the checks we currently have in place.
since there is no way to acquire the asset on the origin branch before token addition execution is confirmed on root
Is it possible to look again? Both will be confirmed at root. Please see poc’s ”3.1.1 show first local token address”.
The address has been printed out from root:
Logs:
New Global Token Address: 0x12Cd3f6571aF11e01137d294866C5fFd1369Bbe9
loal Token Address(first): 0x00000000000000000000000000000000Fa111111
loal Token Address(override): 0x00000000000000000000000000000000fA222222
The problem describes that both addGlobalToken()all work. The second addGlobalToken() overrides the first.
Since these operations are asynchronous (cross-chain), the first step check can be skipped. Because the third step incorrectly uses isLocalToken() to check for legitimacy, the override becomes possible.
I explained the issue more clearly to the sponsor, and is now confirmed:
Really apologize for my misunderstanding, I was not interpreting the issue correctly, seems that during the time between _addGlobalToken and _setLocalToken, multiple tokens can be requested; although, this is to be expected, only the last one created from these requests will be retained in the system instead of the first one.
Due to this, during the time period between the first _setLocalToken execution and the last, the submission of bridgeOut requests would lead to the loss of the deposited tokens. Although, this is a very specific time frame to be possible (the 2 layer zero hops in question), it is a very important situation to be addressed as someone could loose access to their tokens under these circumstances.
The original report as published on Code4rena, by bin2chen. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely the final check in _setLocalToken uses isLocalToken on the newly generated local address, which is always false, instead of checking whether the global token already has a local token on that chain.
Impact
During the time between the first and last _setLocalToken execution, a user who bridges out using the first local token could lose their deposited tokens because the token becomes invalid after being overwritten.
What the attacker needed
Two concurrent addGlobalToken requests for the same global…; a user bridges out using the first local token during the…
The fix
The check in _setLocalToken should use isGlobalToken on the global address and destination chain instead of isLocalToken on the local address; the sponsor addressed this in a remediation commit.
How it was found
Alice calls addGlobalToken for a destination chain, which after cross-chain messages creates a new local token address.
Bob calls addGlobalToken for the same destination chain at nearly the same time, creating a different local token address.
When Alice's request is finally processed on the root chain, the check passes because her local token address is new.
When Bob's request is processed later, the check also passes because his local token address is new, and his address overwrites Alice's.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
This is a bug in a cross-chain token system. When you ask to add a token on another chain, the system creates a new local token address and later records it. Because the recording step checks whether that new address already exists (which it never does), two simultaneous requests can both succeed, and the second one replaces the first. If someone uses the first token before it is replaced, their tokens become invalid and they lose them.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.