Thank you for elaborating on this topic. There’s a few more points that I think should be addressed by this document.
As far as I can tell it is possible to compile (JIT or AOT) EVM bytecode to machine code, only that JUMP instructions may have to be compiled to dynamic dispatch, and stack over/underflow checks at basic block boundaries can’t in general be removed. What is not obvious to me is whether this negates the potential wins of compilation to machine code.
Do the benefits of static jumps materialize even if the VM continues to support dynamic jumps?
Hello @frangio. EIP-8173 isn’t merged yet, so I won’t try to give a full response until it is.
In your example, you can’t resolve and optimize the dynamic JUMP, so you have to directly translate it to a dynamic jump in the target code – if the target has one. If it doesn’t you have to generate some sort of if/else chain over every JUMPDEST in the source code. So it’s a nasty attack surface. Most CPUs have some sort of dynamic jump, but not all possible targets will.
The full benefits of static control flow are only available to MAGIC code where all JUMPs have been validated at CREATE time to take a static argument. The reason to support them outside of MAGIC code is of course backwards compatibility.