Skip to content
Business logic Audit finding Intermediate

Incorrect supply fund transferral in function leave() can be exploited to drain locked collateral source funds in subnet actor contract

The leave() function in the subnet actor contract returns genesis/supply funds from the collateral source instead of the supply source when a subnet is not yet bootstrapped. An attacker could deposit cheap supply tokens, stake a minimal amount, then leave to receive the more valuable collateral funds, draining locked collateral.

sin1st3r__ Follow with 0xAsen, ahahaHard1k and 1 other

Originally disclosed on Code4rena

Submitted by sin1st3r__, also found by 0xAsen, ahahaHard1k, and NexusAudits

https://github.com/code-423n4/2025-02-recall/blob/ab5f90b9b0322016ecce6dd71c528a935544bec5/contracts/contracts/subnet/SubnetActorManagerFacet.sol#L269

Finding description and impact

The function SubnetActorManagerFacet::leave() incorrectly returns genesis/supply funds to its caller if the subnet is bootstrapped. Take a look at the highlighted line:

    function leave() external nonReentrant whenNotPaused notKilled {
        ....................................

        // slither-disable-next-line unused-return
        s.bootstrapOwners.remove(msg.sender);
        delete s.bootstrapNodes[msg.sender];

        if (!s.bootstrapped) {
            // check if the validator had some initial balance and return it if not bootstrapped
            uint256 genesisBalance = s.genesisBalance[msg.sender];
            if (genesisBalance != 0) {
                delete s.genesisBalance[msg.sender];
                s.genesisCircSupply -= genesisBalance;
                LibSubnetActor.rmAddressFromBalanceKey(msg.sender);
        ------> s.collateralSource.transferFunds(payable(msg.sender), genesisBalance);
            }

            // interaction must be performed after checks and changes
            LibStaking.withdrawWithConfirm(msg.sender, amount);
            s.collateralSource.transferFunds(payable(msg.sender), amount);
            return;
        }
        LibStaking.withdraw(msg.sender, amount);
    }

If the subnet is not yet bootstrapped and the caller has already deposited supply/genesis funds through the function SubnetActorManagerFacet::preFund(), the function will attempt to return those funds through the call s.collateralSource.transferFunds(payable(msg.sender), genesisBalance); but this line is flawed because it’s trying to return collateral/staked funds instead of supply/genesis funds.

The correct way to return those funds would be through the following: s.supplySource.transferFunds(payable(msg.sender), genesisBalance);. This aligns with the logic of the function SubnetActorManagerFacet::preRelease() which returns the deposited supply funds to the caller correctly:

    function preRelease(uint256 amount) external nonReentrant {
        if (amount == 0) {
            revert NotEnoughFunds();
        }

        if (s.bootstrapped) {
            revert SubnetAlreadyBootstrapped();
        }

  ----> s.supplySource.transferFunds(payable(msg.sender), amount);

        if (s.genesisBalance[msg.sender] < amount) {
            revert NotEnoughBalance();
        }

        s.genesisBalance[msg.sender] -= amount;
        s.genesisCircSupply -= amount;

        if (s.genesisBalance[msg.sender] == 0) {
            LibSubnetActor.rmAddressFromBalanceKey(msg.sender);
        }
    }

Exploit / PoC

  1. Suppose we have a subnet that is not yet bootstrapped and suppose that it has a supplySource of a ERC20 token which is worth $1 and that the collateralSource is native ETH which is worth $2000.
  2. Attacker deposits 10 supplySource ERC20 tokens by calling the function SubnetActorManagerFacet::preFund() and then joins the subnet by staking a minimal amount of collateralSource (native ETH) by calling SubnetActorManagerFacet::join().
  3. Attacker calls SubnetActorManagerFacet::leave() to the leave the subnet. The leave() function will transfer to the attacker 10 ETH (collateralSource) instead of transferring the 10 ERC20 supplySource tokens he deposited, and it will give him back the minimal amount of collateralSource (native ETH) he staked when he joined.
  4. Attacker walks away with a profit of ~$19,990. The subnet will become unregisterable, and not everybody who has joined the subnet will be able to get his funds back because the SubnetActorManagerFacet won’t have enough funds.

Recommended mitigation steps

In leave() simply change the line s.collateralSource.transferFunds(payable(msg.sender), genesisBalance); to s.supplySource.transferFunds(payable(msg.sender), genesisBalance);.

Recall confirmed


The original report as published on Code4rena, by sin1st3r__. 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 leave() function calls transferFunds on collateralSource instead of supplySource when refunding genesis balance.

Impact

An attacker could drain collateral funds, making the subnet unregisterable and preventing other participants from recovering their funds.

What the attacker needed

Subnet not yet bootstrapped; attacker has supply tokens to deposit; attacker stakes minimal collateral

The fix

The leave() function should transfer genesis balance from supplySource rather than collateralSource.

How it was found

  1. Attacker deposits supply tokens via preFund() and joins by staking a minimal amount of collateral.
  2. Attacker calls leave() on the not-yet-bootstrapped subnet.
  3. The contract transfers collateral funds equal to the genesis balance instead of the supply tokens.

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 contract holds two kinds of money: supply funds and collateral funds. When someone leaves before the subnet starts, the code pays them back from the wrong pot, so they get valuable collateral instead of the cheap tokens they put in. This lets them take more than they deposited.

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 sin1st3r__

View all

11 more disclosed reports, best first.

More from Recall

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.