-
Notifications
You must be signed in to change notification settings - Fork 1.7k
evm interface overhaul #6744
Comments
Is it also possible to clearly separate builtins from executive? |
@tomusdrw I've added it to the list |
I thought that these wasm vm use-cases might be useful to keep in mind if and when performing the overhaul: For now, the wasm engine performs validation of the wasm code each time before executing a contract. The validation run time depends on the code size. Since it depends only on a module itself and nothing else (i.e pure), it doesn't make sense to perform validation each times. It's sufficient to validate once and cache the result of the validation somewhere. Basically it's just a tri-state: not validated, invalid and valid. Apart from that, there is an instrumentation (such as gas metering) of the wasm code that is also performed on each run. It's not so pure as validation, since it might depend on the exact algorithms used (i.e you can do metering by counting each instruction or by summing all instructions in a block. Same result but different algos), but IMO still something worthwhile caching. And, of course, wasm→native compilation: recompiling each time before the execution might be a no-go and definitely needs some sort of caching. So this boils down to the need of caching some data by the vm: ranging from a single flag to a big byte blob. |
I would like to take this refactoring, if that's okay. I think I'll start with "evm should be executed in a loop"/"executive should not use crossbeam to reset the stack" refactoring -- changing CALL/CREATE to trap execution, loop to the next callstack item, and then feed result back in. We probably won't gain any memory improvement in this process, because it's basically just moving callstack from program stack to heap. But after that, we can introduce a "runtime" notion that is global to all current callstack items. This allows us to optimize RETURNDATA buffer to avoid allocating additional buffers per callstack. Regarding "the result of the execution should contain state changes" -- if we don't write state changes directly to the merkle trie but to a hashmap cache, it gives a significant advantage for parallel transaction execution even without ethereum/EIPs#648. But this will introduce a little bit memory overhead. (And full disclaimer, the above design is similar to what we have in SputnikVM. 😄) I'm not sure how we can get rid of |
Another refactoring that might be beneficial is to use c style enum |
@pepyakin mentioned an issue that if we eliminate recursive calls for vm, it might break some of the wasm usage:
|
Can't we keep recursive calls for |
Yeah sounds good. I'll try to get the design based on that. |
Hey guys, I'm actually working with the Parity EVM implementation as a library in a project of mine. Was wondering if there was any possibility of adding a public 'step hook' to the VM. This could even be similar to the current trace functionality, but could be used for real-time debugging. IE, instead of executing the entirety of the code, the user has the choice of executing only one instruction at a time. created an separate issue for this, since I don't think it's very related here: #9035 |
@InsidiousMind maybe just block the thread in the tracer? |
@InsidiousMind @tomusdrw I think there is a way to do that. We basically just need to add an additional "initialize" lifecycle to I mostly got the design for callstack. What I was planning to do is to add in This would actually require |
Just some update on removing crossbeam/recursive stack: This turns out to be a much bigger refactoring than I thought. In addition, I'm having some local commit mess while trying to pull master... So I'm planning to split it and submit smaller PRs. Here's the list of refactoring to be done before we can change
For the actual refactoring on removing crossbeam/recursive stack:
This is as far as where I'm now at right now. We may also need some additional refactorings along the way. |
Current evm interface has been great for us, but as the ethereum virtual machine gets more complicated, we need to revisit how it's done. We need to introduce changes which improve code readability and not decrease the performance.
assumptions:
crossbeam
to reset the stackExternalities
interfaceI think we could target
1.10
with those changes, so 3 months from now.cc @paritytech/core-devs
The text was updated successfully, but these errors were encountered: