Skip to content

Commit 0e48680

Browse files
committed
Refactor: don't validate header before enqueing container
1 parent 29a9dec commit 0e48680

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

lib/evmone/eof.cpp

+10-18
Original file line numberDiff line numberDiff line change
@@ -639,24 +639,25 @@ std::variant<EOFValidationError, int32_t> validate_max_stack_height(
639639

640640
EOFValidationError validate_eof1(evmc_revision rev, bytes_view main_container) noexcept
641641
{
642-
const auto error_or_header = validate_header(rev, main_container);
643-
if (const auto* error = std::get_if<EOFValidationError>(&error_or_header))
644-
return *error;
645-
const auto& main_container_header = std::get<EOF1Header>(error_or_header);
646-
647642
struct Container
648643
{
649644
bytes_view bytes;
650-
EOF1Header header;
651645
bool referenced_by_eofcreate = false;
652646
};
653647
// Queue of containers left to process
654648
std::queue<Container> container_queue;
655-
container_queue.emplace(main_container, main_container_header, false);
649+
container_queue.push({main_container, false});
656650

657651
while (!container_queue.empty())
658652
{
659-
const auto& [container, header, referenced_by_eofcreate] = container_queue.front();
653+
const auto& [container, referenced_by_eofcreate] = container_queue.front();
654+
655+
// Validate header
656+
auto error_or_header = validate_header(rev, container);
657+
if (const auto* error = std::get_if<EOFValidationError>(&error_or_header))
658+
return *error;
659+
660+
auto& header = std::get<EOF1Header>(error_or_header);
660661

661662
// Validate code sections
662663
std::vector<bool> visited_code_sections(header.code_sizes.size());
@@ -720,16 +721,7 @@ EOFValidationError validate_eof1(evmc_revision rev, bytes_view main_container) n
720721
{
721722
const bytes_view subcontainer{header.get_container(container, subcont_idx)};
722723

723-
auto error_subcont_or_header = validate_header(rev, subcontainer);
724-
if (const auto* error_subcont =
725-
std::get_if<EOFValidationError>(&error_subcont_or_header))
726-
return *error_subcont;
727-
728-
auto& subcont_header = std::get<EOF1Header>(error_subcont_or_header);
729-
730-
container_queue.emplace(subcontainer, std::move(subcont_header),
731-
subcontainer_referenced_by_eofcreate[subcont_idx],
732-
subcontainer_referenced_by_returncontract[subcont_idx]);
724+
container_queue.push({subcontainer, subcontainer_referenced_by_eofcreate[subcont_idx]});
733725
}
734726

735727
container_queue.pop();

0 commit comments

Comments
 (0)