Jets are optimization marks. Using jets, users can place optmization marks in an EVM program. An EVM interpreter will then verify the optimization mark claim, and if the verification passes, execute a native code version of the program that is equivalent to the original program.
The optimization mark is defined as two adjencent opcodes.
PUSH11 45 56 4d 4a 45 54 53 <4 bytes of registry ID> POP
Readers can immediately follow that this optimization mark does not have
side effects other than costing 5 gases.
45 56 4d 4a 45 54 53 is a
magic code. The
<4 bytes of registry ID> is interpreted as a
big-endian unsigned integer.
EVMs, on doing the initial
JUMPDEST validity map execution round, can
optionally search for the optimization mark as defined above. If an
optimization mark is found, it then checks whether the
registry ID is
registry ID has an associated code length. The EVM
then verify that opcodes followed by the optimization mark, of code
length, is a pre-defined one. If so, it can mark the beginning of that
A (including the optimization mark) as "jet-able". When
the program counter reads up to
A, the EVM can choose to execute the
jet-ed native code that results in the same state, and costs the same
gas. However, if the program counter instead jumps to the middle of the
code region, it should use the not-jet-ed unoptimized opcode.
Registry ID Assignments
Registry ID of spec-2017-0001 can be assigned in a looser process but similar to how RFC works. EVM implementors can choose to implement any registry ID or not, but should avoid conflicting registry ID assignments. An assigment must also contain:
- The code length of the optimizing block.
- The opcode sequence of the optimizing block.
- Sample implementation of the optimizing block.
Usually for an opcode sequence to be replacable by native codes, it is required that it to be static:
- Jumps need to be deterministic. The sequence can use
PCopcode to jump to an offset of the current position.
- It cannot jump out of its region.
Below we consider the opcode
MUL does not exist, and implement a
jet-able version of
PUSH1 00 DUP2 DUP4 ADD ADD SWAP2 PUSH1 01 SWAP1 SUB SWAP2 DUP3 PC PUSH1 11 SUB SWAP1 JUMPI SWAP2 POP POP
This can be simplified by
MUL -- taking two items from the stack, and
push one new item which is the multiply of the two items. Its gas cost
can also be simplified as
12 + 51 * <mul second item>.