Skip to content
Business logic Audit finding Intermediate

KUMASwap incorrectly reverts when when _maxCoupons has been reached

The KUMASwap contract reverts all bond sales once the number of unique coupons reaches the maximum, even if the bond being sold has a coupon that already exists. This prevents legitimate sales of bonds with existing coupons.

0x52 Follow

Originally disclosed on Code4rena

Submitted by 0x52

Selling bonds with coupons that are already accounted will fail unexpectedly.

Proof of Concept

https://github.com/code-423n4/2023-02-kuma/blob/3f3d2269fcb3437a9f00ffdd67b5029487435b95/src/kuma-protocol/KUMASwap.sol#L116-L118

    if (_coupons.length() == _maxCoupons) {
        revert Errors.MAX_COUPONS_REACHED();
    }

The above lines will cause ALL bonds sales to revert when _coupons.length has reached _maxCoupons. Since bonds may share the same coupon, the swap should continue to accept bonds with a coupon that already exist in the _coupons set.

Recommended Mitigation Steps

sellBond should only revert if the max length has been reached and bond.coupon doesn’t already exist:

-   if (_coupons.length() == _maxCoupons) {
+   if (_coupons.length() == _maxCoupons && !_coupons.contains(bond.coupon)) {
        revert Errors.MAX_COUPONS_REACHED();
    }

m19 (KUMA) confirmed and commented:

Even though this scenario is unlikely to ever happen we have confirmed this issue in a test:

    function test_sellBond_WithExistingCouponWhenMaxCouponsReached() external {
        _KUMASwap.sellBond(1);
        IKUMABondToken.Bond memory bond_ = _bond;

        for (uint256 i; i < 364; i++) {
            bond_.coupon = bond_.coupon + 1;
            _KUMABondToken.issueBond(address(this), bond_);
            _KUMASwap.sellBond(i + 2);
        }

        _KUMABondToken.issueBond(address(this), _bond);

        _KUMASwap.sellBond(365);
    }

We intend to fix this.

Alex the Entreprenerd (judge) commented:

The warden has shown a way in which the system could stop selling coupons due to the handling of duplicate coupons, this relies on a specific condition which may not always happen, for this reason, in lack of an attack that can be used to break the functionality, I agree with Medium Severity.

m19 (KUMA) mitigated: https://github.com/code-423n4/2023-02-kuma/pull/7

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 check for maximum coupons does not account for the possibility that the bond's coupon already exists in the set, causing an unnecessary revert.

What the attacker needed

The contract must have reached the maximum number of…; A bond with an existing coupon must be available for sale.

The fix

The check should only revert if the maximum is reached and the bond's coupon is not already in the set.

How it was found

  1. Sell a bond to add its coupon to the set.
  2. Issue and sell 364 more bonds with unique coupons, reaching the maximum of 365 coupons.
  3. Attempt to sell another bond that has the same coupon as the first bond.
  4. The transaction reverts with MAX_COUPONS_REACHED error.

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 for swapping bonds has a limit on how many different coupons it can track. When that limit is reached, it stops accepting any new bond sales, even if the bond's coupon is already known. This means users cannot sell bonds that should be allowed.

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 KUMA Protocol - Versus 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.