Skip to content

Commit 090d21c

Browse files
committed
chore: push
1 parent 0d4ffeb commit 090d21c

File tree

3 files changed

+76
-100
lines changed

3 files changed

+76
-100
lines changed

script/releases/CrosschainDeployLib.sol

Lines changed: 42 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -15,86 +15,64 @@ interface ICreateX {
1515
) external view returns (address computedAddress);
1616
}
1717

18-
bytes11 constant EMPTY_CONTRACT_SALT = bytes11(uint88(0xffffffffffffffffffffff));
19-
2018
library CrosschainDeployLib {
2119
using CrosschainDeployLib for *;
2220

2321
/// -----------------------------------------------------------------------
2422
/// Write
2523
/// -----------------------------------------------------------------------
2624

27-
/**
25+
/*
2826
* @notice Deploys a crosschain empty contract.
2927
* @dev The empty contract MUST stay consistent across all chains/deployments.
3028
* @dev The empty contract MUST always be deployed with the same salt.
3129
*/
32-
function deployEmptyContract(address deployer) internal returns (address) {
30+
function deployEmptyContract(
31+
address deployer
32+
) internal returns (address) {
3333
address computedAddress =
34-
computeCrosschainAddress(deployer, keccak256(type(EmptyContract).creationCode), EMPTY_CONTRACT_SALT);
34+
computeCrosschainAddress(deployer, keccak256(type(EmptyContract).creationCode), type(EmptyContract).name);
3535
if (computedAddress.code.length != 0) return computedAddress;
36-
return type(EmptyContract).creationCode.deployCrosschain(deployer, EMPTY_CONTRACT_SALT);
36+
return _deployCrosschain(deployer, type(EmptyContract).creationCode, type(EmptyContract).name);
3737
}
3838

3939
/*
40-
* @notice Deploys a crosschain contract with CreateX.
40+
* @notice Deploys a crosschain `TransparentUpgradeableProxy` using CreateX.
41+
* @dev The initial admin is the deployer.
42+
* @dev The implementation MUST also be deterministic to ensure the contract can be deployed on all chains.
43+
* @dev The salt MUST be unique for each proxy deployment sharing the same implementation otherwise address collisions WILL occur.
44+
* @dev The `admin` is also assumed to be the deployer.
4145
*
4246
* @dev Example usage:
4347
* ```solidity
44-
* type(EmptyContract).creationCode.deployCrosschain(EMPTY_CONTRACT_SALT)
48+
* bytes11 salt = bytes11(uint88(0xffffffffffffffffffffff));
49+
* address emptyContract = type(EmptyContract).creationCode.deployCrosschain(deployer);
50+
* address proxy = emptyContract.deployCrosschainProxy(deployer, salt);
51+
* ITransparentUpgradeableProxy(address(proxy)).upgradeTo(address(implementation));
52+
* ITransparentUpgradeableProxy(address(proxy)).changeAdmin(address(admin));
4553
* ```
4654
*/
47-
function deployCrosschain(bytes memory initCode, address deployer, bytes11 salt) internal returns (address) {
48-
return createx.deployCreate2(computeProtectedSalt(deployer, salt), initCode);
55+
function deployCrosschainProxy(
56+
address adminAndDeployer,
57+
address implementation,
58+
string memory name
59+
) internal returns (ITransparentUpgradeableProxy) {
60+
return ITransparentUpgradeableProxy(
61+
_deployCrosschain(adminAndDeployer, computeUpgradeableProxyInitCode(implementation, adminAndDeployer), name)
62+
);
4963
}
5064

51-
// /*
52-
// * @notice Deploys a crosschain contract using CreateX with the `DEFAULT_SALT`.
53-
// *
54-
// * @dev Example usage:
55-
// * ```solidity
56-
// * address emptyContract = type(EmptyContract).creationCode.deployCrosschain();
57-
// * ```
58-
// */
59-
// function deployCrosschain(
60-
// bytes memory initCode
61-
// ) internal returns (address) {
62-
// return deployCrosschain(initCode, EMPTY_CONTRACT_SALT);
63-
// }
64-
6565
/*
66-
* @notice Deploys a crosschain `TransparentUpgradeableProxy` using CreateX.
67-
* @dev The initial admin is msg.sender.
68-
* @dev The implementation MUST also be deterministic to ensure the contract can be deployed on all chains.
69-
* @dev The salt MUST be unique for each proxy deployment sharing the same implementation otherwise address collisions WILL occur.
66+
* @notice Deploys a crosschain contract with CreateX.
7067
*
7168
* @dev Example usage:
7269
* ```solidity
73-
* bytes11 salt = bytes11(uint88(0xffffffffffffffffffffff));
74-
* address emptyContract = type(EmptyContract).creationCode.deployCrosschain();
75-
* address proxy = emptyContract.deployCrosschainProxy(salt);
76-
* ITransparentUpgradeableProxy(address(proxy)).upgradeTo(address(implementation));
77-
* ITransparentUpgradeableProxy(address(proxy)).changeAdmin(address(admin));
70+
* type(EmptyContract).creationCode.deployCrosschain(deployer, EMPTY_CONTRACT_SALT)
7871
* ```
7972
*/
80-
// function deployCrosschainProxy(
81-
// address implementation,
82-
// bytes11 salt
83-
// ) internal returns (ITransparentUpgradeableProxy) {
84-
// return ITransparentUpgradeableProxy(
85-
// deployCrosschain(computeUpgradeableProxyInitCode(implementation, msg.sender), salt)
86-
// );
87-
// }
88-
89-
// /**
90-
// * @notice Deploys a crosschain name salted `TransparentUpgradeableProxy` using CreateX.
91-
// */
92-
// function deployCrosschainProxy(
93-
// address implementation,
94-
// string memory name
95-
// ) internal returns (ITransparentUpgradeableProxy) {
96-
// return deployCrosschainProxy(implementation, bytes11(keccak256(bytes(name))));
97-
// }
73+
function _deployCrosschain(address deployer, bytes memory initCode, string memory name) private returns (address) {
74+
return createx.deployCreate2(computeProtectedSalt(deployer, name), initCode);
75+
}
9876

9977
/// -----------------------------------------------------------------------
10078
/// Helpers
@@ -110,12 +88,17 @@ library CrosschainDeployLib {
11088
return bytes32(
11189
bytes.concat(
11290
bytes20(deployer),
113-
bytes1(uint8(1)), // Cross-chain deployments are allowed (0: false, 1: true)
91+
bytes1(uint8(0)), // Cross-chain redeploy protection disabled (0: false, 1: true)
11492
bytes11(salt)
11593
)
11694
);
11795
}
11896

97+
/// @dev Helper to compute the protected salt for a given name.
98+
function computeProtectedSalt(address deployer, string memory name) internal pure returns (bytes32) {
99+
return computeProtectedSalt(deployer, bytes11(keccak256(bytes(name))));
100+
}
101+
119102
/*
120103
* @notice Returns the initialization code for a transparent upgradeable proxy.
121104
* @dev The returned init code does not include metadata typically appended by the compiler.
@@ -127,25 +110,24 @@ library CrosschainDeployLib {
127110
return abi.encodePacked(type(TransparentUpgradeableProxy).creationCode, abi.encode(implementation, admin, ""));
128111
}
129112

130-
/*
131-
* @notice Returns the predicted address of a contract deployed with CreateX.
132-
*/
133113
function computeCrosschainAddress(
134114
address deployer,
135115
bytes32 initCodeHash,
136-
bytes11 salt
116+
string memory name
137117
) internal view returns (address) {
138-
return createx.computeCreate2Address(computeProtectedSalt(deployer, salt), initCodeHash);
118+
return createx.computeCreate2Address(computeProtectedSalt(deployer, name), initCodeHash);
139119
}
140120

141121
/*
142122
* @notice Returns the predicted address of a `TransparentUpgradeableProxy` deployed with CreateX.
143123
*/
144124
function computeCrosschainUpgradeableProxyAddress(
125+
address adminAndDeployer,
145126
address implementation,
146-
address admin,
147-
bytes11 salt
127+
string memory name
148128
) internal view returns (address) {
149-
return computeCrosschainAddress(admin, keccak256(computeUpgradeableProxyInitCode(implementation, admin)), salt);
129+
return computeCrosschainAddress(
130+
adminAndDeployer, keccak256(computeUpgradeableProxyInitCode(implementation, adminAndDeployer)), name
131+
);
150132
}
151133
}

script/releases/Updated.sol

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ library CrosschainDeployLib {
2929
* @dev The empty contract MUST stay consistent across all chains/deployments.
3030
* @dev The empty contract MUST always be deployed with the same salt.
3131
*/
32-
function deployEmptyContract(address deployer) internal returns (address) {
32+
function deployEmptyContract(
33+
address deployer
34+
) internal returns (address) {
3335
address computedAddress =
3436
computeCrosschainAddress(deployer, keccak256(type(EmptyContract).creationCode), EMPTY_CONTRACT_SALT);
3537
if (computedAddress.code.length != 0) return computedAddress;
@@ -56,14 +58,10 @@ library CrosschainDeployLib {
5658
* address emptyContract = type(EmptyContract).creationCode.deployCrosschain(deployer);
5759
* ```
5860
*/
59-
function deployCrosschain(
60-
bytes memory initCode,
61-
address deployer
62-
) internal returns (address) {
61+
function deployCrosschain(bytes memory initCode, address deployer) internal returns (address) {
6362
return deployCrosschain(initCode, deployer, EMPTY_CONTRACT_SALT);
6463
}
6564

66-
6765
/**
6866
* @notice Deploys a crosschain `TransparentUpgradeableProxy` using CreateX.
6967
* @dev The initial admin is `admin`.
@@ -74,7 +72,7 @@ library CrosschainDeployLib {
7472
* ```solidity
7573
* bytes11 salt = bytes11(uint88(0xffffffffffffffffffffff));
7674
* address emptyContract = type(EmptyContract).creationCode.deployCrosschain(deployer);
77-
* address proxy = emptyContract.deployCrosschainProxy(deployer,salt);
75+
* address proxy = emptyContract.deployCrosschainProxy(deployer,salt);
7876
* ITransparentUpgradeableProxy(address(proxy)).upgradeTo(address(implementation));
7977
* ITransparentUpgradeableProxy(address(proxy)).changeAdmin(address(admin));
8078
* ```

script/releases/v1.7.0-multichain/2-deployDestinationChainProxies.s.sol

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,58 +20,54 @@ contract DeployDestinationChainProxies is MultisigBuilder {
2020
/// forgefmt: disable-next-item
2121
function _runAsMultisig() internal virtual override {
2222
// If we're not on a destination chain, we don't need to deploy any contracts
23-
// if (!Env.isDestinationChain()) {
24-
// return;
25-
// }
23+
if (!Env.isDestinationChain()) {
24+
return;
25+
}
2626

2727
// We don't use the prank modifier here, since we have to write to the env
2828
_startPrank(Env.multichainDeployerMultisig());
2929

3030
// Deploy empty contract
3131
address emptyContract = CrosschainDeployLib.deployEmptyContract(Env.multichainDeployerMultisig());
3232

33-
// // Deploy the proxies pointing to an empty contract
34-
// ITransparentUpgradeableProxy operatorTableUpdaterProxy = CrosschainDeployLib.deployCrosschainProxy({
35-
// implementation: emptyContract,
36-
// admin: Env.multichainDeployerMultisig(),
37-
// name: type(OperatorTableUpdater).name
38-
// });
39-
40-
// ITransparentUpgradeableProxy ecdsaCertificateVerifierProxy = CrosschainDeployLib.deployCrosschainProxy({
41-
// implementation: emptyContract,
42-
// admin: Env.multichainDeployerMultisig(),
43-
// name: type(ECDSACertificateVerifier).name
44-
// });
45-
46-
// ITransparentUpgradeableProxy bn254CertificateVerifierProxy = CrosschainDeployLib.deployCrosschainProxy({
47-
// implementation: emptyContract,
48-
// admin: Env.multichainDeployerMultisig(),
49-
// name: type(BN254CertificateVerifier).name
50-
// });
33+
// Deploy the proxies pointing to an empty contract
34+
ITransparentUpgradeableProxy operatorTableUpdaterProxy = CrosschainDeployLib.deployCrosschainProxy({
35+
implementation: emptyContract,
36+
adminAndDeployer: Env.multichainDeployerMultisig(),
37+
name: type(OperatorTableUpdater).name
38+
});
39+
40+
ITransparentUpgradeableProxy ecdsaCertificateVerifierProxy = CrosschainDeployLib.deployCrosschainProxy({
41+
implementation: emptyContract,
42+
adminAndDeployer: Env.multichainDeployerMultisig(),
43+
name: type(ECDSACertificateVerifier).name
44+
});
45+
46+
ITransparentUpgradeableProxy bn254CertificateVerifierProxy = CrosschainDeployLib.deployCrosschainProxy({
47+
implementation: emptyContract,
48+
adminAndDeployer: Env.multichainDeployerMultisig(),
49+
name: type(BN254CertificateVerifier).name
50+
});
5151

5252
// Stop pranking
5353
_stopPrank();
5454

5555
// Save all the contracts to the env
5656
// NOTE: This is an antipattern, we should update the ZEnvHelpers to support this
57-
console.log("emptyContract", address(emptyContract));
58-
// console.log("operatorTableUpdaterProxy", address(operatorTableUpdaterProxy));
59-
// console.log("ecdsaCertificateVerifierProxy", address(ecdsaCertificateVerifierProxy));
60-
// console.log("bn254CertificateVerifierProxy", address(bn254CertificateVerifierProxy));
61-
// ZEnvHelpers.state().__updateContract(type(EmptyContract).name.impl(), address(emptyContract));
62-
// ZEnvHelpers.state().__updateContract(type(OperatorTableUpdater).name.proxy(), address(operatorTableUpdaterProxy));
63-
// ZEnvHelpers.state().__updateContract(type(ECDSACertificateVerifier).name.proxy(), address(ecdsaCertificateVerifierProxy));
64-
// ZEnvHelpers.state().__updateContract(type(BN254CertificateVerifier).name.proxy(), address(bn254CertificateVerifierProxy));
57+
ZEnvHelpers.state().__updateContract(type(EmptyContract).name.impl(), address(emptyContract));
58+
ZEnvHelpers.state().__updateContract(type(OperatorTableUpdater).name.proxy(), address(operatorTableUpdaterProxy));
59+
ZEnvHelpers.state().__updateContract(type(ECDSACertificateVerifier).name.proxy(), address(ecdsaCertificateVerifierProxy));
60+
ZEnvHelpers.state().__updateContract(type(BN254CertificateVerifier).name.proxy(), address(bn254CertificateVerifierProxy));
6561
}
6662

6763
function testScript() public virtual {
68-
// if (!Env.isDestinationChain()) {
69-
// return;
70-
// }
64+
if (!Env.isDestinationChain()) {
65+
return;
66+
}
7167

7268
execute();
7369

74-
// _validateProxyAdminIsMultisig();
70+
_validateProxyAdminIsMultisig();
7571
}
7672

7773
/// @dev Validate that proxies are owned by the multichain deployer multisig (temporarily)

0 commit comments

Comments
 (0)