@@ -691,8 +691,8 @@ TEST_F(eof_validation, max_stack_height)
691
691
0x400 * OP_POP + OP_STOP + OP_RETF,
692
692
EOFValidationError::max_stack_height_above_limit);
693
693
694
- add_test_case (bytecode{ " EF0001 010008 02000200010C01 040000 00 00800000 000003FF " } + OP_STOP +
695
- 0x400 * bytecode{1 } + 0x400 * OP_POP + OP_RETF,
694
+ add_test_case (eof_bytecode ( callf ( 1 ) + OP_STOP, 0 )
695
+ . code ( 0x400 * bytecode{1 } + 0x400 * OP_POP + OP_RETF, 0 , 0 , 1023 ) ,
696
696
EOFValidationError::invalid_max_stack_height);
697
697
698
698
add_test_case (" EF0001 010008 0200020C010001 040000 00 008003FF 00000000" + 0x400 * bytecode{1 } +
@@ -858,23 +858,24 @@ TEST_F(eof_validation, non_returning_status)
858
858
EOFValidationError::success);
859
859
860
860
// Invalid with RETF
861
- add_test_case (" EF0001 010008 02000200010001 040000 00 0080000000800000 00 E4 " ,
861
+ add_test_case (eof_bytecode ( jumpf ( 1 )). code (OP_RETF, 0 , 0x80 , 0 ) ,
862
862
EOFValidationError::invalid_non_returning_flag);
863
863
add_test_case (" EF0001 010004 0200010001 040000 00 00800000 E4" ,
864
864
EOFValidationError::invalid_non_returning_flag);
865
865
// Invalid with JUMPF to returning
866
866
add_test_case (
867
- " EF0001 01000c 020003000100030001 040000 00 008000000080000000000000 00 E50002 E4" ,
867
+ " EF0001 01000c 020003000300030001 040000 00 008000000080000000000000 E50001 E50002 E4" ,
868
868
EOFValidationError::invalid_non_returning_flag);
869
869
// Invalid with JUMPF to non-returning
870
- add_test_case (" EF0001 010008 02000200010003 040000 00 0080000000000000 00 E50000" ,
870
+ add_test_case (" EF0001 010008 02000200030003 040000 00 0080000000000000 E50001 E50000" ,
871
871
EOFValidationError::invalid_non_returning_flag);
872
872
// Invalid with JUMPF to returning and RETF
873
873
add_test_case (
874
- " EF0001 01000C 020003000100070001 040000 00 008000000180000100000000 00 E10001E4E50002 E4" ,
874
+ " EF0001 01000C 020003000400070001 040000 00 008000010180000100000000 5FE50001 "
875
+ " E10001E4E50002 E4" ,
875
876
EOFValidationError::invalid_non_returning_flag);
876
877
// Invalid with JUMPF to non-returning and RETF
877
- add_test_case (" EF0001 010008 02000200010007 040000 00 0080000001800001 00 E10001E4E50000" ,
878
+ add_test_case (" EF0001 010008 02000200040007 040000 00 0080000101800001 5FE50001 E10001E4E50000" ,
878
879
EOFValidationError::invalid_non_returning_flag);
879
880
880
881
// Circular JUMPF: can be both returning and non-returning
@@ -971,6 +972,20 @@ TEST_F(eof_validation, unreachable_code_sections)
971
972
// Code Section 254 calls itself instead of code section 255, leaving code section 255
972
973
// unreachable
973
974
add_test_case (code_sections_256_err_254, EOFValidationError::unreachable_code_sections);
975
+
976
+ // Code Section 0 calls section 1, which calls itself, leaving section
977
+ // 2 unreachable
978
+ add_test_case (eof_bytecode (jumpf (1 )).code (jumpf (1 ), 0 , 0x80 , 0 ).code (jumpf (2 ), 0 , 0x80 , 0 ),
979
+ EOFValidationError::unreachable_code_sections);
980
+
981
+ // Code Section 0 calls section 1, which calls section 2, section 3 and
982
+ // 4 call each other but are not reachable from section 0
983
+ add_test_case (eof_bytecode (jumpf (1 ))
984
+ .code (jumpf (2 ), 0 , 0x80 , 0 )
985
+ .code (OP_INVALID, 0 , 0x80 , 0 )
986
+ .code (jumpf (4 ), 0 , 0x80 , 0 )
987
+ .code (jumpf (3 ), 0 , 0x80 , 0 ),
988
+ EOFValidationError::unreachable_code_sections);
974
989
}
975
990
}
976
991
@@ -1166,3 +1181,18 @@ TEST_F(eof_validation, EOF1_unreferenced_subcontainer_valid)
1166
1181
const auto embedded = eof_bytecode (bytecode{OP_INVALID});
1167
1182
add_test_case (eof_bytecode (OP_STOP).container (embedded), EOFValidationError::success);
1168
1183
}
1184
+
1185
+ TEST_F (eof_validation, EOF1_subcontainer_containing_unreachable_code_sections)
1186
+ {
1187
+ const auto embedded_1 = eof_bytecode (OP_INVALID).code (OP_INVALID, 0 , 0x80 , 0 );
1188
+ add_test_case (eof_bytecode (OP_INVALID).container (embedded_1),
1189
+ EOFValidationError::unreachable_code_sections);
1190
+
1191
+ const auto embedded_2 = eof_bytecode (jumpf (1 ))
1192
+ .code (jumpf (2 ), 0 , 0x80 , 0 )
1193
+ .code (OP_INVALID, 0 , 0x80 , 0 )
1194
+ .code (jumpf (4 ), 0 , 0x80 , 0 )
1195
+ .code (jumpf (3 ), 0 , 0x80 , 0 );
1196
+ add_test_case (eof_bytecode (OP_INVALID).container (embedded_2),
1197
+ EOFValidationError::unreachable_code_sections);
1198
+ }
0 commit comments