Skip to content
Business logic Audit finding Intermediate

Curve points should be guaranteed to be monotonic increasing

The smart contract's curve points were not validated to be monotonically increasing, so a lower point could be set after a higher one. This could cause deposit and extendLock functions to revert due to underflow when calculating the multiplier.

hickuphh3 Follow with minhquanym, WATCHPUG and 3 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-10-merit-circle-judging/issues/111

Found by

hickuphh3, minhquanym, WATCHPUG, ElKu, berndartmueller, rvierdiiev

Summary

Lack of checks to ensure the points in the curve are monotonic increasing, which can result in a malfunction of deposit() / extendLock() due to underflow when the curve is not set properly.

Vulnerability Detail

In the current implementation, getMultiplier() assume the later point in the curve is always bigger than the previous point, otherwise curve[n + 1] - curve[n] will revert due to underflow.

However, since there is no check in __TimeLockPool_init() / setCurve() / setCurvePoint() to guarantee that, a lower point can actually be set after a higher point.

Impact

deposit() / extendLock() may revert due to underflow.

Code Snippet

https://github.com/sherlock-audit/2022-10-merit-circle/blob/main/merit-liquidity-mining/contracts/TimeLockPool.sol#L35-L63

https://github.com/sherlock-audit/2022-10-merit-circle/blob/main/merit-liquidity-mining/contracts/TimeLockPool.sol#L280-L311

https://github.com/sherlock-audit/2022-10-merit-circle/blob/main/merit-liquidity-mining/contracts/TimeLockPool.sol#L322-L337

Tool used

Manual Review

Recommendation

Consider adding a new internal function to validate the curve points:

Solidity
function checkCurve(uint256[] calldata _curve) internal {
    if (_curve.length < 2) {
        revert ShortCurveError();
    }
    for (uint256 i; i < curve.length - 1; ++i) {
            if (
                curve[i + 1] < curve[i]
            ) {
                revert CurveIncreaseError();
            }
        }
}

Discussion

federava

Agree on the recommendation. Using that logic everywhere the curve is set should be sufficient: setCurve(), setCurvePoint() and in __TimeLockPool_init(). Thanks!

federava

PR from this issue

The original report as published on Sherlock, by hickuphh3. 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

The contract's initialisation and setter functions for the curve did not check that each point is greater than or equal to the previous point, allowing an invalid curve that causes underflow in getMultiplier().

Impact

deposit() and extendLock() may revert due to underflow, preventing users from depositing or extending locks.

What the attacker needed

Ability to set curve points; or initialisation with invalid curve

The fix

The recommendation is to add an internal function that validates the curve points are monotonically increasing and call it in setCurve(), setCurvePoint(), and __TimeLockPool_init().

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 a smart contract, a curve is a list of numbers used to calculate rewards. The code assumes each number is bigger than the previous one. If someone sets a smaller number after a bigger one, the subtraction underflows (goes below zero) and the transaction fails. This means users cannot deposit or extend their lock.

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 hickuphh3

View all

43 more disclosed reports, best first.

More from Merit Circle

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.