Memory Model #
This file defines the memory model.
Main Definitions #
Address- Memory addresses (64-bit)Memory- Memory state (functional map from addresses to bytes)read_mem_bytes- Read multiple bytes from memorywrite_mem_bytes- Write multiple bytes to memoryread_word64- Read a 64-bit word from memory (little-endian)write_word64- Write a 64-bit word to memory (little-endian)
References #
This corresponds to the memory component in HOL Light's model. Source: s2n-bignum/common/components.ml (memory-related definitions)
Memory addresses are 64-bit values.
Equations
Instances For
Memory is modeled as a partial function from addresses to bytes. We use Option to represent potentially uninitialized memory.
Equations
Instances For
Empty memory (all addresses uninitialized).
Equations
Instances For
Read n bytes from memory starting at addr. Returns None if any byte is uninitialized.
Equations
- mem.read_bytes addr n = Bignum.Memory.read_bytes.aux mem addr n n []
Instances For
Write a 64-bit word to memory in little-endian format.
Equations
- mem.write_word64 addr w = mem.write_bytes addr (List.map (fun (i : ℕ) => UInt8.ofNat (w.val / 2 ^ (8 * i) % 256)) (List.range 8))
Instances For
Read a bignum (multiple 64-bit words) from memory. The bignum is stored as an array of n words at address addr.
Corresponds to HOL Light's bignum_from_memory.
Source: s2n-bignum proofs use this extensively (e.g., bignum_add.ml:91-92)
Equations
- mem.read_bignum addr n = Bignum.Memory.read_bignum.aux mem addr n n 0
Instances For
Check if two memory regions do not overlap. This corresponds to HOL Light's
nonoverlapping, used extensively in preconditions.
Source: s2n-bignum/common/overlap.ml
Equations
- Bignum.nonoverlapping addr1 size1 addr2 size2 = (Bignum.Word64.val addr1 + size1 ≤ Bignum.Word64.val addr2 ∨ Bignum.Word64.val addr2 + size2 ≤ Bignum.Word64.val addr1)
Instances For
Bytes are loaded at a given address (no alignment requirement).
Equations
Instances For
Bytes are loaded and aligned at a given address. Corresponds to HOL Light's
aligned_bytes_loaded.
Equations
- Bignum.aligned_bytes_loaded mem addr bytes = (Bignum.Word64.val addr % 4 = 0 ∧ Bignum.bytes_loaded mem addr bytes)
Instances For
Aligned bytes loaded implies bytes loaded.