Skip to content

Commit 28dd490

Browse files
authored
Optimize ERC1167 proxy creation code by 1 opcode (OpenZeppelin#3329)
1 parent bc810db commit 28dd490

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44
* `ERC2981`: make `royaltiInfo` public to allow super call in overrides. ([#3305](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3305))
5+
* `Clones`: optimize clone creation ([#3329](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3329))
56
* `TimelockController`: Migrate `_call` to `_execute` and allow inheritance and overriding similar to `Governor`. ([#3317](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3317))
67

78
## Unreleased

contracts/proxy/Clones.sol

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ library Clones {
2525
function clone(address implementation) internal returns (address instance) {
2626
assembly {
2727
let ptr := mload(0x40)
28-
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
29-
mstore(add(ptr, 0x14), shl(0x60, implementation))
30-
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
31-
instance := create(0, ptr, 0x37)
28+
mstore(ptr, 0x602d8060093d393df3363d3d373d3d3d363d7300000000000000000000000000)
29+
mstore(add(ptr, 0x13), shl(0x60, implementation))
30+
mstore(add(ptr, 0x27), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
31+
instance := create(0, ptr, 0x36)
3232
}
3333
require(instance != address(0), "ERC1167: create failed");
3434
}
@@ -43,10 +43,10 @@ library Clones {
4343
function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
4444
assembly {
4545
let ptr := mload(0x40)
46-
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
47-
mstore(add(ptr, 0x14), shl(0x60, implementation))
48-
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
49-
instance := create2(0, ptr, 0x37, salt)
46+
mstore(ptr, 0x602d8060093d393df3363d3d373d3d3d363d7300000000000000000000000000)
47+
mstore(add(ptr, 0x13), shl(0x60, implementation))
48+
mstore(add(ptr, 0x27), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
49+
instance := create2(0, ptr, 0x36, salt)
5050
}
5151
require(instance != address(0), "ERC1167: create2 failed");
5252
}
@@ -61,13 +61,13 @@ library Clones {
6161
) internal pure returns (address predicted) {
6262
assembly {
6363
let ptr := mload(0x40)
64-
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
65-
mstore(add(ptr, 0x14), shl(0x60, implementation))
66-
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf3ff00000000000000000000000000000000)
67-
mstore(add(ptr, 0x38), shl(0x60, deployer))
68-
mstore(add(ptr, 0x4c), salt)
69-
mstore(add(ptr, 0x6c), keccak256(ptr, 0x37))
70-
predicted := keccak256(add(ptr, 0x37), 0x55)
64+
mstore(ptr, 0x602d8060093d393df3363d3d373d3d3d363d7300000000000000000000000000)
65+
mstore(add(ptr, 0x13), shl(0x60, implementation))
66+
mstore(add(ptr, 0x27), 0x5af43d82803e903d91602b57fd5bf3ff00000000000000000000000000000000)
67+
mstore(add(ptr, 0x37), shl(0x60, deployer))
68+
mstore(add(ptr, 0x4b), salt)
69+
mstore(add(ptr, 0x6b), keccak256(ptr, 0x36))
70+
predicted := keccak256(add(ptr, 0x36), 0x55)
7171
}
7272
}
7373

0 commit comments

Comments
 (0)