Exercising a large amount of options gives significantly higher discounts than supposed to
The option token contract calculated the payment amount using an average of swap outputs for a given amount, which made larger exercises cheaper per token. An attacker could exercise a large number of options in one transaction to get a significantly higher discount than intended.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-06-velocimeter-judging/issues/238
Found by
bughuntoor
Summary
Exercising options in multiple transactions would be significantly more profitable
Vulnerability Detail
Within the OptionTokenV4 contract, in order to calculate the paymentAmount the contract uses its own interpretation of TWAP price. But instead of it just being the actual TWAP price, it's the average amountOut a user would receive during 4 consecutive periods of time.
function getTimeWeightedAveragePrice(
uint256 _amount
) public view returns (uint256) {
uint256[] memory amtsOut = IPair(pair).prices(
underlyingToken,
_amount,
twapPoints
);
uint256 len = amtsOut.length;
uint256 summedAmount;
for (uint256 i = 0; i < len; i++) {
summedAmount += amtsOut[i];
}
return summedAmount / twapPoints;
}
This would mean that the more option tokens are exercised, the better the price would be. (Since the more you swap into the AMM, the more valuable the output token becomes).
A simple example would be if there has been 1e18 of reserves in both tokens.
- Exercising an option for 0.1e18 would cost you 0.09e18 payment token. Average payment/underlying price = 0.9
- Exercising an option for 100e18 would cost you 0.99e18 payment token. Average payment/underlying price = 0.01
Impact
User will be able to exercise options at significantly higher discount than supposed to.
Code Snippet
Tool used
Manual Review
Recommendation
Do not use amountsOut as a way to price the options
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/Velocimeter/v4-contracts/pull/22
sherlock-admin2
The Lead Senior Watson signed off on the fix.
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 contract used the average output amount from swapping the payment token as the option price, instead of a true time-weighted average price, so larger exercises received better prices.
Impact
A user could exercise options at a significantly higher discount than intended, potentially draining value from the protocol.
What the attacker needed
None
The fix
The protocol team fixed this issue in the referenced pull request.
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.
Options let you buy a token at a set price. The contract tried to set that price using a kind of average, but it averaged the results of swapping the payment token for the underlying token. Because swapping a larger amount moves the price, the average came out lower for bigger trades, so exercising more options gave a bigger discount.
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.