-
Notifications
You must be signed in to change notification settings - Fork 285
/
eof_validation_test.cpp
1338 lines (1096 loc) · 54.6 KB
/
eof_validation_test.cpp
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
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2021 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0
#include "eof_validation.hpp"
#include <evmone/constants.hpp>
#include <evmone/eof.hpp>
#include <evmone/instructions_traits.hpp>
#include <gtest/gtest.h>
#include <test/utils/bytecode.hpp>
#include <test/utils/utils.hpp>
using namespace evmone;
using namespace evmone::test;
TEST_F(eof_validation, before_activation)
{
ASSERT_EQ(
evmone::validate_eof(EVMC_CANCUN, ContainerKind::runtime, bytes(eof_bytecode(OP_STOP))),
EOFValidationError::eof_version_unknown);
}
TEST_F(eof_validation, validate_empty_code)
{
add_test_case("", EOFValidationError::invalid_prefix);
}
TEST_F(eof_validation, validate_EOF_prefix)
{
add_test_case("00", EOFValidationError::invalid_prefix);
add_test_case("FE", EOFValidationError::invalid_prefix);
add_test_case("EF", EOFValidationError::invalid_prefix);
add_test_case("EF0101", EOFValidationError::invalid_prefix);
add_test_case("EFEF01", EOFValidationError::invalid_prefix);
add_test_case("EFFF01", EOFValidationError::invalid_prefix);
add_test_case("EF00", EOFValidationError::eof_version_unknown);
add_test_case("EF0001", EOFValidationError::section_headers_not_terminated);
add_test_case("EFFF 01 010004 0200010003 040004 00 00800000 600000 AABBCCDD",
EOFValidationError::invalid_prefix, "valid_except_magic");
}
TEST_F(eof_validation, validate_EOF_version)
{
add_test_case("EF0002", EOFValidationError::eof_version_unknown);
add_test_case("EF00FF", EOFValidationError::eof_version_unknown);
add_test_case("EF0000 010004 0200010003 040004 00 00800000 600000 AABBCCDD",
EOFValidationError::eof_version_unknown, "valid_except_version_00");
add_test_case("EF0002 010004 0200010003 040004 00 00800000 600000 AABBCCDD",
EOFValidationError::eof_version_unknown, "valid_except_version_02");
add_test_case("EF00FF 010004 0200010003 040004 00 00800000 600000 AABBCCDD",
EOFValidationError::eof_version_unknown, "valid_except_version_FF");
}
TEST_F(eof_validation, minimal_valid_EOF1_code)
{
add_test_case(eof_bytecode(OP_INVALID), EOFValidationError::success);
}
TEST_F(eof_validation, minimal_valid_EOF1_code_with_data)
{
add_test_case(eof_bytecode(OP_INVALID).data("DA"), EOFValidationError::success);
}
TEST_F(eof_validation, minimal_valid_EOF1_multiple_code_sections)
{
add_test_case("EF0001 010008 02000200010001 00 00800000 00800000 FE FE",
EOFValidationError::data_section_missing, "no_data_section");
add_test_case(eof_bytecode(jumpf(1)).code(OP_INVALID, 0, 0x80, 0).data("DA"),
EOFValidationError::success, "with_data_section");
add_test_case(eof_bytecode(OP_PUSH0 + callf(1) + OP_STOP, 1)
.code(OP_POP + callf(2) + OP_POP + OP_RETF, 1, 0, 1)
.code(dup1(OP_ADDRESS) + callf(3) + OP_POP + OP_POP + OP_RETF, 0, 1, 3)
.code(bytecode{OP_DUP1} + OP_RETF, 2, 3, 3),
EOFValidationError::success, "non_void_input_output");
}
TEST_F(eof_validation, minimal_valid_EOF1_multiple_container_sections)
{
add_test_case("EF0001 010004 0200010001 0300010001 0300010001 040000 00 00800000 00 00 00",
EOFValidationError::data_section_missing, "no_data_section");
}
TEST_F(eof_validation, EOF1_types_section_missing)
{
add_test_case("EF0001 00", EOFValidationError::type_section_missing);
add_test_case("EF0001 0200010001 00 FE", EOFValidationError::type_section_missing);
add_test_case("EF0001 0200010001 030001 00 FE DA", EOFValidationError::type_section_missing);
add_test_case("EF0001 0200010001 040001 00 FE DA", EOFValidationError::type_section_missing);
add_test_case("EF0001 02000200010001 00 FE FE", EOFValidationError::type_section_missing);
}
TEST_F(eof_validation, EOF1_types_section_0_size)
{
add_test_case("EF0001 010000 0200010001 040000 00 FE", EOFValidationError::zero_section_size);
add_test_case(
"EF0001 010000 0200010001 040001 00 FE DA", EOFValidationError::zero_section_size);
}
TEST_F(eof_validation, EOF1_code_section_missing)
{
add_test_case("EF0001 010004 00", EOFValidationError::code_section_missing);
add_test_case("EF0001 010004 040001 00 00800000 DA", EOFValidationError::code_section_missing);
}
TEST_F(eof_validation, EOF1_code_section_0_size)
{
add_test_case("EF0001 010004 020000 00", EOFValidationError::zero_section_size);
add_test_case("EF0001 010004 020000 040001 00 DA", EOFValidationError::zero_section_size);
}
TEST_F(eof_validation, EOF1_data_section_before_code_section)
{
add_test_case("EF0001 010004 030001 0200010001 00 00800000 AA FE",
EOFValidationError::code_section_missing);
}
TEST_F(eof_validation, EOF1_data_section_before_types_section)
{
add_test_case("EF0001 040001 010004 0200010001 00 AA 00800000 FE",
EOFValidationError::type_section_missing);
}
TEST_F(eof_validation, EOF1_multiple_data_sections)
{
add_test_case("EF0001 010004 0200010001 040001 040001 00 00800000 FE DA DA",
EOFValidationError::header_terminator_missing);
}
TEST_F(eof_validation, EOF1_unknown_section)
{
add_test_case("EF0001 050001 00 FE", EOFValidationError::type_section_missing);
add_test_case("EF0001 FF0001 00 FE", EOFValidationError::type_section_missing);
add_test_case("EF0001 010004 0200010001 050001 00 00800000 FE 00",
EOFValidationError::data_section_missing);
add_test_case("EF0001 010004 0200010001 FF0001 00 00800000 FE 00",
EOFValidationError::data_section_missing);
add_test_case("EF0001 010004 0200010001 040001 050001 00 00800000 FE AA 00",
EOFValidationError::header_terminator_missing);
add_test_case("EF0001 010004 0200010001 040001 FF0001 00 00800000 FE AA 00",
EOFValidationError::header_terminator_missing);
}
TEST_F(eof_validation, EOF1_incomplete_section_size)
{
// TODO: section_headers_not_terminated should rather be incomplete_section_size
// in these examples.
add_test_case("EF0001 0100", EOFValidationError::incomplete_section_size);
add_test_case("EF0001 010004 0200", EOFValidationError::incomplete_section_number);
add_test_case("EF0001 010004 02000100", EOFValidationError::incomplete_section_size);
add_test_case("EF0001 010004 0200010001", EOFValidationError::section_headers_not_terminated);
add_test_case(
"EF0001 010004 0200010001 04", EOFValidationError::section_headers_not_terminated);
add_test_case("EF0001 010004 0200010001 0400", EOFValidationError::incomplete_section_size);
}
TEST_F(eof_validation, EOF1_header_not_terminated)
{
add_test_case("EF0001 01", EOFValidationError::section_headers_not_terminated);
add_test_case("EF0001 010004", EOFValidationError::section_headers_not_terminated);
add_test_case("EF0001 010004 FE", EOFValidationError::code_section_missing);
add_test_case("EF0001 010004 02", EOFValidationError::incomplete_section_number);
add_test_case("EF0001 010004 020001", EOFValidationError::section_headers_not_terminated);
add_test_case(
"EF0001 010004 0200010001 040001", EOFValidationError::section_headers_not_terminated);
add_test_case(
"EF0001 010004 0200010001 040001 FE AA", EOFValidationError::header_terminator_missing);
}
TEST_F(eof_validation, EOF1_truncated_section)
{
add_test_case(
"EF0001 010004 0200010002 040000 00", EOFValidationError::invalid_section_bodies_size);
add_test_case("EF0001 010004 0200010002 040000 00 008000",
EOFValidationError::invalid_section_bodies_size);
add_test_case("EF0001 010004 0200010002 040000 00 00800000 FE",
EOFValidationError::invalid_section_bodies_size);
// Data section may not be truncated in toplevel container
add_test_case(
eof_bytecode(OP_INVALID).data("", 2), EOFValidationError::toplevel_container_truncated);
add_test_case(
eof_bytecode(OP_INVALID).data("aa", 2), EOFValidationError::toplevel_container_truncated);
}
TEST_F(eof_validation, EOF1_code_section_offset)
{
const auto eof = eof_bytecode(jumpf(1)).code(OP_INVALID, 0, 0x80, 0).data("00000000");
add_test_case(eof, EOFValidationError::success);
const auto header = read_valid_eof1_header(bytecode(eof));
ASSERT_EQ(header.code_sizes.size(), 2);
EXPECT_EQ(header.code_sizes[0], 3);
EXPECT_EQ(header.code_sizes[1], 1);
ASSERT_EQ(header.code_offsets.size(), 2);
EXPECT_EQ(header.code_offsets[0], 25);
EXPECT_EQ(header.code_offsets[1], 28);
}
TEST_F(eof_validation, EOF1_trailing_bytes_in_subcontainer)
{
add_test_case(
eof_bytecode(eofcreate() + OP_STOP, 4).container(eof_bytecode(OP_INVALID) + "DEADBEEF"),
EOFValidationError::invalid_section_bodies_size);
add_test_case(eof_bytecode(eofcreate() + OP_STOP, 4)
.container(eof_bytecode(OP_INVALID).data("aabb") + "DEADBEEF"),
EOFValidationError::invalid_section_bodies_size);
}
TEST_F(eof_validation, EOF1_trailing_bytes_top_level)
{
add_test_case("EF0001 010004 0200010001 040000 00 00800000 FE DEADBEEF",
EOFValidationError::invalid_section_bodies_size);
add_test_case("EF0001 010004 0200010001 040002 00 00800000 FE AABB DEADBEEF",
EOFValidationError::invalid_section_bodies_size);
}
TEST_F(eof_validation, EOF1_multiple_type_sections)
{
add_test_case("EF0001 010004 010004 02000200010001 00 00800000 00800000 FE FE",
EOFValidationError::code_section_missing);
// Section order is must be (Types, Code+, Data)
add_test_case("EF0001 030002 010001 010001 040002 00 0000 FE FE 0000",
EOFValidationError::type_section_missing);
}
TEST_F(eof_validation, EOF1_type_section_not_first)
{
add_test_case(
"EF0001 0200010001 010004 00 FE 00800000", EOFValidationError::type_section_missing);
add_test_case(
"EF0001 02000200010001 010004 00 FE FE 00800000", EOFValidationError::type_section_missing);
add_test_case("EF0001 0200010001 010004 040003 00 FE 00800000 AABBCC",
EOFValidationError::type_section_missing);
add_test_case("EF0001 0200010001 040003 010004 00 FE AABBCC 00800000",
EOFValidationError::type_section_missing);
}
TEST_F(eof_validation, EOF1_invalid_type_section_size)
{
add_test_case(
"EF0001 010001 0200010001 040000 00 00 FE", EOFValidationError::invalid_type_section_size);
add_test_case("EF0001 010002 0200010001 040000 00 0080 FE",
EOFValidationError::invalid_type_section_size);
add_test_case("EF0001 010008 0200010001 040000 00 0080000000000000 FE",
EOFValidationError::invalid_type_section_size);
add_test_case("EF0001 010008 020003000100010001 040000 00 0080000000800000 FE FE FE",
EOFValidationError::invalid_type_section_size);
add_test_case(
"EF0001 010010 020003000100010001 040000 00 00800000008000000080000000800000 FE FE FE",
EOFValidationError::invalid_type_section_size);
}
TEST_F(eof_validation, EOF1_invalid_section_0_type)
{
add_test_case("EF0001 010004 0200010001 040000 00 00000000 00",
EOFValidationError::invalid_first_section_type);
add_test_case("EF0001 010004 0200010003 040000 00 00010000 60005C",
EOFValidationError::invalid_first_section_type);
add_test_case("EF0001 010004 0200010001 040000 00 01800000 FE",
EOFValidationError::invalid_first_section_type);
add_test_case("EF0001 010004 0200010003 040000 00 02030000 60005C",
EOFValidationError::invalid_first_section_type);
}
TEST_F(eof_validation, EOF1_too_many_code_sections)
{
auto eof_code_sections_1023 = eof_bytecode(jumpf(1));
for (int i = 1; i < 1022; ++i)
eof_code_sections_1023 =
eof_code_sections_1023.code(jumpf(static_cast<uint16_t>(i + 1)), 0, 0x80, 0);
auto eof_code_sections_1024 = eof_code_sections_1023;
eof_code_sections_1023 = eof_code_sections_1023.code(OP_STOP, 0, 0x80, 0);
eof_code_sections_1024 = eof_code_sections_1024.code(jumpf(1023), 0, 0x80, 0);
auto eof_code_sections_1025 = eof_code_sections_1024;
eof_code_sections_1024 = eof_code_sections_1024.code(OP_STOP, 0, 0x80, 0);
eof_code_sections_1025 =
eof_code_sections_1025.code(jumpf(1024), 0, 0x80, 0).code(OP_STOP, 0, 0x80, 0);
add_test_case(eof_code_sections_1023, EOFValidationError::success, "valid_1023");
add_test_case(eof_code_sections_1024, EOFValidationError::success, "valid_1024");
add_test_case(
eof_code_sections_1025, EOFValidationError::too_many_code_sections, "invalid_1025");
}
TEST_F(eof_validation, EOF1_undefined_opcodes)
{
const auto& gas_table = evmone::instr::gas_costs[EVMC_OSAKA];
for (uint16_t opcode = 0; opcode <= 0xff; ++opcode)
{
// PUSH*, DUPN, SWAPN, RJUMP*, CALLF, JUMPF, EOFCREATE, RETRUNCONTRACT require immediate
// argument to be valid, checked in a separate test.
if ((opcode >= OP_PUSH1 && opcode <= OP_PUSH32) || opcode == OP_DUPN ||
opcode == OP_SWAPN || opcode == OP_EXCHANGE || opcode == OP_RJUMP ||
opcode == OP_RJUMPI || opcode == OP_CALLF || opcode == OP_RJUMPV ||
opcode == OP_DATALOADN || opcode == OP_JUMPF || opcode == OP_EOFCREATE ||
opcode == OP_RETURNCONTRACT)
continue;
// These opcodes are deprecated since Osaka.
// gas_cost table current implementation does not allow to undef instructions.
if (opcode == OP_JUMP || opcode == OP_JUMPI || opcode == OP_PC || opcode == OP_CALLCODE ||
opcode == OP_SELFDESTRUCT || opcode == OP_CALL || opcode == OP_STATICCALL ||
opcode == OP_DELEGATECALL || opcode == OP_CREATE || opcode == OP_CREATE2 ||
opcode == OP_CODESIZE || opcode == OP_CODECOPY || opcode == OP_EXTCODESIZE ||
opcode == OP_EXTCODECOPY || opcode == OP_EXTCODEHASH || opcode == OP_GAS)
continue;
const auto expected = (gas_table[opcode] == evmone::instr::undefined ?
EOFValidationError::undefined_instruction :
EOFValidationError::success);
if (opcode == OP_RETF)
{
// RETF can be tested in 2nd code section.
add_test_case(eof_bytecode(callf(1) + OP_STOP).code(OP_RETF, 0, 0, 0), expected);
}
else
{
auto op_stack_change = instr::traits[opcode].stack_height_change;
auto code = push(1) + 16 * OP_DUP1 + Opcode{static_cast<uint8_t>(opcode)};
if (!instr::traits[opcode].is_terminating)
code += bytecode{OP_STOP};
add_test_case(
eof_bytecode(code, static_cast<uint16_t>(std::max(17, 17 + op_stack_change))),
expected);
}
}
add_test_case(eof_bytecode(OP_INVALID), EOFValidationError::success);
}
TEST_F(eof_validation, EOF1_truncated_push)
{
for (uint8_t opcode = OP_PUSH1; opcode <= OP_PUSH32; ++opcode)
{
const auto required_bytes = static_cast<size_t>(opcode) - OP_PUSH1 + 1;
for (size_t i = 0; i < required_bytes; ++i)
{
auto eof_header = "EF0001 010004 0200010001 040000 00 00800000"_hex;
auto& code_size_byte = eof_header[10];
const bytes code{opcode + bytes(i, 0)};
code_size_byte = static_cast<uint8_t>(code.size());
const auto container = eof_header + code;
add_test_case(container, EOFValidationError::truncated_instruction);
}
const auto container = eof_bytecode(opcode + bytes(required_bytes, 0) + OP_STOP,
static_cast<uint8_t>(instr::traits[opcode].stack_height_change));
add_test_case(container, EOFValidationError::success);
}
}
TEST_F(eof_validation, EOF1_valid_rjump)
{
// offset = 0
add_test_case(eof_bytecode(rjump(0) + OP_STOP), EOFValidationError::success, "offset_zero");
// offset = 3
add_test_case(
eof_bytecode(
rjumpi(5, OP_PUSH0) + OP_PUSH0 + OP_PUSH0 + rjump(3) + OP_PUSH0 + push(1) + OP_STOP, 2),
EOFValidationError::success, "offset_positive");
// offset = -4
add_test_case(
eof_bytecode(OP_JUMPDEST + rjump(-4)), EOFValidationError::success, "offset_negative");
}
TEST_F(eof_validation, EOF1_valid_rjumpi)
{
// offset = 0
add_test_case(
eof_bytecode(rjumpi(0, 0) + OP_STOP, 1), EOFValidationError::success, "offset_zero");
// offset = 3
add_test_case(eof_bytecode(rjumpi(3, 0) + OP_JUMPDEST + OP_JUMPDEST + OP_JUMPDEST + OP_STOP, 1),
EOFValidationError::success, "offset_positive");
// offset = -5
add_test_case(
eof_bytecode(rjumpi(-5, 0) + OP_STOP, 1), EOFValidationError::success, "offset_negative");
}
TEST_F(eof_validation, EOF1_valid_rjumpv)
{
// table = [0] case = 0
add_test_case(eof_bytecode(rjumpv({0}, 0) + push(1) + OP_STOP, 1), EOFValidationError::success,
"single_entry_case_0");
// table = [0,3] case = 0
add_test_case(eof_bytecode(rjumpv({0, 3}, 0) + push(1) + OP_STOP + push(2) + OP_STOP, 1),
EOFValidationError::success, "two_entries_case_0");
// table = [0,3] case = 2
add_test_case(eof_bytecode(rjumpv({0, 3}, 2) + push(1) + OP_STOP + push(2) + OP_STOP, 1),
EOFValidationError::success, "two_entries_case_2");
// table = [0,3,-10] case = 2
add_test_case(eof_bytecode(rjumpv({0, 3, -10}, 2) + push(1) + OP_STOP + push(2) + OP_STOP, 1),
EOFValidationError::success, "three_entries_case_2");
}
TEST_F(eof_validation, EOF1_rjump_truncated)
{
add_test_case("EF0001 010004 0200010001 040000 00 00800000 E0",
EOFValidationError::truncated_instruction);
add_test_case("EF0001 010004 0200010002 040000 00 00800000 E000",
EOFValidationError::truncated_instruction);
}
TEST_F(eof_validation, EOF1_rjumpi_truncated)
{
add_test_case("EF0001 010004 0200010003 040000 00 00800000 6000E1",
EOFValidationError::truncated_instruction);
add_test_case("EF0001 010004 0200010004 040000 00 00800000 6000E100",
EOFValidationError::truncated_instruction);
}
TEST_F(eof_validation, EOF1_rjumpv_truncated)
{
// table = [0] case = 0
add_test_case("EF0001 010004 0200010005 040000 00 00800000 6000E20000",
EOFValidationError::truncated_instruction);
// table = [0,3] case = 0
add_test_case("EF0001 010004 0200010007 040000 00 00800000 6000E201000000",
EOFValidationError::truncated_instruction);
// table = [0,3] case = 2
add_test_case("EF0001 010004 0200010006 040000 00 00800000 6002E2010000",
EOFValidationError::truncated_instruction);
// table = [0,3,-10] case = 2
add_test_case("EF0001 010004 0200010009 040000 00 00800000 6002E20200000003FF",
EOFValidationError::truncated_instruction);
}
TEST_F(eof_validation, EOF1_rjump_invalid_destination)
{
// Into header (offset = -5)
add_test_case(eof_bytecode(rjump(-5) + OP_STOP), EOFValidationError::invalid_rjump_destination);
// To before code begin (offset = -13)
add_test_case(
eof_bytecode(rjump(-13) + OP_STOP), EOFValidationError::invalid_rjump_destination);
// To after code end (offset = 2)
add_test_case(eof_bytecode(rjump(2) + OP_STOP), EOFValidationError::invalid_rjump_destination);
// To code end (offset = 1)
add_test_case(eof_bytecode(rjump(1) + OP_STOP), EOFValidationError::invalid_rjump_destination);
// To the same RJUMP immediate (offset = -1)
add_test_case(eof_bytecode(rjump(-1) + OP_STOP), EOFValidationError::invalid_rjump_destination);
// To PUSH immediate (offset = -4)
add_test_case(
eof_bytecode(push(0) + rjump(-4) + OP_STOP), EOFValidationError::invalid_rjump_destination);
// To EOFCREATE immediate
const auto embedded = eof_bytecode(bytecode{OP_INVALID});
add_test_case(
eof_bytecode(rjump(9) + 0 + 0xff + 0 + 0 + OP_EOFCREATE + Opcode{0} + OP_POP + OP_STOP, 4)
.container(embedded),
EOFValidationError::invalid_rjump_destination);
// To RETURNCONTRACT immediate
add_test_case(
eof_bytecode(rjump(5) + 0 + 0 + OP_RETURNCONTRACT + Opcode{0}, 2).container(embedded),
ContainerKind::initcode, EOFValidationError::invalid_rjump_destination);
}
TEST_F(eof_validation, EOF1_rjumpi_invalid_destination)
{
// Into header (offset = -7)
add_test_case(
eof_bytecode(rjumpi(-7, 0) + OP_STOP, 1), EOFValidationError::invalid_rjump_destination);
// To before code begin (offset = -15)
add_test_case(
eof_bytecode(rjumpi(-15, 0) + OP_STOP, 1), EOFValidationError::invalid_rjump_destination);
// To after code end (offset = 2)
add_test_case(
eof_bytecode(rjumpi(2, 0) + OP_STOP, 1), EOFValidationError::invalid_rjump_destination);
// To code end (offset = 1)
add_test_case(
eof_bytecode(rjumpi(1, 0) + OP_STOP, 1), EOFValidationError::invalid_rjump_destination);
// To the same RJUMPI immediate (offset = -1)
add_test_case(
eof_bytecode(rjumpi(-1, 0) + OP_STOP, 1), EOFValidationError::invalid_rjump_destination);
// To PUSH immediate (offset = -4)
add_test_case(
eof_bytecode(rjumpi(-4, 0) + OP_STOP, 1), EOFValidationError::invalid_rjump_destination);
// To EOFCREATE immediate
const auto embedded = eof_bytecode(bytecode{OP_INVALID});
add_test_case(
eof_bytecode(
rjumpi(9, 0) + 0 + 0xff + 0 + 0 + OP_EOFCREATE + Opcode{0} + OP_POP + OP_STOP, 4)
.container(embedded),
EOFValidationError::invalid_rjump_destination);
// To RETURNCONTRACT immediate
add_test_case(
eof_bytecode(rjumpi(5, 0) + 0 + 0 + OP_RETURNCONTRACT + Opcode{0}, 2).container(embedded),
ContainerKind::initcode, EOFValidationError::invalid_rjump_destination);
}
TEST_F(eof_validation, EOF1_rjumpv_invalid_destination)
{
// table = [-23] case = 0
add_test_case(eof_bytecode(rjumpv({-23}, 0) + push(1) + OP_STOP, 1),
EOFValidationError::invalid_rjump_destination);
// table = [-8] case = 0
add_test_case(eof_bytecode(rjumpv({-8}, 0) + push(1) + OP_STOP, 1),
EOFValidationError::invalid_rjump_destination);
// table = [-1] case = 0
add_test_case(eof_bytecode(rjumpv({-1}, 0) + push(1) + OP_STOP, 1),
EOFValidationError::invalid_rjump_destination);
// table = [3] case = 0
add_test_case(eof_bytecode(rjumpv({3}, 0) + push(1) + OP_STOP, 1),
EOFValidationError::invalid_rjump_destination);
// table = [4] case = 0
add_test_case(eof_bytecode(rjumpv({4}, 0) + push(1) + OP_STOP, 1),
EOFValidationError::invalid_rjump_destination);
// table = [0,3,-27] case = 2
add_test_case(eof_bytecode(rjumpv({0, 3, -27}, 2) + push(1) + OP_STOP + push(2) + OP_STOP, 1),
EOFValidationError::invalid_rjump_destination);
// table = [0,3,-12] case = 2
add_test_case(eof_bytecode(rjumpv({0, 3, -12}, 2) + push(1) + OP_STOP + push(2) + OP_STOP, 1),
EOFValidationError::invalid_rjump_destination);
// table = [0,3,-1] case = 2
add_test_case(eof_bytecode(rjumpv({0, 3, -1}, 2) + push(1) + OP_STOP + push(2) + OP_STOP, 1),
EOFValidationError::invalid_rjump_destination);
// table = [0,3,6] case = 2
add_test_case(eof_bytecode(rjumpv({0, 3, 6}, 2) + push(1) + OP_STOP + push(2) + OP_STOP, 1),
EOFValidationError::invalid_rjump_destination);
// table = [0,3,7] case = 2
add_test_case(eof_bytecode(rjumpv({0, 3, 7}, 2) + push(1) + OP_STOP + push(2) + OP_STOP, 1),
EOFValidationError::invalid_rjump_destination);
// To EOFCREATE immediate
const auto embedded = eof_bytecode(bytecode{OP_INVALID});
add_test_case(
eof_bytecode(
rjumpv({9}, 0) + 0 + 0xff + 0 + 0 + OP_EOFCREATE + Opcode{0} + OP_POP + OP_STOP, 4)
.container(embedded),
EOFValidationError::invalid_rjump_destination);
// To RETURNCONTRACT immediate
add_test_case(
eof_bytecode(rjumpv({5}, 0) + 0 + 0 + OP_RETURNCONTRACT + Opcode{0}, 2).container(embedded),
ContainerKind::initcode, EOFValidationError::invalid_rjump_destination);
}
TEST_F(eof_validation, EOF1_section_order)
{
// 01 02 04
add_test_case("EF0001 010004 0200010006 040002 00 00800001 6000E0000000 AABB",
EOFValidationError::success);
// 01 04 02
add_test_case("EF0001 010004 040002 0200010006 00 00800000 AABB 6000E0000000",
EOFValidationError::code_section_missing);
// 02 01 04
add_test_case("EF0001 0200010006 010004 040002 00 6000E0000000 00800000 AABB",
EOFValidationError::type_section_missing);
// 02 04 01
add_test_case("EF0001 0200010006 040002 010004 00 6000E0000000 AABB 00800000",
EOFValidationError::type_section_missing);
// 04 01 02
add_test_case("EF0001 040002 010004 0200010006 00 AABB 00800000 6000E0000000",
EOFValidationError::type_section_missing);
// 04 02 01
add_test_case("EF0001 040002 0200010006 010004 00 AABB 6000E0000000 00800000",
EOFValidationError::type_section_missing);
// 01 02 03 04
add_test_case(
"EF0001 010004 0200010007 0300010014 040002 00 00800004 5F5F5F5FEC0000 "
"EF000101000402000100010400000000800000FE AABB",
EOFValidationError::success);
// 03 01 02 04
add_test_case(
"EF0001 0300010014 010004 0200010007 040002 00 EF000101000402000100010400000000800000FE "
"00800004 5F5F5F5FEC0000 AABB",
EOFValidationError::type_section_missing);
// 01 03 02 04
add_test_case(
"EF0001 010004 0300010014 0200010007 040002 00 00800004 "
"EF000101000402000100010400000000800000FE 5F5F5F5FEC0000 AABB",
EOFValidationError::code_section_missing);
// 01 02 04 03
add_test_case(
"EF0001 010004 0200010007 040002 0300010014 00 00800004 5F5F5F5FEC0000 AABB "
"EF000101000402000100010400000000800000FE",
EOFValidationError::header_terminator_missing);
}
TEST_F(eof_validation, deprecated_instructions)
{
for (auto op : {OP_CALLCODE, OP_SELFDESTRUCT, OP_JUMP, OP_JUMPI, OP_PC, OP_CALL, OP_STATICCALL,
OP_DELEGATECALL, OP_CREATE, OP_CREATE2, OP_CODESIZE, OP_CODECOPY, OP_EXTCODESIZE,
OP_EXTCODECOPY, OP_EXTCODEHASH, OP_GAS})
add_test_case(eof_bytecode(op), EOFValidationError::undefined_instruction);
}
TEST_F(eof_validation, max_arguments_count)
{
add_test_case(
eof_bytecode(127 * push0() + callf(1) + OP_STOP, 127).code(OP_RETF, 127, 127, 127),
EOFValidationError::success);
add_test_case(eof_bytecode(callf(1) + OP_STOP, 0).code(OP_RETF, 128, 128, 128),
EOFValidationError::inputs_outputs_num_above_limit);
add_test_case(eof_bytecode(callf(1) + OP_STOP, 127).code(127 * push(1) + OP_RETF, 0, 127, 127),
EOFValidationError::success);
add_test_case(eof_bytecode(callf(1) + OP_STOP, 129).code(129 * push(1) + OP_RETF, 0, 129, 129),
EOFValidationError::inputs_outputs_num_above_limit);
add_test_case(eof_bytecode(127 * push0() + callf(1) + OP_STOP, 127)
.code(127 * OP_POP + OP_RETF, 127, 0, 127),
EOFValidationError::success);
add_test_case(eof_bytecode(128 * push(1) + callf(1) + OP_STOP, 128)
.code(128 * OP_POP + OP_RETF, 128, 0, 128),
EOFValidationError::inputs_outputs_num_above_limit);
}
TEST_F(eof_validation, max_stack_height)
{
add_test_case(eof_bytecode(callf(1) + OP_STOP, 0)
.code(0x3FF * push(1) + 0x3FF * OP_POP + OP_RETF, 0, 0, 1023),
EOFValidationError::success);
add_test_case(eof_bytecode(1023 * push(1) + 1023 * OP_POP + callf(1) + OP_STOP, 1023)
.code(OP_RETF, 0, 0, 0),
EOFValidationError::success);
add_test_case(eof_bytecode(1024 * push(1) + OP_STOP, 1024),
EOFValidationError::max_stack_height_above_limit);
add_test_case(eof_bytecode(0x400 * push(1) + callf(1) + 0x400 * OP_POP + OP_STOP, 1024)
.code(OP_RETF, 0, 0, 0),
EOFValidationError::max_stack_height_above_limit);
add_test_case(eof_bytecode(callf(1) + OP_STOP, 0)
.code(0x400 * push(1) + 0x400 * OP_POP + OP_RETF, 0, 0, 1023),
EOFValidationError::invalid_max_stack_height);
add_test_case(eof_bytecode(1024 * push(1) + callf(1) + 1024 * OP_POP + OP_STOP, 1023)
.code(OP_RETF, 0, 0, 0),
EOFValidationError::invalid_max_stack_height);
add_test_case(eof_bytecode(rjumpi(2, 0) + 1 + OP_STOP, 1), EOFValidationError::success);
add_test_case(
eof_bytecode(rjumpi(-3, 0) + OP_STOP, 1), EOFValidationError::stack_height_mismatch);
add_test_case(
eof_bytecode(rjumpv({-4}, 0) + OP_STOP, 1), EOFValidationError::stack_height_mismatch);
}
TEST_F(eof_validation, EOF1_callf_truncated)
{
add_test_case("EF0001 010004 0200010001 040000 00 00800000 E3",
EOFValidationError::truncated_instruction);
add_test_case("EF0001 010004 0200010002 040000 00 00800000 E300",
EOFValidationError::truncated_instruction);
}
TEST_F(eof_validation, callf_invalid_code_section_index)
{
add_test_case(eof_bytecode(callf(1) + OP_STOP), EOFValidationError::invalid_code_section_index);
}
TEST_F(eof_validation, incomplete_section_size)
{
add_test_case("ef0001 010100 02003f 0100", EOFValidationError::incomplete_section_size);
}
TEST_F(eof_validation, data_section_missing)
{
add_test_case(
"ef0001 010004 0200010001 00 00800000 fe", EOFValidationError::data_section_missing);
}
TEST_F(eof_validation, multiple_code_sections_headers)
{
add_test_case(
"0xef0001 010008 020001 0004 020001 0005 040000 00 00800000 045c0000 00405c00 00002e0005",
EOFValidationError::data_section_missing);
}
TEST_F(eof_validation, EOF1_dataloadn_truncated)
{
add_test_case("EF0001 010004 0200010001 040000 00 00800000 D1",
EOFValidationError::truncated_instruction);
add_test_case("EF0001 010004 0200010002 040000 00 00800000 D100",
EOFValidationError::truncated_instruction);
}
TEST_F(eof_validation, dataloadn)
{
// DATALOADN{0}
add_test_case(eof_bytecode(dataloadn(0) + OP_POP + OP_STOP, 1)
.data("0000000000000000111111111111111122222222222222223333333333333333"),
EOFValidationError::success);
// DATALOADN{1}
add_test_case(eof_bytecode(dataloadn(1) + OP_POP + OP_STOP, 1)
.data("000000000000000011111111111111112222222222222222333333333333333344"),
EOFValidationError::success);
// DATALOADN{32}
add_test_case(eof_bytecode(dataloadn(32) + OP_POP + OP_STOP, 1)
.data("0000000000000000111111111111111122222222222222223333333333333333"
"0000000000000000111111111111111122222222222222223333333333333333"),
EOFValidationError::success);
// DATALOADN{0} - no data section
add_test_case(eof_bytecode(dataloadn(0) + OP_POP + OP_STOP, 1),
EOFValidationError::invalid_dataloadn_index);
// DATALOADN{1} - out of data section bounds
add_test_case(eof_bytecode(dataloadn(1) + OP_POP + OP_STOP, 1).data("00"),
EOFValidationError::invalid_dataloadn_index);
// DATALOADN{32} - out of data section bounds
add_test_case(eof_bytecode(dataloadn(32) + OP_POP + OP_STOP, 1)
.data("0000000000000000111111111111111122222222222222223333333333333333"),
EOFValidationError::invalid_dataloadn_index);
// DATALOADN{uint16_max} - out of data section bounds
add_test_case(eof_bytecode(dataloadn(0xffff) + OP_POP + OP_STOP, 1)
.data("0000000000000000111111111111111122222222222222223333333333333333"),
EOFValidationError::invalid_dataloadn_index);
// DATALOADN{32} - truncated word
add_test_case(eof_bytecode(dataloadn(32) + OP_POP + OP_STOP, 1)
.data("0000000000000000111111111111111122222222222222223333333333333333 "
"00000000000000001111111111111111222222222222222233333333333333"),
EOFValidationError::invalid_dataloadn_index);
}
TEST_F(eof_validation, non_returning_status)
{
// Non-returning with no JUMPF and no RETF
add_test_case(eof_bytecode(OP_STOP), EOFValidationError::success);
// Non-returning with JUMPF
add_test_case(eof_bytecode(jumpf(1)).code(OP_STOP, 0, 0x80, 0), EOFValidationError::success);
// Returning with RETF
add_test_case(
eof_bytecode(callf(1) + OP_STOP).code(OP_RETF, 0, 0, 0), EOFValidationError::success);
// Returning with JUMPF
add_test_case(eof_bytecode(callf(1) + OP_STOP).code(jumpf(2), 0, 0, 0).code(OP_RETF, 0, 0, 0),
EOFValidationError::success);
// Returning with JUMPF to returning and RETF
add_test_case(eof_bytecode(OP_PUSH0 + callf(1) + OP_STOP, 1)
.code(bytecode{OP_RJUMPI} + "0001" + OP_RETF + jumpf(2), 1, 0, 1)
.code(OP_RETF, 0, 0, 0),
EOFValidationError::success);
// Returning with JUMPF to non-returning and RETF
add_test_case(eof_bytecode(OP_PUSH0 + callf(1) + OP_STOP, 1)
.code(bytecode{OP_RJUMPI} + "0001" + OP_RETF + jumpf(0), 1, 0, 1),
EOFValidationError::success);
// Invalid with RETF
add_test_case(eof_bytecode(jumpf(1)).code(OP_RETF, 0, 0x80, 0),
EOFValidationError::invalid_non_returning_flag);
add_test_case(eof_bytecode(OP_RETF), EOFValidationError::invalid_non_returning_flag);
// Invalid with JUMPF to returning
add_test_case(eof_bytecode(jumpf(1)).code(jumpf(2), 0, 0x80, 0).code(OP_RETF, 0, 0, 0),
EOFValidationError::invalid_non_returning_flag);
// Invalid with JUMPF to non-returning
add_test_case(eof_bytecode(jumpf(1)).code(jumpf(0), 0, 0, 0),
EOFValidationError::invalid_non_returning_flag);
// Invalid with JUMPF to returning and RETF
add_test_case(eof_bytecode(OP_PUSH0 + jumpf(1), 1)
.code(bytecode{OP_RJUMPI} + "0001" + OP_RETF + jumpf(2), 1, 0x80, 1)
.code(OP_RETF, 0, 0, 0),
EOFValidationError::invalid_non_returning_flag);
// Invalid with JUMPF to non-returning and RETF
add_test_case(eof_bytecode(OP_PUSH0 + jumpf(1), 1)
.code(bytecode{OP_RJUMPI} + "0001" + OP_RETF + jumpf(0), 1, 0x80, 1),
EOFValidationError::invalid_non_returning_flag);
// Circular JUMPF: can be both returning and non-returning
add_test_case(eof_bytecode(jumpf(1)).code(jumpf(2), 0, 0x80, 0).code(jumpf(1), 0, 0x80, 0),
EOFValidationError::success);
add_test_case(eof_bytecode(callf(1) + OP_STOP).code(jumpf(2), 0, 0, 0).code(jumpf(1), 0, 0, 0),
EOFValidationError::success);
}
TEST_F(eof_validation, callf_into_nonreturning)
{
// function 0: (0, non-returning) : CALLF{1} STOP
// function 2: (1, non-returning) : STOP
add_test_case(eof_bytecode(callf(1) + OP_STOP).code(OP_STOP, 0, 0x80, 0),
EOFValidationError::callf_to_non_returning_function);
}
TEST_F(eof_validation, jumpf_equal_outputs)
{
add_test_case(eof_bytecode(callf(1) + OP_STOP, 3)
.code(jumpf(2), 0, 3, 0)
.code(3 * OP_PUSH0 + OP_RETF, 0, 3, 3),
EOFValidationError::success);
}
TEST_F(eof_validation, jumpf_compatible_outputs)
{
add_test_case(eof_bytecode(callf(1) + OP_STOP, 5)
.code(2 * OP_PUSH0 + jumpf(2), 0, 5, 2)
.code(3 * OP_PUSH0 + OP_RETF, 0, 3, 3),
EOFValidationError::success);
}
TEST_F(eof_validation, jumpf_incompatible_outputs)
{
const auto code = eof_bytecode(callf(1) + OP_STOP, 3)
.code(jumpf(2), 0, 3, 0)
.code(5 * OP_PUSH0 + OP_RETF, 0, 5, 3);
add_test_case(code, EOFValidationError::jumpf_destination_incompatible_outputs);
}
TEST_F(eof_validation, unreachable_code_sections)
{
add_test_case(eof_bytecode(OP_INVALID).code(OP_INVALID, 0, 0x80, 0),
EOFValidationError::unreachable_code_sections);
add_test_case(eof_bytecode(callf(1) + OP_STOP, 0)
.code(bytecode{"5B"} + OP_RETF, 0, 0, 0)
.code(bytecode{"FE"}, 0, 0x80, 0),
EOFValidationError::unreachable_code_sections);
add_test_case(eof_bytecode(callf(2) + OP_STOP, 0)
.code(bytecode{"FE"}, 0, 0x80, 0)
.code(bytecode{"5B"} + OP_RETF, 0, 0, 0),
EOFValidationError::unreachable_code_sections);
add_test_case(eof_bytecode(callf(3) + OP_STOP, 0)
.code(bytecode{"FE"}, 0, 0x80, 0)
.code(bytecode{"5B"} + OP_RETF, 0, 0, 0)
.code(callf(2) + OP_RETF, 0, 0, 0),
EOFValidationError::unreachable_code_sections);
add_test_case(eof_bytecode(jumpf(0)).code(jumpf(1), 0, 0x80, 0),
EOFValidationError::unreachable_code_sections);
add_test_case(eof_bytecode(jumpf(1))
.code(bytecode{OP_STOP}, 0, 0x80, 0)
.code(bytecode{"5B"} + OP_RETF, 0, 0, 0),
EOFValidationError::unreachable_code_sections);
{
auto code_sections_256_err_001 = eof_bytecode(jumpf(1)).code(jumpf(1), 0, 0x80, 0);
auto code_sections_256_err_254 = eof_bytecode(jumpf(1)).code(jumpf(2), 0, 0x80, 0);
for (int i = 2; i < 254; ++i)
{
code_sections_256_err_001.code(jumpf(static_cast<uint16_t>(i + 1)), 0, 0x80, 0);
code_sections_256_err_254.code(jumpf(static_cast<uint16_t>(i + 1)), 0, 0x80, 0);
}
code_sections_256_err_001.code(jumpf(255), 0, 0x80, 0)
.code(3 * bytecode{"5B"} + OP_STOP, 0, 0x80, 0);
code_sections_256_err_254.code(jumpf(254), 0, 0x80, 0)
.code(3 * bytecode{"5B"} + OP_STOP, 0, 0x80, 0);
// Code Section 1 calls itself instead of code section 2, leaving code section 2 unreachable
add_test_case(code_sections_256_err_001, EOFValidationError::unreachable_code_sections);
// Code Section 254 calls itself instead of code section 255, leaving code section 255
// unreachable
add_test_case(code_sections_256_err_254, EOFValidationError::unreachable_code_sections);
// Code Section 0 calls section 1, which calls itself, leaving section
// 2 unreachable
add_test_case(eof_bytecode(jumpf(1)).code(jumpf(1), 0, 0x80, 0).code(jumpf(2), 0, 0x80, 0),
EOFValidationError::unreachable_code_sections);
// Code Section 0 calls section 1, which calls section 2, section 3 and
// 4 call each other but are not reachable from section 0
add_test_case(eof_bytecode(jumpf(1))
.code(jumpf(2), 0, 0x80, 0)
.code(OP_INVALID, 0, 0x80, 0)
.code(jumpf(4), 0, 0x80, 0)
.code(jumpf(3), 0, 0x80, 0),
EOFValidationError::unreachable_code_sections);
}
}
TEST_F(eof_validation, EOF1_embedded_container)
{
// no data section
const auto embedded = eof_bytecode(bytecode{OP_INVALID});
add_test_case(
eof_bytecode(eofcreate() + OP_STOP, 4).container(embedded), EOFValidationError::success);
// no data section in container, but anticipated aux_data
// data section is allowed to be truncated in runtime subcontainer
add_test_case(
eof_bytecode(returncontract(0, 0, 2), 2).container(eof_bytecode(OP_INVALID).data("", 2)),
ContainerKind::initcode, EOFValidationError::success);
// data section is allowed to be partially truncated in runtime subcontainer
add_test_case(
eof_bytecode(returncontract(0, 0, 1), 2).container(eof_bytecode(OP_INVALID).data("aa", 2)),
ContainerKind::initcode, EOFValidationError::success);
// with data section
add_test_case(eof_bytecode(eofcreate() + OP_STOP, 4).container(embedded).data("AABB", 2),
EOFValidationError::success);
// garbage in container section - not allowed
add_test_case(eof_bytecode(eofcreate() + OP_STOP, 4).container("aabbccddeeff"),
EOFValidationError::invalid_prefix);
// multiple container sections
add_test_case(eof_bytecode(eofcreate() + OP_POP + eofcreate().container(1) + OP_STOP, 4)
.container(embedded)
.container(eof_bytecode(revert(0, 0), 2)),
EOFValidationError::success);
// Max number (256) of container sections
bytecode code;
for (auto i = 0; i < 256; ++i)
code += eofcreate().container(static_cast<uint8_t>(i)) + OP_POP;
code += bytecode{OP_STOP};
auto container = eof_bytecode(code, 4);
const auto subcontainer = eof_bytecode(OP_INVALID);
for (auto i = 0; i < 256; ++i)
container.container(subcontainer);
add_test_case(container, EOFValidationError::success);
}
TEST_F(eof_validation, EOF1_embedded_container_invalid)
{
// Truncated container header
add_test_case("EF0001 010004 0200010006 03", EOFValidationError::incomplete_section_number);
add_test_case("EF0001 010004 0200010006 0300", EOFValidationError::incomplete_section_number);
add_test_case(
"EF0001 010004 0200010006 030001", EOFValidationError::section_headers_not_terminated);
add_test_case("EF0001 010004 0200010006 03000100", EOFValidationError::incomplete_section_size);
add_test_case(
"EF0001 010004 0200010006 0300010014", EOFValidationError::section_headers_not_terminated);
// Zero container sections
add_test_case("EF0001 010004 0200010006 030000 040000 00 00800001 6000E1000000",
EOFValidationError::zero_section_size);
// Container section with 0 size
add_test_case("EF0001 010004 0200010006 0300010000 040000 00 00800001 6000E1000000",
EOFValidationError::zero_section_size);