SNXConnector.sol TVL calculation is incorrect
The SNXConnector's total value locked calculation double-counts assigned collateral and ignores the debt created when SUSD is minted. This makes the reported position value wrong, which could mislead any logic that relies on it.
Submitted by pkqs90 (View additional reports submitted by other wardens)
SNXConnector allows depositing collateral and minting SUSD.
There are two issues for TVL calculation code:
- It does not account for the debt occurred for minting SUSD
totalDepositedalready includestotalAssigned
Note that the minted SUSD tokens are already calculated into TVL by calling _updateTokenInRegistry(usdToken); while minting SUSD, so the debt part must be calculated as well.
function mintOrBurnSUSD(
uint256 _amount,
uint128 _accountId,
uint128 poolId,
address collateralType,
bool mintOrBurn
) public onlyManager {
// Mint or burn
address usdToken = SNXCoreProxy.getUsdToken();
if (mintOrBurn) {
SNXCoreProxy.mintUsd(_accountId, poolId, collateralType, _amount);
} else {
_approveOperations(usdToken, address(SNXCoreProxy), _amount);
SNXCoreProxy.burnUsd(_accountId, poolId, collateralType, _amount);
}
_updateTokenInRegistry(collateralType);
> _updateTokenInRegistry(usdToken);
}
function _getPositionTVL(HoldingPI memory p, address base) public view override returns (uint256 tvl) {
(uint128 accountId, address collateralType) = abi.decode(p.data, (uint128, address));
(uint256 totalDeposited, uint256 totalAssigned, uint256 totalLocked) =
SNXCoreProxy.getAccountCollateral(accountId, collateralType);
> tvl = _getValue(collateralType, base, totalDeposited + totalAssigned);
}
We can find the implementation of getAccountCollateral here: https://github.com/Synthetixio/synthetix-v3/blob/main/protocol/synthetix/contracts/storage/Account.sol#L101-L116
function getCollateralTotals(
Data storage self,
address collateralType
)
internal
view
returns (uint256 totalDepositedD18, uint256 totalAssignedD18, uint256 totalLockedD18)
{
totalAssignedD18 = getAssignedCollateral(self, collateralType);
> totalDepositedD18 =
> totalAssignedD18 +
> self.collaterals[collateralType].amountAvailableForDelegationD18;
totalLockedD18 = self.collaterals[collateralType].getTotalLocked();
return (totalDepositedD18, totalAssignedD18, totalLockedD18);
}
Recommended Mitigation Steps
The collateral calculation can just use totalDeposited.
However the debt calculation is a bit tricky. The closest API for fetching debt is using updateAccountDebt https://github.com/Synthetixio/synthetix-v3/blob/main/protocol/synthetix/contracts/storage/Pool.sol#L366-L373, but it is not a view function. Not really sure what the best solution here is.
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 TVL formula adds totalDeposited and totalAssigned even though totalDeposited already contains totalAssigned, and it never subtracts the SUSD debt.
Impact
The position value is overstated, so any decision based on it could be wrong; the text does not show a direct theft or loss.
What the attacker needed
A manager role on the connector
The fix
The collateral part should use only totalDeposited, and the debt should be subtracted, though the author notes no clean view function exists for the debt.
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.
This contract reports how much a user's position is worth. The report says that number is calculated wrongly: one part is counted twice, and money borrowed by minting a stablecoin is not subtracted. A wrong value can make the system think a position is safer or bigger than it really is.
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.