Skip to content
Business logic Audit finding Advanced

RBS may redeploy funds automatically if price stays above or below wall for longer than _config.regenWait

The RBS (Range Bound Stability) mechanism may automatically redeploy treasury funds when the asset price stays outside the configured wall for longer than the regeneration wait period, if the regeneration threshold is set too low. This could cause the protocol to buy or sell at prices far from the market, leading to a loss of treasury funds.

0x52 Follow

Originally disclosed on Code4rena

Submitted by 0x52

https://github.com/code-423n4/2022-08-olympus/blob/b5e139d732eb4c07102f149fb9426d356af617aa/src/policies/Operator.sol#L195-L268

Loss of treasury funds.

Proof of Concept

https://github.com/code-423n4/2022-08-olympus/blob/b5e139d732eb4c07102f149fb9426d356af617aa/src/modules/RANGE.sol#L133-L139

if (capacity_ < _range.high.threshold && _range.high.active) {
    // Set wall to inactive
    _range.high.active = false;
    _range.high.lastActive = uint48(block.timestamp);

    emit WallDown(true, block.timestamp, capacity_);
}

_range.high.lastActive and _range.low.lastActive are only updated in RANGE.sol when _range.x.capacity < _range.x.threshold and the _range.x.active == true. After this is tripped, _range.x.active will be set to false, meaning that _range.x.lastActive will not be updated again until the wall is regenerated and capacity is restored.

https://github.com/code-423n4/2022-08-olympus/blob/b5e139d732eb4c07102f149fb9426d356af617aa/src/policies/Operator.sol#L209-L214

    if (
        uint48(block.timestamp) >= RANGE.lastActive(true) + uint48(config_.regenWait) &&
        _status.high.count >= config_.regenThreshold
    ) {
        _regenerate(true);
    }

If 1) the price were to sustain outside of the range (high volatility for volatile asset, black swan for stable) for longer than config_.regenWait and 2) config_regenThreshold satisfies the following equation:

config_.regenThreshold <= _config.regenObserve - config_.regenWait / frequency

then status.high.count could be greater than config.regenThreshold. This would trigger more funds to be deployed even though the price never came back inside the wall price.

In this scenario the wall price would be far from the true price of the asset leading to loss of treasury funds as it buys/sell at prices well above/below market price.

Recommended Mitigation Steps

A check should be added to verify that the price is within the wall price before regenerating. Alternatively, config_.regenTheshold could be set to satisfy the following equation:

config_.regenThreshold > _config.regenObserve - config_.regenWait / frequency

This would eliminate the risk as status.high.count >= config.regenThreshold could never be true for a sustained period where current price is greater than the wall price.

Oighty (Olympus) disagreed with severity and commented:

This is valid. Our intended parameterization of the system would not be subject to this vulnerability, but it would be an issue if the system was incorrectly parameterized. Because it is an edge case, I’m not sure it is a high risk bug though.

Another potential fix is resetting the count to 0 and the observations array to new bool[](regenObserve) to clear out positive values from when a wall goes down. This could be done in the _updateCapacity() function by checking if the new capacity is under the threshold.

0xean (judge) decreased severity to Medium and commented:

Going to downgrade to Medium as the external dependency is a configuration that is not planned to be used by the sponsor.


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

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 regeneration logic relies on a counter that can reach the threshold even when the price is outside the wall, because the lastActive timestamp is not updated while the wall is inactive.

Impact

The protocol could buy or sell at prices well above or below market, leading to a loss of treasury funds; however, the intended parameterisation would not be subject to this vulnerability.

What the attacker needed

Price stays outside wall for regenWait; regenThreshold set too low

The fix

A check should be added to verify that the price is within the wall price before regenerating, or the regeneration threshold should be set high enough to prevent the condition.

How it was found

  1. The asset price stays outside the wall for longer than the regeneration wait period.
  2. The regeneration threshold is set such that the count can exceed it.
  3. The contract regenerates the wall and deploys more funds despite the price not returning.

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.

A smart contract tries to keep a token's price within a range by buying and selling. If the price stays outside that range for a while, the contract might mistakenly think it's safe to add more funds, even though the price hasn't returned. This could make the contract trade at bad prices and lose money.

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 0x52

View all

211 more disclosed reports, best first.

More from Olympus DAO contest

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.