Skip to content
Business logic Audit finding Intermediate

Unreleased locks cause the reward distribution to be flawed in BondNFT

Unreleased expired locks keep their shares in totalShares, so reward distributions are diluted and active bond holders receive less than they should. An attacker could delay releasing an expired bond to cause other bond holders to lose rewards.

Ruhum Follow with wait, __141345__ and 3 others

Originally disclosed on Code4rena

Submitted by Ruhum, also found by wait, 141345, rvierdiiev, Ermaniwe, and HollaDieWaldfee

https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/BondNFT.sol#L150

https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/BondNFT.sol#L225

Impact

After a lock has expired, it doesn’t get any rewards distributed to it. But, unreleased locks cause other existing bonds to not receive the full amount of tokens either. The issue is that as long as the bond is not released, the totalShares value isn’t updated. Everybody receives a smaller cut of the distribution. Thus, bond owners receive less rewards than they should.

A bond can be released after it expired by the owner of it. If the owner doesn’t release it for 7 days, anybody else can release it as well. As long as the owner doesn’t release it, the issue will be in effect for at least 7 epochs.

Since this causes a loss of funds for every bond holder I rate it as HIGH. It’s likely to be an issue since you can’t guarantee that bonds will be released the day they expire.

Proof of Concept

Here’s a test showcasing the issue:

// 09.Bonds.js

    it.only("test", async function () {
      await stabletoken.connect(owner).mintFor(owner.address, ethers.utils.parseEther("100"));
      await lock.connect(owner).lock(StableToken.address, ethers.utils.parseEther("100"), 100);
      await stabletoken.connect(owner).mintFor(user.address, ethers.utils.parseEther("1000"));
      await lock.connect(user).lock(StableToken.address, ethers.utils.parseEther("1000"), 10);
      await stabletoken.connect(owner).mintFor(owner.address, ethers.utils.parseEther("1000"));
      await bond.distribute(stabletoken.address, ethers.utils.parseEther("1000"));

      await network.provider.send("evm_increaseTime", [864000]); // Skip 10 days
      await network.provider.send("evm_mine");

      [,,,,,,,pending,,,] = await bond.idToBond(1);
      expect(pending).to.be.equals("499999999999999999986");
      [,,,,,,,pending,,,] = await bond.idToBond(2);
      expect(pending).to.be.equals("499999999999999999986");

      await stabletoken.connect(owner).mintFor(owner.address, ethers.utils.parseEther("1000"));
      await bond.distribute(stabletoken.address, ethers.utils.parseEther("1000"));

      await network.provider.send("evm_increaseTime", [86400 * 3]); // Skip 3 days
      await network.provider.send("evm_mine");

      // Bond 2 expired, so it doesn't receive any of the new tokens that were distributed
      [,,,,,,,pending,,,] = await bond.idToBond(2);
      expect(pending).to.be.equals("499999999999999999986");

      // Thus, Bond 1 should get all the tokens, increasing its pending value to 1499999999999999999960
      // But, because bond 2 wasn't released (`totalShares` wasn't updated), bond 1 receives less tokens than it should.
      // Thus, the following check below fails
      [,,,,,,,pending,,,] = await bond.idToBond(1);
      expect(pending).to.be.equals("1499999999999999999960");

      await lock.connect(user).release(2);

      expect(await stabletoken.balanceOf(user.address)).to.be.equals("1499999999999999999986");

    });

The totalShares value is only updated after a lock is released:

    function release(
        uint _id,
        address _releaser
    ) external onlyManager() returns(uint amount, uint lockAmount, address asset, address _owner) {
        Bond memory bond = idToBond(_id);
        require(bond.expired, "!expire");
        if (_releaser != bond.owner) {
            unchecked {
                require(bond.expireEpoch + 7 < epoch[bond.asset], "Bond owner priority");
            }
        }
        amount = bond.amount;
        unchecked {
            totalShares[bond.asset] -= bond.shares;
        // ...

Recommended Mitigation Steps

Only shares belonging to an active bond should be used for the distribution logic.

TriHaz (Tigris Trade) disputed and commented:

Since this causes a loss of funds for every bond holder I rate it as HIGH.

Funds are not lost, they will be redistributed when the bond is expired. https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/BondNFT.sol#L180

Alex the Entreprenerd (judge) commented:

I’ve asked the Warden for additional proof.

(Note: See original submission for proof.)

And believe that the finding is valid.

I have adapted the test to also claim after, and believe that the lost rewards cannot be received back (see POC and different values we get back).

Alex the Entreprenerd (judge) decreased severity to Medium and commented:

I have to agree with the Warden’s warning, however, the release function is public, meaning anybody can break expired locks.

For this reason, I believe that Medium Severity is more appropriate.


The original report as published on Code4rena, by Ruhum. 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 totalShares value is only decreased when a bond is released, so expired but unreleased bonds continue to dilute reward distributions.

Impact

Bond holders receive less reward than they should while an expired bond remains unreleased; the lost rewards cannot be recovered, though anyone can release the expired bond after a delay.

What the attacker needed

A bond that has expired but not been released; other active bonds earning rewards

The fix

The distribution logic should only count shares from active bonds, not expired but unreleased ones.

How it was found

  1. Owner locks 100 tokens for 100 days; user locks 1000 tokens for 10 days.
  2. Owner distributes 1000 tokens as rewards; both bonds accrue pending rewards.
  3. Time advances 10 days; user's bond expires but is not released.
  4. Owner distributes another 1000 tokens; because user's bond is expired, it should not receive new rewards, but totalShares still includes it.
  5. Owner's bond receives less than the full new distribution due to the unreleased expired bond's shares.
  6. User releases the expired bond; the lost rewards are not recovered.

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 bond is a lock of tokens that earns rewards. The contract tracks total shares to divide rewards; when a bond expires but is not released, its shares are still counted, so everyone else gets a smaller share. This means other bond holders get less reward than they should until the expired bond is released.

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 Ruhum

View all

55 more disclosed reports, best first.

More from Tigris Trade 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.