Due to a mismatch in decimal handling within StabilityBranch.initiateSwap(), vaults with low-decimal underlying assets (e.g. USDC or wBTC) may incorrectly revert the check for sufficient assets. This can cause the function to reject swap requests even when the vault has enough funds, preventing valid calls to StabilityBranch.initiateSwap().
When StabilityBranch.initiateSwap() is called, it performs various checks, including verifying if the target vault has enough underlying assets to fulfill the swap request (See code snippet from StabilityBranch.initiateSwap() below).
However, there is a problem because ctx.vaultAssetBalance has the same number of decimals as that vault's underlying asset, but ctx.expectedAssetOut has Zaros internal precision (18 decimals). As a consequence, for vaults with underlying assets that have low decimals (like USDC or wBTC), the (ctx.vaultAssetBalance < ctx.expectedAssetOut) check will revert even when there are enough assets for the swap to be fulfilled correctly.
This issue is not caught by the test suite because it provides unrealistic amounts of assets to the vault, so even with the decimal mismatch, the (ctx.vaultAssetBalance < ctx.expectedAssetOut) check passes. For example, one of the potentially affected vault's underlying assets is USDC (6 decimals). In the tests in initiateSwap.t.sol (test/integration/market-making/stability-branch/initiateSwap/initiateSwap.t.sol), depositCap, which equals 2e18, is deposited to the vault during testing. For USDC, this corresponds to approximately 2,000,000,000,000 USD (2 trillion dollars). Due to these unrealistically high amounts of assets given to the vaults, the check (ctx.vaultAssetBalance < ctx.expectedAssetOut) passes during tests without issue.
However, during more realistic scenarios, the check will fail regardless of whether there are enough assets to fulfill the swap request or not on those vaults with low decimals assets. Check the following POC for an example scenario (apply the diff patch below to test/integration/market-making/stability-branch/initiateSwap/initiateSwap.t.sol and run forge build && forge test --mt POC)
Valid calls to StabilityBranch.initiateSwap() will revert due to the aforementioned check in vaults with underlying assets that have low decimals. This prevents StabilityBranch from being used with certain vaults.
Manual Review
Consider converting ctx.vaultAssetBalance to Zaros' internal precision (18 decimals) before checking whether (ctx.vaultAssetBalance < ctx.expectedAssetOut).
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.