Skip to main content
Version: 0.13 (unstable)

Memory procedures

Module miden::core::mem contains a set of utility procedures for working with random access memory.

ProcedureDescription
memcopy_wordsCopies n words from read_ptr to write_ptr.

read_ptr and write_ptr pointers must be word-aligned.

Inputs: [n, read_ptr, write_ptr]
Outputs: []

Total cycles: 15+16num_words15 + 16 * num\_words
memcopy_elementsCopies n elements from read_ptr to write_ptr.

Inputs: [n, read_ptr, write_ptr]
Outputs: []

Total cycles: 7+14num_elements7 + 14 * num\_elements
pipe_double_words_to_memoryCopies an even number of words from the advice_stack to memory.

Inputs: [C, B, A, write_ptr, end_ptr]
Outputs: [C, B, A, write_ptr]

Notice that the end_ptr - write_ptr value must be positive and a multiple of 8.

Total cycles: 9+6num_word_pairs9 + 6 * num\_word\_pairs
pipe_words_to_memoryCopies an arbitrary number of words from the advice stack to memory.

Inputs: [num_words, write_ptr]
Outputs: [C, B, A, write_ptr']

Total cycles:
  • Even num_words: 43+9num_words/243 + 9 * num\_words / 2
  • Odd num_words: 60+9round_down(num_words/2)60 + 9 * round\_down(num\_words / 2)
pipe_preimage_to_memoryMoves an arbitrary number of words from the advice stack to memory and asserts it matches the commitment.

Inputs: [num_words, write_ptr, COMMITMENT]
Outputs: [write_ptr']

Total cycles:
  • Even num_words: 62+9num_words/262 + 9 * num\_words / 2
  • Odd num_words: 79+9round_down(num_words/2)79 + 9 * round\_down(num\_words / 2)
pipe_double_words_preimage_to_memoryMoves an even number of words from the advice stack to memory and asserts it matches the commitment.

Inputs: [num_words, write_ptr, COMMITMENT]
Outputs: [write_ptr']

Total cycles: 56+3num_words/256 + 3 * num\_words / 2