You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Minting UBI from reserve balance is incorrectly handled
Summary
In every function/transaction where we deal with tokens, they get scaled to 18 decimals and saved to struct. If reserveToken happens to be token with decimals less than 18 decimals - function mintUBIFromReserveBalance won't correctly perform calculation or even revert.
function mintUBIFromReserveBalance(bytes32exchangeId) externalreturns (uint256amountMinted) {
IBancorExchangeProvider.PoolExchange memory exchange =IBancorExchangeProvider(address(goodDollarExchangeProvider))
.getPoolExchange(exchangeId);
uint256 contractReserveBalance =IERC20(exchange.reserveAsset).balanceOf(reserve);
@>uint256 additionalReserveBalance = contractReserveBalance - exchange.reserveBalance;
if (additionalReserveBalance >0) {
amountMinted = goodDollarExchangeProvider.mintFromInterest(exchangeId, additionalReserveBalance);
IGoodDollar(exchange.tokenAddress).mint(address(distributionHelper), amountMinted);
// Ignored, because contracts only interacts with trusted contracts and tokens// slither-disable-next-line reentrancy-eventsemitInterestUBIMinted(exchangeId, amountMinted);
}
}
As in above code, IERC20(exchange.reserveAsset).balanceOf(reserve) will return token with their correct decimals (for example 6), but exchange.reserveBalance will return scaled tokens which will lead to underflow/overflow error.
The text was updated successfully, but these errors were encountered:
sherlock-admin3
changed the title
Polished Goldenrod Bison - Minting UBI from reserve balance is incorrectly handled
0xShitgem - Minting UBI from reserve balance is incorrectly handled
Nov 5, 2024
0xShitgem
Medium
Minting UBI from reserve balance is incorrectly handled
Summary
In every function/transaction where we deal with tokens, they get scaled to 18 decimals and saved to struct. If
reserveToken
happens to be token with decimals less than 18 decimals - functionmintUBIFromReserveBalance
won't correctly perform calculation or even revert.As in above code,
IERC20(exchange.reserveAsset).balanceOf(reserve)
will return token with their correct decimals (for example 6), butexchange.reserveBalance
will return scaled tokens which will lead to underflow/overflow error.Root Cause
The root cause is handling incorrectly decimals inside mintUBIFromReserveBalance.
Internal pre-conditions
Tokens with less than 18 decimals
External pre-conditions
Tokens with less than 18 decimals
Attack Path
No response
Impact
Function
mintUBIFromReserveBalance
is unable to execute correctly.PoC
Add below code to
mento-core/test/unit/goodDollar
Mitigation
Scale
balanceOf
and later divide by precision.The text was updated successfully, but these errors were encountered: