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
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
- Suppose we have a subnet that is not yet bootstrapped and suppose that it has a
supplySourceof a ERC20 token which is worth$1and that thecollateralSourceis native ETH which is worth$2000. - Attacker deposits 10
supplySourceERC20 tokens by calling the functionSubnetActorManagerFacet::preFund()and then joins the subnet by staking a minimal amount ofcollateralSource(native ETH) by callingSubnetActorManagerFacet::join(). - Attacker calls
SubnetActorManagerFacet::leave()to the leave the subnet. Theleave()function will transfer to the attacker 10 ETH (collateralSource) instead of transferring the 10 ERC20supplySourcetokens he deposited, and it will give him back the minimal amount ofcollateralSource(native ETH) he staked when he joined. - 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 theSubnetActorManagerFacetwon’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
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
- Attacker deposits supply tokens via preFund() and joins by staking a minimal amount of collateral.
- Attacker calls leave() on the not-yet-bootstrapped subnet.
- 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.