forked from scroll-tech/scroll-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScrollChain.t.sol
1696 lines (1527 loc) · 77.9 KB
/
ScrollChain.t.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: MIT
pragma solidity =0.8.24;
import {console} from "hardhat/console.sol";
import {DSTestPlus} from "solmate/test/utils/DSTestPlus.sol";
import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
import {ITransparentUpgradeableProxy, TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {L1MessageQueue} from "../L1/rollup/L1MessageQueue.sol";
import {ScrollChain, IScrollChain} from "../L1/rollup/ScrollChain.sol";
import {BatchHeaderV0Codec} from "../libraries/codec/BatchHeaderV0Codec.sol";
import {BatchHeaderV1Codec} from "../libraries/codec/BatchHeaderV1Codec.sol";
import {BatchHeaderV3Codec} from "../libraries/codec/BatchHeaderV3Codec.sol";
import {ChunkCodecV0} from "../libraries/codec/ChunkCodecV0.sol";
import {ChunkCodecV1} from "../libraries/codec/ChunkCodecV1.sol";
import {EmptyContract} from "../misc/EmptyContract.sol";
import {ScrollChainMockBlob} from "../mocks/ScrollChainMockBlob.sol";
import {MockRollupVerifier} from "./mocks/MockRollupVerifier.sol";
// solhint-disable no-inline-assembly
contract ScrollChainTest is DSTestPlus {
// from ScrollChain
event UpdateSequencer(address indexed account, bool status);
event UpdateProver(address indexed account, bool status);
event UpdateMaxNumTxInChunk(uint256 oldMaxNumTxInChunk, uint256 newMaxNumTxInChunk);
event CommitBatch(uint256 indexed batchIndex, bytes32 indexed batchHash);
event FinalizeBatch(uint256 indexed batchIndex, bytes32 indexed batchHash, bytes32 stateRoot, bytes32 withdrawRoot);
event RevertBatch(uint256 indexed batchIndex, bytes32 indexed batchHash);
ProxyAdmin internal admin;
EmptyContract private placeholder;
ScrollChain private rollup;
L1MessageQueue internal messageQueue;
MockRollupVerifier internal verifier;
function setUp() public {
placeholder = new EmptyContract();
admin = new ProxyAdmin();
messageQueue = L1MessageQueue(_deployProxy(address(0)));
rollup = ScrollChain(_deployProxy(address(0)));
verifier = new MockRollupVerifier();
// Upgrade the L1MessageQueue implementation and initialize
admin.upgrade(
ITransparentUpgradeableProxy(address(messageQueue)),
address(new L1MessageQueue(address(this), address(rollup), address(1)))
);
messageQueue.initialize(address(this), address(rollup), address(0), address(0), 10000000);
// Upgrade the ScrollChain implementation and initialize
admin.upgrade(
ITransparentUpgradeableProxy(address(rollup)),
address(new ScrollChain(233, address(messageQueue), address(verifier)))
);
rollup.initialize(address(messageQueue), address(verifier), 100);
}
function testInitialized() external {
assertEq(address(this), rollup.owner());
assertEq(rollup.layer2ChainId(), 233);
hevm.expectRevert("Initializable: contract is already initialized");
rollup.initialize(address(messageQueue), address(0), 100);
}
function testCommitBatchV1() external {
bytes memory batchHeader0 = new bytes(89);
// import 10 L1 messages
for (uint256 i = 0; i < 10; i++) {
messageQueue.appendCrossDomainMessage(address(this), 1000000, new bytes(0));
}
// import genesis batch first
assembly {
mstore(add(batchHeader0, add(0x20, 25)), 1)
}
rollup.importGenesisBatch(batchHeader0, bytes32(uint256(1)));
assertEq(rollup.committedBatches(0), keccak256(batchHeader0));
// caller not sequencer, revert
hevm.expectRevert(ScrollChain.ErrorCallerIsNotSequencer.selector);
rollup.commitBatch(1, batchHeader0, new bytes[](0), new bytes(0));
rollup.addSequencer(address(0));
// batch is empty, revert
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorBatchIsEmpty.selector);
rollup.commitBatch(1, batchHeader0, new bytes[](0), new bytes(0));
hevm.stopPrank();
// batch header length too small, revert
bytes memory header = new bytes(120);
assembly {
mstore8(add(header, 0x20), 1) // version
}
hevm.startPrank(address(0));
hevm.expectRevert(BatchHeaderV1Codec.ErrorBatchHeaderV1LengthTooSmall.selector);
rollup.commitBatch(1, header, new bytes[](1), new bytes(0));
hevm.stopPrank();
// wrong bitmap length, revert
header = new bytes(122);
assembly {
mstore8(add(header, 0x20), 1) // version
}
hevm.startPrank(address(0));
hevm.expectRevert(BatchHeaderV1Codec.ErrorIncorrectBitmapLengthV1.selector);
rollup.commitBatch(1, header, new bytes[](1), new bytes(0));
hevm.stopPrank();
// incorrect parent batch hash, revert
assembly {
mstore(add(batchHeader0, add(0x20, 25)), 2) // change data hash for batch0
}
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorIncorrectBatchHash.selector);
rollup.commitBatch(1, batchHeader0, new bytes[](1), new bytes(0));
hevm.stopPrank();
assembly {
mstore(add(batchHeader0, add(0x20, 25)), 1) // change back
}
bytes[] memory chunks = new bytes[](1);
bytes memory chunk0;
// no block in chunk, revert
chunk0 = new bytes(1);
chunks[0] = chunk0;
hevm.startPrank(address(0));
hevm.expectRevert(ChunkCodecV1.ErrorNoBlockInChunkV1.selector);
rollup.commitBatch(1, batchHeader0, chunks, new bytes(0));
hevm.stopPrank();
// invalid chunk length, revert
chunk0 = new bytes(1);
chunk0[0] = bytes1(uint8(1)); // one block in this chunk
chunks[0] = chunk0;
hevm.startPrank(address(0));
hevm.expectRevert(ChunkCodecV1.ErrorIncorrectChunkLengthV1.selector);
rollup.commitBatch(1, batchHeader0, chunks, new bytes(0));
hevm.stopPrank();
// cannot skip last L1 message, revert
chunk0 = new bytes(1 + 60);
bytes memory bitmap = new bytes(32);
chunk0[0] = bytes1(uint8(1)); // one block in this chunk
chunk0[58] = bytes1(uint8(1)); // numTransactions = 1
chunk0[60] = bytes1(uint8(1)); // numL1Messages = 1
bitmap[31] = bytes1(uint8(1));
chunks[0] = chunk0;
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorLastL1MessageSkipped.selector);
rollup.commitBatch(1, batchHeader0, chunks, bitmap);
hevm.stopPrank();
// num txs less than num L1 msgs, revert
chunk0 = new bytes(1 + 60);
bitmap = new bytes(32);
chunk0[0] = bytes1(uint8(1)); // one block in this chunk
chunk0[58] = bytes1(uint8(1)); // numTransactions = 1
chunk0[60] = bytes1(uint8(3)); // numL1Messages = 3
bitmap[31] = bytes1(uint8(3));
chunks[0] = chunk0;
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorNumTxsLessThanNumL1Msgs.selector);
rollup.commitBatch(1, batchHeader0, chunks, bitmap);
hevm.stopPrank();
// revert when ErrorNoBlobFound
chunk0 = new bytes(1 + 60);
chunk0[0] = bytes1(uint8(1)); // one block in this chunk
chunks[0] = chunk0;
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorNoBlobFound.selector);
rollup.commitBatch(1, batchHeader0, chunks, new bytes(0));
hevm.stopPrank();
// @note we cannot check `ErrorFoundMultipleBlobs` here
// upgrade to ScrollChainMockBlob
ScrollChainMockBlob impl = new ScrollChainMockBlob(
rollup.layer2ChainId(),
rollup.messageQueue(),
rollup.verifier()
);
admin.upgrade(ITransparentUpgradeableProxy(address(rollup)), address(impl));
// this is keccak("");
ScrollChainMockBlob(address(rollup)).setBlobVersionedHash(
0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
);
bytes32 batchHash0 = rollup.committedBatches(0);
bytes memory batchHeader1 = new bytes(121);
assembly {
mstore8(add(batchHeader1, 0x20), 1) // version
mstore(add(batchHeader1, add(0x20, 1)), shl(192, 1)) // batchIndex
mstore(add(batchHeader1, add(0x20, 9)), 0) // l1MessagePopped
mstore(add(batchHeader1, add(0x20, 17)), 0) // totalL1MessagePopped
mstore(add(batchHeader1, add(0x20, 25)), 0x246394445f4fe64ed5598554d55d1682d6fb3fe04bf58eb54ef81d1189fafb51) // dataHash
mstore(add(batchHeader1, add(0x20, 57)), 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470) // blobVersionedHash
mstore(add(batchHeader1, add(0x20, 89)), batchHash0) // parentBatchHash
}
// commit batch with one chunk, no tx, correctly
chunk0 = new bytes(1 + 60);
chunk0[0] = bytes1(uint8(1)); // one block in this chunk
chunks[0] = chunk0;
hevm.startPrank(address(0));
assertEq(rollup.committedBatches(1), bytes32(0));
rollup.commitBatch(1, batchHeader0, chunks, new bytes(0));
hevm.stopPrank();
assertEq(rollup.committedBatches(1), keccak256(batchHeader1));
// batch is already committed, revert
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorBatchIsAlreadyCommitted.selector);
rollup.commitBatch(1, batchHeader0, chunks, new bytes(0));
hevm.stopPrank();
// revert when ErrorIncorrectBatchVersion
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorIncorrectBatchVersion.selector);
rollup.commitBatch(3, batchHeader1, chunks, new bytes(0));
hevm.stopPrank();
}
function testFinalizeBatchWithProof4844() external {
// caller not prover, revert
hevm.expectRevert(ScrollChain.ErrorCallerIsNotProver.selector);
rollup.finalizeBatchWithProof4844(new bytes(0), bytes32(0), bytes32(0), bytes32(0), new bytes(0), new bytes(0));
rollup.addProver(address(0));
rollup.addSequencer(address(0));
bytes memory batchHeader0 = new bytes(89);
// import genesis batch
assembly {
mstore(add(batchHeader0, add(0x20, 25)), 1)
}
rollup.importGenesisBatch(batchHeader0, bytes32(uint256(1)));
bytes[] memory chunks = new bytes[](1);
bytes memory chunk0;
// upgrade to ScrollChainMockBlob
ScrollChainMockBlob impl = new ScrollChainMockBlob(
rollup.layer2ChainId(),
rollup.messageQueue(),
rollup.verifier()
);
admin.upgrade(ITransparentUpgradeableProxy(address(rollup)), address(impl));
// from https://etherscan.io/blob/0x013590dc3544d56629ba81bb14d4d31248f825001653aa575eb8e3a719046757?bid=740652
bytes32 blobVersionedHash = 0x013590dc3544d56629ba81bb14d4d31248f825001653aa575eb8e3a719046757;
bytes
memory blobDataProof = hex"2c9d777660f14ad49803a6442935c0d24a0d83551de5995890bf70a17d24e68753ab0fe6807c7081f0885fe7da741554d658a03730b1fa006f8319f8b993bcb0a5a0c9e8a145c5ef6e415c245690effa2914ec9393f58a7251d30c0657da1453d9ad906eae8b97dd60c9a216f81b4df7af34d01e214e1ec5865f0133ecc16d7459e49dab66087340677751e82097fbdd20551d66076f425775d1758a9dfd186b";
ScrollChainMockBlob(address(rollup)).setBlobVersionedHash(blobVersionedHash);
bytes32 batchHash0 = rollup.committedBatches(0);
bytes memory batchHeader1 = new bytes(121);
assembly {
mstore8(add(batchHeader1, 0x20), 1) // version
mstore(add(batchHeader1, add(0x20, 1)), shl(192, 1)) // batchIndex
mstore(add(batchHeader1, add(0x20, 9)), 0) // l1MessagePopped
mstore(add(batchHeader1, add(0x20, 17)), 0) // totalL1MessagePopped
mstore(add(batchHeader1, add(0x20, 25)), 0x246394445f4fe64ed5598554d55d1682d6fb3fe04bf58eb54ef81d1189fafb51) // dataHash
mstore(add(batchHeader1, add(0x20, 57)), blobVersionedHash) // blobVersionedHash
mstore(add(batchHeader1, add(0x20, 89)), batchHash0) // parentBatchHash
}
// batch hash is 0xf7d9af8c2c8e1a84f1fa4b6af9425f85c50a61b24cdd28101a5f6d781906a5b9
// commit one batch
chunk0 = new bytes(1 + 60);
chunk0[0] = bytes1(uint8(1)); // one block in this chunk
chunks[0] = chunk0;
hevm.startPrank(address(0));
rollup.commitBatch(1, batchHeader0, chunks, new bytes(0));
hevm.stopPrank();
assertEq(rollup.committedBatches(1), keccak256(batchHeader1));
// incorrect batch hash, revert
batchHeader1[1] = bytes1(uint8(1)); // change random byte
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorIncorrectBatchHash.selector);
rollup.finalizeBatchWithProof4844(
batchHeader1,
bytes32(uint256(1)),
bytes32(uint256(2)),
bytes32(0),
new bytes(0),
new bytes(0)
);
hevm.stopPrank();
batchHeader1[1] = bytes1(uint8(0)); // change back
// batch header length too small, revert
bytes memory header = new bytes(120);
assembly {
mstore8(add(header, 0x20), 1) // version
}
hevm.startPrank(address(0));
hevm.expectRevert(BatchHeaderV1Codec.ErrorBatchHeaderV1LengthTooSmall.selector);
rollup.finalizeBatchWithProof4844(
header,
bytes32(uint256(1)),
bytes32(uint256(2)),
bytes32(0),
new bytes(0),
new bytes(0)
);
hevm.stopPrank();
// wrong bitmap length, revert
header = new bytes(122);
assembly {
mstore8(add(header, 0x20), 1) // version
}
hevm.startPrank(address(0));
hevm.expectRevert(BatchHeaderV1Codec.ErrorIncorrectBitmapLengthV1.selector);
rollup.finalizeBatchWithProof4844(
header,
bytes32(uint256(1)),
bytes32(uint256(2)),
bytes32(0),
new bytes(0),
new bytes(0)
);
hevm.stopPrank();
// verify success
assertBoolEq(rollup.isBatchFinalized(1), false);
hevm.startPrank(address(0));
rollup.finalizeBatchWithProof4844(
batchHeader1,
bytes32(uint256(1)),
bytes32(uint256(2)),
bytes32(uint256(3)),
blobDataProof,
new bytes(0)
);
hevm.stopPrank();
assertBoolEq(rollup.isBatchFinalized(1), true);
assertEq(rollup.finalizedStateRoots(1), bytes32(uint256(2)));
assertEq(rollup.withdrawRoots(1), bytes32(uint256(3)));
assertEq(rollup.lastFinalizedBatchIndex(), 1);
// batch already verified, revert
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorBatchIsAlreadyVerified.selector);
rollup.finalizeBatchWithProof4844(
batchHeader1,
bytes32(uint256(1)),
bytes32(uint256(2)),
bytes32(uint256(3)),
blobDataProof,
new bytes(0)
);
hevm.stopPrank();
}
function testCommitAndFinalizeWithL1MessagesV1() external {
rollup.addSequencer(address(0));
rollup.addProver(address(0));
// import 300 L1 messages
for (uint256 i = 0; i < 300; i++) {
messageQueue.appendCrossDomainMessage(address(this), 1000000, new bytes(0));
}
// import genesis batch first
bytes memory batchHeader0 = new bytes(89);
assembly {
mstore(add(batchHeader0, add(0x20, 25)), 1)
}
rollup.importGenesisBatch(batchHeader0, bytes32(uint256(1)));
bytes32 batchHash0 = rollup.committedBatches(0);
// upgrade to ScrollChainMockBlob
ScrollChainMockBlob impl = new ScrollChainMockBlob(
rollup.layer2ChainId(),
rollup.messageQueue(),
rollup.verifier()
);
admin.upgrade(ITransparentUpgradeableProxy(address(rollup)), address(impl));
// from https://etherscan.io/blob/0x013590dc3544d56629ba81bb14d4d31248f825001653aa575eb8e3a719046757?bid=740652
bytes32 blobVersionedHash = 0x013590dc3544d56629ba81bb14d4d31248f825001653aa575eb8e3a719046757;
bytes
memory blobDataProof = hex"2c9d777660f14ad49803a6442935c0d24a0d83551de5995890bf70a17d24e68753ab0fe6807c7081f0885fe7da741554d658a03730b1fa006f8319f8b993bcb0a5a0c9e8a145c5ef6e415c245690effa2914ec9393f58a7251d30c0657da1453d9ad906eae8b97dd60c9a216f81b4df7af34d01e214e1ec5865f0133ecc16d7459e49dab66087340677751e82097fbdd20551d66076f425775d1758a9dfd186b";
ScrollChainMockBlob(address(rollup)).setBlobVersionedHash(blobVersionedHash);
bytes memory bitmap;
bytes[] memory chunks;
bytes memory chunk0;
bytes memory chunk1;
// commit batch1, one chunk with one block, 1 tx, 1 L1 message, no skip
// => payload for data hash of chunk0
// 0000000000000000
// 0000000000000000
// 0000000000000000000000000000000000000000000000000000000000000000
// 0000000000000000
// 0001
// a2277fd30bbbe74323309023b56035b376d7768ad237ae4fc46ead7dc9591ae1
// => data hash for chunk0
// 9ef1e5694bdb014a1eea42be756a8f63bfd8781d6332e9ef3b5126d90c62f110
// => data hash for all chunks
// d9cb6bf9264006fcea490d5c261f7453ab95b1b26033a3805996791b8e3a62f3
// => payload for batch header
// 01
// 0000000000000001
// 0000000000000001
// 0000000000000001
// d9cb6bf9264006fcea490d5c261f7453ab95b1b26033a3805996791b8e3a62f3
// 013590dc3544d56629ba81bb14d4d31248f825001653aa575eb8e3a719046757
// 119b828c2a2798d2c957228ebeaff7e10bb099ae0d4e224f3eeb779ff61cba61
// 0000000000000000000000000000000000000000000000000000000000000000
// => hash for batch header
// 66b68a5092940d88a8c6f203d2071303557c024275d8ceaa2e12662bc61c8d8f
bytes memory batchHeader1 = new bytes(121 + 32);
assembly {
mstore8(add(batchHeader1, 0x20), 1) // version
mstore(add(batchHeader1, add(0x20, 1)), shl(192, 1)) // batchIndex = 1
mstore(add(batchHeader1, add(0x20, 9)), shl(192, 1)) // l1MessagePopped = 1
mstore(add(batchHeader1, add(0x20, 17)), shl(192, 1)) // totalL1MessagePopped = 1
mstore(add(batchHeader1, add(0x20, 25)), 0xd9cb6bf9264006fcea490d5c261f7453ab95b1b26033a3805996791b8e3a62f3) // dataHash
mstore(add(batchHeader1, add(0x20, 57)), blobVersionedHash) // blobVersionedHash
mstore(add(batchHeader1, add(0x20, 89)), batchHash0) // parentBatchHash
mstore(add(batchHeader1, add(0x20, 121)), 0) // bitmap0
}
chunk0 = new bytes(1 + 60);
assembly {
mstore(add(chunk0, 0x20), shl(248, 1)) // numBlocks = 1
mstore(add(chunk0, add(0x21, 56)), shl(240, 1)) // numTransactions = 1
mstore(add(chunk0, add(0x21, 58)), shl(240, 1)) // numL1Messages = 1
}
chunks = new bytes[](1);
chunks[0] = chunk0;
bitmap = new bytes(32);
hevm.startPrank(address(0));
hevm.expectEmit(true, true, false, true);
emit CommitBatch(1, keccak256(batchHeader1));
rollup.commitBatch(1, batchHeader0, chunks, bitmap);
hevm.stopPrank();
assertBoolEq(rollup.isBatchFinalized(1), false);
bytes32 batchHash1 = rollup.committedBatches(1);
assertEq(batchHash1, keccak256(batchHeader1));
// finalize batch1
hevm.startPrank(address(0));
hevm.expectEmit(true, true, false, true);
emit FinalizeBatch(1, batchHash1, bytes32(uint256(2)), bytes32(uint256(3)));
rollup.finalizeBatchWithProof4844(
batchHeader1,
bytes32(uint256(1)),
bytes32(uint256(2)),
bytes32(uint256(3)),
blobDataProof,
new bytes(0)
);
hevm.stopPrank();
assertBoolEq(rollup.isBatchFinalized(1), true);
assertEq(rollup.finalizedStateRoots(1), bytes32(uint256(2)));
assertEq(rollup.withdrawRoots(1), bytes32(uint256(3)));
assertEq(rollup.lastFinalizedBatchIndex(), 1);
assertBoolEq(messageQueue.isMessageSkipped(0), false);
assertEq(messageQueue.pendingQueueIndex(), 1);
// commit batch2 with two chunks, correctly
// 1. chunk0 has one block, 3 tx, no L1 messages
// => payload for chunk0
// 0000000000000000
// 0000000000000000
// 0000000000000000000000000000000000000000000000000000000000000000
// 0000000000000000
// 0003
// ... (some tx hashes)
// => data hash for chunk0
// c4e0d99a191bfcb1ba2edd2964a0f0a56c929b1ecdf149ba3ae4f045d6e6ef8b
// 2. chunk1 has three blocks
// 2.1 block0 has 5 tx, 3 L1 messages, no skips
// 2.2 block1 has 10 tx, 5 L1 messages, even is skipped, last is not skipped
// 2.2 block1 has 300 tx, 256 L1 messages, odd position is skipped, last is not skipped
// => payload for chunk1
// 0000000000000000
// 0000000000000000
// 0000000000000000000000000000000000000000000000000000000000000000
// 0000000000000000
// 0005
// 0000000000000000
// 0000000000000000
// 0000000000000000000000000000000000000000000000000000000000000000
// 0000000000000000
// 000a
// 0000000000000000
// 0000000000000000
// 0000000000000000000000000000000000000000000000000000000000000000
// 0000000000000000
// 012c
// => data hash for chunk2
// a84759a83bba5f73e3a748d138ae7b6c5a31a8a5273aeb0e578807bf1ef6ed4e
// => data hash for all chunks
// dae89323bf398ca9f6f8e83b1b0d603334be063fa3920015b6aa9df77a0ccbcd
// => payload for batch header
// 01
// 0000000000000002
// 0000000000000108
// 0000000000000109
// dae89323bf398ca9f6f8e83b1b0d603334be063fa3920015b6aa9df77a0ccbcd
// 013590dc3544d56629ba81bb14d4d31248f825001653aa575eb8e3a719046757
// 66b68a5092940d88a8c6f203d2071303557c024275d8ceaa2e12662bc61c8d8f
// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa28000000000000000000000000000000000000000000000000000000000000002a
// => hash for batch header
// b9dff5d21381176a73b20a9294eb2703c803113f9559e358708c659fa1cf62eb
bytes memory batchHeader2 = new bytes(121 + 32 + 32);
assembly {
mstore8(add(batchHeader2, 0x20), 1) // version
mstore(add(batchHeader2, add(0x20, 1)), shl(192, 2)) // batchIndex = 2
mstore(add(batchHeader2, add(0x20, 9)), shl(192, 264)) // l1MessagePopped = 264
mstore(add(batchHeader2, add(0x20, 17)), shl(192, 265)) // totalL1MessagePopped = 265
mstore(add(batchHeader2, add(0x20, 25)), 0xdae89323bf398ca9f6f8e83b1b0d603334be063fa3920015b6aa9df77a0ccbcd) // dataHash
mstore(add(batchHeader2, add(0x20, 57)), blobVersionedHash) // blobVersionedHash
mstore(add(batchHeader2, add(0x20, 89)), batchHash1) // parentBatchHash
mstore(
add(batchHeader2, add(0x20, 121)),
77194726158210796949047323339125271902179989777093709359638389338608753093160
) // bitmap0
mstore(add(batchHeader2, add(0x20, 153)), 42) // bitmap1
}
chunk0 = new bytes(1 + 60);
assembly {
mstore(add(chunk0, 0x20), shl(248, 1)) // numBlocks = 1
mstore(add(chunk0, add(0x21, 56)), shl(240, 3)) // numTransactions = 3
mstore(add(chunk0, add(0x21, 58)), shl(240, 0)) // numL1Messages = 0
}
chunk1 = new bytes(1 + 60 * 3);
assembly {
mstore(add(chunk1, 0x20), shl(248, 3)) // numBlocks = 3
mstore(add(chunk1, add(33, 56)), shl(240, 5)) // block0.numTransactions = 5
mstore(add(chunk1, add(33, 58)), shl(240, 3)) // block0.numL1Messages = 3
mstore(add(chunk1, add(93, 56)), shl(240, 10)) // block1.numTransactions = 10
mstore(add(chunk1, add(93, 58)), shl(240, 5)) // block1.numL1Messages = 5
mstore(add(chunk1, add(153, 56)), shl(240, 300)) // block1.numTransactions = 300
mstore(add(chunk1, add(153, 58)), shl(240, 256)) // block1.numL1Messages = 256
}
chunks = new bytes[](2);
chunks[0] = chunk0;
chunks[1] = chunk1;
bitmap = new bytes(64);
assembly {
mstore(
add(bitmap, add(0x20, 0)),
77194726158210796949047323339125271902179989777093709359638389338608753093160
) // bitmap0
mstore(add(bitmap, add(0x20, 32)), 42) // bitmap1
}
// too many txs in one chunk, revert
rollup.updateMaxNumTxInChunk(2); // 3 - 1
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorTooManyTxsInOneChunk.selector);
rollup.commitBatch(1, batchHeader1, chunks, bitmap); // first chunk with too many txs
hevm.stopPrank();
rollup.updateMaxNumTxInChunk(185); // 5+10+300 - 2 - 127
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorTooManyTxsInOneChunk.selector);
rollup.commitBatch(1, batchHeader1, chunks, bitmap); // second chunk with too many txs
hevm.stopPrank();
rollup.updateMaxNumTxInChunk(186);
hevm.startPrank(address(0));
hevm.expectEmit(true, true, false, true);
emit CommitBatch(2, keccak256(batchHeader2));
rollup.commitBatch(1, batchHeader1, chunks, bitmap);
hevm.stopPrank();
assertBoolEq(rollup.isBatchFinalized(2), false);
bytes32 batchHash2 = rollup.committedBatches(2);
assertEq(batchHash2, keccak256(batchHeader2));
// verify committed batch correctly
hevm.startPrank(address(0));
hevm.expectEmit(true, true, false, true);
emit FinalizeBatch(2, batchHash2, bytes32(uint256(4)), bytes32(uint256(5)));
rollup.finalizeBatchWithProof4844(
batchHeader2,
bytes32(uint256(2)),
bytes32(uint256(4)),
bytes32(uint256(5)),
blobDataProof,
new bytes(0)
);
hevm.stopPrank();
assertBoolEq(rollup.isBatchFinalized(2), true);
assertEq(rollup.finalizedStateRoots(2), bytes32(uint256(4)));
assertEq(rollup.withdrawRoots(2), bytes32(uint256(5)));
assertEq(rollup.lastFinalizedBatchIndex(), 2);
assertEq(messageQueue.pendingQueueIndex(), 265);
// 1 ~ 4, zero
for (uint256 i = 1; i < 4; i++) {
assertBoolEq(messageQueue.isMessageSkipped(i), false);
}
// 4 ~ 9, even is nonzero, odd is zero
for (uint256 i = 4; i < 9; i++) {
if (i % 2 == 1 || i == 8) {
assertBoolEq(messageQueue.isMessageSkipped(i), false);
} else {
assertBoolEq(messageQueue.isMessageSkipped(i), true);
}
}
// 9 ~ 265, even is nonzero, odd is zero
for (uint256 i = 9; i < 265; i++) {
if (i % 2 == 1 || i == 264) {
assertBoolEq(messageQueue.isMessageSkipped(i), false);
} else {
assertBoolEq(messageQueue.isMessageSkipped(i), true);
}
}
}
function testCommitBatchV3() external {
bytes memory batchHeader0 = new bytes(89);
// import 10 L1 messages
for (uint256 i = 0; i < 10; i++) {
messageQueue.appendCrossDomainMessage(address(this), 1000000, new bytes(0));
}
// import genesis batch first
assembly {
mstore(add(batchHeader0, add(0x20, 25)), 1)
}
rollup.importGenesisBatch(batchHeader0, bytes32(uint256(1)));
assertEq(rollup.committedBatches(0), keccak256(batchHeader0));
// caller not sequencer, revert
hevm.expectRevert(ScrollChain.ErrorCallerIsNotSequencer.selector);
rollup.commitBatchWithBlobProof(3, batchHeader0, new bytes[](0), new bytes(0), new bytes(0));
rollup.addSequencer(address(0));
// revert when ErrorIncorrectBatchVersion
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorIncorrectBatchVersion.selector);
rollup.commitBatchWithBlobProof(2, batchHeader0, new bytes[](0), new bytes(0), new bytes(0));
hevm.stopPrank();
// revert when ErrorBatchIsEmpty
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorBatchIsEmpty.selector);
rollup.commitBatchWithBlobProof(3, batchHeader0, new bytes[](0), new bytes(0), new bytes(0));
hevm.stopPrank();
// revert when ErrorBatchHeaderV3LengthMismatch
bytes memory header = new bytes(192);
assembly {
mstore8(add(header, 0x20), 3) // version
}
hevm.startPrank(address(0));
hevm.expectRevert(BatchHeaderV3Codec.ErrorBatchHeaderV3LengthMismatch.selector);
rollup.commitBatchWithBlobProof(3, header, new bytes[](1), new bytes(0), new bytes(0));
hevm.stopPrank();
// revert when ErrorIncorrectBatchHash
assembly {
mstore(add(batchHeader0, add(0x20, 25)), 2) // change data hash for batch0
}
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorIncorrectBatchHash.selector);
rollup.commitBatchWithBlobProof(3, batchHeader0, new bytes[](1), new bytes(0), new bytes(0));
hevm.stopPrank();
assembly {
mstore(add(batchHeader0, add(0x20, 25)), 1) // change back
}
bytes[] memory chunks = new bytes[](1);
bytes memory chunk0;
// no block in chunk, revert
chunk0 = new bytes(1);
chunks[0] = chunk0;
hevm.startPrank(address(0));
hevm.expectRevert(ChunkCodecV1.ErrorNoBlockInChunkV1.selector);
rollup.commitBatchWithBlobProof(3, batchHeader0, chunks, new bytes(0), new bytes(0));
hevm.stopPrank();
// invalid chunk length, revert
chunk0 = new bytes(1);
chunk0[0] = bytes1(uint8(1)); // one block in this chunk
chunks[0] = chunk0;
hevm.startPrank(address(0));
hevm.expectRevert(ChunkCodecV1.ErrorIncorrectChunkLengthV1.selector);
rollup.commitBatchWithBlobProof(3, batchHeader0, chunks, new bytes(0), new bytes(0));
hevm.stopPrank();
// cannot skip last L1 message, revert
chunk0 = new bytes(1 + 60);
bytes memory bitmap = new bytes(32);
chunk0[0] = bytes1(uint8(1)); // one block in this chunk
chunk0[58] = bytes1(uint8(1)); // numTransactions = 1
chunk0[60] = bytes1(uint8(1)); // numL1Messages = 1
bitmap[31] = bytes1(uint8(1));
chunks[0] = chunk0;
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorLastL1MessageSkipped.selector);
rollup.commitBatchWithBlobProof(3, batchHeader0, chunks, bitmap, new bytes(0));
hevm.stopPrank();
// num txs less than num L1 msgs, revert
chunk0 = new bytes(1 + 60);
bitmap = new bytes(32);
chunk0[0] = bytes1(uint8(1)); // one block in this chunk
chunk0[58] = bytes1(uint8(1)); // numTransactions = 1
chunk0[60] = bytes1(uint8(3)); // numL1Messages = 3
bitmap[31] = bytes1(uint8(3));
chunks[0] = chunk0;
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorNumTxsLessThanNumL1Msgs.selector);
rollup.commitBatchWithBlobProof(3, batchHeader0, chunks, bitmap, new bytes(0));
hevm.stopPrank();
// revert when ErrorNoBlobFound
// revert when ErrorNoBlobFound
chunk0 = new bytes(1 + 60);
chunk0[0] = bytes1(uint8(1)); // one block in this chunk
chunks[0] = chunk0;
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorNoBlobFound.selector);
rollup.commitBatchWithBlobProof(3, batchHeader0, chunks, new bytes(0), new bytes(0));
hevm.stopPrank();
// @note we cannot check `ErrorFoundMultipleBlobs` here
// upgrade to ScrollChainMockBlob
ScrollChainMockBlob impl = new ScrollChainMockBlob(
rollup.layer2ChainId(),
rollup.messageQueue(),
rollup.verifier()
);
admin.upgrade(ITransparentUpgradeableProxy(address(rollup)), address(impl));
// from https://etherscan.io/blob/0x013590dc3544d56629ba81bb14d4d31248f825001653aa575eb8e3a719046757?bid=740652
bytes32 blobVersionedHash = 0x013590dc3544d56629ba81bb14d4d31248f825001653aa575eb8e3a719046757;
bytes
memory blobDataProof = hex"2c9d777660f14ad49803a6442935c0d24a0d83551de5995890bf70a17d24e68753ab0fe6807c7081f0885fe7da741554d658a03730b1fa006f8319f8b993bcb0a5a0c9e8a145c5ef6e415c245690effa2914ec9393f58a7251d30c0657da1453d9ad906eae8b97dd60c9a216f81b4df7af34d01e214e1ec5865f0133ecc16d7459e49dab66087340677751e82097fbdd20551d66076f425775d1758a9dfd186b";
ScrollChainMockBlob(address(rollup)).setBlobVersionedHash(blobVersionedHash);
chunk0 = new bytes(1 + 60);
chunk0[0] = bytes1(uint8(1)); // one block in this chunk
chunks[0] = chunk0;
// revert when ErrorCallPointEvaluationPrecompileFailed
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorCallPointEvaluationPrecompileFailed.selector);
rollup.commitBatchWithBlobProof(3, batchHeader0, chunks, new bytes(0), new bytes(0));
hevm.stopPrank();
bytes32 batchHash0 = rollup.committedBatches(0);
bytes memory batchHeader1 = new bytes(193);
assembly {
mstore8(add(batchHeader1, 0x20), 3) // version
mstore(add(batchHeader1, add(0x20, 1)), shl(192, 1)) // batchIndex
mstore(add(batchHeader1, add(0x20, 9)), 0) // l1MessagePopped
mstore(add(batchHeader1, add(0x20, 17)), 0) // totalL1MessagePopped
mstore(add(batchHeader1, add(0x20, 25)), 0x246394445f4fe64ed5598554d55d1682d6fb3fe04bf58eb54ef81d1189fafb51) // dataHash
mstore(add(batchHeader1, add(0x20, 57)), blobVersionedHash) // blobVersionedHash
mstore(add(batchHeader1, add(0x20, 89)), batchHash0) // parentBatchHash
mstore(add(batchHeader1, add(0x20, 121)), 0) // lastBlockTimestamp
mcopy(add(batchHeader1, add(0x20, 129)), add(blobDataProof, 0x20), 64) // blobDataProof
}
// hash is ed32768c5f910a11edaf1c1ec0c0da847def9d24e0a24567c3c3d284061cf935
// succeed
hevm.startPrank(address(0));
assertEq(rollup.committedBatches(1), bytes32(0));
rollup.commitBatchWithBlobProof(3, batchHeader0, chunks, new bytes(0), blobDataProof);
hevm.stopPrank();
assertEq(rollup.committedBatches(1), keccak256(batchHeader1));
// revert when ErrorBatchIsAlreadyCommitted
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorBatchIsAlreadyCommitted.selector);
rollup.commitBatchWithBlobProof(3, batchHeader0, chunks, new bytes(0), blobDataProof);
hevm.stopPrank();
}
function testFinalizeBundleWithProof() external {
// caller not prover, revert
hevm.expectRevert(ScrollChain.ErrorCallerIsNotProver.selector);
rollup.finalizeBundleWithProof(new bytes(0), bytes32(0), bytes32(0), new bytes(0));
rollup.addProver(address(0));
rollup.addSequencer(address(0));
// import genesis batch
bytes memory batchHeader0 = new bytes(89);
assembly {
mstore(add(batchHeader0, add(0x20, 25)), 1)
}
rollup.importGenesisBatch(batchHeader0, bytes32(uint256(1)));
// upgrade to ScrollChainMockBlob
ScrollChainMockBlob impl = new ScrollChainMockBlob(
rollup.layer2ChainId(),
rollup.messageQueue(),
rollup.verifier()
);
admin.upgrade(ITransparentUpgradeableProxy(address(rollup)), address(impl));
// from https://etherscan.io/blob/0x013590dc3544d56629ba81bb14d4d31248f825001653aa575eb8e3a719046757?bid=740652
bytes32 blobVersionedHash = 0x013590dc3544d56629ba81bb14d4d31248f825001653aa575eb8e3a719046757;
bytes
memory blobDataProof = hex"2c9d777660f14ad49803a6442935c0d24a0d83551de5995890bf70a17d24e68753ab0fe6807c7081f0885fe7da741554d658a03730b1fa006f8319f8b993bcb0a5a0c9e8a145c5ef6e415c245690effa2914ec9393f58a7251d30c0657da1453d9ad906eae8b97dd60c9a216f81b4df7af34d01e214e1ec5865f0133ecc16d7459e49dab66087340677751e82097fbdd20551d66076f425775d1758a9dfd186b";
ScrollChainMockBlob(address(rollup)).setBlobVersionedHash(blobVersionedHash);
bytes[] memory chunks = new bytes[](1);
bytes memory chunk0;
bytes32 batchHash0 = rollup.committedBatches(0);
bytes memory batchHeader1 = new bytes(193);
assembly {
mstore8(add(batchHeader1, 0x20), 3) // version
mstore(add(batchHeader1, add(0x20, 1)), shl(192, 1)) // batchIndex
mstore(add(batchHeader1, add(0x20, 9)), 0) // l1MessagePopped
mstore(add(batchHeader1, add(0x20, 17)), 0) // totalL1MessagePopped
mstore(add(batchHeader1, add(0x20, 25)), 0x246394445f4fe64ed5598554d55d1682d6fb3fe04bf58eb54ef81d1189fafb51) // dataHash
mstore(add(batchHeader1, add(0x20, 57)), blobVersionedHash) // blobVersionedHash
mstore(add(batchHeader1, add(0x20, 89)), batchHash0) // parentBatchHash
mstore(add(batchHeader1, add(0x20, 121)), 0) // lastBlockTimestamp
mcopy(add(batchHeader1, add(0x20, 129)), add(blobDataProof, 0x20), 64) // blobDataProof
}
// hash is ed32768c5f910a11edaf1c1ec0c0da847def9d24e0a24567c3c3d284061cf935
// commit one batch
chunk0 = new bytes(1 + 60);
chunk0[0] = bytes1(uint8(1)); // one block in this chunk
chunks[0] = chunk0;
hevm.startPrank(address(0));
assertEq(rollup.committedBatches(1), bytes32(0));
rollup.commitBatchWithBlobProof(3, batchHeader0, chunks, new bytes(0), blobDataProof);
hevm.stopPrank();
assertEq(rollup.committedBatches(1), keccak256(batchHeader1));
// revert when ErrorStateRootIsZero
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorStateRootIsZero.selector);
rollup.finalizeBundleWithProof(batchHeader1, bytes32(0), bytes32(0), new bytes(0));
hevm.stopPrank();
// revert when ErrorBatchHeaderV3LengthMismatch
bytes memory header = new bytes(192);
assembly {
mstore8(add(header, 0x20), 3) // version
}
hevm.startPrank(address(0));
hevm.expectRevert(BatchHeaderV3Codec.ErrorBatchHeaderV3LengthMismatch.selector);
rollup.finalizeBundleWithProof(header, bytes32(uint256(1)), bytes32(uint256(2)), new bytes(0));
hevm.stopPrank();
// revert when ErrorIncorrectBatchHash
batchHeader1[1] = bytes1(uint8(1)); // change random byte
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorIncorrectBatchHash.selector);
rollup.finalizeBundleWithProof(batchHeader1, bytes32(uint256(1)), bytes32(uint256(2)), new bytes(0));
hevm.stopPrank();
batchHeader1[1] = bytes1(uint8(0)); // change back
// verify success
assertBoolEq(rollup.isBatchFinalized(1), false);
hevm.startPrank(address(0));
rollup.finalizeBundleWithProof(batchHeader1, bytes32(uint256(2)), bytes32(uint256(3)), new bytes(0));
hevm.stopPrank();
assertBoolEq(rollup.isBatchFinalized(1), true);
assertEq(rollup.finalizedStateRoots(1), bytes32(uint256(2)));
assertEq(rollup.withdrawRoots(1), bytes32(uint256(3)));
assertEq(rollup.lastFinalizedBatchIndex(), 1);
// revert when ErrorBatchIsAlreadyVerified
hevm.startPrank(address(0));
hevm.expectRevert(ScrollChain.ErrorBatchIsAlreadyVerified.selector);
rollup.finalizeBundleWithProof(batchHeader1, bytes32(uint256(2)), bytes32(uint256(3)), new bytes(0));
hevm.stopPrank();
}
function _commitBatchV3()
internal
returns (
bytes memory batchHeader0,
bytes memory batchHeader1,
bytes memory batchHeader2
)
{
// import genesis batch first
batchHeader0 = new bytes(89);
assembly {
mstore(add(batchHeader0, add(0x20, 25)), 1)
}
rollup.importGenesisBatch(batchHeader0, bytes32(uint256(1)));
bytes32 batchHash0 = rollup.committedBatches(0);
// upgrade to ScrollChainMockBlob
ScrollChainMockBlob impl = new ScrollChainMockBlob(
rollup.layer2ChainId(),
rollup.messageQueue(),
rollup.verifier()
);
admin.upgrade(ITransparentUpgradeableProxy(address(rollup)), address(impl));
// from https://etherscan.io/blob/0x013590dc3544d56629ba81bb14d4d31248f825001653aa575eb8e3a719046757?bid=740652
bytes32 blobVersionedHash = 0x013590dc3544d56629ba81bb14d4d31248f825001653aa575eb8e3a719046757;
bytes
memory blobDataProof = hex"2c9d777660f14ad49803a6442935c0d24a0d83551de5995890bf70a17d24e68753ab0fe6807c7081f0885fe7da741554d658a03730b1fa006f8319f8b993bcb0a5a0c9e8a145c5ef6e415c245690effa2914ec9393f58a7251d30c0657da1453d9ad906eae8b97dd60c9a216f81b4df7af34d01e214e1ec5865f0133ecc16d7459e49dab66087340677751e82097fbdd20551d66076f425775d1758a9dfd186b";
ScrollChainMockBlob(address(rollup)).setBlobVersionedHash(blobVersionedHash);
bytes memory bitmap;
bytes[] memory chunks;
bytes memory chunk0;
bytes memory chunk1;
// commit batch1, one chunk with one block, 1 tx, 1 L1 message, no skip
// => payload for data hash of chunk0
// 0000000000000000
// 0000000000000123
// 0000000000000000000000000000000000000000000000000000000000000000
// 0000000000000000
// 0001
// a2277fd30bbbe74323309023b56035b376d7768ad237ae4fc46ead7dc9591ae1
// => data hash for chunk0
// 5972b8fa626c873a97abb6db14fb0cb2085e050a6f80ec90b92bb0bbaa12eb5a
// => data hash for all chunks
// f6166fe668c1e6a04e3c75e864452bb02a31358f285efcb7a4e6603eb5750359
// => payload for batch header
// 03
// 0000000000000001
// 0000000000000001
// 0000000000000001
// f6166fe668c1e6a04e3c75e864452bb02a31358f285efcb7a4e6603eb5750359
// 013590dc3544d56629ba81bb14d4d31248f825001653aa575eb8e3a719046757
// 119b828c2a2798d2c957228ebeaff7e10bb099ae0d4e224f3eeb779ff61cba61
// 0000000000000123
// 2c9d777660f14ad49803a6442935c0d24a0d83551de5995890bf70a17d24e687
// 53ab0fe6807c7081f0885fe7da741554d658a03730b1fa006f8319f8b993bcb0
// => hash for batch header
// 07e1bede8c5047cf8ca7ac84f5390837fb6224953af83d7e967488fa63a2065e
batchHeader1 = new bytes(193);
assembly {
mstore8(add(batchHeader1, 0x20), 3) // version
mstore(add(batchHeader1, add(0x20, 1)), shl(192, 1)) // batchIndex = 1
mstore(add(batchHeader1, add(0x20, 9)), shl(192, 1)) // l1MessagePopped = 1
mstore(add(batchHeader1, add(0x20, 17)), shl(192, 1)) // totalL1MessagePopped = 1
mstore(add(batchHeader1, add(0x20, 25)), 0xf6166fe668c1e6a04e3c75e864452bb02a31358f285efcb7a4e6603eb5750359) // dataHash
mstore(add(batchHeader1, add(0x20, 57)), blobVersionedHash) // blobVersionedHash
mstore(add(batchHeader1, add(0x20, 89)), batchHash0) // parentBatchHash
mstore(add(batchHeader1, add(0x20, 121)), shl(192, 0x123)) // lastBlockTimestamp
mcopy(add(batchHeader1, add(0x20, 129)), add(blobDataProof, 0x20), 64) // blobDataProof
}
chunk0 = new bytes(1 + 60);
assembly {
mstore(add(chunk0, 0x20), shl(248, 1)) // numBlocks = 1
mstore(add(chunk0, add(0x21, 8)), shl(192, 0x123)) // timestamp = 0x123
mstore(add(chunk0, add(0x21, 56)), shl(240, 1)) // numTransactions = 1
mstore(add(chunk0, add(0x21, 58)), shl(240, 1)) // numL1Messages = 1
}
chunks = new bytes[](1);
chunks[0] = chunk0;
bitmap = new bytes(32);
hevm.startPrank(address(0));
hevm.expectEmit(true, true, false, true);
emit CommitBatch(1, keccak256(batchHeader1));
rollup.commitBatchWithBlobProof(3, batchHeader0, chunks, bitmap, blobDataProof);
hevm.stopPrank();
assertBoolEq(rollup.isBatchFinalized(1), false);
bytes32 batchHash1 = rollup.committedBatches(1);
assertEq(batchHash1, keccak256(batchHeader1));
assertEq(1, messageQueue.pendingQueueIndex());
assertEq(0, messageQueue.nextUnfinalizedQueueIndex());
assertBoolEq(messageQueue.isMessageSkipped(0), false);
// commit batch2 with two chunks, correctly
// 1. chunk0 has one block, 3 tx, no L1 messages
// => payload for chunk0
// 0000000000000000
// 0000000000000456
// 0000000000000000000000000000000000000000000000000000000000000000
// 0000000000000000
// 0003
// ... (some tx hashes)
// => data hash for chunk0
// 1c7649f248aed8448fa7997e44db7b7028581deb119c6d6aa1a2d126d62564cf
// 2. chunk1 has three blocks
// 2.1 block0 has 5 tx, 3 L1 messages, no skips
// 2.2 block1 has 10 tx, 5 L1 messages, even is skipped, last is not skipped
// 2.2 block1 has 300 tx, 256 L1 messages, odd position is skipped, last is not skipped
// => payload for chunk1
// 0000000000000000
// 0000000000000789
// 0000000000000000000000000000000000000000000000000000000000000000
// 0000000000000000
// 0005
// 0000000000000000