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

EIP3540 run EOF code correctly #2368

Merged
merged 8 commits into from
Oct 24, 2022
Merged

EIP3540 run EOF code correctly #2368

merged 8 commits into from
Oct 24, 2022

Conversation

jochem-brouwer
Copy link
Member

After the new updates in ethereum/tests#847, we have many failing tests, and one of the causes is that we do not run the actual EOF code, but we run the entire container (so EOF code immediately runs into 0xEF, which is the invalid opcode).

Also thanks to @pk910 who discovered this on Shangdong testnet :)

To run:

cd ./packages/ethereum-tests
gh pr checkout 847
cd ../vm

Run tests;

Current:

npm run test:state -- --fork=London+3540+3670
# tests 293
# pass  171
# fail  122
npm run test:blockchain -- --fork=London+3540+3670
# tests 2426
# pass  1588
# fail  838

@codecov
Copy link

codecov bot commented Oct 18, 2022

Codecov Report

Merging #2368 (b317ddd) into master (f9ff861) will decrease coverage by 0.33%.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block ?
blockchain 90.21% <ø> (ø)
common 98.13% <ø> (ø)
devp2p 91.63% <ø> (-0.14%) ⬇️
ethash ∅ <ø> (∅)
rlp ∅ <ø> (∅)
statemanager 89.46% <ø> (ø)
trie 90.66% <ø> (-0.35%) ⬇️
tx ?
util ?
vm 85.30% <ø> (ø)

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

@@ -858,6 +858,9 @@ export class EVM implements EVMInterface {
} else {
message.code = await this.eei.getContractCode(message.codeAddress)
message.isCompiled = false
if (this._common.isActivatedEIP(3540)) {
message.code = getEOFCode(message.code)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need this? runInterpreter checks the code passed in as part of the message for the EOF header and sets the PC to the correct position based on the sections header.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see that more tests fail when I comment it out but from how we handle code in the interpreter, it seems like they shouldn't be failing. I looked back at the original PR and the idea was that we handled all the bits about defining the code section inside interpreter.run so this theoretically should be duplicative.

@jochem-brouwer
Copy link
Member Author

Now have 4 tests failing. This is due to CODECOPY and likely also CODESIZE. If you run these if you CALL a contract, then interpreter.code is not the entire container, it is the runtime code. At this point I do not know how to cleanly fix this though. It seems that we are inconsistent in situations, because if you try to create a contract (so, the to field is undefined) then the .code is actually set to the entire container...

@acolytec3
Copy link
Contributor

Now have 4 tests failing. This is due to CODECOPY and likely also CODESIZE. If you run these if you CALL a contract, then interpreter.code is not the entire container, it is the runtime code. At this point I do not know how to cleanly fix this though. It seems that we are inconsistent in situations, because if you try to create a contract (so, the to field is undefined) then the .code is actually set to the entire container...

See my latest commit. I think this relatively cleanly solves it by adding a new codeContainer field that's only populated when you call _loadCode. The codeContainer only gets referenced by CODESIZE and CODECOPY. EXTCODESIZE and EXTCODECOPY both reference the entire code pulled from the state manager so should work as currently coded with no changes.

@holgerd77
Copy link
Member

Cool!

Why the hell didn't we pack this in the hotfix releases? 😋

@acolytec3
Copy link
Contributor

Never too late 🙃

@acolytec3 acolytec3 marked this pull request as ready for review October 22, 2022 01:09
@acolytec3
Copy link
Contributor

I added a test for the new getEOFCode function so hopefully that will help with the code coverage. Are we ready to merge this? It'd be awesome to restart the Shandong network early next week with EIP-3540 working correctly.

@jochem-brouwer
Copy link
Member Author

I think in general we also want another client (i.e. Geth) to run alongside our Shangdong testnet (we should run this ourselves) so we can quickly figure out if there is a consensus bug.

@acolytec3 can you confirm that the current EIP3540 tests pass?

@acolytec3
Copy link
Contributor

I need to run the state tests but all of the Blockchain tests pass except for that over where I raised the question about the container length which appears to be invalid. I'll check the state tests today and see if there are any remaining failures.

@acolytec3
Copy link
Contributor

I think in general we also want another client (i.e. Geth) to run alongside our Shangdong testnet (we should run this ourselves) so we can quickly figure out if there is a consensus bug.

I believe Nethermind is planning to join and they have implemented EIP3540/3670 as well. I'm not sure if Geth has it integrated in their master branch yet

Copy link
Contributor

@acolytec3 acolytec3 left a comment

Choose a reason for hiding this comment

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

LGTM!

@holgerd77
Copy link
Member

I need to run the state tests but all of the Blockchain tests pass except for that over where I raised the question about the container length which appears to be invalid.

@acolytec3 has this been confirmed (e.g. by the test authors on ethereum/tests or similar) that this test is invalid? Can you provide a reference here?

@jochem-brouwer
Copy link
Member Author

image
image

@holgerd77 holgerd77 merged commit e65e00f into master Oct 24, 2022
@gitpoap-bot
Copy link

gitpoap-bot bot commented Oct 24, 2022

Congrats, your important contribution to this open-source project has earned you a GitPOAP!

GitPOAP: 2022 EthereumJS Contributor:

GitPOAP: 2022 EthereumJS Contributor GitPOAP Badge

Head to gitpoap.io & connect your GitHub account to mint!

Learn more about GitPOAPs here.

@holgerd77 holgerd77 deleted the eip3540-fixes branch October 24, 2022 15:55
@holgerd77
Copy link
Member

I wonder if we should also prepare a quick EVM-only bugfix release on this? Could do this tomorrow morning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants