ethereum.forks.dao_fork.vm.instructions.bitwiseethereum.forks.tangerine_whistle.vm.instructions.bitwise
Ethereum Virtual Machine (EVM) Bitwise Instructions.
.. contents:: Table of Contents :backlinks: none :local:
Introduction
Implementations of the EVM bitwise instructions.
bitwise_and ¶
Bitwise AND operation of the top 2 elements of the stack. Pushes the result back on the stack.
Parameters
evm : The current EVM frame.
bitwise_or ¶
Bitwise OR operation of the top 2 elements of the stack. Pushes the result back on the stack.
Parameters
evm : The current EVM frame.
bitwise_xor ¶
Bitwise XOR operation of the top 2 elements of the stack. Pushes the result back on the stack.
Parameters
evm : The current EVM frame.
bitwise_not ¶
Bitwise NOT operation of the top element of the stack. Pushes the result back on the stack.
Parameters
evm : The current EVM frame.
get_byte ¶
For a word (defined by next top element of the stack), retrieve the Nth byte (0-indexed and defined by top element of stack) from the left (most significant) to right (least significant).
Parameters
evm : The current EVM frame.
def get_byte(evm: Evm) -> None:
| 124 | <snip> |
|---|---|
| 135 | # STACK |
| 136 | byte_index = pop(evm.stack) |
| 137 | word = pop(evm.stack) |
| 138 | |
| 139 | # GAS |
| 140 | charge_gas(evm, GasCosts.OPCODE_BYTE) |
| 141 | |
| 142 | # OPERATION |
| 143 | if byte_index >= U256(32): |
| 144 | result = U256(0) |
| 145 | else: |
| 146 | extra_bytes_to_right = U256(31) - byte_index |
| 147 | # Remove the extra bytes in the right |
| 148 | word = word >> (extra_bytes_to_right * U256(8)) |
| 149 | # Remove the extra bytes in the left |
| 150 | word = word & U256(0xFF) |
| 151 | result = word |
| 152 | |
| 153 | push(evm.stack, result) |
| 154 | |
| 155 | # PROGRAM COUNTER |
| 156 | evm.pc += Uint(1) |