Platform: Code4rena
Start Date: 30/05/2023
Pot Size: $300,500 USDC
Total HM: 79
Participants: 101
Period: about 1 month
Judge: Trust
Total Solo HM: 36
Id: 242
League: ETH
Rank: 94/101
Findings: 1
Award: $23.84
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: peakbolt
Also found by: 0xStalin, 0xTheC0der, BPZ, LokiThe5th, RED-LOTUS-REACH, adeolu, bin2chen, jasonxiale, kodyvim, kutugu, ltyu, ubermensch
23.8445 USDC - $23.84
https://github.com/code-423n4/2023-05-maia/blob/54a45beb1428d85999da3f721f923cbf36ee3d35/src/ulysses-omnichain/BranchBridgeAgent.sol#L1340 https://github.com/code-423n4/2023-05-maia/blob/54a45beb1428d85999da3f721f923cbf36ee3d35/src/ulysses-omnichain/BranchBridgeAgent.sol#L1341
return _decimals == 18 ? _amount : _amount * (10 ** _decimals) / 1 ether;
_normalizeDecimals() is meant to convert tokens amounts with denomiated with decimals other than 18 to 18 decimals. Logic in _normalizeDecimals() of BranchBridgeAgent.sol gives wrong output when decimals is not 18. This leads to bad accounting in protocol. Tokens with other decimals other than 18, usdc for example are wrongly calculated.
The _normalizeDecimals()
is used in the deposit related/briding functions when crossing chains in the protocol.
function _normalizeDecimals(uint256 _amount, uint8 _decimals) internal pure returns (uint256) { return _decimals == 18 ? _amount : _amount * (10 ** _decimals) / 1 ether; }
The above code is snippet from the repo showing faulty logic.
Following above logic if we want to convert a 6 decimal value of usdc to 18 decimals, if we have 10 usdc that is 10_000_000 * (10**6) / 10**18
. This will give a result of 0
since 1e13 /1e18 = 0
. This means for a conversion of 10 usdc value, we register a value of 0.
VS CODE
Change logic to
function _normalizeDecimals(uint256 _amount, uint8 _decimals) internal pure returns (uint256) { return _decimals == 18 ? _amount : _amount * 1 ether / (10 ** _decimals) ; }
This way 10 usdc when converted to an 18 decimal value becomes 10_000_000 * 1e18 / 10 ** 6 = 10 * 1e18
Math
#0 - c4-judge
2023-07-09T15:22:03Z
trust1995 marked the issue as duplicate of #758
#1 - c4-judge
2023-07-09T15:22:20Z
trust1995 marked the issue as satisfactory
#2 - trust1995
2023-07-28T11:18:02Z
Partial credit for detecting 1/3 of the primary's issues.
#3 - c4-judge
2023-07-28T11:18:07Z
trust1995 marked the issue as partial-25