SwapUtils.sol Wrong implementation
The contract stores token precision multipliers that are used in price calculations, but these multipliers are only updated when the owner calls rampTargetPrice or stopRampTargetPrice. As a result, a newly set target price does not take effect until another target price is set or the ramp is stopped.
Submitted by WatchPug
Based on the context, the tokenPrecisionMultipliers used in price calculation should be calculated in realtime based on initialTargetPrice, futureTargetPrice, futureTargetPriceTime and current time, just like getA() and getA2().
However, in the current implementation, tokenPrecisionMultipliers used in price calculation is the stored value, it will only be changed when the owner called rampTargetPrice() and stopRampTargetPrice().
As a result, the targetPrice set by the owner will not be effective until another targetPrice is being set or stopRampTargetPrice() is called.
Recommendation
Consider adding Swap.targetPrice and changing the _xp() at L661 from:
function _xp(Swap storage self, uint256[] memory balances)
internal
view
returns (uint256[] memory)
{
return _xp(balances, self.tokenPrecisionMultipliers);
}
To:
function _xp(Swap storage self, uint256[] memory balances)
internal
view
returns (uint256[] memory)
{
uint256[2] memory tokenPrecisionMultipliers = self.tokenPrecisionMultipliers;
tokenPrecisionMultipliers[0] = self.targetPrice.originalPrecisionMultipliers[0].mul(_getTargetPricePrecise(self)).div(WEI_UNIT)
return _xp(balances, tokenPrecisionMultipliers);
}
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 token precision multipliers are stored and only recalculated on specific owner actions, rather than being derived in real time from the target price parameters.
What the attacker needed
Owner sets a target price
The fix
The recommendation is to add a `Swap.targetPrice` field and modify the `_xp` function to compute the token precision multipliers dynamically using the target price and current time.
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.
This is a smart contract bug where a value used for pricing is not updated when it should be. The owner can set a new target price, but the contract keeps using the old multipliers until another action triggers an update. So the new price doesn't actually apply when expected.
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.