Overview
This audit reviews the Capacity Vault component of the Stabilizer protocol. Capacity Vaults allow approved providers to deposit supported stablecoin collateral and participate in USDZ reward programs. Each vault is associated with a specific collateral asset. Upon accepting a deposit, the funds are processed through the StabilizerAMM mint path. The amount of USDZ minted af ter accounting for applicable fees and any active depeg haircut is recorded as the provider's principal. This principal is tracked in USDZ within the vault rather than being transferred to the provider's wallet. When a provider withdraws, their principal is redeemed through the AMM into the vault's associated collateral asset.
The audit was conducted over four days and involved a comprehensive review of the relevant smart contracts.
During the assessment, we identified one critical-severity issue that allows an attacker to drain tokens from the liquidity pool by exploiting the difference in halfK before and af ter a swap. In addition, we identified two medium-severity issues and two low-severity issues.
All identified issues were either remediated or acknowledged by the development team, and the corresponding fixes were subsequently verified by our auditors.
Following the remediation phase, we conclude that the audit has contributed to improving the protocol's overall security posture and code quality.
Scope
The analyzed resources are located on:
https://github.com/StabilizerLabs/stabilizer-contracts/tree/fe3ece16e17f51d423d5e6daa5f3275836ff29ea
The issues described in this report were fixed in the following PR:
https://github.com/StabilizerLabs/stabilizer-contracts/pull/8
Commits:
- 987c2aa455d5faef74976504393558d591709ef4
- 88ccef455d2c08c5dd9c5712bdb04b23e24dcfb4
- 118c6a4ad7d0a9c8fa830f47f0dd85271ecb1772
- ccff21c8f7e563a0c2081a1afb9211f99e19d513
- b3b61135b8d39b1e4868fde1fe0db578cd9d9ee4
Summary
Weaknesses
This section contains the list of discovered weaknesses.
STBL1-4 | HYBRID SWAPS LET ATTACKERS DRAIN LP LIQUIDITY THROUGH INCONSISTENT REBALANCING
Severity:
Status:
Fixed
Path:
contracts/libabries/StableSwapMath.sol#L100–L190, contracts/StabilizerAMM.sol#L271–L311, contracts/pools/PoolBase.sol#361–L391
Description:
getHybridSwapOutput() prices part of a USDZ-to-asset swap at a 1:1 rate, assuming rebalance() will replenish the pool with the required assets from the adapter. However, rebalance() recalculates its capacity using the post-swap reserves, which include the full USDZ input. A sufficiently large swap increases halfK beyond the adapter's available balance, preventing the expected refill.
This leaves the pool heavily imbalanced, with almost no assets and a large USDZ reserve. The attacker can then swap a small amount of assets back into USDZ at the newly calculated StableSwap invariant. This collapses k, allowing rebalance() to refill the pool from the adapter at 1:1. By repeating this sequence in one transaction, the attacker can extract LP liquidity while the pool remains solvent.
For example, assume the pool initially holds 100,000 USDC and 100,000 USDZ, and the adapter holds approximately 199,990 USDC (approximately 99,990 USDC above halfK).
Dump USDZ: The attacker swaps 400,000 USDZ for approximately 99,999 USDC.- Since the adapter holds approximately 99,990 USDC above
halfK, the first 99,990 USDZ is swapped at 1:1, on the assumption thatrebalance()will refill the pool with the same amount of USDC from the adapter after the swap. - The remaining approximately 299,970 USDZ is priced on the StableSwap curve and returns only approximately 9 USDC. The pool is left with almost no USDC (0.75 USDC) and approximately 499,960 USDZ.
- However,
rebalance()calculates the available capacity from the post-swaptotalLiquidity, which now includes the extra USDZ. The post-swaphalfK(249,980) exceeds the adapter's balance (199,990), sorebalance()does not refill the pool at all, even though99,990USDC was sold at 1:1.
- Since the adapter holds approximately 99,990 USDC above
Buy back USDZ: The attacker swaps 13 USDC for approximately 314,866 USDZ. The pool's totalLiquidity collapses, allowingrebalance()to withdraw approximately 92,540 USDC from the adapter at 1:1, which rebalances the pool to approximately 92,554 USDC and 92,554 USDZ.Extract the difference: Across both swaps, the attacker ends with approximately 99,986 USDC and 314,926 USDZ, compared with 400,060 USDZ initially. The attacker gains approximately 14,852 USD in value, while LPs lose approximately 14,892 USD in pool value. The POC test demonstrates that repeating this attack 15 times in one transaction can reduce a pool's LP value from 200,000 to approximately 45,758, whilerh.isSolvent()remains true.
Root cause:
getHybridSwapOutput() assumes the adapter can supply rebalanceCapacity = adapterReserve − k/2 and prices that portion at 1:1. However, rebalance() independently recalculates capacity using the post-swap totalLiquidity(). The two calculations can therefore disagree, allowing the swap to execute without the refill assumed by its quote.
Remediation:
Make swap pricing and rebalancing use the same capacity calculation. Either transfer the required assets from the adapter before pricing the remaining swap against actual reserves, or ensure rebalance() uses the pre-swap invariant and reverts if it cannot provide the capacity assumed by the quote.
Additionally, enforce a Curve-style invariant check to ensure that the pool's invariant does not decrease across the swap and rebalance, apart from permitted fees.
STBL1-9 | REWARDS ARE PERMANENTLY STUCK IN THE VAULT WHEN THERE IS NO ACTIVE PRINCIPAL
Severity:
Status:
Fixed
Path:
contracts/capacity/CapacityVault.sol#L539-L548
Description:
The CapacityRewardController.activateEpoch() function transfers each vault's reward allocation to the vault and then activates the vault's reward period:
function activateEpoch() external {
if (currentEpoch == 0 || epochClosed || epochActivated) revert InvalidEpoch();
if (block.timestamp < depositWindowEnd || epochEnd <= depositWindowEnd) {
revert EpochNotEnded();
}
_ensureFunding(currentEpoch);
epochActivated = true;
for (uint256 i = 0; i < _vaults.length; i++) {
address vault = _vaults[i];
uint256 allocation = epochAllocation[currentEpoch][vault];
_fundVault(vault, allocation);
ICapacityVault(vault).activateEpoch(
currentEpoch,
allocation,
depositWindowEnd,
epochEnd
);
}
emit EpochActivated(currentEpoch, depositWindowEnd, epochEnd);
}
The vault then streams these rewards over the reward period by increasing accumulatedRewardPerToken in the CapacityVault._updateGlobalRewards() function:
function _updateGlobalRewards() internal {
uint256 applicableTime = block.timestamp;
if (rewardPeriodEnd > 0 && applicableTime > rewardPeriodEnd) {
applicableTime = rewardPeriodEnd;
}
if (applicableTime <= lastRewardUpdate) return;
if (epochActive && totalActivePrincipal > 0 && rewardRatePerSecond > 0) {
accumulatedRewardPerToken += (
(applicableTime - lastRewardUpdate)
* rewardRatePerSecond
* REWARD_SCALE
) / totalActivePrincipal;
}
lastRewardUpdate = applicableTime;
}
However, accumulatedRewardPerToken only increases while totalActivePrincipal > 0, but lastRewardUpdate is always moved forward. As a result, the rewards emitted during any period where the vault has no active principal are not distributed to anyone.
Since these rewards have already been transferred to the vault and the vault does not have any function to sweep or return them, they are permanently stuck in the vault. The CapacityRewardController.withdrawUnusedRewards() function cannot recover them either, because it only withdraws from the controller's own availableRewards.
This can happen in the following cases:
- No provider deposits into the vault during the deposit window. The controller still funds and activates the vault with
totalActivePrincipal == 0, so the whole allocation of the epoch is stuck. This is likely to happen for newly onboarded or less popular vaults. - All providers withdraw their principal during the reward period. The rewards for the rest of the epoch are stuck, and no new provider can deposit to receive them because the deposit window is already closed once the epoch is activated.
Remediation:
Consider tracking the rewards emitted while there is no active principal and allowing them to be returned to the controller:
function _updateGlobalRewards() internal {
...
if (epochActive && totalActivePrincipal > 0 && rewardRatePerSecond > 0) {
accumulatedRewardPerToken += (
(applicableTime - lastRewardUpdate)
* rewardRatePerSecond
* REWARD_SCALE
) / totalActivePrincipal;
}
+ else if (epochActive && rewardRatePerSecond > 0) {
+ undistributedRewards += (applicableTime - lastRewardUpdate) * rewardRatePerSecond;
+ }
lastRewardUpdate = applicableTime;
}
STBL1-1 | MIGRATION ROUTER BYPASSES THE REDEMPTION WHITELIST
Severity:
Status:
Fixed
Path:
contracts/capacity/CapacityMigrationRouter.sol#L57-L60
Description:
The migration router allows users to redeem USDZ through amm.redeemUSDZ() without enforcing the user's whitelist status. The AMM sees the whitelisted router as the caller instead of the actual user.
function migrate(
address sourceVault,
address targetVault,
uint256 amountUSDZ,
uint256 minTargetAssetOut,
uint256 minTargetPrincipal
) external returns (uint256 targetPrincipal) {
ICapacityVault(sourceVault).withdrawUSDZTo(
msg.sender,
address(this),
amountUSDZ
);
...
uint256 targetAssetOut = IStabilizerAMM(targetAmm).redeemUSDZ(
targetAsset,
amountUSDZ
);
...
}
For example,
- Mallory holds USDZ but is not whitelisted. She deploys two contracts:
PushSource, which transfers her USDZ to the migration router, andCollectTarget, which receives the redeemed collateral and forwards it to her. - Mallory calls
migrationRouter.migrate()with these contracts, specifying USDT as the collateral to redeem. - The migration router transfers Mallory's USDZ to the AMM and calls
amm.redeemUSDZ(). Because the router is whitelisted, the AMM accepts the redemption without checking Mallory's whitelist status. - The router forwards the redeemed USDT to
CollectTarget, which transfers it to Mallory. Mallory successfully redeems USDZ despite never being whitelisted. The same steps work even after the admin removes her from the whitelist, allowing her to cash out despite the attempted freeze.
As the consequence, anyone holding USDZ can bypass the redemption whitelist and redeem for available collateral, regardless of their own whitelist status. This also defeats the whitelist's ability to block an attacker from cashing out during incident response. The only remaining option is to pause the entire AMM, blocking legitimate users from minting and redeeming.
Remediation:
Enforce the actual user's whitelist status when processing redemptions through the migration router. Do not rely solely on the router's whitelist status; ensure the redemption authorization cannot be bypassed through intermediary contracts.
STBL1-10 | SETTING THE DEPOSIT WINDOW DURATION EQUAL TO THE EPOCH DURATION PERMANENTLY BLOCKS THE EPOCH PROGRESSION
Severity:
Status:
Fixed
Path:
contracts/capacity/CapacityRewardController.sol#L84, contracts/capacity/CapacityRewardController.sol#L114
Description:
The CapacityRewardController.initialize() and CapacityRewardController.setEpochDurations() functions validate that the deposit window duration does not exceed the epoch duration:
function setEpochDurations(
uint64 newEpochDuration,
uint64 newDepositWindowDuration
) external onlyOwner {
if (
newEpochDuration == 0 ||
newDepositWindowDuration > newEpochDuration ||
currentEpoch != 0
) revert InvalidDuration();
epochDuration = newEpochDuration;
depositWindowDuration = newDepositWindowDuration;
}
However, the check allows depositWindowDuration == epochDuration. In this case, depositWindowEnd == epochEnd for every epoch, and the CapacityRewardController.activateEpoch() function always reverts:
function activateEpoch() external {
if (currentEpoch == 0 || epochClosed || epochActivated) revert InvalidEpoch();
if (block.timestamp < depositWindowEnd || epochEnd <= depositWindowEnd) {
revert EpochNotEnded();
}
...
}
Even if this check is removed, the call would still revert in CapacityVault.activateEpoch(), because rewardStart >= rewardEnd.
Since the epoch can never be activated, the controller is stuck in the first epoch:
closeEpoch()requiresepochActivated, so the epoch can never be closed.startNextEpoch()requiresepochClosed, so the next epoch can never be started.setEpochDurations()requirescurrentEpoch == 0, so the owner cannot fix the durations afterstartFirstEpoch()has been called. As a result, no reward is ever distributed, and the controller and all of its vaults are unusable until the controller is upgraded.
Remediation:
Consider requiring the deposit window duration to be strictly less than the epoch duration in both the CapacityRewardController.initialize() and CapacityRewardController.setEpochDurations() functions:
if (
newEpochDuration == 0 ||
- newDepositWindowDuration > newEpochDuration ||
+ newDepositWindowDuration >= newEpochDuration ||
currentEpoch != 0
) revert InvalidDuration();
STBL1-8 | ANYONE CAN START THE NEXT EPOCH BEFORE ITS REWARD ALLOCATION IS SET
Severity:
Status:
Fixed
Path:
contracts/capacity/CapacityRewardController.sol#L213
Description:
The CapacityRewardController.startNextEpoch() function is permissionless and only checks that the total allocation of the next epoch does not exceed availableRewards:
function startNextEpoch() external {
if (currentEpoch == 0 || !epochClosed) revert EpochNotClosed();
uint256 nextEpoch = currentEpoch + 1;
_ensureFunding(nextEpoch);
...
}
Once the epoch has advanced, the reward admin can no longer set the allocation for it, because setEpochAllocation() only accepts currentEpoch + 1:
if (epoch != currentEpoch + 1) revert InvalidEpoch();
Since closeEpoch() is also permissionless, anyone can call closeEpoch() and startNextEpoch() right at epochEnd. If the reward admin has not finished configuring the next epochs allocations by then, the vaults that are not configured yet are activated with rewardBudget = 0 and earn no rewards for the entire epoch, with no way to recover.
This is not limited to the case where no allocation is set at all. setEpochAllocation() configures one vault per call, so if the epoch is advanced (or the admins transactions are front run) while the admin is in the middle of configuring the vaults, the configured vaults are rewarded normally while the remaining ones receive nothing.
Note that the issue only happens if the reward admin does not finish configuring the next epochs allocations during the current epoch, since setEpochAllocation() accepts currentEpoch + 1 at any time before epochEnd. No funds are locked: providers can still withdraw, and the unallocated rewards remain in availableRewards.
Remediation:
Consider restricting startNextEpoch() to the epochAdmin:
- function startNextEpoch() external {
+ function startNextEpoch() external onlyEpochAdmin {