Skip to content
Audit finding Intermediate

Price feed in MCAGRateFeed#getRate is not sufficiently validated and can return stale price

The smart contract's price feed function did not check the timestamp of the oracle data, so it could use an outdated price. An attacker could then buy or sell bonds at incorrect prices, harming other token holders.

0x52 Follow

Originally disclosed on Code4rena

Submitted by 0x52

MCAGRateFeed#getRate may return stale data.

Proof of Concept

    (, int256 answer,,,) = oracle.latestRoundData();

getRate only uses answer but never checks the freshness of the data, which can lead to stale bond pricing data. Stale pricing data can lead to bonds being bought and sold on KUMASwap that otherwise should not be available. This would harm KIBToken holders as KUMASwap may accept bond with too low of a coupon and reduce rewards.

Recommended Mitigation Steps

Validate that updatedAt has been updated recently enough:

-   (, int256 answer,,,) = oracle.latestRoundData();
+   (, int256 answer,,updatedAt,) = oracle.latestRoundData();

+   if (updatedAt < block.timestamp - MAX_DELAY) {
+       revert();
+   }

    if (answer < 0) {
        return _MIN_RATE_COUPON;
    }

Alex the Entreprenerd (judge) commented:

The Warden has shown how, the system will not check for a stale price.

In times of high network congestion, liquidations or if the feed has any downtime, the protocol may end-up using a stale price which can leak value.

For these reasons, I agree with Medium Severity.

m19 (KUMA) disagreed with severity and commented:

This issue is tricky: central bank rate updates are not expected more than a handful of times a year, at most. We failed to document this properly and the lack of a fresh updatedAt check was on purpose.

If we were only transmitting rates when an actual rate change happens, it’s impossible to determine how “fresh” the data should be, a central bank rate change could happen every 3 months or twice a year or any timeframe really. So should the staleness check be 90 days, 180 days etc?

We agree that the oracle transmitter could just repeat the current rate on a daily or weekly basis instead making a stale data check useful again.

Because central bank rates are not volatile we still disagree with the severity in this case.

Alex the Entreprenerd (judge) commented:

I empathize with the Sponsor’s answer and agree that in a way the maximum delay for the check is hard to determine, however, it’s important that we acknowledge that the smart contract cannot “defend itself” unless we offer some sort of constraint that avoids it leaking value incorrectly.

In contrast to the front-run, which can be viewed as a nuance / technicality;

The lack of a check would allow the bond to be sold for a time that is not intended, this could also have KumaSwap accept bonds for which the yield is no longer competitive.

I believe the observation from the sponsor to be valid that the changes may be few and far between, however, because the contract relies on the oracle for its decision making, and no check is there to ensure that the decision “makes sense”;

Given the possibility of:

  • Unintended behaviour (selling of bond when that should not be possible)
  • Loss of yield as a consequence

I believe Medium Severity to be the more appropriate of the options.

Alex the Entreprenerd (judge) commented:

The warden has added a comment in terms of suggested mitigation:

We agree that the oracle transmitter could just repeat the current rate on a daily or weekly basis instead making a stale data check useful again.

To quote the sponsor, I believe this would be the best course of action. Even thought the rate does not change frequently, its valuable to have a heartbeat to confirm that all systems are working as intended. Better to experience potential downtime for buys/sells than to have systems unknowingly down during an important rate change.

m19 (KUMA) mitigated:

https://github.com/code-423n4/2023-02-kuma/pull/6

Status: Mitigation confirmed by 0xsomeone, 0x52, and hihen.


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

The contract called the oracle's latestRoundData function but ignored the updatedAt timestamp, so it never verified that the price was recent.

Impact

The protocol could use a stale price, allowing bonds to be bought or sold when they should not be, which could reduce rewards for KIBToken holders.

What the attacker needed

Access to the bond market; oracle price becomes stale

The fix

The contract should check that the oracle's updatedAt timestamp is recent enough and revert if it is too old; the project later mitigated this.

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 relies on an outside service (an oracle) to get the current interest rate. The contract never checked how old that rate was, so it might use a very old rate. This could let someone trade bonds at a price that is no longer fair, causing losses for other users.

More by 0x52

View all

211 more disclosed reports, best first.

More from KUMA Protocol - Versus contest

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.