Market rate never used due to decimal discrepancy
A decimal precision mismatch between the market rate (18 decimals) and the redeem rate (6 decimals) in Pool.sol causes the comparison marketRate < redeemRate to always be false. As a result, the market rate is never used, and users redeeming tokens may receive more reserve tokens than intended if the true market rate is lower.
Source: https://github.com/sherlock-audit/2024-12-plaza-finance-judging/issues/561
Found by
0x52, 0xadrii, 0xc0ffEE, Hueber, Ryonen, X0sauce, ZoA, bretzel, farman1094, future, fuzzysquirrel, shui, stuart_the_minion, tinnohofficial
Summary
A decimal precision mismatch between marketRate (18 decimal precision) and redeemRate (6 decimal precision) in Pool.sol will cause the market rate to never be used.
Root Cause
In Pool.sol#L512-L516, the redeemRate is calculated and implicitly uses a precision of 6 decimal precision :
- Pool#512
- Pool#516
- Pool#516 : The constant
BOND_TARGET_PRICE = 100multiplied byPRECISION = 1e6= 100e6.
However, the marketRate will be normalized to 18dp :
The BPT token itself has 18 decimals (BalancerPoolToken.sol) so totalSupply() is 18dp.
When calculating the price of a BPT it will formalize each price of the asset of the BPT pool to 18dp : "balancer math works with 18 dec" BalancerOracleAdapter.sol#L109.
It implies that the decimals of BalancerOracleAdapter is set to 18.
Then the final value will have a precision of 18dp.
The comparison marketRate < redeemRate will always be false due to this difference in decimal precision.
Internal Pre-conditions
- A Chainlink price feed for the bond token must exist and be registered in
OracleFeeds. - The
marketRatefrom the Balancer oracle is lower than the calculatedredeemRatewhen both are expressed with the same decimal precision. getOracleDecimals(reserveToken, USD)returns 18
External Pre-conditions
N/A
Attack Path
- A user initiates a redeem transaction.
- The
simulateRedeemandgetRedeemAmountfunctions are called. - The condition
marketRate < redeemRateevaluates to false due to the decimal mismatch. - The
redeemRate, which might be higher than the actual market rate, is used to calculate the amount of reserve tokens the user receives.
Impact
The intended functionality of considering the market rate for redemptions is completely bypassed.
Users redeeming tokens might receive more reserve tokens than expected if the true market rate (with correct decimals) is lower than the calculated redeemRate.
PoC
N/A
Mitigation
Change the normalization in simulateRedeem to use the bondToken.SHARES_DECIMALS() instead of oracleDecimals.
uint256 marketRate;
address feed = OracleFeeds(oracleFeeds).priceFeeds(address(bondToken), USD);
uint8 sharesDecimals = bondToken.SHARES_DECIMALS(); // Get the decimals of the shares
if (feed != address(0)) {
marketRate = getOraclePrice(address(bondToken), USD).normalizeAmount(
getOracleDecimals(address(bondToken), USD),
sharesDecimals // Normalize to sharesDecimals
);
}
Modify the normalization of marketRate in Pool.sol's simulateRedeem function to use the same decimal precision as redeemRate (6 decimals). Specifically, change the normalization to use bondToken.SHARES_DECIMALS() instead of oracleDecimals:
if (feed != address(0)) {
+ uint8 sharesDecimals = bondToken.SHARES_DECIMALS(); // Use sharesDecimals for consistent precision
marketRate = getOraclePrice(address(bondToken), USD)
.normalizeAmount(
getOracleDecimals(address(bondToken), USD),
- oracleDecimals // this is the decimals of the reserve token chainlink feed
+ sharesDecimals
);
}
return getRedeemAmount(tokenType, depositAmount, bondSupply, levSupply, poolReserves, getOraclePrice(reserveToken, USD), oracleDecimals, marketRate)
.normalizeAmount(COMMON_DECIMALS, IERC20(reserveToken).safeDecimals());
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/Convexity-Research/plaza-evm/pull/156
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
Impact
The intended functionality of considering the market rate for redemptions is completely bypassed, and users redeeming tokens might receive more reserve tokens than expected if the true market rate is lower than the calculated redeemRate.
What the attacker needed
A Chainlink price feed for the bond token exists; Market rate lower than redeem rate (same decimals); getOracleDecimals returns 18
The fix
The protocol team fixed this issue by changing the normalization in simulateRedeem to use bondToken.SHARES_DECIMALS() instead of oracleDecimals.
How it was found
- A user initiates a redeem transaction.
- The simulateRedeem and getRedeemAmount functions are called.
- The condition marketRate < redeemRate evaluates to false due to the decimal mismatch.
- The redeemRate, which might be higher than the actual market rate, is used to calculate the amount of reserve tokens the user receives.
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.
In smart contracts, numbers are stored as integers with a fixed number of decimal places. If you compare two numbers with different decimal places, the comparison can be wrong. Here, the market rate had 18 decimal places while the redeem rate had 6, so the check that should use the lower rate never triggered, letting users get a better rate than they should.
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.