Skip to content
Business logic Audit finding Intermediate

Updating SafeManager address in the Vault721 will disable NFV minting

The Vault721 contract tracks the next NFT ID via the ODSafeManager's _safeId, which resets to zero when governance changes the safe manager address. This causes minting to revert because the new manager tries to mint an NFT with an ID that already exists.

hals Follow with perseus, yashar and 2 others

Originally disclosed on Code4rena

Submitted by hals, also found by perseus, yashar, 0xprinc, and nmirchev8

  • Vault721 contract is the ERC721 “Non-fungible Vault” (NFV) that manages all SAFEs ownership, transfers, and approvals via the ERC721 standard, the minter of the NFV is the ODSafeManager contract.

  • ODSafeManager contract acts as interface to the SAFEEngine to facilitate the management of SAFEs; such as opening safes,modifying SAFE collateral, moving SAFE collateral, etc.

  • When a user opens a SAFE via ODSafeManager.openSAFE function; a NFV will be minted to the user where it will have the same id as the SAFE id so that the ids of any of them can be used interchangeably in the system, and the _safeId is the state variable that tracks the number of the opened safes/and minted NFV by the ODSafeManager contract.

  • The initial value of the _safeId is zero; and it will be incremented with each opened SAFE.

  • But a problem will be caused if the governance change the ODSafeManager address via Vault721.setSafeManager; as this will result in adding a new deployed safe manager where it will have the _safeId set to zero, which will result in breaking the synchronization between the _safeId and the last minted NFV id (breaking an invariant).

  • But how could this be a problem? Well, this will result in disabling SAFE opening and NFV minting:

    1. The old safe manager contract has a _safeId of 1000, and this matches the id of the last minted NFV, so the next NFV id supposed to be 1001, and that should match the value of _safeId.
    2. The governance decided to change the safe manager address (with a new deployed one) with extra/updated features; so the _safeId of the new ODSafeManager will be zero.
    3. Now a user tries to open a SAFE; so the _safeId will be incremeted by 1 (and will equal one) and when the Vault721.mint is called to mint a NFV; the function will revert as it’s requested to mint a NFV with id=_safeId=1, and this NFV has been already deployed by the old safe manager contract.

Proof of Concept

Vault721.setSafeManager function

  function setSafeManager(address _safeManager) external onlyGovernor {
    _setSafeManager(_safeManager);
  }

Vault721._setSafeManager function

  function _setSafeManager(address _safeManager) internal nonZero(_safeManager) {
    safeManager = IODSafeManager(_safeManager);
  }

ODSafeManager.openSAFE function

  function openSAFE(bytes32 _cType, address _usr) external returns (uint256 _id) {
   //some code...

    ++_safeId;

   //some code...

    vault721.mint(_usr, _safeId);

    //some code...
  }

Vault721.mint function

function mint(address _proxy, uint256 _safeId) external {
    require(msg.sender == address(safeManager), 'V721: only safeManager');
    require(_proxyRegistry[_proxy] != address(0), 'V721: non-native proxy');
    address _user = _proxyRegistry[_proxy];
    _safeMint(_user, _safeId);
  }

Recommended Mitigation Steps

Add a mechanism in the ODSafeManger to initialize the _safeId based on the total number of previously minted NFV + 1 (another variable to be added to the Vault721 to track the total number of minted NFVs).

MiloTruck (Judge) decreased severity to Medium and commented:

Since the current implementation of ODSafeManager doesn’t have the ability to migrate information to a newer version, it will break the Vault721 contract if the newer version is not modified.

Note that the issue of a new ODSafeManager not having the state of the previous contract can be addressed in the new contract itself (eg. add functions in the new ODSafeManager implementation to set _safeId, _safeData, etc… to the same values as the current one).

However, given that the sponsor was not aware of the bug beforehand (see #326), I believe that this report and its duplicates has provided value to the sponsor and therefore medium severity is appropriate.


The original report as published on Code4rena, by hals. 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 the new ODSafeManager contract does not inherit or initialise the _safeId from the previous contract, so it starts at zero and collides with existing NFT IDs.

Impact

Opening new SAFEs and minting NFVs is disabled after the safe manager is updated, unless the new contract is modified to carry over state.

What the attacker needed

Governance changes safe manager address; new safe manager has _safeId zero

The fix

The new ODSafeManager should be initialised with _safeId set to the total number of previously minted NFVs plus one, or the Vault721 should track the total minted count.

How it was found

  1. The old safe manager has _safeId of 1000, matching the last minted NFT ID.
  2. Governance changes the safe manager address to a new deployed contract with _safeId zero.
  3. A user tries to open a SAFE, incrementing _safeId to 1.
  4. Vault721.mint is called with id=1, but that NFT already exists, so the transaction 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.

This is a smart contract bug where two contracts share a counter for creating unique tokens. If the contract that manages the counter is replaced, the new one starts counting from zero again, so it tries to create a token with an ID that already exists, which fails. This stops users from opening new safes and getting their tokens.

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 hals

View all

5 more disclosed reports, best first.

More from Open Dollar

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.