@inco/lightning 0.6.8 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +29 -2
- package/manifest.yaml +35 -42
- package/package.json +5 -2
- package/src/CreateXHelper.sol +3 -1
- package/src/DeployUtils.sol +36 -71
- package/src/Errors.sol +1 -1
- package/src/IIncoLightning.sol +2 -0
- package/src/IncoLightning.sol +5 -17
- package/src/IncoVerifier.sol +12 -18
- package/src/Lib.alphanet.sol +1 -1
- package/src/Lib.sol +1 -1
- package/src/Lib.template.sol +35 -153
- package/src/Types.sol +231 -97
- package/src/interfaces/IIncoLightning.sol +2 -0
- package/src/interfaces/IIncoVerifier.sol +6 -12
- package/src/interfaces/automata-interfaces/BELE.sol +2 -0
- package/src/interfaces/automata-interfaces/IAutomataEnclaveIdentityDao.sol +9 -11
- package/src/interfaces/automata-interfaces/IFmspcTcbDao.sol +3 -3
- package/src/interfaces/automata-interfaces/IPCCSRouter.sol +13 -47
- package/src/interfaces/automata-interfaces/IPCCSRouterExtended.sol +2 -0
- package/src/interfaces/automata-interfaces/IPcsDao.sol +6 -11
- package/src/interfaces/automata-interfaces/IQuoteVerifier.sol +4 -7
- package/src/interfaces/automata-interfaces/Types.sol +7 -6
- package/src/libs/incoLightning_alphanet_v2_976644394.sol +478 -0
- package/src/libs/incoLightning_devnet_v1_887305889.sol +5 -3
- package/src/libs/incoLightning_testnet_v1_938327937.sol +5 -3
- package/src/lightning-parts/AccessControl/AdvancedAccessControl.sol +39 -72
- package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +31 -62
- package/src/lightning-parts/AccessControl/interfaces/IAdvancedAccessControl.sol +8 -15
- package/src/lightning-parts/AccessControl/interfaces/IBaseAccessControlList.sol +5 -12
- package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +44 -84
- package/src/lightning-parts/AccessControl/test/TestBaseAccessControl.t.sol +2 -0
- package/src/lightning-parts/DecryptionAttester.sol +14 -28
- package/src/lightning-parts/EncryptedInput.sol +23 -52
- package/src/lightning-parts/EncryptedOperations.sol +96 -438
- package/src/lightning-parts/Fee.sol +3 -1
- package/src/lightning-parts/TEELifecycle.sol +94 -223
- package/src/lightning-parts/TEELifecycle.types.sol +4 -3
- package/src/lightning-parts/TrivialEncryption.sol +6 -20
- package/src/lightning-parts/interfaces/IDecryptionAttester.sol +7 -2
- package/src/lightning-parts/interfaces/IEncryptedInput.sol +5 -12
- package/src/lightning-parts/interfaces/IEncryptedOperations.sol +17 -61
- package/src/lightning-parts/interfaces/ITEELifecycle.sol +7 -11
- package/src/lightning-parts/interfaces/ITrivialEncryption.sol +2 -0
- package/src/lightning-parts/primitives/EventCounter.sol +7 -8
- package/src/lightning-parts/primitives/HandleGeneration.sol +20 -32
- package/src/lightning-parts/primitives/HandleMetadata.sol +7 -17
- package/src/lightning-parts/primitives/LightningAddressGetter.sol +3 -0
- package/src/lightning-parts/primitives/SignatureVerifier.sol +91 -27
- package/src/lightning-parts/primitives/VerifierAddressGetter.sol +3 -0
- package/src/lightning-parts/primitives/interfaces/IEventCounter.sol +2 -0
- package/src/lightning-parts/primitives/interfaces/IHandleGeneration.sol +10 -2
- package/src/lightning-parts/primitives/interfaces/ISignatureVerifier.sol +4 -2
- package/src/lightning-parts/primitives/interfaces/IVerifierAddressGetter.sol +2 -0
- package/src/lightning-parts/primitives/test/SignatureVerifier.t.sol +838 -0
- package/src/lightning-parts/test/Fee.t.sol +6 -6
- package/src/lightning-parts/test/HandleMetadata.t.sol +21 -76
- package/src/lightning-parts/test/InputsFee.t.sol +7 -28
- package/src/lightning-parts/test/TestDecryptionAttestationInSynchronousFlow.t.sol +16 -48
- package/src/pasted-dependencies/CreateX.sol +154 -455
- package/src/pasted-dependencies/ICreateX.sol +55 -102
- package/src/periphery/SessionVerifier.sol +10 -8
- package/src/shared/IOwnable.sol +3 -0
- package/src/shared/IUUPSUpgradable.sol +5 -1
- package/src/shared/JsonUtils.sol +3 -5
- package/src/shared/TestUtils.sol +15 -13
- package/src/test/AddTwo.sol +9 -7
- package/src/test/FakeIncoInfra/FakeComputeServer.sol +11 -53
- package/src/test/FakeIncoInfra/FakeDecryptionAttester.sol +35 -119
- package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +31 -48
- package/src/test/FakeIncoInfra/FakeQuoteVerifier.sol +4 -7
- package/src/test/FakeIncoInfra/KVStore.sol +2 -0
- package/src/test/FakeIncoInfra/MockOpHandler.sol +9 -31
- package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +50 -21
- package/src/test/IncoTest.sol +22 -9
- package/src/test/OpsTest.sol +438 -0
- package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +57 -104
- package/src/test/TestAddTwo.t.sol +4 -3
- package/src/test/TestDeploy.t.sol +5 -6
- package/src/test/TestExtractDataOfEventTooLarge.t.sol +7 -9
- package/src/test/TestFakeInfra.t.sol +15 -38
- package/src/test/TestUpgrade.t.sol +40 -135
- package/src/test/TestVersion.t.sol +6 -5
- package/src/version/IncoLightningConfig.sol +2 -2
- package/src/version/Version.sol +46 -48
- package/src/version/interfaces/IVersion.sol +6 -0
|
@@ -3,8 +3,8 @@ pragma solidity ^0.8;
|
|
|
3
3
|
|
|
4
4
|
// inco note : pasted because importing createx using github forces a solc version we don't use
|
|
5
5
|
|
|
6
|
-
address constant
|
|
7
|
-
address constant
|
|
6
|
+
address constant CREATE_X_ADDRESS = 0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed;
|
|
7
|
+
address constant CREATE_X_DEPLOYER = 0xeD456e05CaAb11d66C4c797dD6c1D6f9A7F352b5;
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @title CreateX Factory Smart Contract
|
|
@@ -21,6 +21,7 @@ address constant createXDeployer = 0xeD456e05CaAb11d66C4c797dD6c1D6f9A7F352b5;
|
|
|
21
21
|
* @custom:security-contact See https://web.archive.org/web/20230921105029/https://raw.githubusercontent.com/pcaversaccio/createx/main/SECURITY.md.
|
|
22
22
|
*/
|
|
23
23
|
contract CreateX {
|
|
24
|
+
|
|
24
25
|
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
25
26
|
/* IMMUTABLES */
|
|
26
27
|
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
@@ -82,10 +83,7 @@ contract CreateX {
|
|
|
82
83
|
* @param newContract The address of the new proxy contract.
|
|
83
84
|
* @param salt The 32-byte random value used to create the proxy address.
|
|
84
85
|
*/
|
|
85
|
-
event Create3ProxyContractCreation(
|
|
86
|
-
address indexed newContract,
|
|
87
|
-
bytes32 indexed salt
|
|
88
|
-
);
|
|
86
|
+
event Create3ProxyContractCreation(address indexed newContract, bytes32 indexed salt);
|
|
89
87
|
|
|
90
88
|
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
91
89
|
/* CUSTOM ERRORS */
|
|
@@ -135,15 +133,9 @@ contract CreateX {
|
|
|
135
133
|
* @param initCode The creation bytecode.
|
|
136
134
|
* @return newContract The 20-byte address where the contract was deployed.
|
|
137
135
|
*/
|
|
138
|
-
function deployCreate(
|
|
139
|
-
bytes memory initCode
|
|
140
|
-
) public payable returns (address newContract) {
|
|
136
|
+
function deployCreate(bytes memory initCode) public payable returns (address newContract) {
|
|
141
137
|
assembly ("memory-safe") {
|
|
142
|
-
newContract := create(
|
|
143
|
-
callvalue(),
|
|
144
|
-
add(initCode, 0x20),
|
|
145
|
-
mload(initCode)
|
|
146
|
-
)
|
|
138
|
+
newContract := create(callvalue(), add(initCode, 0x20), mload(initCode))
|
|
147
139
|
}
|
|
148
140
|
_requireSuccessfulContractCreation({newContract: newContract});
|
|
149
141
|
emit ContractCreation({newContract: newContract});
|
|
@@ -164,43 +156,28 @@ contract CreateX {
|
|
|
164
156
|
* a mutex lock to keep it as use-case agnostic as possible. Please ensure at the protocol
|
|
165
157
|
* level that potentially malicious reentrant calls do not affect your smart contract system.
|
|
166
158
|
*/
|
|
167
|
-
function deployCreateAndInit(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
) public payable returns (address newContract) {
|
|
159
|
+
function deployCreateAndInit(bytes memory initCode, bytes memory data, Values memory values, address refundAddress)
|
|
160
|
+
public
|
|
161
|
+
payable
|
|
162
|
+
returns (address newContract)
|
|
163
|
+
{
|
|
173
164
|
assembly ("memory-safe") {
|
|
174
|
-
newContract := create(
|
|
175
|
-
mload(values),
|
|
176
|
-
add(initCode, 0x20),
|
|
177
|
-
mload(initCode)
|
|
178
|
-
)
|
|
165
|
+
newContract := create(mload(values), add(initCode, 0x20), mload(initCode))
|
|
179
166
|
}
|
|
180
167
|
_requireSuccessfulContractCreation({newContract: newContract});
|
|
181
168
|
emit ContractCreation({newContract: newContract});
|
|
182
169
|
|
|
183
|
-
(bool success, bytes memory returnData) = newContract.call{
|
|
184
|
-
value: values.initCallAmount
|
|
185
|
-
}(data);
|
|
170
|
+
(bool success, bytes memory returnData) = newContract.call{value: values.initCallAmount}(data);
|
|
186
171
|
if (!success) {
|
|
187
|
-
revert FailedContractInitialisation({
|
|
188
|
-
emitter: _SELF,
|
|
189
|
-
revertData: returnData
|
|
190
|
-
});
|
|
172
|
+
revert FailedContractInitialisation({emitter: _SELF, revertData: returnData});
|
|
191
173
|
}
|
|
192
174
|
|
|
193
175
|
if (_SELF.balance != 0) {
|
|
194
176
|
// Any wei amount previously forced into this contract (e.g. by using the `SELFDESTRUCT`
|
|
195
177
|
// opcode) will be part of the refund transaction.
|
|
196
|
-
(success, returnData) = refundAddress.call{value: _SELF.balance}(
|
|
197
|
-
""
|
|
198
|
-
);
|
|
178
|
+
(success, returnData) = refundAddress.call{value: _SELF.balance}("");
|
|
199
179
|
if (!success) {
|
|
200
|
-
revert FailedEtherTransfer({
|
|
201
|
-
emitter: _SELF,
|
|
202
|
-
revertData: returnData
|
|
203
|
-
});
|
|
180
|
+
revert FailedEtherTransfer({emitter: _SELF, revertData: returnData});
|
|
204
181
|
}
|
|
205
182
|
}
|
|
206
183
|
}
|
|
@@ -219,17 +196,12 @@ contract CreateX {
|
|
|
219
196
|
* a mutex lock to keep it as use-case agnostic as possible. Please ensure at the protocol
|
|
220
197
|
* level that potentially malicious reentrant calls do not affect your smart contract system.
|
|
221
198
|
*/
|
|
222
|
-
function deployCreateAndInit(
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
newContract = deployCreateAndInit({
|
|
228
|
-
initCode: initCode,
|
|
229
|
-
data: data,
|
|
230
|
-
values: values,
|
|
231
|
-
refundAddress: msg.sender
|
|
232
|
-
});
|
|
199
|
+
function deployCreateAndInit(bytes memory initCode, bytes memory data, Values memory values)
|
|
200
|
+
public
|
|
201
|
+
payable
|
|
202
|
+
returns (address newContract)
|
|
203
|
+
{
|
|
204
|
+
newContract = deployCreateAndInit({initCode: initCode, data: data, values: values, refundAddress: msg.sender});
|
|
233
205
|
}
|
|
234
206
|
|
|
235
207
|
/**
|
|
@@ -244,22 +216,13 @@ contract CreateX {
|
|
|
244
216
|
* a mutex lock to keep it as use-case agnostic as possible. Please ensure at the protocol
|
|
245
217
|
* level that potentially malicious reentrant calls do not affect your smart contract system.
|
|
246
218
|
*/
|
|
247
|
-
function deployCreateClone(
|
|
248
|
-
address implementation,
|
|
249
|
-
bytes memory data
|
|
250
|
-
) public payable returns (address proxy) {
|
|
219
|
+
function deployCreateClone(address implementation, bytes memory data) public payable returns (address proxy) {
|
|
251
220
|
bytes20 implementationInBytes = bytes20(implementation);
|
|
252
221
|
assembly ("memory-safe") {
|
|
253
222
|
let clone := mload(0x40)
|
|
254
|
-
mstore(
|
|
255
|
-
clone,
|
|
256
|
-
hex"3d_60_2d_80_60_0a_3d_39_81_f3_36_3d_3d_37_3d_3d_3d_36_3d_73_00_00_00_00_00_00_00_00_00_00_00_00"
|
|
257
|
-
)
|
|
223
|
+
mstore(clone, hex"3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000")
|
|
258
224
|
mstore(add(clone, 0x14), implementationInBytes)
|
|
259
|
-
mstore(
|
|
260
|
-
add(clone, 0x28),
|
|
261
|
-
hex"5a_f4_3d_82_80_3e_90_3d_91_60_2b_57_fd_5b_f3_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00"
|
|
262
|
-
)
|
|
225
|
+
mstore(add(clone, 0x28), hex"5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000")
|
|
263
226
|
proxy := create(0, clone, 0x37)
|
|
264
227
|
}
|
|
265
228
|
if (proxy == address(0)) {
|
|
@@ -267,13 +230,9 @@ contract CreateX {
|
|
|
267
230
|
}
|
|
268
231
|
emit ContractCreation({newContract: proxy});
|
|
269
232
|
|
|
270
|
-
(bool success, bytes memory returnData) = proxy.call{value: msg.value}(
|
|
271
|
-
data
|
|
272
|
-
);
|
|
233
|
+
(bool success, bytes memory returnData) = proxy.call{value: msg.value}(data);
|
|
273
234
|
_requireSuccessfulContractInitialisation({
|
|
274
|
-
success: success,
|
|
275
|
-
returnData: returnData,
|
|
276
|
-
implementation: implementation
|
|
235
|
+
success: success, returnData: returnData, implementation: implementation
|
|
277
236
|
});
|
|
278
237
|
}
|
|
279
238
|
|
|
@@ -291,10 +250,7 @@ contract CreateX {
|
|
|
291
250
|
* @param nonce The next 32-byte nonce of the deployer address.
|
|
292
251
|
* @return computedAddress The 20-byte address where a contract will be stored.
|
|
293
252
|
*/
|
|
294
|
-
function computeCreateAddress(
|
|
295
|
-
address deployer,
|
|
296
|
-
uint256 nonce
|
|
297
|
-
) public view returns (address computedAddress) {
|
|
253
|
+
function computeCreateAddress(address deployer, uint256 nonce) public view returns (address computedAddress) {
|
|
298
254
|
bytes memory data;
|
|
299
255
|
bytes1 len = bytes1(0x94);
|
|
300
256
|
|
|
@@ -320,69 +276,21 @@ contract CreateX {
|
|
|
320
276
|
// 0x94 = 0x80 + 0x14 (= the bytes length of an address, 20 bytes, in hex),
|
|
321
277
|
// 0x84 = 0x80 + 0x04 (= the bytes length of the nonce, 4 bytes, in hex).
|
|
322
278
|
else if (nonce <= type(uint8).max) {
|
|
323
|
-
data = abi.encodePacked(
|
|
324
|
-
bytes1(0xd7),
|
|
325
|
-
len,
|
|
326
|
-
deployer,
|
|
327
|
-
bytes1(0x81),
|
|
328
|
-
uint8(nonce)
|
|
329
|
-
);
|
|
279
|
+
data = abi.encodePacked(bytes1(0xd7), len, deployer, bytes1(0x81), uint8(nonce));
|
|
330
280
|
} else if (nonce <= type(uint16).max) {
|
|
331
|
-
data = abi.encodePacked(
|
|
332
|
-
bytes1(0xd8),
|
|
333
|
-
len,
|
|
334
|
-
deployer,
|
|
335
|
-
bytes1(0x82),
|
|
336
|
-
uint16(nonce)
|
|
337
|
-
);
|
|
281
|
+
data = abi.encodePacked(bytes1(0xd8), len, deployer, bytes1(0x82), uint16(nonce));
|
|
338
282
|
} else if (nonce <= type(uint24).max) {
|
|
339
|
-
data = abi.encodePacked(
|
|
340
|
-
bytes1(0xd9),
|
|
341
|
-
len,
|
|
342
|
-
deployer,
|
|
343
|
-
bytes1(0x83),
|
|
344
|
-
uint24(nonce)
|
|
345
|
-
);
|
|
283
|
+
data = abi.encodePacked(bytes1(0xd9), len, deployer, bytes1(0x83), uint24(nonce));
|
|
346
284
|
} else if (nonce <= type(uint32).max) {
|
|
347
|
-
data = abi.encodePacked(
|
|
348
|
-
bytes1(0xda),
|
|
349
|
-
len,
|
|
350
|
-
deployer,
|
|
351
|
-
bytes1(0x84),
|
|
352
|
-
uint32(nonce)
|
|
353
|
-
);
|
|
285
|
+
data = abi.encodePacked(bytes1(0xda), len, deployer, bytes1(0x84), uint32(nonce));
|
|
354
286
|
} else if (nonce <= type(uint40).max) {
|
|
355
|
-
data = abi.encodePacked(
|
|
356
|
-
bytes1(0xdb),
|
|
357
|
-
len,
|
|
358
|
-
deployer,
|
|
359
|
-
bytes1(0x85),
|
|
360
|
-
uint40(nonce)
|
|
361
|
-
);
|
|
287
|
+
data = abi.encodePacked(bytes1(0xdb), len, deployer, bytes1(0x85), uint40(nonce));
|
|
362
288
|
} else if (nonce <= type(uint48).max) {
|
|
363
|
-
data = abi.encodePacked(
|
|
364
|
-
bytes1(0xdc),
|
|
365
|
-
len,
|
|
366
|
-
deployer,
|
|
367
|
-
bytes1(0x86),
|
|
368
|
-
uint48(nonce)
|
|
369
|
-
);
|
|
289
|
+
data = abi.encodePacked(bytes1(0xdc), len, deployer, bytes1(0x86), uint48(nonce));
|
|
370
290
|
} else if (nonce <= type(uint56).max) {
|
|
371
|
-
data = abi.encodePacked(
|
|
372
|
-
bytes1(0xdd),
|
|
373
|
-
len,
|
|
374
|
-
deployer,
|
|
375
|
-
bytes1(0x87),
|
|
376
|
-
uint56(nonce)
|
|
377
|
-
);
|
|
291
|
+
data = abi.encodePacked(bytes1(0xdd), len, deployer, bytes1(0x87), uint56(nonce));
|
|
378
292
|
} else {
|
|
379
|
-
data = abi.encodePacked(
|
|
380
|
-
bytes1(0xde),
|
|
381
|
-
len,
|
|
382
|
-
deployer,
|
|
383
|
-
bytes1(0x88),
|
|
384
|
-
uint64(nonce)
|
|
385
|
-
);
|
|
293
|
+
data = abi.encodePacked(bytes1(0xde), len, deployer, bytes1(0x88), uint64(nonce));
|
|
386
294
|
}
|
|
387
295
|
|
|
388
296
|
computedAddress = address(uint160(uint256(keccak256(data))));
|
|
@@ -401,9 +309,7 @@ contract CreateX {
|
|
|
401
309
|
* @param nonce The next 32-byte nonce of this contract.
|
|
402
310
|
* @return computedAddress The 20-byte address where a contract will be stored.
|
|
403
311
|
*/
|
|
404
|
-
function computeCreateAddress(
|
|
405
|
-
uint256 nonce
|
|
406
|
-
) public view returns (address computedAddress) {
|
|
312
|
+
function computeCreateAddress(uint256 nonce) public view returns (address computedAddress) {
|
|
407
313
|
computedAddress = computeCreateAddress({deployer: _SELF, nonce: nonce});
|
|
408
314
|
}
|
|
409
315
|
|
|
@@ -420,18 +326,10 @@ contract CreateX {
|
|
|
420
326
|
* @param initCode The creation bytecode.
|
|
421
327
|
* @return newContract The 20-byte address where the contract was deployed.
|
|
422
328
|
*/
|
|
423
|
-
function deployCreate2(
|
|
424
|
-
bytes32 salt,
|
|
425
|
-
bytes memory initCode
|
|
426
|
-
) public payable returns (address newContract) {
|
|
329
|
+
function deployCreate2(bytes32 salt, bytes memory initCode) public payable returns (address newContract) {
|
|
427
330
|
bytes32 guardedSalt = _guard({salt: salt});
|
|
428
331
|
assembly ("memory-safe") {
|
|
429
|
-
newContract := create2(
|
|
430
|
-
callvalue(),
|
|
431
|
-
add(initCode, 0x20),
|
|
432
|
-
mload(initCode),
|
|
433
|
-
guardedSalt
|
|
434
|
-
)
|
|
332
|
+
newContract := create2(callvalue(), add(initCode, 0x20), mload(initCode), guardedSalt)
|
|
435
333
|
}
|
|
436
334
|
_requireSuccessfulContractCreation({newContract: newContract});
|
|
437
335
|
emit ContractCreation({newContract: newContract, salt: guardedSalt});
|
|
@@ -446,15 +344,10 @@ contract CreateX {
|
|
|
446
344
|
* @param initCode The creation bytecode.
|
|
447
345
|
* @return newContract The 20-byte address where the contract was deployed.
|
|
448
346
|
*/
|
|
449
|
-
function deployCreate2(
|
|
450
|
-
bytes memory initCode
|
|
451
|
-
) public payable returns (address newContract) {
|
|
347
|
+
function deployCreate2(bytes memory initCode) public payable returns (address newContract) {
|
|
452
348
|
// Note that the safeguarding function `_guard` is called as part of the overloaded function
|
|
453
349
|
// `deployCreate2`.
|
|
454
|
-
newContract = deployCreate2({
|
|
455
|
-
salt: _generateSalt(),
|
|
456
|
-
initCode: initCode
|
|
457
|
-
});
|
|
350
|
+
newContract = deployCreate2({salt: _generateSalt(), initCode: initCode});
|
|
458
351
|
}
|
|
459
352
|
|
|
460
353
|
/**
|
|
@@ -482,37 +375,22 @@ contract CreateX {
|
|
|
482
375
|
) public payable returns (address newContract) {
|
|
483
376
|
bytes32 guardedSalt = _guard({salt: salt});
|
|
484
377
|
assembly ("memory-safe") {
|
|
485
|
-
newContract := create2(
|
|
486
|
-
mload(values),
|
|
487
|
-
add(initCode, 0x20),
|
|
488
|
-
mload(initCode),
|
|
489
|
-
guardedSalt
|
|
490
|
-
)
|
|
378
|
+
newContract := create2(mload(values), add(initCode, 0x20), mload(initCode), guardedSalt)
|
|
491
379
|
}
|
|
492
380
|
_requireSuccessfulContractCreation({newContract: newContract});
|
|
493
381
|
emit ContractCreation({newContract: newContract, salt: guardedSalt});
|
|
494
382
|
|
|
495
|
-
(bool success, bytes memory returnData) = newContract.call{
|
|
496
|
-
value: values.initCallAmount
|
|
497
|
-
}(data);
|
|
383
|
+
(bool success, bytes memory returnData) = newContract.call{value: values.initCallAmount}(data);
|
|
498
384
|
if (!success) {
|
|
499
|
-
revert FailedContractInitialisation({
|
|
500
|
-
emitter: _SELF,
|
|
501
|
-
revertData: returnData
|
|
502
|
-
});
|
|
385
|
+
revert FailedContractInitialisation({emitter: _SELF, revertData: returnData});
|
|
503
386
|
}
|
|
504
387
|
|
|
505
388
|
if (_SELF.balance != 0) {
|
|
506
389
|
// Any wei amount previously forced into this contract (e.g. by using the `SELFDESTRUCT`
|
|
507
390
|
// opcode) will be part of the refund transaction.
|
|
508
|
-
(success, returnData) = refundAddress.call{value: _SELF.balance}(
|
|
509
|
-
""
|
|
510
|
-
);
|
|
391
|
+
(success, returnData) = refundAddress.call{value: _SELF.balance}("");
|
|
511
392
|
if (!success) {
|
|
512
|
-
revert FailedEtherTransfer({
|
|
513
|
-
emitter: _SELF,
|
|
514
|
-
revertData: returnData
|
|
515
|
-
});
|
|
393
|
+
revert FailedEtherTransfer({emitter: _SELF, revertData: returnData});
|
|
516
394
|
}
|
|
517
395
|
}
|
|
518
396
|
}
|
|
@@ -532,20 +410,15 @@ contract CreateX {
|
|
|
532
410
|
* a mutex lock to keep it as use-case agnostic as possible. Please ensure at the protocol
|
|
533
411
|
* level that potentially malicious reentrant calls do not affect your smart contract system.
|
|
534
412
|
*/
|
|
535
|
-
function deployCreate2AndInit(
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
) public payable returns (address newContract) {
|
|
413
|
+
function deployCreate2AndInit(bytes32 salt, bytes memory initCode, bytes memory data, Values memory values)
|
|
414
|
+
public
|
|
415
|
+
payable
|
|
416
|
+
returns (address newContract)
|
|
417
|
+
{
|
|
541
418
|
// Note that the safeguarding function `_guard` is called as part of the overloaded function
|
|
542
419
|
// `deployCreate2AndInit`.
|
|
543
420
|
newContract = deployCreate2AndInit({
|
|
544
|
-
salt: salt,
|
|
545
|
-
initCode: initCode,
|
|
546
|
-
data: data,
|
|
547
|
-
values: values,
|
|
548
|
-
refundAddress: msg.sender
|
|
421
|
+
salt: salt, initCode: initCode, data: data, values: values, refundAddress: msg.sender
|
|
549
422
|
});
|
|
550
423
|
}
|
|
551
424
|
|
|
@@ -566,20 +439,15 @@ contract CreateX {
|
|
|
566
439
|
* a mutex lock to keep it as use-case agnostic as possible. Please ensure at the protocol
|
|
567
440
|
* level that potentially malicious reentrant calls do not affect your smart contract system.
|
|
568
441
|
*/
|
|
569
|
-
function deployCreate2AndInit(
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
) public payable returns (address newContract) {
|
|
442
|
+
function deployCreate2AndInit(bytes memory initCode, bytes memory data, Values memory values, address refundAddress)
|
|
443
|
+
public
|
|
444
|
+
payable
|
|
445
|
+
returns (address newContract)
|
|
446
|
+
{
|
|
575
447
|
// Note that the safeguarding function `_guard` is called as part of the overloaded function
|
|
576
448
|
// `deployCreate2AndInit`.
|
|
577
449
|
newContract = deployCreate2AndInit({
|
|
578
|
-
salt: _generateSalt(),
|
|
579
|
-
initCode: initCode,
|
|
580
|
-
data: data,
|
|
581
|
-
values: values,
|
|
582
|
-
refundAddress: refundAddress
|
|
450
|
+
salt: _generateSalt(), initCode: initCode, data: data, values: values, refundAddress: refundAddress
|
|
583
451
|
});
|
|
584
452
|
}
|
|
585
453
|
|
|
@@ -599,19 +467,15 @@ contract CreateX {
|
|
|
599
467
|
* a mutex lock to keep it as use-case agnostic as possible. Please ensure at the protocol
|
|
600
468
|
* level that potentially malicious reentrant calls do not affect your smart contract system.
|
|
601
469
|
*/
|
|
602
|
-
function deployCreate2AndInit(
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
470
|
+
function deployCreate2AndInit(bytes memory initCode, bytes memory data, Values memory values)
|
|
471
|
+
public
|
|
472
|
+
payable
|
|
473
|
+
returns (address newContract)
|
|
474
|
+
{
|
|
607
475
|
// Note that the safeguarding function `_guard` is called as part of the overloaded function
|
|
608
476
|
// `deployCreate2AndInit`.
|
|
609
477
|
newContract = deployCreate2AndInit({
|
|
610
|
-
salt: _generateSalt(),
|
|
611
|
-
initCode: initCode,
|
|
612
|
-
data: data,
|
|
613
|
-
values: values,
|
|
614
|
-
refundAddress: msg.sender
|
|
478
|
+
salt: _generateSalt(), initCode: initCode, data: data, values: values, refundAddress: msg.sender
|
|
615
479
|
});
|
|
616
480
|
}
|
|
617
481
|
|
|
@@ -628,24 +492,18 @@ contract CreateX {
|
|
|
628
492
|
* a mutex lock to keep it as use-case agnostic as possible. Please ensure at the protocol
|
|
629
493
|
* level that potentially malicious reentrant calls do not affect your smart contract system.
|
|
630
494
|
*/
|
|
631
|
-
function deployCreate2Clone(
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
495
|
+
function deployCreate2Clone(bytes32 salt, address implementation, bytes memory data)
|
|
496
|
+
public
|
|
497
|
+
payable
|
|
498
|
+
returns (address proxy)
|
|
499
|
+
{
|
|
636
500
|
bytes32 guardedSalt = _guard({salt: salt});
|
|
637
501
|
bytes20 implementationInBytes = bytes20(implementation);
|
|
638
502
|
assembly ("memory-safe") {
|
|
639
503
|
let clone := mload(0x40)
|
|
640
|
-
mstore(
|
|
641
|
-
clone,
|
|
642
|
-
hex"3d_60_2d_80_60_0a_3d_39_81_f3_36_3d_3d_37_3d_3d_3d_36_3d_73_00_00_00_00_00_00_00_00_00_00_00_00"
|
|
643
|
-
)
|
|
504
|
+
mstore(clone, hex"3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000")
|
|
644
505
|
mstore(add(clone, 0x14), implementationInBytes)
|
|
645
|
-
mstore(
|
|
646
|
-
add(clone, 0x28),
|
|
647
|
-
hex"5a_f4_3d_82_80_3e_90_3d_91_60_2b_57_fd_5b_f3_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00"
|
|
648
|
-
)
|
|
506
|
+
mstore(add(clone, 0x28), hex"5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000")
|
|
649
507
|
proxy := create2(0, clone, 0x37, guardedSalt)
|
|
650
508
|
}
|
|
651
509
|
if (proxy == address(0)) {
|
|
@@ -653,13 +511,9 @@ contract CreateX {
|
|
|
653
511
|
}
|
|
654
512
|
emit ContractCreation({newContract: proxy, salt: guardedSalt});
|
|
655
513
|
|
|
656
|
-
(bool success, bytes memory returnData) = proxy.call{value: msg.value}(
|
|
657
|
-
data
|
|
658
|
-
);
|
|
514
|
+
(bool success, bytes memory returnData) = proxy.call{value: msg.value}(data);
|
|
659
515
|
_requireSuccessfulContractInitialisation({
|
|
660
|
-
success: success,
|
|
661
|
-
returnData: returnData,
|
|
662
|
-
implementation: implementation
|
|
516
|
+
success: success, returnData: returnData, implementation: implementation
|
|
663
517
|
});
|
|
664
518
|
}
|
|
665
519
|
|
|
@@ -677,17 +531,10 @@ contract CreateX {
|
|
|
677
531
|
* a mutex lock to keep it as use-case agnostic as possible. Please ensure at the protocol
|
|
678
532
|
* level that potentially malicious reentrant calls do not affect your smart contract system.
|
|
679
533
|
*/
|
|
680
|
-
function deployCreate2Clone(
|
|
681
|
-
address implementation,
|
|
682
|
-
bytes memory data
|
|
683
|
-
) public payable returns (address proxy) {
|
|
534
|
+
function deployCreate2Clone(address implementation, bytes memory data) public payable returns (address proxy) {
|
|
684
535
|
// Note that the safeguarding function `_guard` is called as part of the overloaded function
|
|
685
536
|
// `deployCreate2Clone`.
|
|
686
|
-
proxy = deployCreate2Clone({
|
|
687
|
-
salt: _generateSalt(),
|
|
688
|
-
implementation: implementation,
|
|
689
|
-
data: data
|
|
690
|
-
});
|
|
537
|
+
proxy = deployCreate2Clone({salt: _generateSalt(), implementation: implementation, data: data});
|
|
691
538
|
}
|
|
692
539
|
|
|
693
540
|
/**
|
|
@@ -700,11 +547,11 @@ contract CreateX {
|
|
|
700
547
|
* @param deployer The 20-byte deployer address.
|
|
701
548
|
* @return computedAddress The 20-byte address where a contract will be stored.
|
|
702
549
|
*/
|
|
703
|
-
function computeCreate2Address(
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
address
|
|
707
|
-
|
|
550
|
+
function computeCreate2Address(bytes32 salt, bytes32 initCodeHash, address deployer)
|
|
551
|
+
public
|
|
552
|
+
pure
|
|
553
|
+
returns (address computedAddress)
|
|
554
|
+
{
|
|
708
555
|
assembly ("memory-safe") {
|
|
709
556
|
// | | ↓ ptr ... ↓ ptr + 0x0B (start) ... ↓ ptr + 0x20 ... ↓ ptr + 0x40 ... |
|
|
710
557
|
// |----------------------|---------------------------------------------------------------------------|
|
|
@@ -733,15 +580,8 @@ contract CreateX {
|
|
|
733
580
|
* @param initCodeHash The 32-byte bytecode digest of the contract creation bytecode.
|
|
734
581
|
* @return computedAddress The 20-byte address where a contract will be stored.
|
|
735
582
|
*/
|
|
736
|
-
function computeCreate2Address(
|
|
737
|
-
|
|
738
|
-
bytes32 initCodeHash
|
|
739
|
-
) public view returns (address computedAddress) {
|
|
740
|
-
computedAddress = computeCreate2Address({
|
|
741
|
-
salt: salt,
|
|
742
|
-
initCodeHash: initCodeHash,
|
|
743
|
-
deployer: _SELF
|
|
744
|
-
});
|
|
583
|
+
function computeCreate2Address(bytes32 salt, bytes32 initCodeHash) public view returns (address computedAddress) {
|
|
584
|
+
computedAddress = computeCreate2Address({salt: salt, initCodeHash: initCodeHash, deployer: _SELF});
|
|
745
585
|
}
|
|
746
586
|
|
|
747
587
|
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
@@ -762,36 +602,21 @@ contract CreateX {
|
|
|
762
602
|
* the first 20 bytes equal to `msg.sender` in the `salt` to prevent maliciously intended frontrun
|
|
763
603
|
* proxy deployments on other chains.
|
|
764
604
|
*/
|
|
765
|
-
function deployCreate3(
|
|
766
|
-
bytes32 salt,
|
|
767
|
-
bytes memory initCode
|
|
768
|
-
) public payable returns (address newContract) {
|
|
605
|
+
function deployCreate3(bytes32 salt, bytes memory initCode) public payable returns (address newContract) {
|
|
769
606
|
bytes32 guardedSalt = _guard({salt: salt});
|
|
770
|
-
bytes
|
|
771
|
-
memory proxyChildBytecode = hex"67_36_3d_3d_37_36_3d_34_f0_3d_52_60_08_60_18_f3";
|
|
607
|
+
bytes memory proxyChildBytecode = hex"67363d3d37363d34f03d5260086018f3";
|
|
772
608
|
address proxy;
|
|
773
609
|
assembly ("memory-safe") {
|
|
774
|
-
proxy := create2(
|
|
775
|
-
0,
|
|
776
|
-
add(proxyChildBytecode, 32),
|
|
777
|
-
mload(proxyChildBytecode),
|
|
778
|
-
guardedSalt
|
|
779
|
-
)
|
|
610
|
+
proxy := create2(0, add(proxyChildBytecode, 32), mload(proxyChildBytecode), guardedSalt)
|
|
780
611
|
}
|
|
781
612
|
if (proxy == address(0)) {
|
|
782
613
|
revert FailedContractCreation({emitter: _SELF});
|
|
783
614
|
}
|
|
784
|
-
emit Create3ProxyContractCreation({
|
|
785
|
-
newContract: proxy,
|
|
786
|
-
salt: guardedSalt
|
|
787
|
-
});
|
|
615
|
+
emit Create3ProxyContractCreation({newContract: proxy, salt: guardedSalt});
|
|
788
616
|
|
|
789
617
|
newContract = computeCreate3Address({salt: guardedSalt});
|
|
790
|
-
(bool success,
|
|
791
|
-
_requireSuccessfulContractCreation({
|
|
792
|
-
success: success,
|
|
793
|
-
newContract: newContract
|
|
794
|
-
});
|
|
618
|
+
(bool success,) = proxy.call{value: msg.value}(initCode);
|
|
619
|
+
_requireSuccessfulContractCreation({success: success, newContract: newContract});
|
|
795
620
|
emit ContractCreation({newContract: newContract});
|
|
796
621
|
}
|
|
797
622
|
|
|
@@ -806,15 +631,10 @@ contract CreateX {
|
|
|
806
631
|
* @param initCode The creation bytecode.
|
|
807
632
|
* @return newContract The 20-byte address where the contract was deployed.
|
|
808
633
|
*/
|
|
809
|
-
function deployCreate3(
|
|
810
|
-
bytes memory initCode
|
|
811
|
-
) public payable returns (address newContract) {
|
|
634
|
+
function deployCreate3(bytes memory initCode) public payable returns (address newContract) {
|
|
812
635
|
// Note that the safeguarding function `_guard` is called as part of the overloaded function
|
|
813
636
|
// `deployCreate3`.
|
|
814
|
-
newContract = deployCreate3({
|
|
815
|
-
salt: _generateSalt(),
|
|
816
|
-
initCode: initCode
|
|
817
|
-
});
|
|
637
|
+
newContract = deployCreate3({salt: _generateSalt(), initCode: initCode});
|
|
818
638
|
}
|
|
819
639
|
|
|
820
640
|
/**
|
|
@@ -846,57 +666,33 @@ contract CreateX {
|
|
|
846
666
|
address refundAddress
|
|
847
667
|
) public payable returns (address newContract) {
|
|
848
668
|
bytes32 guardedSalt = _guard({salt: salt});
|
|
849
|
-
bytes
|
|
850
|
-
memory proxyChildBytecode = hex"67_36_3d_3d_37_36_3d_34_f0_3d_52_60_08_60_18_f3";
|
|
669
|
+
bytes memory proxyChildBytecode = hex"67363d3d37363d34f03d5260086018f3";
|
|
851
670
|
address proxy;
|
|
852
671
|
assembly ("memory-safe") {
|
|
853
|
-
proxy := create2(
|
|
854
|
-
0,
|
|
855
|
-
add(proxyChildBytecode, 32),
|
|
856
|
-
mload(proxyChildBytecode),
|
|
857
|
-
guardedSalt
|
|
858
|
-
)
|
|
672
|
+
proxy := create2(0, add(proxyChildBytecode, 32), mload(proxyChildBytecode), guardedSalt)
|
|
859
673
|
}
|
|
860
674
|
if (proxy == address(0)) {
|
|
861
675
|
revert FailedContractCreation({emitter: _SELF});
|
|
862
676
|
}
|
|
863
|
-
emit Create3ProxyContractCreation({
|
|
864
|
-
newContract: proxy,
|
|
865
|
-
salt: guardedSalt
|
|
866
|
-
});
|
|
677
|
+
emit Create3ProxyContractCreation({newContract: proxy, salt: guardedSalt});
|
|
867
678
|
|
|
868
679
|
newContract = computeCreate3Address({salt: guardedSalt});
|
|
869
|
-
(bool success,
|
|
870
|
-
|
|
871
|
-
);
|
|
872
|
-
_requireSuccessfulContractCreation({
|
|
873
|
-
success: success,
|
|
874
|
-
newContract: newContract
|
|
875
|
-
});
|
|
680
|
+
(bool success,) = proxy.call{value: values.constructorAmount}(initCode);
|
|
681
|
+
_requireSuccessfulContractCreation({success: success, newContract: newContract});
|
|
876
682
|
emit ContractCreation({newContract: newContract});
|
|
877
683
|
|
|
878
684
|
bytes memory returnData;
|
|
879
|
-
(success, returnData) = newContract.call{value: values.initCallAmount}(
|
|
880
|
-
data
|
|
881
|
-
);
|
|
685
|
+
(success, returnData) = newContract.call{value: values.initCallAmount}(data);
|
|
882
686
|
if (!success) {
|
|
883
|
-
revert FailedContractInitialisation({
|
|
884
|
-
emitter: _SELF,
|
|
885
|
-
revertData: returnData
|
|
886
|
-
});
|
|
687
|
+
revert FailedContractInitialisation({emitter: _SELF, revertData: returnData});
|
|
887
688
|
}
|
|
888
689
|
|
|
889
690
|
if (_SELF.balance != 0) {
|
|
890
691
|
// Any wei amount previously forced into this contract (e.g. by using the `SELFDESTRUCT`
|
|
891
692
|
// opcode) will be part of the refund transaction.
|
|
892
|
-
(success, returnData) = refundAddress.call{value: _SELF.balance}(
|
|
893
|
-
""
|
|
894
|
-
);
|
|
693
|
+
(success, returnData) = refundAddress.call{value: _SELF.balance}("");
|
|
895
694
|
if (!success) {
|
|
896
|
-
revert FailedEtherTransfer({
|
|
897
|
-
emitter: _SELF,
|
|
898
|
-
revertData: returnData
|
|
899
|
-
});
|
|
695
|
+
revert FailedEtherTransfer({emitter: _SELF, revertData: returnData});
|
|
900
696
|
}
|
|
901
697
|
}
|
|
902
698
|
}
|
|
@@ -921,20 +717,15 @@ contract CreateX {
|
|
|
921
717
|
* the first 20 bytes equal to `msg.sender` in the `salt` to prevent maliciously intended frontrun
|
|
922
718
|
* proxy deployments on other chains.
|
|
923
719
|
*/
|
|
924
|
-
function deployCreate3AndInit(
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
) public payable returns (address newContract) {
|
|
720
|
+
function deployCreate3AndInit(bytes32 salt, bytes memory initCode, bytes memory data, Values memory values)
|
|
721
|
+
public
|
|
722
|
+
payable
|
|
723
|
+
returns (address newContract)
|
|
724
|
+
{
|
|
930
725
|
// Note that the safeguarding function `_guard` is called as part of the overloaded function
|
|
931
726
|
// `deployCreate3AndInit`.
|
|
932
727
|
newContract = deployCreate3AndInit({
|
|
933
|
-
salt: salt,
|
|
934
|
-
initCode: initCode,
|
|
935
|
-
data: data,
|
|
936
|
-
values: values,
|
|
937
|
-
refundAddress: msg.sender
|
|
728
|
+
salt: salt, initCode: initCode, data: data, values: values, refundAddress: msg.sender
|
|
938
729
|
});
|
|
939
730
|
}
|
|
940
731
|
|
|
@@ -956,20 +747,15 @@ contract CreateX {
|
|
|
956
747
|
* a mutex lock to keep it as use-case agnostic as possible. Please ensure at the protocol
|
|
957
748
|
* level that potentially malicious reentrant calls do not affect your smart contract system.
|
|
958
749
|
*/
|
|
959
|
-
function deployCreate3AndInit(
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
) public payable returns (address newContract) {
|
|
750
|
+
function deployCreate3AndInit(bytes memory initCode, bytes memory data, Values memory values, address refundAddress)
|
|
751
|
+
public
|
|
752
|
+
payable
|
|
753
|
+
returns (address newContract)
|
|
754
|
+
{
|
|
965
755
|
// Note that the safeguarding function `_guard` is called as part of the overloaded function
|
|
966
756
|
// `deployCreate3AndInit`.
|
|
967
757
|
newContract = deployCreate3AndInit({
|
|
968
|
-
salt: _generateSalt(),
|
|
969
|
-
initCode: initCode,
|
|
970
|
-
data: data,
|
|
971
|
-
values: values,
|
|
972
|
-
refundAddress: refundAddress
|
|
758
|
+
salt: _generateSalt(), initCode: initCode, data: data, values: values, refundAddress: refundAddress
|
|
973
759
|
});
|
|
974
760
|
}
|
|
975
761
|
|
|
@@ -990,19 +776,15 @@ contract CreateX {
|
|
|
990
776
|
* a mutex lock to keep it as use-case agnostic as possible. Please ensure at the protocol
|
|
991
777
|
* level that potentially malicious reentrant calls do not affect your smart contract system.
|
|
992
778
|
*/
|
|
993
|
-
function deployCreate3AndInit(
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
779
|
+
function deployCreate3AndInit(bytes memory initCode, bytes memory data, Values memory values)
|
|
780
|
+
public
|
|
781
|
+
payable
|
|
782
|
+
returns (address newContract)
|
|
783
|
+
{
|
|
998
784
|
// Note that the safeguarding function `_guard` is called as part of the overloaded function
|
|
999
785
|
// `deployCreate3AndInit`.
|
|
1000
786
|
newContract = deployCreate3AndInit({
|
|
1001
|
-
salt: _generateSalt(),
|
|
1002
|
-
initCode: initCode,
|
|
1003
|
-
data: data,
|
|
1004
|
-
values: values,
|
|
1005
|
-
refundAddress: msg.sender
|
|
787
|
+
salt: _generateSalt(), initCode: initCode, data: data, values: values, refundAddress: msg.sender
|
|
1006
788
|
});
|
|
1007
789
|
}
|
|
1008
790
|
|
|
@@ -1015,19 +797,13 @@ contract CreateX {
|
|
|
1015
797
|
* @param deployer The 20-byte deployer address.
|
|
1016
798
|
* @return computedAddress The 20-byte address where a contract will be stored.
|
|
1017
799
|
*/
|
|
1018
|
-
function computeCreate3Address(
|
|
1019
|
-
bytes32 salt,
|
|
1020
|
-
address deployer
|
|
1021
|
-
) public pure returns (address computedAddress) {
|
|
800
|
+
function computeCreate3Address(bytes32 salt, address deployer) public pure returns (address computedAddress) {
|
|
1022
801
|
assembly ("memory-safe") {
|
|
1023
802
|
let ptr := mload(0x40)
|
|
1024
803
|
mstore(0x00, deployer)
|
|
1025
804
|
mstore8(0x0b, 0xff)
|
|
1026
805
|
mstore(0x20, salt)
|
|
1027
|
-
mstore(
|
|
1028
|
-
0x40,
|
|
1029
|
-
hex"21_c3_5d_be_1b_34_4a_24_88_cf_33_21_d6_ce_54_2f_8e_9f_30_55_44_ff_09_e4_99_3a_62_31_9a_49_7c_1f"
|
|
1030
|
-
)
|
|
806
|
+
mstore(0x40, hex"21c35dbe1b344a2488cf3321d6ce542f8e9f305544ff09e4993a62319a497c1f")
|
|
1031
807
|
mstore(0x14, keccak256(0x0b, 0x55))
|
|
1032
808
|
mstore(0x40, ptr)
|
|
1033
809
|
mstore(0x00, 0xd694)
|
|
@@ -1044,9 +820,7 @@ contract CreateX {
|
|
|
1044
820
|
* @param salt The 32-byte random value used to create the proxy contract address.
|
|
1045
821
|
* @return computedAddress The 20-byte address where a contract will be stored.
|
|
1046
822
|
*/
|
|
1047
|
-
function computeCreate3Address(
|
|
1048
|
-
bytes32 salt
|
|
1049
|
-
) public view returns (address computedAddress) {
|
|
823
|
+
function computeCreate3Address(bytes32 salt) public view returns (address computedAddress) {
|
|
1050
824
|
computedAddress = computeCreate3Address({salt: salt, deployer: _SELF});
|
|
1051
825
|
}
|
|
1052
826
|
|
|
@@ -1068,50 +842,30 @@ contract CreateX {
|
|
|
1068
842
|
* @return guardedSalt The guarded 32-byte random value used to create the contract address.
|
|
1069
843
|
*/
|
|
1070
844
|
function _guard(bytes32 salt) internal view returns (bytes32 guardedSalt) {
|
|
1071
|
-
(
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
) = _parseSalt({salt: salt});
|
|
1075
|
-
|
|
1076
|
-
if (
|
|
1077
|
-
senderBytes == SenderBytes.MsgSender &&
|
|
1078
|
-
redeployProtectionFlag == RedeployProtectionFlag.True
|
|
1079
|
-
) {
|
|
845
|
+
(SenderBytes senderBytes, RedeployProtectionFlag redeployProtectionFlag) = _parseSalt({salt: salt});
|
|
846
|
+
|
|
847
|
+
if (senderBytes == SenderBytes.MsgSender && redeployProtectionFlag == RedeployProtectionFlag.True) {
|
|
1080
848
|
// Configures a permissioned deploy protection as well as a cross-chain redeploy protection.
|
|
1081
|
-
guardedSalt = keccak256(
|
|
1082
|
-
|
|
1083
|
-
);
|
|
1084
|
-
} else if (
|
|
1085
|
-
senderBytes == SenderBytes.MsgSender &&
|
|
1086
|
-
redeployProtectionFlag == RedeployProtectionFlag.False
|
|
1087
|
-
) {
|
|
849
|
+
guardedSalt = keccak256(abi.encode(msg.sender, block.chainid, salt));
|
|
850
|
+
} else if (senderBytes == SenderBytes.MsgSender && redeployProtectionFlag == RedeployProtectionFlag.False) {
|
|
1088
851
|
// Configures solely a permissioned deploy protection.
|
|
1089
|
-
guardedSalt = _efficientHash({
|
|
1090
|
-
a: bytes32(uint256(uint160(msg.sender))),
|
|
1091
|
-
b: salt
|
|
1092
|
-
});
|
|
852
|
+
guardedSalt = _efficientHash({a: bytes32(uint256(uint160(msg.sender))), b: salt});
|
|
1093
853
|
} else if (senderBytes == SenderBytes.MsgSender) {
|
|
1094
854
|
// Reverts if the 21st byte is greater than `0x01` in order to enforce developer explicitness.
|
|
1095
855
|
revert InvalidSalt({emitter: _SELF});
|
|
1096
|
-
} else if (
|
|
1097
|
-
senderBytes == SenderBytes.ZeroAddress &&
|
|
1098
|
-
redeployProtectionFlag == RedeployProtectionFlag.True
|
|
1099
|
-
) {
|
|
856
|
+
} else if (senderBytes == SenderBytes.ZeroAddress && redeployProtectionFlag == RedeployProtectionFlag.True) {
|
|
1100
857
|
// Configures solely a cross-chain redeploy protection. In order to prevent a pseudo-randomly
|
|
1101
858
|
// generated cross-chain redeploy protection, we enforce the zero address check for the first 20 bytes.
|
|
1102
859
|
guardedSalt = _efficientHash({a: bytes32(block.chainid), b: salt});
|
|
1103
860
|
} else if (
|
|
1104
|
-
senderBytes == SenderBytes.ZeroAddress &&
|
|
1105
|
-
redeployProtectionFlag == RedeployProtectionFlag.Unspecified
|
|
861
|
+
senderBytes == SenderBytes.ZeroAddress && redeployProtectionFlag == RedeployProtectionFlag.Unspecified
|
|
1106
862
|
) {
|
|
1107
863
|
// Reverts if the 21st byte is greater than `0x01` in order to enforce developer explicitness.
|
|
1108
864
|
revert InvalidSalt({emitter: _SELF});
|
|
1109
865
|
} else {
|
|
1110
866
|
// For the non-pseudo-random cases, the salt value `salt` is hashed to prevent the safeguard mechanisms
|
|
1111
867
|
// from being bypassed. Otherwise, the salt value `salt` is not modified.
|
|
1112
|
-
guardedSalt = (salt != _generateSalt())
|
|
1113
|
-
? keccak256(abi.encode(salt))
|
|
1114
|
-
: salt;
|
|
868
|
+
guardedSalt = (salt != _generateSalt()) ? keccak256(abi.encode(salt)) : salt;
|
|
1115
869
|
}
|
|
1116
870
|
}
|
|
1117
871
|
|
|
@@ -1123,69 +877,29 @@ contract CreateX {
|
|
|
1123
877
|
* @return redeployProtectionFlag The 8-byte enum for the selection of a cross-chain redeploy
|
|
1124
878
|
* protection.
|
|
1125
879
|
*/
|
|
1126
|
-
function _parseSalt(
|
|
1127
|
-
bytes32 salt
|
|
1128
|
-
)
|
|
880
|
+
function _parseSalt(bytes32 salt)
|
|
1129
881
|
internal
|
|
1130
882
|
view
|
|
1131
|
-
returns (
|
|
1132
|
-
SenderBytes senderBytes,
|
|
1133
|
-
RedeployProtectionFlag redeployProtectionFlag
|
|
1134
|
-
)
|
|
883
|
+
returns (SenderBytes senderBytes, RedeployProtectionFlag redeployProtectionFlag)
|
|
1135
884
|
{
|
|
1136
|
-
if (
|
|
1137
|
-
|
|
1138
|
-
) {
|
|
1139
|
-
(senderBytes, redeployProtectionFlag) = (
|
|
1140
|
-
SenderBytes.MsgSender,
|
|
1141
|
-
RedeployProtectionFlag.True
|
|
1142
|
-
);
|
|
1143
|
-
} else if (
|
|
1144
|
-
address(bytes20(salt)) == msg.sender && bytes1(salt[20]) == hex"00"
|
|
1145
|
-
) {
|
|
1146
|
-
(senderBytes, redeployProtectionFlag) = (
|
|
1147
|
-
SenderBytes.MsgSender,
|
|
1148
|
-
RedeployProtectionFlag.False
|
|
1149
|
-
);
|
|
885
|
+
if (address(bytes20(salt)) == msg.sender && bytes1(salt[20]) == hex"01") {
|
|
886
|
+
(senderBytes, redeployProtectionFlag) = (SenderBytes.MsgSender, RedeployProtectionFlag.True);
|
|
887
|
+
} else if (address(bytes20(salt)) == msg.sender && bytes1(salt[20]) == hex"00") {
|
|
888
|
+
(senderBytes, redeployProtectionFlag) = (SenderBytes.MsgSender, RedeployProtectionFlag.False);
|
|
1150
889
|
} else if (address(bytes20(salt)) == msg.sender) {
|
|
1151
|
-
(senderBytes, redeployProtectionFlag) = (
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
address(bytes20(salt)) == address(0) && bytes1(salt[20]) == hex"01"
|
|
1157
|
-
) {
|
|
1158
|
-
(senderBytes, redeployProtectionFlag) = (
|
|
1159
|
-
SenderBytes.ZeroAddress,
|
|
1160
|
-
RedeployProtectionFlag.True
|
|
1161
|
-
);
|
|
1162
|
-
} else if (
|
|
1163
|
-
address(bytes20(salt)) == address(0) && bytes1(salt[20]) == hex"00"
|
|
1164
|
-
) {
|
|
1165
|
-
(senderBytes, redeployProtectionFlag) = (
|
|
1166
|
-
SenderBytes.ZeroAddress,
|
|
1167
|
-
RedeployProtectionFlag.False
|
|
1168
|
-
);
|
|
890
|
+
(senderBytes, redeployProtectionFlag) = (SenderBytes.MsgSender, RedeployProtectionFlag.Unspecified);
|
|
891
|
+
} else if (address(bytes20(salt)) == address(0) && bytes1(salt[20]) == hex"01") {
|
|
892
|
+
(senderBytes, redeployProtectionFlag) = (SenderBytes.ZeroAddress, RedeployProtectionFlag.True);
|
|
893
|
+
} else if (address(bytes20(salt)) == address(0) && bytes1(salt[20]) == hex"00") {
|
|
894
|
+
(senderBytes, redeployProtectionFlag) = (SenderBytes.ZeroAddress, RedeployProtectionFlag.False);
|
|
1169
895
|
} else if (address(bytes20(salt)) == address(0)) {
|
|
1170
|
-
(senderBytes, redeployProtectionFlag) = (
|
|
1171
|
-
SenderBytes.ZeroAddress,
|
|
1172
|
-
RedeployProtectionFlag.Unspecified
|
|
1173
|
-
);
|
|
896
|
+
(senderBytes, redeployProtectionFlag) = (SenderBytes.ZeroAddress, RedeployProtectionFlag.Unspecified);
|
|
1174
897
|
} else if (bytes1(salt[20]) == hex"01") {
|
|
1175
|
-
(senderBytes, redeployProtectionFlag) = (
|
|
1176
|
-
SenderBytes.Random,
|
|
1177
|
-
RedeployProtectionFlag.True
|
|
1178
|
-
);
|
|
898
|
+
(senderBytes, redeployProtectionFlag) = (SenderBytes.Random, RedeployProtectionFlag.True);
|
|
1179
899
|
} else if (bytes1(salt[20]) == hex"00") {
|
|
1180
|
-
(senderBytes, redeployProtectionFlag) = (
|
|
1181
|
-
SenderBytes.Random,
|
|
1182
|
-
RedeployProtectionFlag.False
|
|
1183
|
-
);
|
|
900
|
+
(senderBytes, redeployProtectionFlag) = (SenderBytes.Random, RedeployProtectionFlag.False);
|
|
1184
901
|
} else {
|
|
1185
|
-
(senderBytes, redeployProtectionFlag) = (
|
|
1186
|
-
SenderBytes.Random,
|
|
1187
|
-
RedeployProtectionFlag.Unspecified
|
|
1188
|
-
);
|
|
902
|
+
(senderBytes, redeployProtectionFlag) = (SenderBytes.Random, RedeployProtectionFlag.Unspecified);
|
|
1189
903
|
}
|
|
1190
904
|
}
|
|
1191
905
|
|
|
@@ -1195,10 +909,7 @@ contract CreateX {
|
|
|
1195
909
|
* @param b The second 32-byte value to be concatenated and hashed.
|
|
1196
910
|
* @return hash The 32-byte `keccak256` hash of `a` and `b`.
|
|
1197
911
|
*/
|
|
1198
|
-
function _efficientHash(
|
|
1199
|
-
bytes32 a,
|
|
1200
|
-
bytes32 b
|
|
1201
|
-
) internal pure returns (bytes32 hash) {
|
|
912
|
+
function _efficientHash(bytes32 a, bytes32 b) internal pure returns (bytes32 hash) {
|
|
1202
913
|
assembly ("memory-safe") {
|
|
1203
914
|
mstore(0x00, a)
|
|
1204
915
|
mstore(0x20, b)
|
|
@@ -1241,21 +952,14 @@ contract CreateX {
|
|
|
1241
952
|
* @param success The Boolean success condition.
|
|
1242
953
|
* @param newContract The 20-byte address where the contract was deployed.
|
|
1243
954
|
*/
|
|
1244
|
-
function _requireSuccessfulContractCreation(
|
|
1245
|
-
bool success,
|
|
1246
|
-
address newContract
|
|
1247
|
-
) internal view {
|
|
955
|
+
function _requireSuccessfulContractCreation(bool success, address newContract) internal view {
|
|
1248
956
|
// Note that reverting if `newContract == address(0)` isn't strictly necessary here, as if
|
|
1249
957
|
// the deployment fails, `success == false` should already hold. However, since the `CreateX`
|
|
1250
958
|
// contract should be usable and safe on a wide range of chains, this check is cheap enough
|
|
1251
959
|
// that there is no harm in including it (security > gas optimisations). It can potentially
|
|
1252
960
|
// protect against unexpected chain behaviour or a hypothetical compiler bug that doesn't surface
|
|
1253
961
|
// the call success status properly.
|
|
1254
|
-
if (
|
|
1255
|
-
!success ||
|
|
1256
|
-
newContract == address(0) ||
|
|
1257
|
-
newContract.code.length == 0
|
|
1258
|
-
) {
|
|
962
|
+
if (!success || newContract == address(0) || newContract.code.length == 0) {
|
|
1259
963
|
revert FailedContractCreation({emitter: _SELF});
|
|
1260
964
|
}
|
|
1261
965
|
}
|
|
@@ -1264,9 +968,7 @@ contract CreateX {
|
|
|
1264
968
|
* @dev Ensures that `newContract` is a non-zero byte contract.
|
|
1265
969
|
* @param newContract The 20-byte address where the contract was deployed.
|
|
1266
970
|
*/
|
|
1267
|
-
function _requireSuccessfulContractCreation(
|
|
1268
|
-
address newContract
|
|
1269
|
-
) internal view {
|
|
971
|
+
function _requireSuccessfulContractCreation(address newContract) internal view {
|
|
1270
972
|
if (newContract == address(0) || newContract.code.length == 0) {
|
|
1271
973
|
revert FailedContractCreation({emitter: _SELF});
|
|
1272
974
|
}
|
|
@@ -1278,16 +980,13 @@ contract CreateX {
|
|
|
1278
980
|
* @param returnData The return data from the contract initialisation call.
|
|
1279
981
|
* @param implementation The 20-byte address where the implementation was deployed.
|
|
1280
982
|
*/
|
|
1281
|
-
function _requireSuccessfulContractInitialisation(
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
) internal view {
|
|
983
|
+
function _requireSuccessfulContractInitialisation(bool success, bytes memory returnData, address implementation)
|
|
984
|
+
internal
|
|
985
|
+
view
|
|
986
|
+
{
|
|
1286
987
|
if (!success || implementation.code.length == 0) {
|
|
1287
|
-
revert FailedContractInitialisation({
|
|
1288
|
-
emitter: _SELF,
|
|
1289
|
-
revertData: returnData
|
|
1290
|
-
});
|
|
988
|
+
revert FailedContractInitialisation({emitter: _SELF, revertData: returnData});
|
|
1291
989
|
}
|
|
1292
990
|
}
|
|
991
|
+
|
|
1293
992
|
}
|