Deadlock in vaults with underlying token with less then 18 decimals
The vault stores withdrawal ratios in a fixed 1e18 scale but does not convert them to the underlying token's decimals when calculating transfer amounts. For tokens with fewer than 18 decimals, this causes an underflow and revert in the claim function, locking all funds in the vault and withdraw proxy.
Submitted by Tointer, also found by joestakey, gz627, Jeiwan, obront, unforgiven, rvierdiiev, and chaduke
If underlying token for the vault would have less then 18 decimals, then after liquidation there would be no way to process epoch, because claim function in WithdrawProxy.sol would revert, this would lock all user out of their funds both in vault and in withdraw proxy. Alternatively, if there is more then 18 decimals, claim would leave much less funds than needed for withdraw, resulting in withdrawers losing funds.
To make report more concise, I would focus on tokens with less then 18 decimals, because they are much more frequent. For example, WBTC have 8 decimals and most stablecoins have 6.
Why is this happening
https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/PublicVault.sol#L314-L316 this part making sure that withdraw ratio are always stored in 1e18 scale.
https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/WithdrawProxy.sol#L271-L274
but here, we are not transforming it into token decimals scale. transferAmount would be orders of magnitudes larger than balance
https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/WithdrawProxy.sol#L277
then, here we would have underflow of balance value
https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/WithdrawProxy.sol#L281 and finally, here function would revert.
https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/WithdrawProxy.sol#L156
https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/PublicVault.sol#L299
because PublicVault.sol need claim to proccess epoch, and WithdrawProxy.sol unlocks funds only after claim, it will result in deadlock of the whole system.
Proof of Concept
First, creating token with 8 decimals:
contract Token8Decimals is ERC20{
constructor() ERC20("TEST", "TEST", 8) {}
function mint(address to, uint amount) public{
_mint(to, amount);
}
}
Second, I changed _bid function in TestHelpers.t.sol contract, so it could take token address as a last parameter, and use it instead of WETH.
Then, here is modified “testLiquidation5050Split” test:
function testLiquidation5050Split() public {
TestNFT nft = new TestNFT(2);
_mintNoDepositApproveRouter(address(nft), 5);
address tokenContract = address(nft);
uint256 tokenId = uint256(1);
Token8Decimals token = new Token8Decimals();
// create a PublicVault with a 14-day epoch
vm.startPrank(strategistOne);
//bps
address publicVault = (ASTARIA_ROUTER.newPublicVault(
14 days,
strategistTwo,
address(token),
uint256(0),
false,
new address[](0),
uint256(0)
));
vm.stopPrank();
uint amountToLend = 10**8 * 1000;
token.mint(address(1), amountToLend);
vm.startPrank(address(1));
token.approve(address(TRANSFER_PROXY), amountToLend);
ASTARIA_ROUTER.depositToVault(
IERC4626(publicVault),
address(1),
amountToLend,
uint256(0)
);
vm.stopPrank();
ILienToken.Details memory lien = standardLienDetails;
lien.liquidationInitialAsk = amountToLend*2;
(, ILienToken.Stack[] memory stack1) = _commitToLien({
vault: publicVault,
strategist: strategistOne,
strategistPK: strategistOnePK,
tokenContract: tokenContract,
tokenId: tokenId,
lienDetails: lien,
amount: amountToLend/4,
isFirstLien: true
});
uint256 collateralId = tokenContract.computeId(tokenId);
_signalWithdraw(address(1), publicVault);
WithdrawProxy withdrawProxy = PublicVault(publicVault).getWithdrawProxy(
PublicVault(publicVault).getCurrentEpoch()
);
skip(14 days);
OrderParameters memory listedOrder1 = ASTARIA_ROUTER.liquidate(
stack1,
uint8(0)
);
token.mint(bidder, amountToLend);
_bid(Bidder(bidder, bidderPK), listedOrder1, amountToLend/2, address(token));
vm.warp(withdrawProxy.getFinalAuctionEnd());
emit log_named_uint("finalAuctionEnd", block.timestamp);
PublicVault(publicVault).processEpoch();
skip(13 days);
withdrawProxy.claim();
}
withdrawProxy.claim(); at the last line would revert
Recommended Mitigation Steps
https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/WithdrawProxy.sol#L273
Change this line to 10**18
Severity
I think this is high risk, because
- There are high demand for stablecoin denominated vaults, and Astaria are designed to support that.
- This bug is sneaky, there could be many epochs before first liquidation that would trigger the deadlock.
- ALL funds would be lost, which is catastrophic.
SantiagoGregory (Astaria) confirmed via duplicate issue #482
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
Impact
All user funds in both the vault and the withdraw proxy become permanently locked because the claim function reverts, preventing epoch processing.
What the attacker needed
Vault uses token with <18 decimals; liquidation occurs; withdrawal epoch processed
The fix
The line calculating the transfer amount should use 10**18 instead of the token's decimals to avoid the underflow.
How it was found
- Create a token with 8 decimals and a vault using that token.
- Deposit into the vault and create a lien.
- Signal a withdrawal and wait for the epoch to end.
- Liquidate the lien and bid on the auction.
- Process the epoch and wait for the final auction end.
- Call claim on the withdraw proxy, which reverts.
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 vault is a smart contract that holds users' money. When users withdraw, the contract calculates how much each person should get using a fixed scale of 1e18, but if the token itself uses fewer decimals (like 8 for WBTC), the calculated amount is far too large. This makes the withdrawal function crash, and the money gets stuck forever.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.