@@ -659,25 +659,13 @@ EOFValidationError validate_eof1(evmc_revision rev, bytes_view main_container) n
659
659
{
660
660
const auto & [container, header, referenced_by_eofcreate] = container_queue.front ();
661
661
662
- // Validate subcontainer headers
663
- std::vector<ContainerValidation> subcontainers;
664
- for (size_t subcont_idx = 0 ; subcont_idx < header.container_sizes .size (); ++subcont_idx)
665
- {
666
- const bytes_view subcontainer{header.get_container (container, subcont_idx)};
667
-
668
- auto error_subcont_or_header = validate_header (rev, subcontainer);
669
- if (const auto * error_subcont =
670
- std::get_if<EOFValidationError>(&error_subcont_or_header))
671
- return *error_subcont;
672
-
673
- auto & subcont_header = std::get<EOF1Header>(error_subcont_or_header);
674
- subcontainers.push_back ({subcontainer, std::move (subcont_header), false });
675
- }
676
-
677
662
// Validate code sections
678
663
std::vector<bool > visited_code_sections (header.code_sizes .size ());
679
664
std::queue<uint16_t > code_sections_queue ({0 });
680
665
666
+ const auto subcontainer_count = header.container_sizes .size ();
667
+ std::vector<bool > subcontainer_referenced_by_eofcreate (subcontainer_count, false );
668
+
681
669
while (!code_sections_queue.empty ())
682
670
{
683
671
const auto code_idx = code_sections_queue.front ();
@@ -702,7 +690,7 @@ EOFValidationError validate_eof1(evmc_revision rev, bytes_view main_container) n
702
690
for (const auto & [index , opcode] : subcontainer_references)
703
691
{
704
692
if (opcode == OP_EOFCREATE)
705
- subcontainers [index ]. referenced_by_eofcreate = true ;
693
+ subcontainer_referenced_by_eofcreate [index ] = true ;
706
694
}
707
695
708
696
// TODO(C++23): can use push_range()
@@ -729,11 +717,23 @@ EOFValidationError validate_eof1(evmc_revision rev, bytes_view main_container) n
729
717
if (referenced_by_eofcreate && !header.can_init (container.size ()))
730
718
return EOFValidationError::eofcreate_with_truncated_container;
731
719
732
- container_queue.pop ();
720
+ // Enqueue subcontainers
721
+ for (size_t subcont_idx = 0 ; subcont_idx < subcontainer_count; ++subcont_idx)
722
+ {
723
+ const bytes_view subcontainer{header.get_container (container, subcont_idx)};
724
+
725
+ auto error_subcont_or_header = validate_header (rev, subcontainer);
726
+ if (const auto * error_subcont =
727
+ std::get_if<EOFValidationError>(&error_subcont_or_header))
728
+ return *error_subcont;
729
+
730
+ auto & subcont_header = std::get<EOF1Header>(error_subcont_or_header);
733
731
734
- // enqueue subcontainers
735
- for (auto & subcontainer : subcontainers)
736
- container_queue.emplace (std::move (subcontainer));
732
+ container_queue.emplace (subcontainer, std::move (subcont_header),
733
+ subcontainer_referenced_by_eofcreate[subcont_idx]);
734
+ }
735
+
736
+ container_queue.pop ();
737
737
}
738
738
739
739
return EOFValidationError::success;
0 commit comments