Submitted by 0xA5DF, also found by 242, 0x, 0xsanson, Critical, sorrynotsorry, unforgiven, and zzzitron
https://github.com/code-423n4/2022-07-fractional/blob/8f2697ae727c60c93ea47276f8fa128369abfe51/src/VaultFactory.sol#L19-L22
https://github.com/code-423n4/2022-07-fractional/blob/8f2697ae727c60c93ea47276f8fa128369abfe51/src/Vault.sol#L11-L25
This is a basic uninitialized proxy bug, the VaultFactory creates a single implementation of Vault and then creates a proxy to that implementation every time a new vault needs to be deployed.
The problem is that that implementation vault is not initialized , which means that anybody can initialize the contract to become the owner, and then destroy it by doing a delegate call (via the execute function) to a function with the selfdestruct opcode.
Once the implementation is destroyed all of the vaults will be unusable. And since theres no logic in the proxies to update the implementation - that means this is permanent (i.e. theres no way to call any function on any vault anymore, theyre simply dead).
This is a critical bug, since ALL assets held by ALL vaults will be lost. Theres no way to transfer them out and theres no way to run any function on any vault.
Also, theres no way to fix the current deployed contracts (modules and registry), since they all depend on the factory vault, and theres no way to update them to a different factory. That means Fractional would have to deploy a new set of contracts after fixing the bug (this is a relatively small issue though).
I created the PoC based on the scripts/deploy.js file, heres a stripped-down version of that:
Destructor.sol file:
Output:
Sidenote: as the comment in the code says, we dont really need to transfer the ownership to the zero address.
Its just that Foundrys forge did revert the destruction when I didnt do it, with the error of OwnerChanged (i.e. once the selfdestruct was called the owner became the zero address, which is different than the original owner) so I decided to add this just in case.
This is probably a bug in forge, since the contract shouldnt destruct till the end of the tx (Hardhat indeed didnt revert the destruction even when the attacker was the owner).
Hardhat
Add init in Vaults constructor (and make the init function public instead of external):
Alternately you can add init in VaultFactory.sol constructor, but I think initializing in the contract itself is a better practice.
After mitigation the PoC will output this:
stevennevins (Fractional) confirmed and commented:
HardlyDifficult (judge) commented:
