It’s possible to change for Vault and lost control on it
The VaultFactory contract allows an admin to set a new Controller for a market without verifying that the new Controller's VaultFactory address matches the current VaultFactory. This mismatch causes the Controller to be unable to locate the market's vaults, so functions like triggerDepeg and triggerEndEpoch fail, resulting in a loss of functionality.
Originally disclosed on Code4rena
Submitted by rvierdiiev, also found by async
https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/VaultFactory.sol#L345-L359
https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Controller.sol#L136
https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Controller.sol#L152
https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/VaultFactory.sol#L187-L190
Impact
VaultFactory allows admin to change controller for marketId(hedge and risk vaults) using VaultFactory.changeController. This method then set controller to both vaults. This address is important for Vault contract as it allows to call different functions.
VaultFactory take care about different pair vaults through indexVaults mapping. Controller can get info about pairs vaults only through the correct VaultFactory that is provided to Controller in constructor.
It’s possible that VaultFactory.changeController will set controller whose vaultFactory field is not equal to current VaultFactory. That means that when Controller.triggerDepeg or Controller.triggerEndEpoch will be called they will not be able to find the market.
So current controller will not be able to call hedge and risk vaults.
Proof of Concept
This is how the controller is set to vaults. https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/VaultFactory.sol#L345-L359
Controller depends on VaultFactory to find vault for market. https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Controller.sol#L136
https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Controller.sol#L152
Recommended Mitigation Steps
Use same check as you used in VaultFactory.createNewMarket https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/VaultFactory.sol#L187-L190
MiguelBits (Y2K Finance) disputed
Agree with the issue that the incoming
Controller’sVaultFactoryshould be verified to be the VaultFactory’s address itself. Otherwise, there’s a loss of functionality.
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 changeController function lacks a check that the new Controller's vaultFactory address equals the current VaultFactory address.
Impact
The Controller cannot find the market's vaults, so triggerDepeg and triggerEndEpoch fail, causing a loss of functionality.
What the attacker needed
Admin calls changeController with mismatched Controller
The fix
The changeController function should verify that the new Controller's vaultFactory address matches the current VaultFactory, as is done in createNewMarket.
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 VaultFactory lets an admin change which Controller contract manages a market. The new Controller must be linked to the same VaultFactory to find the market's vaults. If it is not, the Controller cannot find the vaults and important functions stop working.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.