@inco/lightning 0.6.7 → 0.6.9
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/README.md +29 -2
- package/manifest.yaml +0 -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.template.sol +40 -159
- package/src/Types.sol +233 -97
- package/src/interfaces/IIncoLightning.sol +2 -0
- package/src/interfaces/IIncoVerifier.sol +7 -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_devnet_v1_887305889.sol +5 -3
- package/src/libs/incoLightning_testnet_v1_938327937.sol +5 -3
- package/src/lightning-parts/AccessControl/AdvancedAccessControl.sol +41 -75
- 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 +42 -83
- 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 +93 -440
- package/src/lightning-parts/Fee.sol +3 -1
- package/src/lightning-parts/TEELifecycle.sol +95 -225
- 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 +146 -419
- package/src/pasted-dependencies/ICreateX.sol +58 -102
- package/src/periphery/SessionVerifier.sol +5 -7
- 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 +14 -13
- package/src/test/AddTwo.sol +9 -7
- package/src/test/FakeIncoInfra/FakeComputeServer.sol +11 -53
- package/src/test/FakeIncoInfra/FakeDecryptionAttester.sol +35 -118
- 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 +44 -21
- package/src/test/IncoTest.sol +15 -9
- package/src/test/OpsTest.sol +429 -0
- package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +58 -104
- package/src/test/TestAddTwo.t.sol +4 -3
- package/src/test/TestDeploy.t.sol +5 -6
- package/src/test/TestExtractDataOfEventTooLarge.t.sol +7 -14
- 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 +1 -1
- package/src/version/Version.sol +48 -51
- 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,9 +230,7 @@ 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
235
|
success: success,
|
|
275
236
|
returnData: returnData,
|
|
@@ -291,10 +252,7 @@ contract CreateX {
|
|
|
291
252
|
* @param nonce The next 32-byte nonce of the deployer address.
|
|
292
253
|
* @return computedAddress The 20-byte address where a contract will be stored.
|
|
293
254
|
*/
|
|
294
|
-
function computeCreateAddress(
|
|
295
|
-
address deployer,
|
|
296
|
-
uint256 nonce
|
|
297
|
-
) public view returns (address computedAddress) {
|
|
255
|
+
function computeCreateAddress(address deployer, uint256 nonce) public view returns (address computedAddress) {
|
|
298
256
|
bytes memory data;
|
|
299
257
|
bytes1 len = bytes1(0x94);
|
|
300
258
|
|
|
@@ -320,69 +278,21 @@ contract CreateX {
|
|
|
320
278
|
// 0x94 = 0x80 + 0x14 (= the bytes length of an address, 20 bytes, in hex),
|
|
321
279
|
// 0x84 = 0x80 + 0x04 (= the bytes length of the nonce, 4 bytes, in hex).
|
|
322
280
|
else if (nonce <= type(uint8).max) {
|
|
323
|
-
data = abi.encodePacked(
|
|
324
|
-
bytes1(0xd7),
|
|
325
|
-
len,
|
|
326
|
-
deployer,
|
|
327
|
-
bytes1(0x81),
|
|
328
|
-
uint8(nonce)
|
|
329
|
-
);
|
|
281
|
+
data = abi.encodePacked(bytes1(0xd7), len, deployer, bytes1(0x81), uint8(nonce));
|
|
330
282
|
} else if (nonce <= type(uint16).max) {
|
|
331
|
-
data = abi.encodePacked(
|
|
332
|
-
bytes1(0xd8),
|
|
333
|
-
len,
|
|
334
|
-
deployer,
|
|
335
|
-
bytes1(0x82),
|
|
336
|
-
uint16(nonce)
|
|
337
|
-
);
|
|
283
|
+
data = abi.encodePacked(bytes1(0xd8), len, deployer, bytes1(0x82), uint16(nonce));
|
|
338
284
|
} else if (nonce <= type(uint24).max) {
|
|
339
|
-
data = abi.encodePacked(
|
|
340
|
-
bytes1(0xd9),
|
|
341
|
-
len,
|
|
342
|
-
deployer,
|
|
343
|
-
bytes1(0x83),
|
|
344
|
-
uint24(nonce)
|
|
345
|
-
);
|
|
285
|
+
data = abi.encodePacked(bytes1(0xd9), len, deployer, bytes1(0x83), uint24(nonce));
|
|
346
286
|
} else if (nonce <= type(uint32).max) {
|
|
347
|
-
data = abi.encodePacked(
|
|
348
|
-
bytes1(0xda),
|
|
349
|
-
len,
|
|
350
|
-
deployer,
|
|
351
|
-
bytes1(0x84),
|
|
352
|
-
uint32(nonce)
|
|
353
|
-
);
|
|
287
|
+
data = abi.encodePacked(bytes1(0xda), len, deployer, bytes1(0x84), uint32(nonce));
|
|
354
288
|
} else if (nonce <= type(uint40).max) {
|
|
355
|
-
data = abi.encodePacked(
|
|
356
|
-
bytes1(0xdb),
|
|
357
|
-
len,
|
|
358
|
-
deployer,
|
|
359
|
-
bytes1(0x85),
|
|
360
|
-
uint40(nonce)
|
|
361
|
-
);
|
|
289
|
+
data = abi.encodePacked(bytes1(0xdb), len, deployer, bytes1(0x85), uint40(nonce));
|
|
362
290
|
} else if (nonce <= type(uint48).max) {
|
|
363
|
-
data = abi.encodePacked(
|
|
364
|
-
bytes1(0xdc),
|
|
365
|
-
len,
|
|
366
|
-
deployer,
|
|
367
|
-
bytes1(0x86),
|
|
368
|
-
uint48(nonce)
|
|
369
|
-
);
|
|
291
|
+
data = abi.encodePacked(bytes1(0xdc), len, deployer, bytes1(0x86), uint48(nonce));
|
|
370
292
|
} else if (nonce <= type(uint56).max) {
|
|
371
|
-
data = abi.encodePacked(
|
|
372
|
-
bytes1(0xdd),
|
|
373
|
-
len,
|
|
374
|
-
deployer,
|
|
375
|
-
bytes1(0x87),
|
|
376
|
-
uint56(nonce)
|
|
377
|
-
);
|
|
293
|
+
data = abi.encodePacked(bytes1(0xdd), len, deployer, bytes1(0x87), uint56(nonce));
|
|
378
294
|
} else {
|
|
379
|
-
data = abi.encodePacked(
|
|
380
|
-
bytes1(0xde),
|
|
381
|
-
len,
|
|
382
|
-
deployer,
|
|
383
|
-
bytes1(0x88),
|
|
384
|
-
uint64(nonce)
|
|
385
|
-
);
|
|
295
|
+
data = abi.encodePacked(bytes1(0xde), len, deployer, bytes1(0x88), uint64(nonce));
|
|
386
296
|
}
|
|
387
297
|
|
|
388
298
|
computedAddress = address(uint160(uint256(keccak256(data))));
|
|
@@ -401,9 +311,7 @@ contract CreateX {
|
|
|
401
311
|
* @param nonce The next 32-byte nonce of this contract.
|
|
402
312
|
* @return computedAddress The 20-byte address where a contract will be stored.
|
|
403
313
|
*/
|
|
404
|
-
function computeCreateAddress(
|
|
405
|
-
uint256 nonce
|
|
406
|
-
) public view returns (address computedAddress) {
|
|
314
|
+
function computeCreateAddress(uint256 nonce) public view returns (address computedAddress) {
|
|
407
315
|
computedAddress = computeCreateAddress({deployer: _SELF, nonce: nonce});
|
|
408
316
|
}
|
|
409
317
|
|
|
@@ -420,18 +328,10 @@ contract CreateX {
|
|
|
420
328
|
* @param initCode The creation bytecode.
|
|
421
329
|
* @return newContract The 20-byte address where the contract was deployed.
|
|
422
330
|
*/
|
|
423
|
-
function deployCreate2(
|
|
424
|
-
bytes32 salt,
|
|
425
|
-
bytes memory initCode
|
|
426
|
-
) public payable returns (address newContract) {
|
|
331
|
+
function deployCreate2(bytes32 salt, bytes memory initCode) public payable returns (address newContract) {
|
|
427
332
|
bytes32 guardedSalt = _guard({salt: salt});
|
|
428
333
|
assembly ("memory-safe") {
|
|
429
|
-
newContract := create2(
|
|
430
|
-
callvalue(),
|
|
431
|
-
add(initCode, 0x20),
|
|
432
|
-
mload(initCode),
|
|
433
|
-
guardedSalt
|
|
434
|
-
)
|
|
334
|
+
newContract := create2(callvalue(), add(initCode, 0x20), mload(initCode), guardedSalt)
|
|
435
335
|
}
|
|
436
336
|
_requireSuccessfulContractCreation({newContract: newContract});
|
|
437
337
|
emit ContractCreation({newContract: newContract, salt: guardedSalt});
|
|
@@ -446,15 +346,10 @@ contract CreateX {
|
|
|
446
346
|
* @param initCode The creation bytecode.
|
|
447
347
|
* @return newContract The 20-byte address where the contract was deployed.
|
|
448
348
|
*/
|
|
449
|
-
function deployCreate2(
|
|
450
|
-
bytes memory initCode
|
|
451
|
-
) public payable returns (address newContract) {
|
|
349
|
+
function deployCreate2(bytes memory initCode) public payable returns (address newContract) {
|
|
452
350
|
// Note that the safeguarding function `_guard` is called as part of the overloaded function
|
|
453
351
|
// `deployCreate2`.
|
|
454
|
-
newContract = deployCreate2({
|
|
455
|
-
salt: _generateSalt(),
|
|
456
|
-
initCode: initCode
|
|
457
|
-
});
|
|
352
|
+
newContract = deployCreate2({salt: _generateSalt(), initCode: initCode});
|
|
458
353
|
}
|
|
459
354
|
|
|
460
355
|
/**
|
|
@@ -482,37 +377,22 @@ contract CreateX {
|
|
|
482
377
|
) public payable returns (address newContract) {
|
|
483
378
|
bytes32 guardedSalt = _guard({salt: salt});
|
|
484
379
|
assembly ("memory-safe") {
|
|
485
|
-
newContract := create2(
|
|
486
|
-
mload(values),
|
|
487
|
-
add(initCode, 0x20),
|
|
488
|
-
mload(initCode),
|
|
489
|
-
guardedSalt
|
|
490
|
-
)
|
|
380
|
+
newContract := create2(mload(values), add(initCode, 0x20), mload(initCode), guardedSalt)
|
|
491
381
|
}
|
|
492
382
|
_requireSuccessfulContractCreation({newContract: newContract});
|
|
493
383
|
emit ContractCreation({newContract: newContract, salt: guardedSalt});
|
|
494
384
|
|
|
495
|
-
(bool success, bytes memory returnData) = newContract.call{
|
|
496
|
-
value: values.initCallAmount
|
|
497
|
-
}(data);
|
|
385
|
+
(bool success, bytes memory returnData) = newContract.call{value: values.initCallAmount}(data);
|
|
498
386
|
if (!success) {
|
|
499
|
-
revert FailedContractInitialisation({
|
|
500
|
-
emitter: _SELF,
|
|
501
|
-
revertData: returnData
|
|
502
|
-
});
|
|
387
|
+
revert FailedContractInitialisation({emitter: _SELF, revertData: returnData});
|
|
503
388
|
}
|
|
504
389
|
|
|
505
390
|
if (_SELF.balance != 0) {
|
|
506
391
|
// Any wei amount previously forced into this contract (e.g. by using the `SELFDESTRUCT`
|
|
507
392
|
// opcode) will be part of the refund transaction.
|
|
508
|
-
(success, returnData) = refundAddress.call{value: _SELF.balance}(
|
|
509
|
-
""
|
|
510
|
-
);
|
|
393
|
+
(success, returnData) = refundAddress.call{value: _SELF.balance}("");
|
|
511
394
|
if (!success) {
|
|
512
|
-
revert FailedEtherTransfer({
|
|
513
|
-
emitter: _SELF,
|
|
514
|
-
revertData: returnData
|
|
515
|
-
});
|
|
395
|
+
revert FailedEtherTransfer({emitter: _SELF, revertData: returnData});
|
|
516
396
|
}
|
|
517
397
|
}
|
|
518
398
|
}
|
|
@@ -532,12 +412,11 @@ contract CreateX {
|
|
|
532
412
|
* a mutex lock to keep it as use-case agnostic as possible. Please ensure at the protocol
|
|
533
413
|
* level that potentially malicious reentrant calls do not affect your smart contract system.
|
|
534
414
|
*/
|
|
535
|
-
function deployCreate2AndInit(
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
) public payable returns (address newContract) {
|
|
415
|
+
function deployCreate2AndInit(bytes32 salt, bytes memory initCode, bytes memory data, Values memory values)
|
|
416
|
+
public
|
|
417
|
+
payable
|
|
418
|
+
returns (address newContract)
|
|
419
|
+
{
|
|
541
420
|
// Note that the safeguarding function `_guard` is called as part of the overloaded function
|
|
542
421
|
// `deployCreate2AndInit`.
|
|
543
422
|
newContract = deployCreate2AndInit({
|
|
@@ -566,12 +445,11 @@ contract CreateX {
|
|
|
566
445
|
* a mutex lock to keep it as use-case agnostic as possible. Please ensure at the protocol
|
|
567
446
|
* level that potentially malicious reentrant calls do not affect your smart contract system.
|
|
568
447
|
*/
|
|
569
|
-
function deployCreate2AndInit(
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
) public payable returns (address newContract) {
|
|
448
|
+
function deployCreate2AndInit(bytes memory initCode, bytes memory data, Values memory values, address refundAddress)
|
|
449
|
+
public
|
|
450
|
+
payable
|
|
451
|
+
returns (address newContract)
|
|
452
|
+
{
|
|
575
453
|
// Note that the safeguarding function `_guard` is called as part of the overloaded function
|
|
576
454
|
// `deployCreate2AndInit`.
|
|
577
455
|
newContract = deployCreate2AndInit({
|
|
@@ -599,11 +477,11 @@ contract CreateX {
|
|
|
599
477
|
* a mutex lock to keep it as use-case agnostic as possible. Please ensure at the protocol
|
|
600
478
|
* level that potentially malicious reentrant calls do not affect your smart contract system.
|
|
601
479
|
*/
|
|
602
|
-
function deployCreate2AndInit(
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
480
|
+
function deployCreate2AndInit(bytes memory initCode, bytes memory data, Values memory values)
|
|
481
|
+
public
|
|
482
|
+
payable
|
|
483
|
+
returns (address newContract)
|
|
484
|
+
{
|
|
607
485
|
// Note that the safeguarding function `_guard` is called as part of the overloaded function
|
|
608
486
|
// `deployCreate2AndInit`.
|
|
609
487
|
newContract = deployCreate2AndInit({
|
|
@@ -628,24 +506,18 @@ contract CreateX {
|
|
|
628
506
|
* a mutex lock to keep it as use-case agnostic as possible. Please ensure at the protocol
|
|
629
507
|
* level that potentially malicious reentrant calls do not affect your smart contract system.
|
|
630
508
|
*/
|
|
631
|
-
function deployCreate2Clone(
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
509
|
+
function deployCreate2Clone(bytes32 salt, address implementation, bytes memory data)
|
|
510
|
+
public
|
|
511
|
+
payable
|
|
512
|
+
returns (address proxy)
|
|
513
|
+
{
|
|
636
514
|
bytes32 guardedSalt = _guard({salt: salt});
|
|
637
515
|
bytes20 implementationInBytes = bytes20(implementation);
|
|
638
516
|
assembly ("memory-safe") {
|
|
639
517
|
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
|
-
)
|
|
518
|
+
mstore(clone, hex"3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000")
|
|
644
519
|
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
|
-
)
|
|
520
|
+
mstore(add(clone, 0x28), hex"5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000")
|
|
649
521
|
proxy := create2(0, clone, 0x37, guardedSalt)
|
|
650
522
|
}
|
|
651
523
|
if (proxy == address(0)) {
|
|
@@ -653,9 +525,7 @@ contract CreateX {
|
|
|
653
525
|
}
|
|
654
526
|
emit ContractCreation({newContract: proxy, salt: guardedSalt});
|
|
655
527
|
|
|
656
|
-
(bool success, bytes memory returnData) = proxy.call{value: msg.value}(
|
|
657
|
-
data
|
|
658
|
-
);
|
|
528
|
+
(bool success, bytes memory returnData) = proxy.call{value: msg.value}(data);
|
|
659
529
|
_requireSuccessfulContractInitialisation({
|
|
660
530
|
success: success,
|
|
661
531
|
returnData: returnData,
|
|
@@ -677,17 +547,10 @@ contract CreateX {
|
|
|
677
547
|
* a mutex lock to keep it as use-case agnostic as possible. Please ensure at the protocol
|
|
678
548
|
* level that potentially malicious reentrant calls do not affect your smart contract system.
|
|
679
549
|
*/
|
|
680
|
-
function deployCreate2Clone(
|
|
681
|
-
address implementation,
|
|
682
|
-
bytes memory data
|
|
683
|
-
) public payable returns (address proxy) {
|
|
550
|
+
function deployCreate2Clone(address implementation, bytes memory data) public payable returns (address proxy) {
|
|
684
551
|
// Note that the safeguarding function `_guard` is called as part of the overloaded function
|
|
685
552
|
// `deployCreate2Clone`.
|
|
686
|
-
proxy = deployCreate2Clone({
|
|
687
|
-
salt: _generateSalt(),
|
|
688
|
-
implementation: implementation,
|
|
689
|
-
data: data
|
|
690
|
-
});
|
|
553
|
+
proxy = deployCreate2Clone({salt: _generateSalt(), implementation: implementation, data: data});
|
|
691
554
|
}
|
|
692
555
|
|
|
693
556
|
/**
|
|
@@ -700,11 +563,11 @@ contract CreateX {
|
|
|
700
563
|
* @param deployer The 20-byte deployer address.
|
|
701
564
|
* @return computedAddress The 20-byte address where a contract will be stored.
|
|
702
565
|
*/
|
|
703
|
-
function computeCreate2Address(
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
address
|
|
707
|
-
|
|
566
|
+
function computeCreate2Address(bytes32 salt, bytes32 initCodeHash, address deployer)
|
|
567
|
+
public
|
|
568
|
+
pure
|
|
569
|
+
returns (address computedAddress)
|
|
570
|
+
{
|
|
708
571
|
assembly ("memory-safe") {
|
|
709
572
|
// | | ↓ ptr ... ↓ ptr + 0x0B (start) ... ↓ ptr + 0x20 ... ↓ ptr + 0x40 ... |
|
|
710
573
|
// |----------------------|---------------------------------------------------------------------------|
|
|
@@ -733,15 +596,8 @@ contract CreateX {
|
|
|
733
596
|
* @param initCodeHash The 32-byte bytecode digest of the contract creation bytecode.
|
|
734
597
|
* @return computedAddress The 20-byte address where a contract will be stored.
|
|
735
598
|
*/
|
|
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
|
-
});
|
|
599
|
+
function computeCreate2Address(bytes32 salt, bytes32 initCodeHash) public view returns (address computedAddress) {
|
|
600
|
+
computedAddress = computeCreate2Address({salt: salt, initCodeHash: initCodeHash, deployer: _SELF});
|
|
745
601
|
}
|
|
746
602
|
|
|
747
603
|
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
@@ -762,36 +618,21 @@ contract CreateX {
|
|
|
762
618
|
* the first 20 bytes equal to `msg.sender` in the `salt` to prevent maliciously intended frontrun
|
|
763
619
|
* proxy deployments on other chains.
|
|
764
620
|
*/
|
|
765
|
-
function deployCreate3(
|
|
766
|
-
bytes32 salt,
|
|
767
|
-
bytes memory initCode
|
|
768
|
-
) public payable returns (address newContract) {
|
|
621
|
+
function deployCreate3(bytes32 salt, bytes memory initCode) public payable returns (address newContract) {
|
|
769
622
|
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";
|
|
623
|
+
bytes memory proxyChildBytecode = hex"67363d3d37363d34f03d5260086018f3";
|
|
772
624
|
address proxy;
|
|
773
625
|
assembly ("memory-safe") {
|
|
774
|
-
proxy := create2(
|
|
775
|
-
0,
|
|
776
|
-
add(proxyChildBytecode, 32),
|
|
777
|
-
mload(proxyChildBytecode),
|
|
778
|
-
guardedSalt
|
|
779
|
-
)
|
|
626
|
+
proxy := create2(0, add(proxyChildBytecode, 32), mload(proxyChildBytecode), guardedSalt)
|
|
780
627
|
}
|
|
781
628
|
if (proxy == address(0)) {
|
|
782
629
|
revert FailedContractCreation({emitter: _SELF});
|
|
783
630
|
}
|
|
784
|
-
emit Create3ProxyContractCreation({
|
|
785
|
-
newContract: proxy,
|
|
786
|
-
salt: guardedSalt
|
|
787
|
-
});
|
|
631
|
+
emit Create3ProxyContractCreation({newContract: proxy, salt: guardedSalt});
|
|
788
632
|
|
|
789
633
|
newContract = computeCreate3Address({salt: guardedSalt});
|
|
790
|
-
(bool success,
|
|
791
|
-
_requireSuccessfulContractCreation({
|
|
792
|
-
success: success,
|
|
793
|
-
newContract: newContract
|
|
794
|
-
});
|
|
634
|
+
(bool success,) = proxy.call{value: msg.value}(initCode);
|
|
635
|
+
_requireSuccessfulContractCreation({success: success, newContract: newContract});
|
|
795
636
|
emit ContractCreation({newContract: newContract});
|
|
796
637
|
}
|
|
797
638
|
|
|
@@ -806,15 +647,10 @@ contract CreateX {
|
|
|
806
647
|
* @param initCode The creation bytecode.
|
|
807
648
|
* @return newContract The 20-byte address where the contract was deployed.
|
|
808
649
|
*/
|
|
809
|
-
function deployCreate3(
|
|
810
|
-
bytes memory initCode
|
|
811
|
-
) public payable returns (address newContract) {
|
|
650
|
+
function deployCreate3(bytes memory initCode) public payable returns (address newContract) {
|
|
812
651
|
// Note that the safeguarding function `_guard` is called as part of the overloaded function
|
|
813
652
|
// `deployCreate3`.
|
|
814
|
-
newContract = deployCreate3({
|
|
815
|
-
salt: _generateSalt(),
|
|
816
|
-
initCode: initCode
|
|
817
|
-
});
|
|
653
|
+
newContract = deployCreate3({salt: _generateSalt(), initCode: initCode});
|
|
818
654
|
}
|
|
819
655
|
|
|
820
656
|
/**
|
|
@@ -846,57 +682,33 @@ contract CreateX {
|
|
|
846
682
|
address refundAddress
|
|
847
683
|
) public payable returns (address newContract) {
|
|
848
684
|
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";
|
|
685
|
+
bytes memory proxyChildBytecode = hex"67363d3d37363d34f03d5260086018f3";
|
|
851
686
|
address proxy;
|
|
852
687
|
assembly ("memory-safe") {
|
|
853
|
-
proxy := create2(
|
|
854
|
-
0,
|
|
855
|
-
add(proxyChildBytecode, 32),
|
|
856
|
-
mload(proxyChildBytecode),
|
|
857
|
-
guardedSalt
|
|
858
|
-
)
|
|
688
|
+
proxy := create2(0, add(proxyChildBytecode, 32), mload(proxyChildBytecode), guardedSalt)
|
|
859
689
|
}
|
|
860
690
|
if (proxy == address(0)) {
|
|
861
691
|
revert FailedContractCreation({emitter: _SELF});
|
|
862
692
|
}
|
|
863
|
-
emit Create3ProxyContractCreation({
|
|
864
|
-
newContract: proxy,
|
|
865
|
-
salt: guardedSalt
|
|
866
|
-
});
|
|
693
|
+
emit Create3ProxyContractCreation({newContract: proxy, salt: guardedSalt});
|
|
867
694
|
|
|
868
695
|
newContract = computeCreate3Address({salt: guardedSalt});
|
|
869
|
-
(bool success,
|
|
870
|
-
|
|
871
|
-
);
|
|
872
|
-
_requireSuccessfulContractCreation({
|
|
873
|
-
success: success,
|
|
874
|
-
newContract: newContract
|
|
875
|
-
});
|
|
696
|
+
(bool success,) = proxy.call{value: values.constructorAmount}(initCode);
|
|
697
|
+
_requireSuccessfulContractCreation({success: success, newContract: newContract});
|
|
876
698
|
emit ContractCreation({newContract: newContract});
|
|
877
699
|
|
|
878
700
|
bytes memory returnData;
|
|
879
|
-
(success, returnData) = newContract.call{value: values.initCallAmount}(
|
|
880
|
-
data
|
|
881
|
-
);
|
|
701
|
+
(success, returnData) = newContract.call{value: values.initCallAmount}(data);
|
|
882
702
|
if (!success) {
|
|
883
|
-
revert FailedContractInitialisation({
|
|
884
|
-
emitter: _SELF,
|
|
885
|
-
revertData: returnData
|
|
886
|
-
});
|
|
703
|
+
revert FailedContractInitialisation({emitter: _SELF, revertData: returnData});
|
|
887
704
|
}
|
|
888
705
|
|
|
889
706
|
if (_SELF.balance != 0) {
|
|
890
707
|
// Any wei amount previously forced into this contract (e.g. by using the `SELFDESTRUCT`
|
|
891
708
|
// opcode) will be part of the refund transaction.
|
|
892
|
-
(success, returnData) = refundAddress.call{value: _SELF.balance}(
|
|
893
|
-
""
|
|
894
|
-
);
|
|
709
|
+
(success, returnData) = refundAddress.call{value: _SELF.balance}("");
|
|
895
710
|
if (!success) {
|
|
896
|
-
revert FailedEtherTransfer({
|
|
897
|
-
emitter: _SELF,
|
|
898
|
-
revertData: returnData
|
|
899
|
-
});
|
|
711
|
+
revert FailedEtherTransfer({emitter: _SELF, revertData: returnData});
|
|
900
712
|
}
|
|
901
713
|
}
|
|
902
714
|
}
|
|
@@ -921,12 +733,11 @@ contract CreateX {
|
|
|
921
733
|
* the first 20 bytes equal to `msg.sender` in the `salt` to prevent maliciously intended frontrun
|
|
922
734
|
* proxy deployments on other chains.
|
|
923
735
|
*/
|
|
924
|
-
function deployCreate3AndInit(
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
) public payable returns (address newContract) {
|
|
736
|
+
function deployCreate3AndInit(bytes32 salt, bytes memory initCode, bytes memory data, Values memory values)
|
|
737
|
+
public
|
|
738
|
+
payable
|
|
739
|
+
returns (address newContract)
|
|
740
|
+
{
|
|
930
741
|
// Note that the safeguarding function `_guard` is called as part of the overloaded function
|
|
931
742
|
// `deployCreate3AndInit`.
|
|
932
743
|
newContract = deployCreate3AndInit({
|
|
@@ -956,12 +767,11 @@ contract CreateX {
|
|
|
956
767
|
* a mutex lock to keep it as use-case agnostic as possible. Please ensure at the protocol
|
|
957
768
|
* level that potentially malicious reentrant calls do not affect your smart contract system.
|
|
958
769
|
*/
|
|
959
|
-
function deployCreate3AndInit(
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
) public payable returns (address newContract) {
|
|
770
|
+
function deployCreate3AndInit(bytes memory initCode, bytes memory data, Values memory values, address refundAddress)
|
|
771
|
+
public
|
|
772
|
+
payable
|
|
773
|
+
returns (address newContract)
|
|
774
|
+
{
|
|
965
775
|
// Note that the safeguarding function `_guard` is called as part of the overloaded function
|
|
966
776
|
// `deployCreate3AndInit`.
|
|
967
777
|
newContract = deployCreate3AndInit({
|
|
@@ -990,11 +800,11 @@ contract CreateX {
|
|
|
990
800
|
* a mutex lock to keep it as use-case agnostic as possible. Please ensure at the protocol
|
|
991
801
|
* level that potentially malicious reentrant calls do not affect your smart contract system.
|
|
992
802
|
*/
|
|
993
|
-
function deployCreate3AndInit(
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
803
|
+
function deployCreate3AndInit(bytes memory initCode, bytes memory data, Values memory values)
|
|
804
|
+
public
|
|
805
|
+
payable
|
|
806
|
+
returns (address newContract)
|
|
807
|
+
{
|
|
998
808
|
// Note that the safeguarding function `_guard` is called as part of the overloaded function
|
|
999
809
|
// `deployCreate3AndInit`.
|
|
1000
810
|
newContract = deployCreate3AndInit({
|
|
@@ -1015,19 +825,13 @@ contract CreateX {
|
|
|
1015
825
|
* @param deployer The 20-byte deployer address.
|
|
1016
826
|
* @return computedAddress The 20-byte address where a contract will be stored.
|
|
1017
827
|
*/
|
|
1018
|
-
function computeCreate3Address(
|
|
1019
|
-
bytes32 salt,
|
|
1020
|
-
address deployer
|
|
1021
|
-
) public pure returns (address computedAddress) {
|
|
828
|
+
function computeCreate3Address(bytes32 salt, address deployer) public pure returns (address computedAddress) {
|
|
1022
829
|
assembly ("memory-safe") {
|
|
1023
830
|
let ptr := mload(0x40)
|
|
1024
831
|
mstore(0x00, deployer)
|
|
1025
832
|
mstore8(0x0b, 0xff)
|
|
1026
833
|
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
|
-
)
|
|
834
|
+
mstore(0x40, hex"21c35dbe1b344a2488cf3321d6ce542f8e9f305544ff09e4993a62319a497c1f")
|
|
1031
835
|
mstore(0x14, keccak256(0x0b, 0x55))
|
|
1032
836
|
mstore(0x40, ptr)
|
|
1033
837
|
mstore(0x00, 0xd694)
|
|
@@ -1044,9 +848,7 @@ contract CreateX {
|
|
|
1044
848
|
* @param salt The 32-byte random value used to create the proxy contract address.
|
|
1045
849
|
* @return computedAddress The 20-byte address where a contract will be stored.
|
|
1046
850
|
*/
|
|
1047
|
-
function computeCreate3Address(
|
|
1048
|
-
bytes32 salt
|
|
1049
|
-
) public view returns (address computedAddress) {
|
|
851
|
+
function computeCreate3Address(bytes32 salt) public view returns (address computedAddress) {
|
|
1050
852
|
computedAddress = computeCreate3Address({salt: salt, deployer: _SELF});
|
|
1051
853
|
}
|
|
1052
854
|
|
|
@@ -1068,50 +870,30 @@ contract CreateX {
|
|
|
1068
870
|
* @return guardedSalt The guarded 32-byte random value used to create the contract address.
|
|
1069
871
|
*/
|
|
1070
872
|
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
|
-
) {
|
|
873
|
+
(SenderBytes senderBytes, RedeployProtectionFlag redeployProtectionFlag) = _parseSalt({salt: salt});
|
|
874
|
+
|
|
875
|
+
if (senderBytes == SenderBytes.MsgSender && redeployProtectionFlag == RedeployProtectionFlag.True) {
|
|
1080
876
|
// 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
|
-
) {
|
|
877
|
+
guardedSalt = keccak256(abi.encode(msg.sender, block.chainid, salt));
|
|
878
|
+
} else if (senderBytes == SenderBytes.MsgSender && redeployProtectionFlag == RedeployProtectionFlag.False) {
|
|
1088
879
|
// Configures solely a permissioned deploy protection.
|
|
1089
|
-
guardedSalt = _efficientHash({
|
|
1090
|
-
a: bytes32(uint256(uint160(msg.sender))),
|
|
1091
|
-
b: salt
|
|
1092
|
-
});
|
|
880
|
+
guardedSalt = _efficientHash({a: bytes32(uint256(uint160(msg.sender))), b: salt});
|
|
1093
881
|
} else if (senderBytes == SenderBytes.MsgSender) {
|
|
1094
882
|
// Reverts if the 21st byte is greater than `0x01` in order to enforce developer explicitness.
|
|
1095
883
|
revert InvalidSalt({emitter: _SELF});
|
|
1096
|
-
} else if (
|
|
1097
|
-
senderBytes == SenderBytes.ZeroAddress &&
|
|
1098
|
-
redeployProtectionFlag == RedeployProtectionFlag.True
|
|
1099
|
-
) {
|
|
884
|
+
} else if (senderBytes == SenderBytes.ZeroAddress && redeployProtectionFlag == RedeployProtectionFlag.True) {
|
|
1100
885
|
// Configures solely a cross-chain redeploy protection. In order to prevent a pseudo-randomly
|
|
1101
886
|
// generated cross-chain redeploy protection, we enforce the zero address check for the first 20 bytes.
|
|
1102
887
|
guardedSalt = _efficientHash({a: bytes32(block.chainid), b: salt});
|
|
1103
888
|
} else if (
|
|
1104
|
-
senderBytes == SenderBytes.ZeroAddress &&
|
|
1105
|
-
redeployProtectionFlag == RedeployProtectionFlag.Unspecified
|
|
889
|
+
senderBytes == SenderBytes.ZeroAddress && redeployProtectionFlag == RedeployProtectionFlag.Unspecified
|
|
1106
890
|
) {
|
|
1107
891
|
// Reverts if the 21st byte is greater than `0x01` in order to enforce developer explicitness.
|
|
1108
892
|
revert InvalidSalt({emitter: _SELF});
|
|
1109
893
|
} else {
|
|
1110
894
|
// For the non-pseudo-random cases, the salt value `salt` is hashed to prevent the safeguard mechanisms
|
|
1111
895
|
// from being bypassed. Otherwise, the salt value `salt` is not modified.
|
|
1112
|
-
guardedSalt = (salt != _generateSalt())
|
|
1113
|
-
? keccak256(abi.encode(salt))
|
|
1114
|
-
: salt;
|
|
896
|
+
guardedSalt = (salt != _generateSalt()) ? keccak256(abi.encode(salt)) : salt;
|
|
1115
897
|
}
|
|
1116
898
|
}
|
|
1117
899
|
|
|
@@ -1123,69 +905,29 @@ contract CreateX {
|
|
|
1123
905
|
* @return redeployProtectionFlag The 8-byte enum for the selection of a cross-chain redeploy
|
|
1124
906
|
* protection.
|
|
1125
907
|
*/
|
|
1126
|
-
function _parseSalt(
|
|
1127
|
-
bytes32 salt
|
|
1128
|
-
)
|
|
908
|
+
function _parseSalt(bytes32 salt)
|
|
1129
909
|
internal
|
|
1130
910
|
view
|
|
1131
|
-
returns (
|
|
1132
|
-
SenderBytes senderBytes,
|
|
1133
|
-
RedeployProtectionFlag redeployProtectionFlag
|
|
1134
|
-
)
|
|
911
|
+
returns (SenderBytes senderBytes, RedeployProtectionFlag redeployProtectionFlag)
|
|
1135
912
|
{
|
|
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
|
-
);
|
|
913
|
+
if (address(bytes20(salt)) == msg.sender && bytes1(salt[20]) == hex"01") {
|
|
914
|
+
(senderBytes, redeployProtectionFlag) = (SenderBytes.MsgSender, RedeployProtectionFlag.True);
|
|
915
|
+
} else if (address(bytes20(salt)) == msg.sender && bytes1(salt[20]) == hex"00") {
|
|
916
|
+
(senderBytes, redeployProtectionFlag) = (SenderBytes.MsgSender, RedeployProtectionFlag.False);
|
|
1150
917
|
} 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
|
-
);
|
|
918
|
+
(senderBytes, redeployProtectionFlag) = (SenderBytes.MsgSender, RedeployProtectionFlag.Unspecified);
|
|
919
|
+
} else if (address(bytes20(salt)) == address(0) && bytes1(salt[20]) == hex"01") {
|
|
920
|
+
(senderBytes, redeployProtectionFlag) = (SenderBytes.ZeroAddress, RedeployProtectionFlag.True);
|
|
921
|
+
} else if (address(bytes20(salt)) == address(0) && bytes1(salt[20]) == hex"00") {
|
|
922
|
+
(senderBytes, redeployProtectionFlag) = (SenderBytes.ZeroAddress, RedeployProtectionFlag.False);
|
|
1169
923
|
} else if (address(bytes20(salt)) == address(0)) {
|
|
1170
|
-
(senderBytes, redeployProtectionFlag) = (
|
|
1171
|
-
SenderBytes.ZeroAddress,
|
|
1172
|
-
RedeployProtectionFlag.Unspecified
|
|
1173
|
-
);
|
|
924
|
+
(senderBytes, redeployProtectionFlag) = (SenderBytes.ZeroAddress, RedeployProtectionFlag.Unspecified);
|
|
1174
925
|
} else if (bytes1(salt[20]) == hex"01") {
|
|
1175
|
-
(senderBytes, redeployProtectionFlag) = (
|
|
1176
|
-
SenderBytes.Random,
|
|
1177
|
-
RedeployProtectionFlag.True
|
|
1178
|
-
);
|
|
926
|
+
(senderBytes, redeployProtectionFlag) = (SenderBytes.Random, RedeployProtectionFlag.True);
|
|
1179
927
|
} else if (bytes1(salt[20]) == hex"00") {
|
|
1180
|
-
(senderBytes, redeployProtectionFlag) = (
|
|
1181
|
-
SenderBytes.Random,
|
|
1182
|
-
RedeployProtectionFlag.False
|
|
1183
|
-
);
|
|
928
|
+
(senderBytes, redeployProtectionFlag) = (SenderBytes.Random, RedeployProtectionFlag.False);
|
|
1184
929
|
} else {
|
|
1185
|
-
(senderBytes, redeployProtectionFlag) = (
|
|
1186
|
-
SenderBytes.Random,
|
|
1187
|
-
RedeployProtectionFlag.Unspecified
|
|
1188
|
-
);
|
|
930
|
+
(senderBytes, redeployProtectionFlag) = (SenderBytes.Random, RedeployProtectionFlag.Unspecified);
|
|
1189
931
|
}
|
|
1190
932
|
}
|
|
1191
933
|
|
|
@@ -1195,10 +937,7 @@ contract CreateX {
|
|
|
1195
937
|
* @param b The second 32-byte value to be concatenated and hashed.
|
|
1196
938
|
* @return hash The 32-byte `keccak256` hash of `a` and `b`.
|
|
1197
939
|
*/
|
|
1198
|
-
function _efficientHash(
|
|
1199
|
-
bytes32 a,
|
|
1200
|
-
bytes32 b
|
|
1201
|
-
) internal pure returns (bytes32 hash) {
|
|
940
|
+
function _efficientHash(bytes32 a, bytes32 b) internal pure returns (bytes32 hash) {
|
|
1202
941
|
assembly ("memory-safe") {
|
|
1203
942
|
mstore(0x00, a)
|
|
1204
943
|
mstore(0x20, b)
|
|
@@ -1241,21 +980,14 @@ contract CreateX {
|
|
|
1241
980
|
* @param success The Boolean success condition.
|
|
1242
981
|
* @param newContract The 20-byte address where the contract was deployed.
|
|
1243
982
|
*/
|
|
1244
|
-
function _requireSuccessfulContractCreation(
|
|
1245
|
-
bool success,
|
|
1246
|
-
address newContract
|
|
1247
|
-
) internal view {
|
|
983
|
+
function _requireSuccessfulContractCreation(bool success, address newContract) internal view {
|
|
1248
984
|
// Note that reverting if `newContract == address(0)` isn't strictly necessary here, as if
|
|
1249
985
|
// the deployment fails, `success == false` should already hold. However, since the `CreateX`
|
|
1250
986
|
// contract should be usable and safe on a wide range of chains, this check is cheap enough
|
|
1251
987
|
// that there is no harm in including it (security > gas optimisations). It can potentially
|
|
1252
988
|
// protect against unexpected chain behaviour or a hypothetical compiler bug that doesn't surface
|
|
1253
989
|
// the call success status properly.
|
|
1254
|
-
if (
|
|
1255
|
-
!success ||
|
|
1256
|
-
newContract == address(0) ||
|
|
1257
|
-
newContract.code.length == 0
|
|
1258
|
-
) {
|
|
990
|
+
if (!success || newContract == address(0) || newContract.code.length == 0) {
|
|
1259
991
|
revert FailedContractCreation({emitter: _SELF});
|
|
1260
992
|
}
|
|
1261
993
|
}
|
|
@@ -1264,9 +996,7 @@ contract CreateX {
|
|
|
1264
996
|
* @dev Ensures that `newContract` is a non-zero byte contract.
|
|
1265
997
|
* @param newContract The 20-byte address where the contract was deployed.
|
|
1266
998
|
*/
|
|
1267
|
-
function _requireSuccessfulContractCreation(
|
|
1268
|
-
address newContract
|
|
1269
|
-
) internal view {
|
|
999
|
+
function _requireSuccessfulContractCreation(address newContract) internal view {
|
|
1270
1000
|
if (newContract == address(0) || newContract.code.length == 0) {
|
|
1271
1001
|
revert FailedContractCreation({emitter: _SELF});
|
|
1272
1002
|
}
|
|
@@ -1278,16 +1008,13 @@ contract CreateX {
|
|
|
1278
1008
|
* @param returnData The return data from the contract initialisation call.
|
|
1279
1009
|
* @param implementation The 20-byte address where the implementation was deployed.
|
|
1280
1010
|
*/
|
|
1281
|
-
function _requireSuccessfulContractInitialisation(
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
) internal view {
|
|
1011
|
+
function _requireSuccessfulContractInitialisation(bool success, bytes memory returnData, address implementation)
|
|
1012
|
+
internal
|
|
1013
|
+
view
|
|
1014
|
+
{
|
|
1286
1015
|
if (!success || implementation.code.length == 0) {
|
|
1287
|
-
revert FailedContractInitialisation({
|
|
1288
|
-
emitter: _SELF,
|
|
1289
|
-
revertData: returnData
|
|
1290
|
-
});
|
|
1016
|
+
revert FailedContractInitialisation({emitter: _SELF, revertData: returnData});
|
|
1291
1017
|
}
|
|
1292
1018
|
}
|
|
1019
|
+
|
|
1293
1020
|
}
|