After proposed 0.8.0 upgrade kicks in, L2 finalizeInboundTransfer might not work
The L2GraphTokenGateway contract uses an address alias calculation that relies on integer overflow, which will revert under Solidity 0.8.0. If the upgrade occurs, finalizeInboundTransfer may fail for about 6.5% of L1 gateway addresses.
Submitted by Trust
L2GraphTokenGateway uses the onlyL1Counterpart modifier to make sure finalizeInboundTransfer is only called from L1GraphTokenGateway. Its implementation is:
modifier onlyL1Counterpart() {
require(
msg.sender == AddressAliasHelper.applyL1ToL2Alias(l1Counterpart),
"ONLY_COUNTERPART_GATEWAY"
);
_;
}
It uses applyL1ToL2Alias defined as:
uint160 constant offset = uint160(0x1111000000000000000000000000000000001111);
/// @notice Utility function that converts the address in the L1 that submitted a tx to
/// @return l2Address L2 address as viewed in msg.sender
function applyL1ToL2Alias(address l1Address) internal pure returns (address l2Address) {
l2Address = address(uint160(l1Address) + offset);
}
This behavior matches with how Arbitrum augments the sender’s address to L2. The issue is that I’ve spoken with the team and they are planning an upgrade from Solidity 0.7.6 to 0.8.0. Their proposed changes will break this function, because under 0.8.0, this line has a ~ 1/15 chance to overflow:
l2Address = address(uint160(l1Address) + offset);
Interestingly, the sum intentionally wraps around using the uint160 type to return a correct address, but this wrapping will overflow in 0.8.0
Impact
There is a ~6.5% chance that finalizeInboundTransfer will not work.
Proof of Concept
l1Address is L1GraphTokenGateway, suppose its address is 0xF000000000000000000000000000000000000000.
Then 0xF000000000000000000000000000000000000000 + 0x1111000000000000000000000000000000001111 > UINT160_MAX , meaning overflow.
Recommended Mitigation Steps
Wrap the calculation in an unchecked block, which will make it behave correctly.
This seems out of scope. The code has been asked to be audited given a certain compiler version. Will wait for sponsor review before closing as out of scope.
pcarranzav (The Graph) confirmed and commented:
While I agree the submission is technically out of scope, I do consider it valuable. It’s unclear if we’ll upgrade to 0.8 soon or not, but knowing this does prevent a pretty bad potential issue if we do. Not sure if/how it would fit in the severity scale, but I would appreciate it if you could consider this eligible for awarding.
Great, happy to leave it as a Medium risk and valid.
pcarranzav (The Graph) resolved and commented:
(Preemptively) fixed in https://github.com/graphprotocol/contracts/pull/738
Trust (warden) reviewed mitigation:
Fixed in future 0.8.0 upgrade branch PR. Fixed by wrapping the potential overflowing and underflowing operations in an unchecked block.
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 code intentionally relies on integer overflow to compute an alias, but Solidity 0.8.0 makes overflow revert by default.
What the attacker needed
Upgrade to Solidity 0.8.0; L1 gateway address causes overflow
The fix
The calculation should be wrapped in an unchecked block to allow the intended overflow.
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.
Smart contracts are computer programs on a blockchain. This one adds a fixed number to an address to check who is calling. In newer versions of the programming language, that addition can cause an error if the result is too big, so the check would fail and the function would stop working.
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.