Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove initializer from proxy address CREATE2 salt #237

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ProxyFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract ProxyFactory is IProxyFactory {
/// @inheritdoc IProxyFactory
function deployProxy(address implementation, bytes memory initializer, uint256 saltNonce) external override {
if (implementation == address(0) || implementation.code.length == 0) revert InvalidImplementation();
bytes32 salt = keccak256(abi.encodePacked(msg.sender, keccak256(initializer), saltNonce));
bytes32 salt = keccak256(abi.encodePacked(msg.sender, saltNonce));
if (predictProxyAddress(implementation, salt).code.length > 0) revert SaltAlreadyUsed();
address proxy = address(new ERC1967Proxy{ salt: salt }(implementation, ""));
// solhint-disable-next-line avoid-low-level-calls
Expand Down
23 changes: 5 additions & 18 deletions test/ProxyFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,7 @@ contract SpaceFactoryTest is Test, IProxyFactoryEvents, IProxyFactoryErrors, ISp
);

// Pre-computed address of the space (possible because of CREATE2 deployment)
address spaceProxy = _predictProxyAddress(
address(factory),
address(this),
address(masterSpace),
initializer,
saltNonce
);
address spaceProxy = _predictProxyAddress(address(factory), address(this), address(masterSpace), saltNonce);

vm.expectEmit(true, true, true, true);
emit ProxyDeployed(address(masterSpace), spaceProxy);
Expand Down Expand Up @@ -193,13 +187,7 @@ contract SpaceFactoryTest is Test, IProxyFactoryEvents, IProxyFactoryErrors, ISp
);

factory.deployProxy(address(masterSpace), initializer, saltNonce);
address spaceProxy = _predictProxyAddress(
address(factory),
address(this),
address(masterSpace),
initializer,
saltNonce
);
address spaceProxy = _predictProxyAddress(address(factory), address(this), address(masterSpace), saltNonce);

// Initializing the space should revert as the space is already initialized
vm.expectRevert("Initializable: contract is already initialized");
Expand Down Expand Up @@ -238,19 +226,18 @@ contract SpaceFactoryTest is Test, IProxyFactoryEvents, IProxyFactoryErrors, ISp
authenticators
)
);
bytes32 salt = keccak256(abi.encodePacked(address(this), keccak256(initializer), saltNonce));
bytes32 salt = keccak256(abi.encodePacked(address(this), saltNonce));
// Checking predictProxyAddress in the factory returns the same address as the helper in this test
assertEq(
address(factory.predictProxyAddress(address(masterSpace), salt)),
_predictProxyAddress(address(factory), address(this), address(masterSpace), initializer, saltNonce)
_predictProxyAddress(address(factory), address(this), address(masterSpace), saltNonce)
);
}

function _predictProxyAddress(
address _factory,
address _sender,
address implementation,
bytes memory initializer,
uint256 saltNonce
) internal pure returns (address) {
return
Expand All @@ -261,7 +248,7 @@ contract SpaceFactoryTest is Test, IProxyFactoryEvents, IProxyFactoryErrors, ISp
abi.encodePacked(
bytes1(0xff),
_factory,
keccak256(abi.encodePacked(_sender, keccak256(initializer), saltNonce)),
keccak256(abi.encodePacked(_sender, saltNonce)),
keccak256(
abi.encodePacked(type(ERC1967Proxy).creationCode, abi.encode(implementation, ""))
)
Expand Down
Loading