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.
Submitted by hals, also found by perseus, yashar, 0xprinc, and nmirchev8
-
Vault721contract 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 theODSafeManagercontract. -
ODSafeManagercontract 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.openSAFEfunction; 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_safeIdis the state variable that tracks the number of the opened safes/and minted NFV by theODSafeManagercontract. -
The initial value of the
_safeIdis zero; and it will be incremented with each opened SAFE. -
But a problem will be caused if the governance change the
ODSafeManageraddress viaVault721.setSafeManager; as this will result in adding a new deployed safe manager where it will have the_safeIdset to zero, which will result in breaking the synchronization between the_safeIdand 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:
- The old safe manager contract has a
_safeIdof 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. - The governance decided to change the safe manager address (with a new deployed one) with extra/updated features; so the
_safeIdof the newODSafeManagerwill be zero. - Now a user tries to open a SAFE; so the
_safeIdwill be incremeted by 1 (and will equal one) and when theVault721.mintis 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.
- The old safe manager contract has a
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...
}
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
ODSafeManagerdoesn’t have the ability to migrate information to a newer version, it will break theVault721contract if the newer version is not modified.Note that the issue of a new
ODSafeManagernot having the state of the previous contract can be addressed in the new contract itself (eg. add functions in the newODSafeManagerimplementation 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.
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
- The old safe manager has _safeId of 1000, matching the last minted NFT ID.
- Governance changes the safe manager address to a new deployed contract with _safeId zero.
- A user tries to open a SAFE, incrementing _safeId to 1.
- 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.