Skip to content
Business logic Audit finding Intermediate

meta.tuneBelowCapacity param is not updated when BondBaseSDA.setIntervals is called

The setIntervals function updates tuneInterval and tuneIntervalCapacity but fails to update tuneBelowCapacity, which is used to decide when price tuning occurs. This can cause tuning to be skipped when it should happen or to occur when it should not, disrupting the market's price adjustment mechanism.

rvierdiiev Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-11-bond-judging/issues/9

Found by

rvierdiiev

Summary

When BondBaseSDA.setIntervals function is called then meta.tuneBelowCapacity param is not updated which has impact on price tuning.

Vulnerability Detail

BondBaseSDA.setIntervals function allows for market owner to change some market interval. One of them is meta.tuneInterval. https://github.com/sherlock-audit/2022-11-bond/blob/main/src/bases/BondBaseSDA.sol#L303-L333

Solidity
    function setIntervals(uint256 id_, uint32[3] calldata intervals_) external override {
        // Check that the market is live
        if (!isLive(id_)) revert Auctioneer_InvalidParams();


        // Check that the intervals are non-zero
        if (intervals_[0] == 0 || intervals_[1] == 0 || intervals_[2] == 0)
            revert Auctioneer_InvalidParams();


        // Check that tuneInterval >= tuneAdjustmentDelay
        if (intervals_[0] < intervals_[1]) revert Auctioneer_InvalidParams();


        BondMetadata storage meta = metadata[id_];
        // Check that tuneInterval >= depositInterval
        if (intervals_[0] < meta.depositInterval) revert Auctioneer_InvalidParams();


        // Check that debtDecayInterval >= minDebtDecayInterval
        if (intervals_[2] < minDebtDecayInterval) revert Auctioneer_InvalidParams();


        // Check that sender is market owner
        BondMarket memory market = markets[id_];
        if (msg.sender != market.owner) revert Auctioneer_OnlyMarketOwner();


        // Update intervals
        meta.tuneInterval = intervals_[0];
        meta.tuneIntervalCapacity = market.capacity.mulDiv(
            uint256(intervals_[0]),
            uint256(terms[id_].conclusion) - block.timestamp
        ); // don't have a stored value for market duration, this will update tuneIntervalCapacity based on time remaining
        meta.tuneAdjustmentDelay = intervals_[1];
        meta.debtDecayInterval = intervals_[2];
    }

meta.tuneInterval has impact on meta.tuneIntervalCapacity. That means that when you change tuning interval you also change the capacity that is operated during tuning. There is also one more param that depends on this, but is not counted here.

This is meta.tuneBelowCapacity param and it is needed to say if the market has overselled tokens. In another words it says if meta.tuneIntervalCapacity is already sold. This param is checked while tuning and then is updated after the tuning. https://github.com/sherlock-audit/2022-11-bond/blob/main/src/bases/BondBaseSDA.sol#L576-L621

Solidity
        if (
            (market.capacity < meta.tuneBelowCapacity && timeNeutralCapacity < initialCapacity) ||
            (time_ >= meta.lastTune + meta.tuneInterval && timeNeutralCapacity > initialCapacity)
        ) {
            // Calculate the correct payout to complete on time assuming each bond
            // will be max size in the desired deposit interval for the remaining time
            //
            // i.e. market has 10 days remaining. deposit interval is 1 day. capacity
            // is 10,000 TOKEN. max payout would be 1,000 TOKEN (10,000 * 1 / 10).
            markets[id_].maxPayout = capacity.mulDiv(uint256(meta.depositInterval), timeRemaining);


            // Calculate ideal target debt to satisty capacity in the remaining time
            // The target debt is based on whether the market is under or oversold at this point in time
            // This target debt will ensure price is reactive while ensuring the magnitude of being over/undersold
            // doesn't cause larger fluctuations towards the end of the market.
            //
            // Calculate target debt from the timeNeutralCapacity and the ratio of debt decay interval and the length of the market
            uint256 targetDebt = timeNeutralCapacity.mulDiv(
                uint256(meta.debtDecayInterval),
                uint256(meta.length)
            );


            // Derive a new control variable from the target debt
            uint256 controlVariable = terms[id_].controlVariable;
            uint256 newControlVariable = price_.mulDivUp(market.scale, targetDebt);


            emit Tuned(id_, controlVariable, newControlVariable);


            if (newControlVariable < controlVariable) {
                // If decrease, control variable change will be carried out over the tune interval
                // this is because price will be lowered
                uint256 change = controlVariable - newControlVariable;
                adjustments[id_] = Adjustment(change, time_, meta.tuneAdjustmentDelay, true);
            } else {
                // Tune up immediately
                terms[id_].controlVariable = newControlVariable;
                // Set current adjustment to inactive (e.g. if we are re-tuning early)
                adjustments[id_].active = false;
            }


            metadata[id_].lastTune = time_;
            metadata[id_].tuneBelowCapacity = market.capacity > meta.tuneIntervalCapacity
                ? market.capacity - meta.tuneIntervalCapacity
                : 0;
            metadata[id_].lastTuneDebt = targetDebt;
        }

If you don't update meta.tuneBelowCapacity when changing intervals you have a risk, that price will not be tuned when tuneIntervalCapacity was decreased or it will be still tuned when tuneIntervalCapacity was increased.

As a result tuning will not be completed when needed.

Impact

Tuning logic will not be completed when needed.

Code Snippet

Provided above

Tool used

Manual Review

Recommendation

Update meta.tuneBelowCapacity in BondBaseSDA.setIntervals function.

Discussion

Evert0x

Message from sponsor


Agree. We added a line to set meta.tuneBelowCapacity in the setIntervals function to fix this.

xiaoming9090

Fixed in https://github.com/Bond-Protocol/bonds/commit/bfd9eea0cc035b3ef1cca4072356f83695f960eb

The original report as published on Sherlock, by rvierdiiev. 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 setIntervals function updates tuneInterval and tuneIntervalCapacity but omits updating tuneBelowCapacity, which depends on tuneIntervalCapacity.

Impact

Tuning logic may not be completed when needed, potentially causing the market price to be adjusted incorrectly.

What the attacker needed

Market owner calls setIntervals

The fix

The sponsor added a line to set meta.tuneBelowCapacity in the setIntervals function, and the issue was fixed in a commit.

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 for a bond market. The market owner can change how often the price is adjusted. When they do, one related setting is not updated, so the price adjustment may happen at the wrong time or not at all.

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 rvierdiiev

View all

72 more disclosed reports, best first.

More from Bond Options

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.