-
Notifications
You must be signed in to change notification settings - Fork 285
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
EOF code validation (EIP-3670) #366
Conversation
7765c0b
to
d27046d
Compare
Codecov Report
@@ Coverage Diff @@
## eof-execution #366 +/- ##
==============================================
Coverage 99.57% 99.58%
==============================================
Files 37 37
Lines 4487 4551 +64
==============================================
+ Hits 4468 4532 +64
Misses 19 19
Flags with carried forward coverage won't be shown. Click here to find out more.
|
b166534
to
850d7b8
Compare
d27046d
to
cac511b
Compare
1ccc8aa
to
f82ac27
Compare
e07ffef
to
de74fc2
Compare
3b42a85
to
2411d77
Compare
8127c9b
to
6181dd1
Compare
a73f066
to
eb773aa
Compare
d387060
to
38461f6
Compare
47fc7d9
to
5e9154c
Compare
1f16ee5
to
7fefde0
Compare
return {{}, error}; | ||
assert(code.size() > 0); // guaranteed by EOF headers validation | ||
|
||
size_t i = 0; |
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 isn't this an iterator instead?
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.
Because with an iterator loop end condition can be only it != code.end()
, but loop can overrun end in case of truncated immediate.
{ | ||
op = code[i]; | ||
const auto& since = instr::traits[op].since; | ||
if (!since.has_value() || *since > rev) |
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.
I think this doesn't cover the case when we want to remove an opcode (e.g.calldata
) from EOF contracts?
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.
Yes, when that happens I guess we will need to add final revision to traits
.
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.
Yes. This looks like a good solution if needed.
fc7e218
to
58c98b9
Compare
6c563f4
to
7ac440c
Compare
Validate that all used instructions are defined and code ends with a terminating instruction.
7ac440c
to
3fdc2c5
Compare
#include <gtest/gtest.h> | ||
#include <test/utils/utils.hpp> | ||
|
||
using namespace evmone; | ||
|
||
namespace | ||
{ | ||
inline EOFValidationError validate_eof(bytes_view cont, evmc_revision rev = EVMC_SHANGHAI) noexcept |
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.
inline EOFValidationError validate_eof(bytes_view cont, evmc_revision rev = EVMC_SHANGHAI) noexcept | |
inline EOFValidationError validate_eof(bytes_view container, evmc_revision rev = EVMC_SHANGHAI) noexcept |
#include <gtest/gtest.h> | ||
#include <test/utils/utils.hpp> | ||
|
||
using namespace evmone; | ||
|
||
namespace | ||
{ | ||
inline EOFValidationError validate_eof(bytes_view cont, evmc_revision rev = EVMC_SHANGHAI) noexcept | ||
{ | ||
return ::validate_eof(rev, cont); |
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.
Does it call evmone::validate_eof()
? I'm confused.
{ | ||
return ::validate_eof(rev, cont); | ||
} | ||
|
||
inline EOFValidationError validate_eof( | ||
std::string_view code_hex, evmc_revision rev = EVMC_SHANGHAI) noexcept |
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.
It seems this overload is used once and there is another use case as validate_eof(from_hex(...))
. I'm rather for removing this overload. It sometimes become confusing when a unit tests multiple levels of wrappers. Using from_hex()
or bytecode{}
is fine or you can use bytecode
as the type of the parameter.
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.
Changed it to a single helper with bytecode
parameter, can be called with either hex string or bytes 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.
clang-tidy want it as const bytecode&
. I think changing it like this should not be a problem.
while (i < code.size()) | ||
{ | ||
op = code[i]; | ||
const auto& since = instr::traits[op].since; |
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.
I think it is fine for now, but instr::traits
has sub-optimal layout for runtime use.
{ | ||
op = code[i]; | ||
const auto& since = instr::traits[op].since; | ||
if (!since.has_value() || *since > rev) |
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.
Yes. This looks like a good solution if needed.
3fdc2c5
to
b328d7f
Compare
b328d7f
to
08aab70
Compare
No description provided.