Skip to content
Smart contracts Audit finding Intermediate

POSITION LIMIT COULD BE FULLY REDUCED TO ZERO BY CLONES

A newly opened position's limit could be fully reduced to zero by a cloner, leaving the original owner unable to mint any Frankencoin. This happens because the clone reduction calculation can allocate the entire remaining limit to the cloner.

Josiah Follow with rbserver, 0xDACA and 12 others

Originally disclosed on Code4rena

Submitted by Josiah, also found by rbserver, 0xDACA, Kumpa, Emmanuel, Diana, 141345, bin2chen, lil_eth, carlitox477, Ruhum, Nyx, nobody2018, nobody2018, and RaymondFam

Lines of code

https://github.com/code-423n4/2023-04-frankencoin/blob/main/contracts/MintingHub.sol#L126 https://github.com/code-423n4/2023-04-frankencoin/blob/main/contracts/Position.sol#L97-L101

Impact

A newly opened position could have its limit fully reduced to zero as soon as the cooldown period has elapsed.

Proof of Concept

As seen in the function below, a newly opened position with 0 Frankencoin minted could have its limit turn 0 if the function parameter, _minimum, is inputted with an amount equal to limit. In this case, reduction is equal to 0, making limit - _minimum = 0 while the cloner is assigned reduction + _minimum = 0 + limit = limit:

Position.sol#L97-L101

    function reduceLimitForClone(uint256 _minimum) external noChallenge noCooldown alive onlyHub returns (uint256) {
        uint256 reduction = (limit - minted - _minimum)/2; // this will fail with an underflow if minimum is too high
        limit -= reduction + _minimum;
        return reduction + _minimum;
    }

With the limit now fully allocated to the cloner, the original position owner is left with zero limit to mint Frankencoin after spending 1000 Frankencoin to open this position. This situation could readily happen especially when it involves popular position contracts.

Recommended Mitigation Steps

It is recommended position contract charging fees to cloners. Additionally, a reserve limit should be left untouched allocated solely to the original owner to be in line with the context of position opening.

0xA5DF (lookout) commented:

Setting this one as primary since it shows how a single clone can reduce the remaining limit to zero.

luziusmeisser (Frankencoin) acknowledged and commented:

Charging clones a fee payable to the original is an interesting idea!

If the position comes with a high enough fee, this should not be relevant in practice as the limit will not be reached or new positions being created if there is enough demand.


The original report as published on Code4rena, by Josiah. 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 clone reduction formula allows the entire remaining limit to be transferred to the cloner when the minimum parameter equals the limit.

Impact

The original position owner could lose the ability to mint any Frankencoin from their position, despite having paid the opening fee.

What the attacker needed

A position with zero minted; cooldown period elapsed; attacker can call reduceLimitForClone

The fix

The position contract should charge fees to cloners and leave a reserve limit allocated solely to the original owner.

How it was found

  1. Open a new position with zero Frankencoin minted.
  2. Wait for the cooldown period to elapse.
  3. Call reduceLimitForClone with _minimum equal to the position's limit.
  4. The position's limit becomes zero and the cloner receives the full limit.

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.

In this system, a position has a limit on how much of a stablecoin it can create. When someone clones a position, they take away part of that limit. The bug lets a cloner take the entire limit, leaving the original owner with nothing.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More from Frankencoin

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.