ethereum.homestead.vm.memory
Ethereum Virtual Machine (EVM) Memory ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. contents:: Table of Contents :backlinks: none :local:
Introduction
EVM memory operations.
memory_write
Writes to memory.
Parameters
memory : Memory contents of the EVM. start_position : Starting pointer to the memory. value : Data to write to memory.
def memory_write(memory: bytearray, start_position: U256, value: Bytes) -> None:
22 | """ |
---|---|
23 | Writes to memory. |
24 |
|
25 | Parameters |
26 | ---------- |
27 | memory : |
28 | Memory contents of the EVM. |
29 | start_position : |
30 | Starting pointer to the memory. |
31 | value : |
32 | Data to write to memory. |
33 | """ |
34 | memory[start_position : Uint(start_position) + len(value)] = value |
memory_read_bytes
Read bytes from memory.
Parameters
memory :
Memory contents of the EVM.
start_position :
Starting pointer to the memory.
size :
Size of the data that needs to be read from start_position
.
Returns
data_bytes : Data read from memory.
def memory_read_bytes(memory: bytearray, start_position: U256, size: U256) -> bytearray:
40 | """ |
---|---|
41 | Read bytes from memory. |
42 |
|
43 | Parameters |
44 | ---------- |
45 | memory : |
46 | Memory contents of the EVM. |
47 | start_position : |
48 | Starting pointer to the memory. |
49 | size : |
50 | Size of the data that needs to be read from `start_position`. |
51 |
|
52 | Returns |
53 | ------- |
54 | data_bytes : |
55 | Data read from memory. |
56 | """ |
57 | return memory[start_position : Uint(start_position) + Uint(size)] |
buffer_read
Read bytes from a buffer. Padding with zeros if necessary.
Parameters
buffer :
Memory contents of the EVM.
start_position :
Starting pointer to the memory.
size :
Size of the data that needs to be read from start_position
.
Returns
data_bytes : Data read from memory.
def buffer_read(buffer: Bytes, start_position: U256, size: U256) -> Bytes:
61 | """ |
---|---|
62 | Read bytes from a buffer. Padding with zeros if necessary. |
63 |
|
64 | Parameters |
65 | ---------- |
66 | buffer : |
67 | Memory contents of the EVM. |
68 | start_position : |
69 | Starting pointer to the memory. |
70 | size : |
71 | Size of the data that needs to be read from `start_position`. |
72 |
|
73 | Returns |
74 | ------- |
75 | data_bytes : |
76 | Data read from memory. |
77 | """ |
78 | return right_pad_zero_bytes( |
79 | buffer[start_position : Uint(start_position) + Uint(size)], size |
80 | ) |