Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No Validation Of create2 Return Value #18

Open
spyboy7711 opened this issue Jul 28, 2023 · 1 comment
Open

No Validation Of create2 Return Value #18

spyboy7711 opened this issue Jul 28, 2023 · 1 comment

Comments

@spyboy7711
Copy link

Impact

The BoringFactory.deploy() function is used to deploy lightweight proxy contracts . 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.

Proof of Concept

https://github.com/boringcrypto/BoringSolidity/blob/master/contracts/BoringFactory.sol#L32-L68

Recommended Mitigation Steps

The recommended mitigation is to check returned address by create2 that is cloneAddress variable for non zero adddress and non zero code size .

            // pass along failure message from failed contract deployment and revert.
           iszero(extcodesize(cloneAddress )) {
                returndatacopy(0, 0, returndatasize())
                revert(0, returndatasize())
            }
@boringcrypto
Copy link
Owner

Thanks for reporting this. What is the failure case here? Under which conditions would create2 not revert after failure? The specs say it should throw.

See https://eips.ethereum.org/EIPS/eip-1014

If a contract creation is attempted, due to either a creation transaction or the CREATE (or future CREATE2) opcode, and the destination address already has either nonzero nonce, or nonempty code, then the creation throws immediately, with exactly the same behavior as would arise if the first byte in the init code were an invalid opcode. This applies retroactively starting from genesis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants