importDev0x - Smart contract users can Bridge ETH or ERC20 tokens from their account to themselves with `bridgeETHTo` and `bridgeERC20To` functions #62
Smart contract users can Bridge ETH or ERC20 tokens from their account to themselves with bridgeETHTo and bridgeERC20To functions
Summary
Smart contract users are limited to bridging ETH or ERC20 tokens to themselves because of the onlyEOA modifier in the bridgeETH and bridgeERC20 functions. However, they can bridge ETH or ERC20 tokens using the bridgeETHTo and bridgeERC20To functions without any restrictions, which provide the same functionality as bridgeETH and bridgeERC20. The only requirement for smart contract users is to set the _to parameter of the bridgeETHTo and bridgeERC20To functions to the address of their contract.
In the test below, it is expected that a smart contract user cannot bridge ETH when the destination address (_to) is set to msg.sender. However, it runs without any issues, resulting in the test failing.
Please copy the test function below and add it to the end of the L1StandardBridge.t.sol file.
msg.sender and _to should not be the same in the bridgeETHTo and bridgeERC20To functions. Therefore, we can perform this check at the beginning of these two functions. If EOA (Externally Owned Account) users want to bridge ETH or ERC20 tokens to themselves, they can use the bridgeETH and bridgeERC20 functions as intended.
importDev0x
High
Smart contract users can Bridge ETH or ERC20 tokens from their account to themselves with
bridgeETHTo
andbridgeERC20To
functionsSummary
Smart contract users are limited to bridging ETH or ERC20 tokens to themselves because of the
onlyEOA
modifier in thebridgeETH
andbridgeERC20
functions. However, they can bridge ETH or ERC20 tokens using thebridgeETHTo
andbridgeERC20To
functions without any restrictions, which provide the same functionality asbridgeETH
andbridgeERC20
. The only requirement for smart contract users is to set the_to
parameter of thebridgeETHTo
andbridgeERC20To
functions to the address of their contract.https://github.com/sherlock-audit/2024-08-tokamak-network/blob/main/tokamak-thanos/packages/contracts-bedrock/src/universal/StandardBridge.sol#L187
https://github.com/sherlock-audit/2024-08-tokamak-network/blob/main/tokamak-thanos/packages/contracts-bedrock/src/universal/StandardBridge.sol#L222
Vulnerability Detail
In the test below, it is expected that a smart contract user cannot bridge ETH when the destination address (
_to
) is set tomsg.sender
. However, it runs without any issues, resulting in the test failing.Please copy the test function below and add it to the end of the L1StandardBridge.t.sol file.
Recommendation
msg.sender
and_to
should not be the same in thebridgeETHTo
andbridgeERC20To
functions. Therefore, we can perform this check at the beginning of these two functions. If EOA (Externally Owned Account) users want to bridge ETH or ERC20 tokens to themselves, they can use thebridgeETH
andbridgeERC20
functions as intended.