Skip to content

Commit fda55ef

Browse files
authored
🥢 Reduce lines (ethereum#634)
1 parent d273d71 commit fda55ef

File tree

2 files changed

+21
-44
lines changed

2 files changed

+21
-44
lines changed

‎.gas-snapshot

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ LibCloneTest:testDeployDeterministicERC1967RevertsIfAddressAlreadyUsed() (gas: 9
508508
LibCloneTest:testDeployERC1967() (gas: 99367)
509509
LibCloneTest:testDeployERC1967(uint256) (runs: 256, μ: 99418, ~: 99418)
510510
LibCloneTest:testInitialDeposit() (gas: 323861)
511-
LibCloneTest:testStartsWithCaller(uint256) (runs: 256, μ: 28162, ~: 28405)
511+
LibCloneTest:testStartsWithCaller(uint256) (runs: 256, μ: 28133, ~: 28405)
512512
LibCloneTest:test__codesize() (gas: 17564)
513513
LibMapTest:testFoundStatementDifferential(uint256,uint256,uint256) (runs: 256, μ: 499, ~: 499)
514514
LibMapTest:testGeneralMapFunctionsGas() (gas: 3304775)
@@ -712,17 +712,17 @@ LibStringTest:testToStringZeroBrutalized() (gas: 613803)
712712
LibStringTest:testToStringZeroRightPadded(uint256) (runs: 256, μ: 718269, ~: 613726)
713713
LibStringTest:test__codesize() (gas: 40236)
714714
LibZipTest:testCdCompress() (gas: 166411)
715-
LibZipTest:testCdCompressDecompress(bytes) (runs: 256, μ: 763819, ~: 651126)
716-
LibZipTest:testCdCompressDecompress(uint256) (runs: 256, μ: 800823, ~: 712072)
715+
LibZipTest:testCdCompressDecompress(bytes) (runs: 256, μ: 736755, ~: 651126)
716+
LibZipTest:testCdCompressDecompress(uint256) (runs: 256, μ: 792317, ~: 709500)
717717
LibZipTest:testCdDecompressOnInvalidInput() (gas: 34920)
718718
LibZipTest:testCdFallback() (gas: 5684348)
719-
LibZipTest:testCdFallback(bytes,uint256) (runs: 256, μ: 1193207, ~: 1044365)
720-
LibZipTest:testCdFallbackDecompressor(bytes) (runs: 256, μ: 121269, ~: 117242)
721-
LibZipTest:testCdFallbackDecompressor(uint256) (runs: 256, μ: 167589, ~: 153865)
722-
LibZipTest:testCdFallbackMaskTrick(uint256,uint256) (runs: 256, μ: 686, ~: 663)
723-
LibZipTest:testDecompressWontRevert(bytes) (runs: 256, μ: 720927, ~: 630393)
719+
LibZipTest:testCdFallback(bytes,uint256) (runs: 256, μ: 1198868, ~: 1044779)
720+
LibZipTest:testCdFallbackDecompressor(bytes) (runs: 256, μ: 121307, ~: 117716)
721+
LibZipTest:testCdFallbackDecompressor(uint256) (runs: 256, μ: 169962, ~: 156242)
722+
LibZipTest:testCdFallbackMaskTrick(uint256,uint256) (runs: 256, μ: 687, ~: 663)
723+
LibZipTest:testDecompressWontRevert(bytes) (runs: 256, μ: 743856, ~: 631132)
724724
LibZipTest:testFlzCompressDecompress() (gas: 2162941)
725-
LibZipTest:testFlzCompressDecompress(bytes) (runs: 256, μ: 890883, ~: 687002)
725+
LibZipTest:testFlzCompressDecompress(bytes) (runs: 256, μ: 851386, ~: 683566)
726726
LibZipTest:testFlzCompressDecompress2() (gas: 1015228)
727727
LibZipTest:test__codesize() (gas: 21762)
728728
MerkleProofLibTest:testEmptyCalldataHelpers() (gas: 1086)

‎src/utils/LibClone.sol

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,11 @@ library LibClone {
114114
mstore(0x14, implementation)
115115
mstore(0x00, 0x602c3d8160093d39f33d3d3d3d363d3d37363d73)
116116
instance := create(value, 0x0c, 0x35)
117-
// If `instance` is zero, revert.
118117
if iszero(instance) {
119118
mstore(0x00, 0x30116425) // `DeploymentFailed()`.
120119
revert(0x1c, 0x04)
121120
}
122-
// Restore the part of the free memory pointer that has been overwritten.
123-
mstore(0x21, 0)
121+
mstore(0x21, 0) // Restore the overwritten part of the free memory pointer.
124122
}
125123
}
126124

@@ -143,13 +141,11 @@ library LibClone {
143141
mstore(0x14, implementation)
144142
mstore(0x00, 0x602c3d8160093d39f33d3d3d3d363d3d37363d73)
145143
instance := create2(value, 0x0c, 0x35, salt)
146-
// If `instance` is zero, revert.
147144
if iszero(instance) {
148145
mstore(0x00, 0x30116425) // `DeploymentFailed()`.
149146
revert(0x1c, 0x04)
150147
}
151-
// Restore the part of the free memory pointer that has been overwritten.
152-
mstore(0x21, 0)
148+
mstore(0x21, 0) // Restore the overwritten part of the free memory pointer.
153149
}
154150
}
155151

@@ -162,8 +158,7 @@ library LibClone {
162158
mstore(0x14, implementation)
163159
mstore(0x00, 0x602c3d8160093d39f33d3d3d3d363d3d37363d73)
164160
hash := keccak256(0x0c, 0x35)
165-
// Restore the part of the free memory pointer that has been overwritten.
166-
mstore(0x21, 0)
161+
mstore(0x21, 0) // Restore the overwritten part of the free memory pointer.
167162
}
168163
}
169164

@@ -257,13 +252,11 @@ library LibClone {
257252
mstore(0x14, implementation) // 20
258253
mstore(0x00, 0x602d5f8160095f39f35f5f365f5f37365f73) // 9 + 9
259254
instance := create(value, 0x0e, 0x36)
260-
// If `instance` is zero, revert.
261255
if iszero(instance) {
262256
mstore(0x00, 0x30116425) // `DeploymentFailed()`.
263257
revert(0x1c, 0x04)
264258
}
265-
// Restore the part of the free memory pointer that has been overwritten.
266-
mstore(0x24, 0)
259+
mstore(0x24, 0) // Restore the overwritten part of the free memory pointer.
267260
}
268261
}
269262

@@ -286,13 +279,11 @@ library LibClone {
286279
mstore(0x14, implementation) // 20
287280
mstore(0x00, 0x602d5f8160095f39f35f5f365f5f37365f73) // 9 + 9
288281
instance := create2(value, 0x0e, 0x36, salt)
289-
// If `instance` is zero, revert.
290282
if iszero(instance) {
291283
mstore(0x00, 0x30116425) // `DeploymentFailed()`.
292284
revert(0x1c, 0x04)
293285
}
294-
// Restore the part of the free memory pointer that has been overwritten.
295-
mstore(0x24, 0)
286+
mstore(0x24, 0) // Restore the overwritten part of the free memory pointer.
296287
}
297288
}
298289

@@ -305,8 +296,7 @@ library LibClone {
305296
mstore(0x14, implementation) // 20
306297
mstore(0x00, 0x602d5f8160095f39f35f5f365f5f37365f73) // 9 + 9
307298
hash := keccak256(0x0e, 0x36)
308-
// Restore the part of the free memory pointer that has been overwritten.
309-
mstore(0x24, 0)
299+
mstore(0x24, 0) // Restore the overwritten part of the free memory pointer.
310300
}
311301
}
312302

@@ -431,10 +421,9 @@ library LibClone {
431421
* f3 | RETURN | | [0..rds): returndata |
432422
* ---------------------------------------------------------------------------------------------------+
433423
*/
434-
// Write the bytecode before the data.
435-
mstore(data, 0x5af43d3d93803e606057fd5bf3)
436-
// Write the address of the implementation.
437-
mstore(sub(data, 0x0d), implementation)
424+
425+
mstore(data, 0x5af43d3d93803e606057fd5bf3) // Write the bytecode before the data.
426+
mstore(sub(data, 0x0d), implementation) // Write the address of the implementation.
438427
// Write the rest of the bytecode.
439428
mstore(
440429
sub(data, 0x21),
@@ -452,10 +441,7 @@ library LibClone {
452441
)
453442
mstore(dataEnd, shl(0xf0, extraLength))
454443

455-
// Create the instance.
456444
instance := create(value, sub(data, 0x4c), add(extraLength, 0x6c))
457-
458-
// If `instance` is zero, revert.
459445
if iszero(instance) {
460446
mstore(0x00, 0x30116425) // `DeploymentFailed()`.
461447
revert(0x1c, 0x04)
@@ -499,10 +485,8 @@ library LibClone {
499485
// +2 bytes for telling how much data there is appended to the call.
500486
let extraLength := add(dataLength, 2)
501487

502-
// Write the bytecode before the data.
503-
mstore(data, 0x5af43d3d93803e606057fd5bf3)
504-
// Write the address of the implementation.
505-
mstore(sub(data, 0x0d), implementation)
488+
mstore(data, 0x5af43d3d93803e606057fd5bf3) // Write the bytecode before the data.
489+
mstore(sub(data, 0x0d), implementation) // Write the address of the implementation.
506490
// Write the rest of the bytecode.
507491
mstore(
508492
sub(data, 0x21),
@@ -520,10 +504,7 @@ library LibClone {
520504
)
521505
mstore(dataEnd, shl(0xf0, extraLength))
522506

523-
// Create the instance.
524507
instance := create2(value, sub(data, 0x4c), add(extraLength, 0x6c), salt)
525-
526-
// If `instance` is zero, revert.
527508
if iszero(instance) {
528509
mstore(0x00, 0x30116425) // `DeploymentFailed()`.
529510
revert(0x1c, 0x04)
@@ -581,7 +562,6 @@ library LibClone {
581562
)
582563
mstore(dataEnd, shl(0xf0, extraLength))
583564

584-
// Compute and store the bytecode hash.
585565
hash := keccak256(sub(data, 0x4c), add(extraLength, 0x6c))
586566

587567
// Restore the overwritten memory surrounding `data`.
@@ -694,7 +674,6 @@ library LibClone {
694674
mstore(0x1e, implementation)
695675
mstore(0x0a, 0x603d3d8160223d3973)
696676
instance := create(value, 0x21, 0x5f)
697-
// If `instance` is zero, revert.
698677
if iszero(instance) {
699678
mstore(0x00, 0x30116425) // `DeploymentFailed()`.
700679
revert(0x1c, 0x04)
@@ -726,7 +705,6 @@ library LibClone {
726705
mstore(0x1e, implementation)
727706
mstore(0x0a, 0x603d3d8160223d3973)
728707
instance := create2(value, 0x21, 0x5f, salt)
729-
// If `instance` is zero, revert.
730708
if iszero(instance) {
731709
mstore(0x00, 0x30116425) // `DeploymentFailed()`.
732710
revert(0x1c, 0x04)
@@ -785,8 +763,7 @@ library LibClone {
785763
mstore(0x01, shl(96, deployer))
786764
mstore(0x15, salt)
787765
predicted := keccak256(0x00, 0x55)
788-
// Restore the part of the free memory pointer that has been overwritten.
789-
mstore(0x35, 0)
766+
mstore(0x35, 0) // Restore the overwritten part of the free memory pointer.
790767
}
791768
}
792769

0 commit comments

Comments
 (0)