def carry_limbs

bend-collections-laws-crypto@1.0.0.0 · proofs/crypto/secp256k1/bounds.bend:52

import bend-collections-laws-crypto@1.0.0.0/proofs/crypto/secp256k1/bounds.bend as Bounds
import Base
import bend-collections-laws-crypto@1.0.0.0/spec/lib/common.bend as C
import bend-collections-laws-crypto@1.0.0.0/spec/crypto/secp256k1/field.bend as FS
import bend-collections-laws-crypto@1.0.0.0/src/crypto/secp256k1/limbs.bend as L
import bend-collections-laws-crypto@1.0.0.0/proofs/lib/logic.bend as Lg

52# the first j <= n limbs of a carry pass: exactly j limbs below 2^16
53def carry_limbs(+one: Nat, +h1: {one == 1n : Nat}, n: Nat, j: Nat, xs: List<&2, Nat>, +u: Nat, +hj: {Nat.is_le(j, n) == True{} : Bool}) -> {FS.limbs16(one, j, L.take(j, L.carry(n, xs, u))) == True{} : Bool}:
54  match n j xs:
55    case 0n 0n Nil{}:
56      {==}
57    case 0n 0n x <> t:
58      {==}
59    case 0n 1n+i _:
60      Empty.absurd({FS.limbs16(one, 1n+i, L.take(1n+i, L.carry(0n, xs, u))) == True{} : Bool}, Lg.false_true(hj))
61    case 1n+k 0n Nil{}:
62      {==}
63    case 1n+k 0n x <> t:
64      {==}
65    case 1n+ +k 1n+ +i Nil{}:
66      +s = Nat.add(u, 0n)
67      Lg.and_intro(Nat.is_lt(L.lo16(s), C.shift(16n, one)), FS.limbs16(one, i, L.take(i, L.carry(k, [], L.hi16(s)))), lo16_lt(one, h1, s), carry_limbs(one, h1, k, i, [], L.hi16(s), hj))
68    case 1n+ +k 1n+ +i +x <> +t:
69      +s = Nat.add(u, x)
70      Lg.and_intro(Nat.is_lt(L.lo16(s), C.shift(16n, one)), FS.limbs16(one, i, L.take(i, L.carry(k, t, L.hi16(s)))), lo16_lt(one, h1, s), carry_limbs(one, h1, k, i, t, L.hi16(s), hj))

Uses (16)

Used by (8)