Skip to content

Commit

Permalink
feat: push0 opcode (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
obatirou authored Aug 14, 2023
1 parent 7791799 commit c204602
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ There is an open issue to implement the validation if needed [here](https://gith

## Compatibility

The HyVM does not yet support `PUSH0` as most of the chains do not support it.
It is compiled with `Paris` EVM version.
The HyVM supports `PUSH0`. It possible to execute bytecode compiled with `Shanghai` EVM version.
As the HyVM is deployed with the `Paris` EVM version, it will be converted to `PUSH1 0x00` during the execution.
This is due to the fact that most chains do not support `PUSH0` yet.

## HyVM / EVM divergence

Expand Down
4 changes: 3 additions & 1 deletion src/HyVM.huff
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,9 @@
// do nothing
CONTINUE()


op_push0:
0x00
CONTINUE()
op_push1:
0x01
PICK_DATA()
Expand Down
2 changes: 1 addition & 1 deletion src/Jump-table.huff
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
op_sha3 unused unused unused unused unused unused unused unused unused unused unused unused unused unused unused
op_address op_balance op_origin op_caller op_callvalue op_calldataload op_calldatasize op_calldatacopy op_codesize op_codecopy op_gasprice op_extcodesize op_extcodecopy op_returndatasize op_returndatacopy op_extcodehash
op_blockhash op_coinbase op_timestamp op_number op_difficulty op_gaslimit op_chainid op_selfbalance op_basefee unused unused unused unused unused unused unused
op_pop op_mload op_mstore op_mstore8 op_sload op_sstore op_jump op_jumpi op_pc op_msize op_gas op_jumpdest unused unused unused unused
op_pop op_mload op_mstore op_mstore8 op_sload op_sstore op_jump op_jumpi op_pc op_msize op_gas op_jumpdest unused unused unused op_push0
op_push1 op_push2 op_push3 op_push4 op_push5 op_push6 op_push7 op_push8 op_push9 op_push10 op_push11 op_push12 op_push13 op_push14 op_push15 op_push16
op_push17 op_push18 op_push19 op_push20 op_push21 op_push22 op_push23 op_push24 op_push25 op_push26 op_push27 op_push28 op_push29 op_push30 op_push31 op_push32
op_dup1 op_dup2 op_dup3 op_dup4 op_dup5 op_dup6 op_dup7 op_dup8 op_dup9 op_dup10 op_dup11 op_dup12 op_dup13 op_dup14 op_dup15 op_dup16
Expand Down
8 changes: 8 additions & 0 deletions test/HyVM/Opcodes.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,14 @@ contract OpcodesTest is Test {
assertEq(result, 0x43);
}

function testPush0() public {
// bytecode generated using: easm test/opcodes/push0 but push0 is not supported hence added by hand
(bool success, bytes memory data) = hyvm.delegatecall(hex"5f5f5260205ff3");
assertEq(success, true);
uint256 result = abi.decode(data, (uint256));
assertEq(result, uint256(0));
}

function testPush1() public {
// bytecode generated using: easm test/opcodes/push1
(bool success, bytes memory data) = hyvm.delegatecall(hex"60ff60005260ff6000f3");
Expand Down
8 changes: 8 additions & 0 deletions test/HyVM/opcodes/push0
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PUSH0

# return result
PUSH0
MSTORE
PUSH1 0x20
PUSH0
RETURN

0 comments on commit c204602

Please sign in to comment.