Skip to content
Business logic Audit finding Intermediate

`epochsByBuyer[]` can lose records

Cancelling one limit order removes the buyer's epoch record even though the user may still have other open orders, so the per-buyer epoch list becomes inaccurate. Users relying on that list for new orders could be misled and potentially lose funds.

__141345__ Follow with rvierdiiev, hansfriese and 1 other

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-09-knox-judging/issues/86

Found by

__141345__, rvierdiiev, hansfriese, bin2chen

Summary

When cancelLimitOrder(), the epoch will be removed from epochsByBuyer[], but the user could have other orders on the orderbook, the record will be inaccurate and mislead the users.

Vulnerability Detail

If a user put 2 limit orders with different prices, 2 separate id will be assigned, but only 1 epoch will be added to the epochsByBuyer[] array. If the user cancel 1 of the orders, the epoch will be removed from epochsByBuyer[], it will be impossible to track the other orders put by the user. And the getEpochsByBuyer() function will return inaccurate result.

Impact

If some users rely on the results of getEpochsByBuyer() for new orders, the returned inaccurate results could be misleading, and cause potential loss to the users due to wrong information.

Code Snippet

https://github.com/sherlock-audit/2022-09-knox/blob/main/knox-contracts/contracts/auction/AuctionInternal.sol#L545-L553

https://github.com/sherlock-audit/2022-09-knox/blob/main/knox-contracts/contracts/auction/Auction.sol#L220

Tool used

Manual Review

Recommendation

Only remove the epochsByBuyer records when all the orders of the user is cancelled.

Discussion

0xCourtney

https://github.com/KnoxFinance/knox-contracts/pull/90

rcstanciu

Reply from @arbitrary-CodeBeholder


looks good

The original report as published on Sherlock, by __141345__. 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 cancellation logic deletes the buyer's epoch entry unconditionally instead of checking whether the buyer still has other active orders in that epoch.

Impact

Users who rely on the returned epoch list when placing new orders could be misled and may suffer losses from acting on wrong information.

What the attacker needed

A user with multiple open limit orders

How it was found

  1. A user places two limit orders at different prices, which get separate ids but only one epoch entry.
  2. The user cancels one of the two orders.
  3. The epoch is removed from the buyer's epoch list even though the other order remains.
  4. The getEpochsByBuyer function then returns an inaccurate result.

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 keeps a list of which auction rounds (epochs) each buyer has taken part in. When a buyer cancels just one of several orders, the code wipes their whole entry from that list, so the contract forgets the orders that are still open. Anyone reading that list afterwards gets wrong information.

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 __141345__

View all

18 more disclosed reports, best first.

More from Knox Finance

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.