Skip to content
Business logic Audit finding Intermediate

Incorrect deployment/missing contract will break functionality

The KeroseneManager contract is expected to contain only backing vaults to avoid infinite loops in UnboundedKerosineVault, but VaultManagerV2's getKeroseneValue function requires the same manager to license kerosene deposit vaults, which are not included in the deployment. As a result, getKeroseneValue always returns zero, breaking the valuation of kerosene deposits.

carrotsmuggler Follow with tchkvsky, pontifex and 28 others

Originally disclosed on Code4rena

Submitted by carrotsmuggler, also found by tchkvsky, pontifex, falconhoof, Hueber, Tychai0s, Evo, 0xlemon, d3e4, Mahmud, sashik_eth (1, 2), 0xleadwizard, SBSecurity, oakcobalt, Circolors, 3th, 0xSecuri, 0xtankr, alix40, ke1caM (1, 2), n4nika, TheSchnilch, btk, bbl4de, steadyman, Egis_Security, ducanh2706, lian886 (1, 2), zhuying, Aamir, TheSavageTeddy, itsabinashb (1, 2), 0xAlix2, Bauchibred, and Abdessamed

The kerosene manager is the contract responsible for managing kerosene prices. In the current state it has broken functionality due to the design. The KeroseneManager contract contains a list of vaults.

When we look at UnboundedKerosineVault contract, we see what those vaults are used for:

function assetPrice()
    public
    view
    override
    returns (uint) {
      // ...
      address[] memory vaults = kerosineManager.getVaults();
      uint numberOfVaults = vaults.length;
      for (uint i = 0; i < numberOfVaults; i++) {
        Vault vault = Vault(vaults[i]);
        // ...
                * vault.assetPrice() * 1e18
        // ...
      }

The KeroseneManager contract is expected to have a list of the backing vaults. This list is then queried for the individual assetPrice(). Crucially, the KeroseneManager contract will not have the vault which takes kerosene as the asset. This is because calling assetPrice on a vault handling kerosene will make it go into an infinite loop.

So this section of the code expects the KeroseneManager contract to only contain a list of the vaults which has exo collateral.

Now, let’s look at VaultManagerV2.sol contract’s getKeroseneValue function. This function is supposed to return the value of kerosene tokens a user has deposited. It should do this by querying all the vaults, which takes kerosene as the deposit.

function getKeroseneValue(
    uint id
  )
    public
    view
    returns (uint) {
      uint numberOfVaults = vaultsKerosene[id].length();
      for (uint i = 0; i < numberOfVaults; i++) {
        Vault vault = Vault(vaultsKerosene[id].at(i));
        if (keroseneManager.isLicensed(address(vault))) {
          usdValue = vault.getUsdValue(id);
        }
        //...
  }

So the vaultsKerosene should hold the vaults which take kerosene as its deposit. Then, the code calls keroseneManager.isLicensed(address(vault). The isLicensed function only checks in the same vaults array in the kerosene manager.

function isLicensed(
    address vault
  )
    return vaults.contains(vault);

So, this expects the KeroseneManager to also contain the kerosene accepting vaults as well!

We have shown that in UnboundedKerosineVault, the KeroseneManager contract is expected to have only the backing vaults, not the kerosene deposit vaults itself, or it will enter an infinite loop. We have also shown that in VaultManagerV2, the KeroseneManager contract is expected to have the kerosene deposit vaults as well, or it will not be able to pass the isLicensed check.

Both the above statements cannot be true at the same time. This is a design flaw. The KeroseneManager contract, if it contains the kerosene deposit vaults will break the kerosene pricing mechanism, and if it does not, it will break the manager contract. Thus, the current design is flawed and will break the functionality.

If we look at the deployment script, we see that the kerosene manager only has the backing vaults:

kerosineManager.add(address(ethVault));
kerosineManager.add(address(wstEth));

This means the manager’s isLicensed call will fail for vaults which accept kerosene.

Proof of Concept

This is a design flaw as described above. A proof of concept cannot be shown since its broken functionality.

Recommended Mitigation Steps

Store the kerosene vaults info in the Licenser contract. Then change the keroseneManager.isLicensed call to vaultLicenser.isLicensed in the manager contract.

Assessed type

Error

shafu0x (DYAD) disputed and commented:

Kerosene Manager only uses vaults with exogenous collateral.

Koolex (judge) commented:

The getKeroseneValue() function should return the value of vaults that have kerosene tokens. However, as you mentioned, Kerosene Manager only uses vaults with exogenous collateral. So, those vaults won’t be licensed by Kerosene Manager as they don’t hold any kerosene tokens.

From Deploy V2 script:

    KerosineManager kerosineManager = new KerosineManager();

    kerosineManager.add(address(ethVault));
    kerosineManager.add(address(wstEth));

This result in, getKeroseneValue will always return zero.

Instead of this condition: if (keroseneManager.isLicensed(address(vault))) {. We should probably have this: if (!keroseneManager.isLicensed(address(vault)) and vaultLicenser.isLicensed(address(vault))).

This checks that the vault is a kerosene, since it is licensed by Licenser and not licensed by Kerosene Manager.

shafu0x (DYAD) confirmed and commented:

Ahh, ok now it makes sense. Thanks for the clarification. This is a correct find.


The original report as published on Code4rena, by carrotsmuggler. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 a design flaw where the same KeroseneManager list is used for two conflicting purposes: pricing (which must exclude kerosene vaults to avoid recursion) and licensing (which must include kerosene vaults), and the deployment only satisfies the former.

What the attacker needed

None

The fix

The fix should store kerosene vault information in the Licenser contract and change the isLicensed check in VaultManagerV2 to use vaultLicenser instead of keroseneManager.

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 smart contract called KeroseneManager keeps a list of vaults. One part of the system expects that list to contain only certain vaults (backing vaults) to avoid an infinite loop, while another part expects it to also contain kerosene deposit vaults. Because the deployment only includes backing vaults, the function that calculates the value of a user's kerosene deposit always returns zero, so the system cannot correctly value those deposits.

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.

More by carrotsmuggler

View all

42 more disclosed reports, best first.

More from DYAD

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.