Skip to content

Commit cfe2f2f

Browse files
atarparaAmxxernestognw
authored
⚡Optimize Create3 Lib (#6564)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: ernestognw <ernestognw@gmail.com>
1 parent 7cb6178 commit cfe2f2f

2 files changed

Lines changed: 21 additions & 23 deletions

File tree

contracts/utils/Create3.sol

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,34 @@ library Create3 {
3333
* 0x05 | 5F | PUSH0 | 0 cds | [0..cds): calldata
3434
* 0x06 | 34 | CALLVALUE | value 0 cds | [0..cds): calldata
3535
* 0x07 | f0 | CREATE | addr | [0..cds): calldata
36-
* 0x08 | 3D | RETURNDATASIZE | rds addr |
37-
* 0x09 | 5F | PUSH0 | 0 rds addr |
38-
* 0x0A | 5F | PUSH0 | 0 0 rds addr |
39-
* 0x0B | 3E | RETURNDATACOPY | addr | [0..rds): returndata
40-
* 0x0C | 5F | PUSH0 | 0 addr | [0..rds): returndata
41-
* 0x0D | 3D | RETURNDATASIZE | rds 0 addr | [0..rds): returndata
42-
* 0x0E | 91 | SWAP2 | addr 0 rds | [0..rds): returndata
43-
* 0x0F | 6013 | PUSH1 0x13 | 0x13 addr 0 rds | [0..rds): returndata
44-
* 0x11 | 57 | JUMPI | 0 rds | [0..rds): returndata
45-
* 0x12 | FD | REVERT | |
46-
* 0x13 | 5b | JUMPDEST | 0 rds | [0..rds): returndata
47-
* 0x14 | f3 | RETURN | |
36+
* 0x08 | 6012 | PUSH1 0x12 | 0x12 addr |
37+
* 0x0A | 57 | JUMPI | |
38+
* 0x0B | 3D | RETURNDATASIZE | rds |
39+
* 0x0C | 5F | PUSH0 | 0 rds |
40+
* 0x0D | 5F | PUSH0 | 0 0 rds |
41+
* 0x0E | 3E | RETURNDATACOPY | | [0..rds): returndata
42+
* 0x0F | 3D | RETURNDATASIZE | rds | [0..rds): returndata
43+
* 0x10 | 5F | PUSH0 | 0 rds | [0..rds): returndata
44+
* 0x11 | FD | REVERT | |
45+
* 0x12 | 5b | JUMPDEST | |
46+
* 0x13 | 00 | STOP | |
4847
*
4948
* ================================[ DEPLOYMENT CODE ]=================================
5049
* Offset | Opcode | Mnemonic | Stack | Memory
5150
* -------|-------------|------------------|-----------------|-------------------------
52-
* 0x00 | 74 bytecode | PUSH21 bytecode | bytecode |
53-
* 0x16 | 5F | PUSH0 | 0 bytecode |
54-
* 0x17 | 52 | MSTORE | | [0x0B..0x20): bytecode
55-
* 0x18 | 6015 | PUSH1 0x15 | 0x15 | [0x0B..0x20): bytecode
56-
* 0x1A | 600B | PUSH1 0x0B | 0x0B 0x15 | [0x0B..0x20): bytecode
57-
* 0x1C | f3 | RETURN | | [0x0B..0x20): bytecode
51+
* 0x00 | 73 bytecode | PUSH20 bytecode | bytecode |
52+
* 0x15 | 5F | PUSH0 | 0 bytecode |
53+
* 0x16 | 52 | MSTORE | | [0x0C..0x20): bytecode
54+
* 0x17 | 6014 | PUSH1 0x14 | 0x14 | [0x0C..0x20): bytecode
55+
* 0x19 | 600C | PUSH1 0x0C | 0x0C 0x14 | [0x0C..0x20): bytecode
56+
* 0x1B | f3 | RETURN | | [0x0C..0x20): bytecode
5857
*/
59-
6058
/// @dev The proxy initialization code.
61-
bytes29 private constant PROXY_INITCODE = 0x74365F5F37365F34f03D5F5F3E5F3D91601357FD5bf35F526015600Bf3;
59+
bytes28 private constant PROXY_INITCODE = 0x73365f5f37365f34f06012573d5f5f3e3d5ffd5b005f526014600cf3;
6260

6361
/// @dev Hash of the `PROXY_INITCODE`.
64-
/// Equivalent to `keccak256(hex"74365F5F37365F34f03D5F5F3E5F3D91601357FD5bf35F526015600Bf3")`.
65-
bytes32 internal constant PROXY_INITCODE_HASH = 0xd61bbde0460e6c48ddd99fb8b7e1ad36529d2ec79cbac1db0300b3d26ddcdc2a;
62+
/// Equivalent to `keccak256(hex"73365f5f37365f34f06012573d5f5f3e3d5ffd5b005f526014600cf3")`.
63+
bytes32 internal constant PROXY_INITCODE_HASH = 0x57a34f6e879358dd76825d6700df87013ad6a3fb43c0d0c602f70a8772c153bd;
6664

6765
/**
6866
* @dev There's no code to deploy.

test/utils/Create3.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { PANIC_CODES } = require('@nomicfoundation/hardhat-chai-matchers/panic');
55

66
const { RevertType } = require('../helpers/enums');
77

8-
const PROXY_INITCODE_HASH = '0xd61bbde0460e6c48ddd99fb8b7e1ad36529d2ec79cbac1db0300b3d26ddcdc2a';
8+
const PROXY_INITCODE_HASH = '0x57a34f6e879358dd76825d6700df87013ad6a3fb43c0d0c602f70a8772c153bd';
99
const getCreate3Address = (deployer, salt) =>
1010
ethers.getCreateAddress({ from: ethers.getCreate2Address(deployer, salt, PROXY_INITCODE_HASH), nonce: 1 });
1111

0 commit comments

Comments
 (0)