~/bend-docscommunity

packed-proof.bend checks

raw source on the hub · import bend-kit-bytes@0.3.3.2/packed-proof.bend as Packed_proof

The packed byte memory invariant, linked to the actual Bytes.peek / Bytes.poke.

7 imports
import Base
import ./bytes.bend as Bytes
import ./array-proof.bend as ArrayModel
import ./word-proof.bend as WordModel
import bend-kit-lemmas@0.1.5.1/lemmas.bend as Lemmas
import bend-mathlib@0.8.0.0/nat.bend as MNat
import bend-mathlib@0.8.0.0/bool.bend as MBool

Definitions

def slot source · line 10 · raw

@+i:U32 -> Nat

def lane source · line 13 · raw

@+i:U32 -> Nat

def byte_at source · line 16 · raw

@+l:List<&2, U32> -> @+i:U32 -> U32

def write_at source · line 19 · raw

@+l:List<&2, U32> -> @+i:U32 -> @+v:U32 -> List<&2, U32>

def capacity source · line 23 · raw

@+d:Nat -> Nat

Capacity is in bytes: pow2(d) * 4, with the recursive factor first.

def byte_lt16 source · line 26 · raw

@+d:Nat -> @+i:U32 -> @hd:0x78e347bf8d0582a322c01b02c727566f/nat.lt(d, 3n) -> @hi:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(i), capacity(d)) -> 0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(i), 16n)

def Layout source · line 37 · raw

@+i:U32 -> Type

def layout_at source · line 42 · raw

@n:Nat -> @+i:U32 -> @e:{n == U32.to_nat(i) : Nat} -> @h:0x78e347bf8d0582a322c01b02c727566f/nat.lt(n, 16n) -> Layout(i)

def layout source · line 95 · raw

@+i:U32 -> @h:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(i), 16n) -> Layout(i)

def shift_exact.of source · line 98 · raw

@-i:U32 -> @r:Layout(i) -> {Nat.mul(lane(i), 8n) == 0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.shift(i) : Nat}

def shift_exact source · line 102 · raw

@+i:U32 -> @h:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(i), 16n) -> {Nat.mul(lane(i), 8n) == 0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.shift(i) : Nat}

def lane_bound.of source · line 105 · raw

@-i:U32 -> @r:Layout(i) -> 0x78e347bf8d0582a322c01b02c727566f/nat.lt(lane(i), 4n)

def lane_bound source · line 110 · raw

@+i:U32 -> @h:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(i), 16n) -> 0x78e347bf8d0582a322c01b02c727566f/nat.lt(lane(i), 4n)

def address_split.of source · line 113 · raw

@-i:U32 -> @r:Layout(i) -> {Nat.add(Nat.mul(slot(i), 4n), lane(i)) == U32.to_nat(i) : Nat}

def address_split source · line 118 · raw

@+i:U32 -> @h:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(i), 16n) -> {Nat.add(Nat.mul(slot(i), 4n), lane(i)) == U32.to_nat(i) : Nat}

def scale_bound source · line 121 · raw

@+q:Nat -> @+r:Nat -> @+c:Nat -> @h:0x78e347bf8d0582a322c01b02c727566f/nat.lt(Nat.add(Nat.mul(q, 4n), r), Nat.mul(c, 4n)) -> 0x78e347bf8d0582a322c01b02c727566f/nat.lt(q, c)

def slot_bound source · line 136 · raw

@+d:Nat -> @+i:U32 -> @+hd:0x78e347bf8d0582a322c01b02c727566f/nat.lt(d, 3n) -> @+hi:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(i), capacity(d)) -> 0x78e347bf8d0582a322c01b02c727566f/nat.lt(slot(i), 0xd8f70327683b21776ccf8aa205a4e092/lemmas.pow2(d))

def peek_model source · line 141 · raw

@+d:Nat -> @+l:List<&2, U32> -> @+i:U32 -> @+hd:0x78e347bf8d0582a322c01b02c727566f/nat.lt(d, 3n) -> @+hi:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(i), capacity(d)) -> {0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.peek(0x166a26e38c43ec5f8fe3323f5850e3d8/array-proof.build(d, l), i) == (0x166a26e38c43ec5f8fe3323f5850e3d8/array-proof.build(d, l), byte_at(l, i)) : Pair(Array<U32>, U32)}

def poke_model source · line 146 · raw

@+d:Nat -> @+l:List<&2, U32> -> @+i:U32 -> @+v:U32 -> @+hd:0x78e347bf8d0582a322c01b02c727566f/nat.lt(d, 3n) -> @+hi:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(i), capacity(d)) -> @hl:0x78e347bf8d0582a322c01b02c727566f/nat.le(0xd8f70327683b21776ccf8aa205a4e092/lemmas.pow2(d), 0x166a26e38c43ec5f8fe3323f5850e3d8/array-proof.len(l)) -> {0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.poke(0x166a26e38c43ec5f8fe3323f5850e3d8/array-proof.build(d, l), i, v) == 0x166a26e38c43ec5f8fe3323f5850e3d8/array-proof.build(d, write_at(l, i, v)) : Array<U32>}

def write_length source · line 151 · raw

@+l:List<&2, U32> -> @+i:U32 -> @+v:U32 -> {0x166a26e38c43ec5f8fe3323f5850e3d8/array-proof.len(write_at(l, i, v)) == 0x166a26e38c43ec5f8fe3323f5850e3d8/array-proof.len(l) : Nat}

def byte_write_same source · line 154 · raw

@+l:List<&2, U32> -> @+i:U32 -> @+v:U32 -> @hs:0x78e347bf8d0582a322c01b02c727566f/nat.lt(slot(i), 0x166a26e38c43ec5f8fe3323f5850e3d8/array-proof.len(l)) -> @hl:0x78e347bf8d0582a322c01b02c727566f/nat.lt(lane(i), 4n) -> {byte_at(write_at(l, i, v), i) == U32.and(v, 255) : U32}

def nat_eq_true source · line 158 · raw

@+a:Nat -> @+b:Nat -> @h:{Nat.is_eq(a, b) == True{} : Bool} -> {a == b : Nat}

def address_inj source · line 170 · raw

@+i:U32 -> @+j:U32 -> @hi:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(i), 16n) -> @hj:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(j), 16n) -> @es:{slot(i) == slot(j) : Nat} -> @el:{lane(i) == lane(j) : Nat} -> {i == j : U32}

def byte_write_other.if source · line 178 · raw

@same:Bool -> @+l:List<&2, U32> -> @+i:U32 -> @+j:U32 -> @+v:U32 -> @+hi:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(i), 16n) -> @+hj:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(j), 16n) -> @hs:0x78e347bf8d0582a322c01b02c727566f/nat.lt(slot(i), 0x166a26e38c43ec5f8fe3323f5850e3d8/array-proof.len(l)) -> @ne:(@_:{i == j : U32} -> Empty) -> @e:{same == Nat.is_eq(slot(i), slot(j)) : Bool} -> {byte_at(write_at(l, i, v), j) == byte_at(l, j) : U32}

def byte_write_other source · line 189 · raw

@+l:List<&2, U32> -> @+i:U32 -> @+j:U32 -> @+v:U32 -> @hi:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(i), 16n) -> @hj:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(j), 16n) -> @hs:0x78e347bf8d0582a322c01b02c727566f/nat.lt(slot(i), 0x166a26e38c43ec5f8fe3323f5850e3d8/array-proof.len(l)) -> @ne:(@_:{i == j : U32} -> Empty) -> {byte_at(write_at(l, i, v), j) == byte_at(l, j) : U32}

def peek_poke_same source · line 192 · raw

@+d:Nat -> @+l:List<&2, U32> -> @+i:U32 -> @+v:U32 -> @+hd:0x78e347bf8d0582a322c01b02c727566f/nat.lt(d, 3n) -> @+hi:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(i), capacity(d)) -> @+hl:0x78e347bf8d0582a322c01b02c727566f/nat.le(0xd8f70327683b21776ccf8aa205a4e092/lemmas.pow2(d), 0x166a26e38c43ec5f8fe3323f5850e3d8/array-proof.len(l)) -> {0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.peek(0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.poke(0x166a26e38c43ec5f8fe3323f5850e3d8/array-proof.build(d, l), i, v), i) == (0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.poke(0x166a26e38c43ec5f8fe3323f5850e3d8/array-proof.build(d, l), i, v), 0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.b8(v)) : Pair(Array<U32>, U32)}

def peek_poke_other source · line 197 · raw

@+d:Nat -> @+l:List<&2, U32> -> @+i:U32 -> @+j:U32 -> @+v:U32 -> @+hd:0x78e347bf8d0582a322c01b02c727566f/nat.lt(d, 3n) -> @+hi:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(i), capacity(d)) -> @+hj:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(j), capacity(d)) -> @+hl:0x78e347bf8d0582a322c01b02c727566f/nat.le(0xd8f70327683b21776ccf8aa205a4e092/lemmas.pow2(d), 0x166a26e38c43ec5f8fe3323f5850e3d8/array-proof.len(l)) -> @ne:(@_:{i == j : U32} -> Empty) -> {0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.peek(0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.poke(0x166a26e38c43ec5f8fe3323f5850e3d8/array-proof.build(d, l), i, v), j) == (0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.poke(0x166a26e38c43ec5f8fe3323f5850e3d8/array-proof.build(d, l), i, v), byte_at(l, j)) : Pair(Array<U32>, U32)}