Memory
A extendable memory used by the evm interpreter.
Properties
struct {
/// The inner allocator used to grow the memory
allocator: Allocator
/// The underlaying memory buffer.
buffer: []u8
/// Set of memory checkpoints
checkpoints: ArrayListUnmanaged(usize)
/// The last memory checkpoint
last_checkpoint: usize
/// The max memory size
memory_limit: u64
/// The total allocated capacity of this memory.
total_capacity: usize
}Error
Set of errors when resizing errors.
error{MaxMemoryReached}InitEmpty
Create the interpreter's memory. This will not error. No initial capacity is set. It's essentially empty memory.
Signature
pub fn initEmpty(
allocator: Allocator,
limit: ?u64,
) MemoryInitWithDefaultCapacity
Creates the memory with default 4096 capacity.
Signature
pub fn initWithDefaultCapacity(
allocator: Allocator,
limit: ?u64,
) Allocator.Error!MemoryInitWithCapacity
Creates the memory with capacity.
Signature
pub fn initWithCapacity(
allocator: Allocator,
capacity: usize,
limit: ?u64,
) Allocator.Error!MemoryDeinit
Frees the underlaying memory buffers.
Signature
pub fn deinit(self: *Memory) voidFreeContext
Prepares the memory for returning to the previous context.
Signature
pub fn freeContext(self: *Memory) voidGetCurrentMemorySize
Gets the current size of the Memory range.
Signature
pub fn getCurrentMemorySize(self: Memory) u64GetMemoryByte
Gets a byte from the list's buffer.
Signature
pub fn getMemoryByte(
self: Memory,
offset: usize,
) u8GetMemoryWord
Gets a Word from memory of in other words it gets a slice
of 32 bytes from the inner memory buffer.
Signature
pub fn getMemoryWord(
self: Memory,
offset: usize,
) WordGetSlice
Gets a memory slice based on the last checkpoints until the end of the buffer.
Signature
pub fn getSlice(self: Memory) []u8MemoryCopy
Copies elements from one part of the buffer to another part of itself. Asserts that the provided indexes are not out of bound.
Signature
pub fn memoryCopy(
self: *Memory,
destination: usize,
source: usize,
length: usize,
) voidNewContext
Prepares the memory for a new context.
Signature
pub fn newContext(self: *Memory) Allocator.Error!voidResize
Resizes the underlaying memory buffer.
Uses the allocator's resize method in case it's possible.
If the new len is lower than the current buffer size data will be lost.
Signature
pub fn resize(
self: *Memory,
new_len: usize,
) (Allocator.Error || Memory.Error)!voidWordToInt
Converts a memory "Word" into a u256 number.
This reads the word as Big endian.
Signature
pub fn wordToInt(
self: Memory,
offset: usize,
) u256WriteByte
Writes a single byte into this memory buffer. This can overwrite to existing memory.
Signature
pub fn writeByte(
self: Memory,
offset: usize,
byte: u8,
) voidWriteWord
Writes a memory Word into the memory buffer.
This can overwrite existing memory.
Signature
pub fn writeWord(
self: Memory,
offset: usize,
word: [32]u8,
) voidWriteInt
Writes a u256 number into the memory buffer.
This can overwrite to existing memory.
Signature
pub fn writeInt(
self: Memory,
offset: usize,
data: u256,
) voidWrite
Writes a slice to the memory buffer based on a offset. This can overwrite to existing memory.
Signature
pub fn write(
self: Memory,
offset: usize,
data: []const u8,
) voidWriteData
Writes a slice to a given offset in memory + the provided data's offset. This can overwrite existing memory.
Signature
pub fn writeData(
self: Memory,
offset: usize,
data_offset: usize,
len: usize,
data: []u8,
) voidError
Set of errors when resizing errors.
error{MaxMemoryReached}AvailableWords
Returns number of words what would fit to provided number of bytes, It rounds up the number bytes to number of words.
Signature
pub inline fn availableWords(size: u64) usize