Skip to content

Commit 8af2223

Browse files
author
omriss
committed
ProxyFactory: replace getProxyInitCodeHash by getProxyInitCode
1 parent 674d9fd commit 8af2223

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

src/ProxyFactory.sol

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ contract ProxyFactory is IProxyFactory, Ownable {
1414
/// @notice Address of the master Proxy contract to be cloned
1515
address public immutable MASTER_PROXY;
1616

17-
/// @dev Keccak256 hash of the init code of the clone of the master Proxy contract
18-
bytes32 internal immutable MASTER_PROXY_CLONE_CODE_HASH;
19-
2017
/// @notice Whitelisted addresses allowed to create new proxies
2118
mapping(address => bool) public whitelisted;
2219

@@ -30,15 +27,6 @@ contract ProxyFactory is IProxyFactory, Ownable {
3027
// Master proxy is never initialized - it serves only as a bytecode template.
3128
// Each clone has independent storage and is initialized separately via _initProxy.
3229
MASTER_PROXY = address(new Proxy());
33-
34-
/// @dev EIP-1167 minimal proxy bytecode format:
35-
/// 3d602d80600a3d3981f3363d3d373d3d3d363d73{implementation}5af43d82803e903d91602b57fd5bf3
36-
/// where {implementation} is the 20-byte address of MASTER_PROXY
37-
MASTER_PROXY_CLONE_CODE_HASH = keccak256(
38-
abi.encodePacked(
39-
hex"3d602d80600a3d3981f3363d3d373d3d3d363d73", MASTER_PROXY, hex"5af43d82803e903d91602b57fd5bf3"
40-
)
41-
);
4230
}
4331

4432
/// @inheritdoc IProxyFactory
@@ -48,8 +36,13 @@ contract ProxyFactory is IProxyFactory, Ownable {
4836
}
4937

5038
/// @inheritdoc IProxyFactory
51-
function getProxyInitCodeHash() external view returns (bytes32) {
52-
return MASTER_PROXY_CLONE_CODE_HASH;
39+
function getProxyInitCode() external view returns (bytes memory) {
40+
/// @dev EIP-1167 minimal proxy bytecode format:
41+
/// 3d602d80600a3d3981f3363d3d373d3d3d363d73{implementation}5af43d82803e903d91602b57fd5bf3
42+
/// where {implementation} is the 20-byte address of MASTER_PROXY
43+
return abi.encodePacked(
44+
hex"3d602d80600a3d3981f3363d3d373d3d3d363d73", MASTER_PROXY, hex"5af43d82803e903d91602b57fd5bf3"
45+
);
5346
}
5447

5548
/// @inheritdoc IProxyFactory

src/interfaces/IProxyFactory.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ interface IProxyFactory {
3939
/// @notice Check if the addr is allowed to create new proxies
4040
function whitelisted(address addr) external view returns (bool);
4141

42-
/// @notice Get keccak256 hash of Proxy creationCode for CREATE2
43-
function getProxyInitCodeHash() external view returns (bytes32);
42+
/// @notice Get master proxy init code for CREATE2
43+
function getProxyInitCode() external view returns (bytes memory);
4444

4545
/// @notice Get address of Proxy deployed using CREATE2 with given salt
4646
/// @param salt Salt to get CREATE2 deployment address

test/ProxyFactory.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ contract ProxyFactoryTest is Test {
154154
ProxyFactory factory = new ProxyFactory();
155155

156156
address predicted1 = factory.predictAddress("0x1234");
157-
address predicted2 = _getCreate2Address("0x1234", factory.getProxyInitCodeHash(), address(factory));
157+
address predicted2 = _getCreate2Address("0x1234", keccak256(factory.getProxyInitCode()), address(factory));
158158
assertEq(predicted1, predicted2, "getCreate2Address works in the same way as predictAddress");
159159
}
160160

0 commit comments

Comments
 (0)