Skip to content

Commit dc1d74c

Browse files
committed
Refactor: don't validate header before enqueing container
1 parent d7d2936 commit dc1d74c

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

lib/evmone/eof.cpp

+10-17
Original file line numberDiff line numberDiff line change
@@ -640,24 +640,25 @@ std::variant<EOFValidationError, int32_t> validate_max_stack_height(
640640

641641
EOFValidationError validate_eof1(evmc_revision rev, bytes_view main_container) noexcept
642642
{
643-
const auto error_or_header = validate_header(rev, main_container);
644-
if (const auto* error = std::get_if<EOFValidationError>(&error_or_header))
645-
return *error;
646-
const auto& main_container_header = std::get<EOF1Header>(error_or_header);
647-
648643
struct ContainerValidation
649644
{
650645
bytes_view bytes;
651-
EOF1Header header;
652646
bool referenced_by_eofcreate = false;
653647
};
654648
// Queue of containers left to process
655649
std::queue<ContainerValidation> container_queue;
656-
container_queue.emplace(main_container, main_container_header, false);
650+
container_queue.push({main_container, false});
657651

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

662663
// Validate code sections
663664
std::vector<bool> visited_code_sections(header.code_sizes.size());
@@ -722,15 +723,7 @@ EOFValidationError validate_eof1(evmc_revision rev, bytes_view main_container) n
722723
{
723724
const bytes_view subcontainer{header.get_container(container, subcont_idx)};
724725

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);
731-
732-
container_queue.emplace(subcontainer, std::move(subcont_header),
733-
subcontainer_referenced_by_eofcreate[subcont_idx]);
726+
container_queue.push({subcontainer, subcontainer_referenced_by_eofcreate[subcont_idx]});
734727
}
735728

736729
container_queue.pop();

0 commit comments

Comments
 (0)