Skip to content

Commit 35b1fbb

Browse files
committed
Add revert if the bytecode length is not greater than zero
1 parent 0449062 commit 35b1fbb

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

contracts/utils/Create2.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ library Create2 {
1919
*/
2020
function deploy(bytes32 salt, bytes memory bytecode) internal returns (address) {
2121
address addr;
22+
require(bytecode.length > 0, "Create2: bytecode must have a length");
2223
// solhint-disable-next-line no-inline-assembly
2324
assembly {
2425
addr := create2(0, add(bytecode, 0x20), mload(bytecode), salt)

test/utils/Create2.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ describe('Create2', function () {
5959
this.factory.deploy(saltHex, constructorByteCode, { from: deployerAccount }), 'Create2: Failed on deploy'
6060
);
6161
});
62+
it('should failed deploying a contract in an existent address', async function () {
63+
await expectRevert(
64+
this.factory.deploy(saltHex, '0x0', { from: deployerAccount }), 'Create2: bytecode must have a length'
65+
);
66+
});
6267
});
6368

6469
function computeCreate2Address (saltHex, bytecode, deployer) {

0 commit comments

Comments
 (0)