-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor subcontainer validation #888
Conversation
80df8c9
to
0e48680
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #888 +/- ##
==========================================
- Coverage 98.50% 98.50% -0.01%
==========================================
Files 130 130
Lines 15621 15625 +4
==========================================
+ Hits 15388 15391 +3
- Misses 233 234 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
/// Pairs of (container_index, opcode) of all opcodes referencing subcontainers in this section. | ||
std::vector<std::pair<uint8_t, Opcode>> subcontainer_references; | ||
/// Set of accessed code section indices. | ||
std::unordered_set<uint16_t> accessed_code_sections; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be a vector, if we're cautios of sets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be a performance issue. But it is fine for now, just leave an issue or TODO comment.
I think we could optimize out "list of references to subcontainers" if we rely more on non-const reference arguments to instruction validation, but I think this version looks cleaner, I would start with it at least. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lib/evmone/eof.cpp
Outdated
// Queue of (container, header) pairs left to process | ||
std::queue<std::pair<bytes_view, EOF1Header>> container_queue; | ||
container_queue.emplace(main_container, main_container_header); | ||
struct Container |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a more specific name here, like "ValidatedContainer" or "ContainerValidationInfo"?
0e48680
to
e406e19
Compare
/// Pairs of (container_index, opcode) of all opcodes referencing subcontainers in this section. | ||
std::vector<std::pair<uint8_t, Opcode>> subcontainer_references; | ||
/// Set of accessed code section indices. | ||
std::unordered_set<uint16_t> accessed_code_sections; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be a performance issue. But it is fine for now, just leave an issue or TODO comment.
const auto& [accessed_code_sections] = | ||
std::get<InstructionValidationResult>(instr_validation_result_or_error); | ||
for (const auto section_id : accessed_code_sections) | ||
code_sections_queue.push(section_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C++23 has .push_range()
. You can add TODO(C++23)
comment.
@@ -310,8 +310,12 @@ std::variant<EOF1Header, EOFValidationError> validate_header( | |||
}; | |||
} | |||
|
|||
/// Result of validating instructions in a code section. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pedantic: should be in the first commit, but fine to leave it as it.
std::get<InstructionValidationResult>(instr_validation_result_or_error); | ||
|
||
// Mark what instructions referenced which subcontainers. | ||
for (const auto& [index, opcode] : subcontainer_references) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be std::ranges::any_of()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, can be std::for_each()
or std::ranges::for_each()
, but maybe not much point.
bool referenced_by_eofcreate = false; | ||
}; | ||
// Queue of containers left to process | ||
std::queue<ContainerValidation> container_queue; | ||
container_queue.emplace(main_container, main_container_header, false); | ||
container_queue.push({main_container, false}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why emplace
→ push
is needed?
lib/evmone/eof.cpp
Outdated
container_queue.emplace(std::move(subcontainer)); | ||
container_queue.emplace(subcontainer, std::move(subcont_header), | ||
subcontainer_referenced_by_eofcreate[subcont_idx], | ||
subcontainer_referenced_by_returncontract[subcont_idx]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fields doesn't exist in ContainerValidation
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
e406e19
to
dc1d74c
Compare
Refactoring pulled out of #876
Main idea:
1.1. (Not directly related, but I moved returning accessed section list into returned
InstructionValidationResult
struct instead of non-const reference argument)EOFCREATE
with truncated data is moved out of instruction validation into being done once for a referenced container, after it is already validated.Then it gets handy for additional container kind validation in #876.