ethereum.forks.dao_fork.vm.instructions.memoryethereum.forks.tangerine_whistle.vm.instructions.memory
Ethereum Virtual Machine (EVM) Memory Instructions.
.. contents:: Table of Contents :backlinks: none :local:
Introduction
Implementations of the EVM Memory instructions.
mstore ¶
Stores a word to memory. This also expands the memory, if the memory is insufficient to store the word.
Parameters
evm : The current EVM frame.
def mstore(evm: Evm) -> None:
| 28 | <snip> |
|---|---|
| 39 | # STACK |
| 40 | start_position = pop(evm.stack) |
| 41 | value = pop(evm.stack).to_be_bytes32() |
| 42 | |
| 43 | # GAS |
| 44 | extend_memory = calculate_gas_extend_memory( |
| 45 | evm.memory, [(start_position, U256(len(value)))] |
| 46 | ) |
| 47 | |
| 48 | charge_gas(evm, GasCosts.OPCODE_MSTORE_BASE + extend_memory.cost) |
| 49 | |
| 50 | # OPERATION |
| 51 | evm.memory += b"\x00" * extend_memory.expand_by |
| 52 | memory_write(evm.memory, start_position, value) |
| 53 | |
| 54 | # PROGRAM COUNTER |
| 55 | evm.pc += Uint(1) |
mstore8 ¶
Stores a byte to memory. This also expands the memory, if the memory is insufficient to store the word.
Parameters
evm : The current EVM frame.
def mstore8(evm: Evm) -> None:
| 59 | <snip> |
|---|---|
| 70 | # STACK |
| 71 | start_position = pop(evm.stack) |
| 72 | value = pop(evm.stack) |
| 73 | |
| 74 | # GAS |
| 75 | extend_memory = calculate_gas_extend_memory( |
| 76 | evm.memory, [(start_position, U256(1))] |
| 77 | ) |
| 78 | |
| 79 | charge_gas(evm, GasCosts.OPCODE_MSTORE8_BASE + extend_memory.cost) |
| 80 | |
| 81 | # OPERATION |
| 82 | evm.memory += b"\x00" * extend_memory.expand_by |
| 83 | normalized_bytes_value = Bytes([value & U256(0xFF)]) |
| 84 | memory_write(evm.memory, start_position, normalized_bytes_value) |
| 85 | |
| 86 | # PROGRAM COUNTER |
| 87 | evm.pc += Uint(1) |
mload ¶
Loads a word from memory.
Parameters
evm : The current EVM frame.
def mload(evm: Evm) -> None:
| 91 | <snip> |
|---|---|
| 100 | # STACK |
| 101 | start_position = pop(evm.stack) |
| 102 | |
| 103 | # GAS |
| 104 | extend_memory = calculate_gas_extend_memory( |
| 105 | evm.memory, [(start_position, U256(32))] |
| 106 | ) |
| 107 | charge_gas(evm, GasCosts.OPCODE_MLOAD_BASE + extend_memory.cost) |
| 108 | |
| 109 | # OPERATION |
| 110 | evm.memory += b"\x00" * extend_memory.expand_by |
| 111 | value = U256.from_be_bytes( |
| 112 | memory_read_bytes(evm.memory, start_position, U256(32)) |
| 113 | ) |
| 114 | push(evm.stack, value) |
| 115 | |
| 116 | # PROGRAM COUNTER |
| 117 | evm.pc += Uint(1) |
msize ¶
Pushes the size of active memory in bytes onto the stack.
Parameters
evm : The current EVM frame.