BondOracleAdapter will cause massive loss of funds for a large number of bond tokens
The BondOracleAdapter returns the pool price directly and hardcodes the oracle decimals to the bond token's decimals, but the pool may order the bond token as token0 instead of token1, causing the price to be denominated in the wrong token. This leads to an incorrect market rate and massive loss of funds for bond token holders when redeeming.
Source: https://github.com/sherlock-audit/2024-12-plaza-finance-judging/issues/440
Found by
0x52, ZoA, bladeee
Summary
BondOracleAdapter both directly returns the price from the pool and hardcodes the oracle decimals to bondToken.decimals(). The combination of these two factors will cause the adapter to return an incorrect value for any bondToken that is not alphanumerically greater than USDC. The dex pool always prices tokenA in terms of tokenB and because the decimals of the oracle are hardcoded to the decimals of the bond token, the bond token must be tokenB or else the decimals will be incorrect. This incorrect pricing will cause massive loss of funds to user withdrawing from the pool as the market price will be much too low.
When initializing the BondOracleAdapter, it pulls the pool address from the getPool mapping. While this will pull the relevant pool for those tokens, it does not ensure that the tokens are in the correct order.
getPool[token0][token1][tickSpacing] = pool;
// populate mapping in the reverse direction, deliberate choice to avoid the cost of comparing addresses
getPool[token1][token0][tickSpacing] = pool;
We see that get pool is populated in both orders even though they are sorted alphanumerically. Therefore when the pool is retrieved for BondOracleAdapter the tokens can be in any order.
return (uint80(0), int256(getPriceX96FromSqrtPriceX96(getSqrtTwapX96)), block.timestamp, block.timestamp, uint80(0));
We see that when price is returned it is always returned directly as returned by the underlying dex pool. The issues is that if the bond token is not tokenB then the decimal of the return value will be the liquidity token rather than the bond token.
if (marketRate != 0 && marketRate < redeemRate) {
redeemRate = marketRate;
}
As a result when redeeming bond tokens the value will be significantly lower than expected and will result in bond holders losing large amounts of value.
Root Cause
BondOracleAdapter#L113 always return price directly
BondOracleAdapter.sol#L62 always assumes that price is denominated in bond tokens
Internal Pre-conditions
address(bondToken) > address(liquidityToken)
External Pre-conditions
N/A
Attack Path
N/A
Impact
Loss of funds for redeeming bond token holders
PoC
No response
Mitigation
BondOracleAdapter#initialize should set decimals to either bondToken or liquidityToken depending on token order in the pool
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/Convexity-Research/plaza-evm/pull/158
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
Likely the BondOracleAdapter assumes the bond token is always token1 in the pool and hardcodes the oracle decimals to the bond token's decimals, without checking the actual token order.
Impact
Bond token holders redeeming their tokens could lose a large amount of funds because the market rate is incorrectly low.
What the attacker needed
Address(bondToken) > address(liquidityToken)
The fix
The BondOracleAdapter's initialize function should set the decimals based on the actual token order in the pool, using either the bond token's or the liquidity token's decimals as appropriate.
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.
A bond token is a token that represents a bond. The BondOracleAdapter is a contract that provides the price of the bond token. It gets the price from a trading pool, but it assumes the bond token is always the second token in the pool. If the bond token's address is smaller than the other token's address, the pool orders them differently, and the price is wrong. This makes the bond token appear much cheaper than it is, so people redeeming it get less money.