Skip to content
Smart contracts Audit finding Intermediate

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.

leastwood Follow

Originally disclosed on Code4rena

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.

ryuheimat (Mochi) confirmed

The original report as published on Code4rena, by leastwood. 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

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.

More by leastwood

View all

70 more disclosed reports, best first.

More from Mochi contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.