Skip to content

Commit

Permalink
Add revert if the bytecode length is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
corydickson committed Mar 11, 2020
1 parent 0449062 commit 7a77eb2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions contracts/utils/Create2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ library Create2 {
*/
function deploy(bytes32 salt, bytes memory bytecode) internal returns (address) {
address addr;
require(bytecode.length != 0, "Create2: bytecode must have a length");
// solhint-disable-next-line no-inline-assembly
assembly {
addr := create2(0, add(bytecode, 0x20), mload(bytecode), salt)
Expand Down
5 changes: 5 additions & 0 deletions test/utils/Create2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ describe('Create2', function () {
this.factory.deploy(saltHex, constructorByteCode, { from: deployerAccount }), 'Create2: Failed on deploy'
);
});
it('should failed deploying a contract in an existent address', async function () {
await expectRevert(
this.factory.deploy(saltHex, '0x0', { from: deployerAccount }), 'Create2: bytecode must have a length'
);
});
});

function computeCreate2Address (saltHex, bytecode, deployer) {
Expand Down

0 comments on commit 7a77eb2

Please sign in to comment.