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

EVM refactor (old) #1912

Closed

Conversation

jochem-brouwer
Copy link
Member

@jochem-brouwer jochem-brouwer commented May 26, 2022

Closes #1903

NOTE: change target branch to develop!!

Commit after branching off from develop; ae950d2

TODOs related to refactor: (probably incomplete)

  • Create interfaces for EEI and EVM inside EVM package
  • Ensure VM has option to pass in custom EEI or EVM which honour above interfaces
  • Improve naming (EEI._state -> state, or probably a better name, (journal?))
  • Remove VmState dependency from EVM
  • Remove runCode from EVM and fit this logic inside runCall -> Will not do this, will be part of standard EVM, but will not be part of EVM interface (since this is not used internally in any of our packages)
  • Possibly add a submodule to Interpreter to cover all the methods moved from EEI into EVM -> This can be refactored in a later PR and is non-breaking.
  • Check if some methods moved into Interpreter can be optimized or removed (directly read from _env, for instance getCallValue() (maybe make _env -> env)
  • Move EVM into a new package
  • Check commits for any TODOs
  • (?) move touched account logic into EVM -> will not do, this is essentially the same as warm addresses. It is possible to add it to the EVM but that is still a very big change and there is no time left.
  • (?) move transientStorage logic into EVM
  • VM and EVM are extensions of AsyncEventEmitter, but the latter does not have a type, therefore VM and EVM are interpreted as any type with certain fields which are sure there, but we want to ensure they are cast as right type.
  • Add types for the step event (an enum to ensure one does not subscribe to e.g. VM.step -> should subscribe to EVM.step)
  • Remove StateManager from VM as dependency (All chain through EEI)
  • Check input types to EVM, their names are sometimes inconsistent
  • Checkt output type of EVM, also sometimes inconsistent (two gasUsed, one for interpreter and one for tx (which also covers data cost))
  • Check if more methods in VM/EVM should be marked as protected and/or readonly
  • Fix client + client tests
  • Fix VM API tests
  • Figure out reason of underscore object properties (_eei instead of eei) and if we should keep this (and be consistent)
  • Make the state of Interpreter/Env/RunState consistent. (For instance auth seems to be something which should go into runState). Possibly also consider the frame types introduced in types.ts (FrameEnvironment types)
  • Move the activePrecompiles logic into EVM (from VM)

Note: warm address logic should be kept into EEI because we need to set this up before calling into EVM (add warm addresses in the access list + own account + target account). TODO this is not true, can set this up as input into the EVM.

Cleanups:

  • Move dynamic gas usage of EXP from functions.ts into gas.ts (this also ensures the step event produces the right dynamic gas once it is invoked)

@jochem-brouwer jochem-brouwer added the type: test all hardforks This special label enables VM state and blockchain tests for all hardforks on the respective PR. label May 26, 2022
@jochem-brouwer
Copy link
Member Author

jochem-brouwer commented May 26, 2022

ac33941 is temporary, need to approach this in small steps otherwise I exhaust myself with too many tasks to do at the same time (and then fixing consensus bugs is gonna be very hard)

(Also writing this down bit for myself)

Next steps: (keeping old steps for journaling)

Inject TransientStorage into EEI
Remove CreateEIOptions
EEI factory should probably be removed, EEI is instantiated once on EVM creation

Next steps

  • Remove ENV from EEI and move ENV into Interpreter
  • Move ENV from EEI into Interpreter. Should be accessible into RunState
  • Move gasLeft and selfdestruct from EEI into Interpreter (RunState) (also logs?)
  • All call logic goes into Interpreter
  • VmState is preserved

@codecov
Copy link

codecov bot commented May 26, 2022

Codecov Report

Merging #1912 (00e29e4) into develop-evm-refactor-branch-pr-1912 (66f8779) will increase coverage by 4.15%.
The diff coverage is n/a.

Impacted file tree graph

Flag Coverage Δ
block 85.28% <ø> (ø)
blockchain 83.13% <ø> (?)
client ?
common 94.92% <ø> (ø)
devp2p 82.70% <ø> (-0.14%) ⬇️
ethash 90.81% <ø> (?)
rlp ?
statemanager 84.24% <ø> (ø)
trie 80.77% <ø> (?)
tx 92.09% <ø> (?)
util 87.29% <ø> (?)
vm ?

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

@jochem-brouwer
Copy link
Member Author

jochem-brouwer commented May 26, 2022

This message keeps track of the commits passing ethereum/tests (state + blockchain tests) CI:

Pass f447394
Pass 6e27483
Pass 4ac4ef2
Pass 2b14275
Pass d479e9e
Pass 700b228
Pass 51e5582
Pass 1acc189
Pass adae093

@jochem-brouwer
Copy link
Member Author

jochem-brouwer commented May 26, 2022

EEI and EVM both blend some revert/commit logic. Not all revert/commit logic should move to EVM but things like refund counters can easily be handled in EVM. Interpreter is always created also when a new EEI is created so this is a fantastic candidate to move things to. Probably want to create a subclass later not to bloat Interpreter too much, but for now this seems fine.

Commit notes
e4fbe4a - this removes underscores from methods in EVM/EEI

@jochem-brouwer jochem-brouwer changed the base branch from develop to evm-refactor-BAK June 6, 2022 20:34
@jochem-brouwer jochem-brouwer changed the base branch from evm-refactor-BAK to develop-evm-refactor-branch-pr-1912 June 6, 2022 20:58
beforeMessage: (data: Message, resolve?: (result: any) => void) => void
afterTx: (data: EVMResult, resolve?: (result: any) => void) => void
step: (data: InterpreterStep, resolve?: (result: any) => void) => void
}
Copy link
Member

Choose a reason for hiding this comment

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

Ok, besides all the fear I have that too much stuff is getting into this PR I have to say:

This is a dramatic improvement on the current status quo!!! 🎉 🙏 💯

Copy link
Member

Choose a reason for hiding this comment

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

(is it correct to have the afterTx event here and another one in VM?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, I copied these function sigs around and forgot to remove afterTx

Copy link
Member Author

Choose a reason for hiding this comment

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

And yes, the types are absolutely fantastic 😍

runCall(opts: RunCallOpts): Promise<EVMResult>
runCode?(opts: RunCodeOpts): Promise<ExecResult>
precompiles: Map<string, any> // Note: the `any` type is used because VM only needs to have the addresses of the precompiles (not their functions)
}
Copy link
Member

Choose a reason for hiding this comment

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

👍

@holgerd77
Copy link
Member

Ok, I very much think we can close here since work is continued in #1950 and will actually do, feel free to reopen if this was mistaken.

@holgerd77 holgerd77 closed this Jun 10, 2022
@holgerd77 holgerd77 changed the title EVM refactor EVM refactor (old) Jun 10, 2022
@jochem-brouwer
Copy link
Member Author

Yep that's right, but will use this original post to keep track of the remaining points

@holgerd77 holgerd77 deleted the evm-refactor branch March 2, 2023 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: vm PR state: WIP type: refactor type: test all hardforks This special label enables VM state and blockchain tests for all hardforks on the respective PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants