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)
https://github.com/code-423n4/2024-04-dyad/blob/cd48c684a58158de444b24854ffd8f07d046c31b/script/deploy/Deploy.V2.s.sol#L64-L65
https://github.com/code-423n4/2024-04-dyad/blob/cd48c684a58158de444b24854ffd8f07d046c31b/script/deploy/Deploy.V2.s.sol#L95-L96
Due to a design flaw in the protocols 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.
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.
and:
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:
Exploit #2: The DeployV2 script calls the licensing tx functions on the kerosine vaults using the vaultLicenser:
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:
Foundry test
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.
Lets assume these were implemented, we have now two mappings. The DeployV2 should change as follows:
Assuming the addVaultForOracleCalculation feeds a mapping that will be used by UnboundedKerosineVault::assetPrice while add doesnt.
shafu0x (DYAD) acknowledged
Note: For full discussion, see here.
