Skip to content
Business logic Audit finding Beginner

Spend limit on owner can be bypassed

The owner's spend limit in the distributor and community contracts was never reduced after a spend, so the limit was not enforced. An owner could call the spend function repeatedly, each time for the full limit, and move far more than intended.

Anurag Jain Follow

Originally disclosed on Code4rena

Submitted by csanuragjain, also found by cmichel

https://github.com/code-423n4/2022-02-anchor/blob/main/contracts/anchor-token-contracts/contracts/distributor/src/contract.rs#L140 https://github.com/code-423n4/2022-02-anchor/blob/main/contracts/anchor-token-contracts/contracts/community/src/contract.rs#L69

It seems that the owner is only allowed to spend amount uptil config.spend_limit. However it was observed that this config.spend_limit is never decreased even if owner has spend an amount. This makes config.spend_limit useless as owner can simply send 2-multiple transactions each of config.spend_limit which will all pass and hence bypassing the spend limit placed on owner.

Proof of Concept

  1. Assume spend limit of 100 is placed on owner
  2. Owner simply calls the spend function at either distributor or community contract with amount 100
  3. Ideally after this transaction owner should not be allowed to perform any more spend operation
  4. Since config.spend_limit remains unchanged, owner can call step 2 multiple times which will spend amount 100 several times bypassing spend limit

Recommended Mitigation Steps

After successful spend, the config.spend_limit should be decreased by the amount spend.

Albert Chon (judge) commented via duplicate issue #34:

Indeed, this is a serious oversight, unless one expects the whitelisted addresses to not exceed the spend limit (which is not a good assumption to bake in).


The original report as published on Code4rena, by csanuragjain. 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 spend function compared the requested amount to the configured limit but never reduced the stored limit after a successful transfer.

Impact

The owner could move funds well beyond the intended cap, so the spend limit offered no real protection.

What the attacker needed

Owner role on the contract

The fix

After a successful spend, the contract should reduce the stored spend limit by the amount spent.

How it was found

  1. Set a spend limit of 100 on the owner.
  2. Owner calls the spend function on the distributor or community contract for the full limit.
  3. The limit is not reduced, so the owner repeats the spend call and moves another full limit each time.

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 spend limit is meant to cap how much a privileged account can move. Here the contract checked the amount against the limit but never subtracted what had already been spent, so the same allowance could be used again and again. The limit looked like a safeguard but did nothing.

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 Anurag Jain

View all

63 more disclosed reports, best first.

More from Anchor 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.