Skip to content
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 validation of subcontainer kinds #876

Merged
merged 8 commits into from
Jun 24, 2024
Merged

Conversation

gumb0
Copy link
Member

@gumb0 gumb0 commented Apr 29, 2024

Implementing ipsilon/eof#86

Depends on #888

TODO:

@gumb0 gumb0 added the EOF label Apr 29, 2024
Copy link

codecov bot commented Apr 29, 2024

Codecov Report

Attention: Patch coverage is 95.23810% with 9 lines in your changes missing coverage. Please review.

Project coverage is 95.11%. Comparing base (85a89e5) to head (37ed902).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #876      +/-   ##
==========================================
- Coverage   95.15%   95.11%   -0.04%     
==========================================
  Files         140      140              
  Lines       15805    15881      +76     
==========================================
+ Hits        15039    15106      +67     
- Misses        766      775       +9     
Flag Coverage Δ
eof_execution_spec_tests 16.37% <14.81%> (-0.01%) ⬇️
ethereum_tests 26.87% <13.22%> (-0.06%) ⬇️
ethereum_tests_silkpre 18.36% <0.59%> (-0.10%) ⬇️
execution_spec_tests 17.83% <0.52%> (-0.11%) ⬇️
unittests 90.26% <95.23%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
lib/evmone/baseline.cpp 100.00% <100.00%> (ø)
lib/evmone/eof.hpp 100.00% <ø> (ø)
lib/evmone/instructions.hpp 100.00% <100.00%> (ø)
lib/evmone/instructions_calls.cpp 98.66% <100.00%> (ø)
test/eofparse/eofparse.cpp 91.42% <100.00%> (ø)
test/state/host.cpp 100.00% <100.00%> (ø)
test/statetest/statetest_loader.cpp 96.87% <100.00%> (ø)
test/unittests/eof_test.cpp 93.02% <100.00%> (+0.16%) ⬆️
test/unittests/eof_validation.hpp 71.42% <100.00%> (+21.42%) ⬆️
test/unittests/eof_validation_test.cpp 99.32% <100.00%> (+0.13%) ⬆️
... and 7 more

lib/evmone/eof.hpp Outdated Show resolved Hide resolved
@gumb0 gumb0 force-pushed the validate-subcontainer-kinds branch 10 times, most recently from e51ba64 to 7c4ee1e Compare May 8, 2024 11:03
@gumb0 gumb0 force-pushed the validate-subcontainer-kinds branch 4 times, most recently from 9f3f46e to e26fdad Compare May 10, 2024 12:33
@gumb0 gumb0 force-pushed the validate-subcontainer-kinds branch from e26fdad to face250 Compare May 13, 2024 12:22
@gumb0 gumb0 changed the base branch from master to validate-instr-refactor May 13, 2024 12:22
@gumb0 gumb0 force-pushed the validate-subcontainer-kinds branch from face250 to b6abd3e Compare May 13, 2024 12:55
@gumb0 gumb0 force-pushed the validate-subcontainer-kinds branch 2 times, most recently from ba1ced0 to 1380198 Compare May 14, 2024 08:55
Base automatically changed from validate-instr-refactor to master May 14, 2024 15:16
gumb0 added a commit that referenced this pull request May 14, 2024
Refactoring pulled out of #876 

Main idea:
1. Instruction validation returns the list of references to
subcontainers (instruction, subcontainer_idx)
1.1. (Not directly related, but I moved returning accessed section list
into returned `InstructionValidationResult` struct instead of non-const
reference argument)
3. The check for `EOFCREATE` with truncated data is moved out of
instruction validation into being done once for a referenced container,
after it is already validated.
4. This way we don't need to split subcontainer header validation and
instructions validation and the loop over containers gets simpler.

Then it gets handy for additional container kind validation in #876.
@gumb0 gumb0 force-pushed the validate-subcontainer-kinds branch from 1380198 to 9e8b3e1 Compare May 14, 2024 15:18
if (referenced_by_eofcreate)
return EOFValidationError::incompatible_container_kind;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validation whether subcontainer is referenced by anything can be added here, or below in "enqueue subcontainers" loop, better in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add TODO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@gumb0 gumb0 force-pushed the validate-subcontainer-kinds branch 5 times, most recently from 92e80be to 0a3b1e0 Compare June 4, 2024 12:51
return ContainerKind::runtime;
else if (s == "initcode")
return ContainerKind::initcode;
else if (s == "initcode_runtime")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it makes much sense to support this mode in the tests. If we don't then probably validate_eof() also shouldn't support it as input (should fail with special error?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is proposed to remove this from the spec and #916 has a commit that implements the removal.

@gumb0 gumb0 force-pushed the validate-subcontainer-kinds branch 2 times, most recently from e5f5c92 to 783757c Compare June 6, 2024 16:07
@gumb0
Copy link
Member Author

gumb0 commented Jun 6, 2024

Required ethereum/tests update:

  • It requires the change in validation tests format (adding optional kind field) - I currently have done this manually in ipsilon/eof-initcode-tests branch, but proper support would require change in retesteth.
  • Alternatively we remove the failing cases from ethereum/tests and port them to EEST.

cc @hugo-dc

I'm also fine merging this PR with my "temporary" manual fix of thereum/tests.

@gumb0
Copy link
Member Author

gumb0 commented Jun 21, 2024

  • Alternatively we remove the failing cases from ethereum/tests and port them to EEST.

I plan to do this.

void from_json(const json::json& j, EOFValidationTest::Case& o)
{
const auto op_code = evmc::from_hex(j.at("code").get<std::string>());
if (!op_code)
throw std::invalid_argument{"code is invalid hex string"};
o.code = *op_code;

if (const auto it_kind = j.find("kind"); it_kind != j.end())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this standardized?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is not supported anywhere, but I plan to try to add this to EEST.

@@ -1162,7 +1062,7 @@ TEST_F(state_transition, txcreate_initcontainer_return)
tx.to = To;
pre.insert(*tx.to, {.nonce = 1, .code = factory_container});

expect.post[*tx.to].nonce = pre.get(*tx.to).nonce + 1;
expect.post[*tx.to].nonce = pre.get(*tx.to).nonce;
expect.post[*tx.to].storage[0x00_bytes32] = 0x00_bytes32;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not exactly void, the check is only done if a value is assigned to "expect". There are std::optionals.

@@ -2089,7 +1989,7 @@ TEST_F(state_transition, txcreate_failure_after_txcreate_success)
sstore(0, txcreate().initcode(keccak256(init_container)).salt(Salt)) +
sstore(1, txcreate().initcode(keccak256(init_container)).salt(Salt)) + // address collision
sstore(2, returndatasize()) + sstore(3, 1) + OP_STOP;
const auto factory_container = eof_bytecode(factory_code, 5).container(init_container);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this change about?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a bug in original test, so it was failing for the wrong reason I guess.

else if (opcode == OP_RETURNCONTRACT)
subcontainer_referenced_by_returncontract[index] = true;
else
assert(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use intx::unreachable().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed.

@gumb0 gumb0 force-pushed the validate-subcontainer-kinds branch from 71afb81 to d91990a Compare June 24, 2024 10:39
@gumb0 gumb0 force-pushed the validate-subcontainer-kinds branch from d91990a to 37ed902 Compare June 24, 2024 11:07
@gumb0 gumb0 merged commit b790bc7 into master Jun 24, 2024
26 checks passed
@gumb0 gumb0 deleted the validate-subcontainer-kinds branch June 24, 2024 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants