After unregisterSingularity() , position has not been unlocked and will be locked in the contract
The unregisterSingularity function deletes a singularity's registration without checking whether users still have locked positions in it. If a singularity is unregistered while positions remain, those users cannot call unlock and their tokens stay locked in the contract.
bin2chen Follow with deadrxsezzz and cccz
Originally disclosed on Code4rena
Submitted by bin2chen, also found by deadrxsezzz and cccz
When singularity.rescue==true, owner can execute unregisterSingularity(). This method will delete activeSingularities[]/sglAssetIDToAddress[].
function unregisterSingularity(IERC20 singularity) external onlyOwner updateTotalSGLPoolWeights {
uint256 sglAssetID = activeSingularities[singularity].sglAssetID;
if (sglAssetID == 0) revert NotRegistered();
if (!activeSingularities[singularity].rescue) revert NotInRescueMode();
unchecked {
uint256[] memory _singularities = singularities;
uint256 sglLength = _singularities.length;
uint256 sglLastIndex = sglLength - 1;
for (uint256 i; i < sglLength; i++) {
if (_singularities[i] == sglAssetID) {
// If in the middle, copy last element on deleted element, then pop
@> delete activeSingularities[singularity];
@> delete sglAssetIDToAddress[sglAssetID];
if (i != sglLastIndex) {
singularities[i] = _singularities[sglLastIndex];
}
singularities.pop();
emit UnregisterSingularity(address(singularity), sglAssetID);
break;
}
}
}
emit UnregisterSingularity(address(singularity), sglAssetID);
}
However, this method does not determine whether there are still has locked positions. In this way, if the user wants to unlock(), it will not be executed and the token will be locked in the contract.
activeSingularities[_singularity] has been deleted.
function unlock(uint256 _tokenId, IERC20 _singularity, address _to) external {
...
@> SingularityPool memory sgl = activeSingularities[_singularity];
yieldBox.transfer(address(this), _to, lockPosition.sglAssetID, lockPosition.ybShares);
@> activeSingularities[_singularity].totalDeposited -= lockPosition.ybShares;
emit Burn(_to, lockPosition.sglAssetID, _tokenId);
}
Recommended Mitigation
function unregisterSingularity(IERC20 singularity) external onlyOwner updateTotalSGLPoolWeights {
...
for (uint256 i; i < sglLength; i++) {
if (_singularities[i] == sglAssetID) {
+ //check totalDeposited
+ require(activeSingularities[singularity].totalDeposited == 0 , "invalid");
// If in the middle, copy last element on deleted element, then pop
delete activeSingularities[singularity];
delete sglAssetIDToAddress[sglAssetID];
if (i != sglLastIndex) {
singularities[i] = _singularities[sglLastIndex];
}
singularities.pop();
emit UnregisterSingularity(address(singularity), sglAssetID);
break;
}
}
}
Assessed type
Context
cryptotechmaker (Tapioca) confirmed and commented:
PR here.
0xRektora (Tapioca) commented:
@LSDan, This one should be QA.
Although it makes sense to add this change, but there’ll never realistically be
0total deposited in a pool, leaving some dust. Furthermore, it opens up an attack vector to DoS this functionality. I’d say it’s the responsibility of the DAO to make sane decision about when to unregister the pool. There’s already a 2 day cooldown period as a safeguard.
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 unregister function deletes the pool's registration without verifying that no user positions remain locked in it.
Impact
Users with locked positions in an unregistered pool cannot unlock them, so their tokens remain locked in the contract; the project argues this is unrealistic because pools rarely reach zero deposits and the DAO has a cooldown safeguard.
What the attacker needed
Owner calls unregisterSingularity; pool is in rescue mode; users still have locked positions
The fix
The unregister function should require that the pool's totalDeposited is zero before deleting its registration.
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 lets the owner remove a pool from its list of active pools. But it does not check if people still have tokens locked in that pool. After removal, the unlock function cannot find the pool and fails, so those tokens are stuck.
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.