Lack of support for ERC20 token that is not 18 decimals
The PublicVault contract hardcodes its decimals to 18 instead of mirroring the underlying ERC20 token's decimals. For tokens with fewer decimals, such as USDC (6 decimals), this mismatch breaks share-to-asset conversions and liquidation ratio calculations.
ladboy233 Follow with rvierdiiev
Originally disclosed on Code4rena
Submitted by ladboy233, also found by rvierdiiev
https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/PublicVault.sol#L66 https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/PublicVault.sol#L73
Lack of support for ERC20 token that is not 18 decimals in PublicVault.sol.
Proof of Concept
We need to look into the PublicVault.sol implementation
contract PublicVault is VaultImplementation, IPublicVault, ERC4626Cloned {
the issue that is the decimal precision in the PublicVault is hardcoded to 18
function decimals()
public
pure
virtual
override(IERC20Metadata)
returns (uint8)
{
return 18;
}
According to
https://eips.ethereum.org/EIPS/eip-4626
Although the convertTo functions should eliminate the need for any use of an EIP-4626 Vault’s decimals variable, it is still strongly recommended to mirror the underlying token’s decimals if at all possible, to eliminate possible sources of confusion and simplify integration across front-ends and for other off-chain users.
The solmate ERC4626 implementation did mirror the underlying token decimals
constructor(
ERC20 _asset,
string memory _name,
string memory _symbol
) ERC20(_name, _symbol, _asset.decimals()) {
asset = _asset;
}
but the token decimals is over-written to 18 decimals.
https://github.com/d-xo/weird-erc20#low-decimals
Some tokens have low decimals (e.g. USDC has 6). Even more extreme, some tokens like Gemini USD only have 2 decimals.
For example, if the underlying token is USDC and has 6 decimals, the convertToAssets() function will be broken.
function convertToAssets(uint256 shares) public view virtual returns (uint256) {
uint256 supply = totalSupply; // Saves an extra SLOAD if totalSupply is non-zero.
return supply == 0 ? shares : shares.mulDivDown(totalAssets(), supply);
}
The totalSupply is in 18 deimals, but the totalAssets is in 6 deciimals, but the totalSupply should be 6 decimals as well to match the underlying token precision.
There are place that the code assume the token is 18 decimals, if the token is not 18 decimals, the logic for liquidatoin ratio calculation is broken as well because the hardcoded 1e18 is used.
s.liquidationWithdrawRatio = proxySupply
.mulDivDown(1e18, totalSupply())
.safeCastTo88();
currentWithdrawProxy.setWithdrawRatio(s.liquidationWithdrawRatio);
uint256 expected = currentWithdrawProxy.getExpected();
unchecked {
if (totalAssets() > expected) {
s.withdrawReserve = (totalAssets() - expected)
.mulWadDown(s.liquidationWithdrawRatio)
.safeCastTo88();
} else {
s.withdrawReserve = 0;
}
}
_setYIntercept(
s,
s.yIntercept -
totalAssets().mulDivDown(s.liquidationWithdrawRatio, 1e18)
);
And in the claim function for WithdrawProxy.sol
if (balance < s.expected) {
PublicVault(VAULT()).decreaseYIntercept(
(s.expected - balance).mulWadDown(1e18 - s.withdrawRatio)
);
} else {
PublicVault(VAULT()).increaseYIntercept(
(balance - s.expected).mulWadDown(1e18 - s.withdrawRatio)
);
}
Recommended Mitigation Steps
We recommend the protocol make the PublicVault.sol decimal match the underlying token decimals.
SantiagoGregory (Astaria) confirmed
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
The vault overrides the decimals function to always return 18 instead of using the underlying token's decimals.
Impact
For tokens with fewer than 18 decimals, the convertToAssets function and liquidation ratio calculations produce incorrect results, which could lead to financial errors in the vault.
What the attacker needed
Vault uses a token with fewer than 18 decimals
The fix
The vault should be changed so that its decimals match the underlying token's decimals.
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.
Some digital tokens use fewer decimal places than others; for example, USDC uses 6 while many tokens use 18. This vault always reports 18 decimals no matter which token it holds, so its maths for converting between shares and assets gives wrong numbers when the token has fewer decimals. That can lead to incorrect liquidation calculations.
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.