Improper Validation Of create2 Return Value
The BeaconProxyDeployer.deploy() function checks the address returned by create2 against zero, but create2 never returns zero even on failure, so a failed deployment goes undetected. An attacker could cause a failed proxy deployment to be treated as successful, potentially leaving assets without a working vault.
Submitted by leastwood
Impact
The BeaconProxyDeployer.deploy() function is used to deploy lightweight proxy contracts that act as each asset’s vault. The function does not revert properly if there is a failed contract deployment or revert from the create2 opcode as it does not properly check the returned address for bytecode. The create2 opcode returns the expected address which will never be the zero address (as is what is currently checked).
Proof of Concept
Tools Used
- Manual code review
- Discussions with the Mochi team
- Discussions with library dev
Recommended Mitigation Steps
The recommended mitigation was to update iszero(result) to iszero(extcodesize(result)) in the line mentioned above. This change has already been made in the corresponding library which can be found here, however, this needs to also be reflected in Mochi’s contracts.
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
The code checks the returned address against zero instead of checking whether any code was actually deployed at that address.
Impact
A failed proxy deployment could go undetected, potentially leaving an asset without a functional vault, though the text does not describe a concrete exploit.
What the attacker needed
A failed contract deployment
The fix
The check should be changed from testing the address against zero to testing whether the address has deployed bytecode, and this fix needs to be applied in Mochi's contracts.
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.
When a smart contract creates another contract, it gets back an address. The code only checked that this address was not zero, but the address is never zero even if the creation failed. So a failure could go unnoticed, and the system might think a vault exists when it does not.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.