Skip to content
Business logic Audit finding Intermediate

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.

bughuntoor Follow

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.

Solidity
    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.

  1. Exercising an option for 0.1e18 would cost you 0.09e18 payment token. Average payment/underlying price = 0.9
  2. 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

https://github.com/sherlock-audit/2024-06-velocimeter/blob/main/v4-contracts/contracts/OptionTokenV4.sol#L323

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.

The original report as published on Sherlock, by bughuntoor. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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.

More by bughuntoor

View all

16 more disclosed reports, best first.

More from Velocimeter

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.