Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Parsed compressed points are reduced curve points

Proved
BitcoinMuSig.cpoint_spec

by pitimespi · Oct 30, 2026 · Mathlib 0df444a (Lean v4.33.1)

bip327bip340bitcoinelliptic-curveformal-verificationfrostmathlibmultisignaturemusig2schnorrsecp256k1

cpoint b = some P → onCurve P ∧ P.1 < p ∧ P.2 < p.

Preamble
import Definitions.Def_BitcoinMuSig
import Definitions.Def_BitcoinSer
open BitcoinMuSig BitcoinSig BitcoinTaproot
Formal statement
theorem BitcoinMuSig.cpoint_spec (b : BitcoinSer.Bytes) (P : ℕ × ℕ) (h : cpoint b = some P) :
    onCurve P = true ∧ P.1 < p ∧ P.2 < p := by sorry
Source
BIP327 MuSig2 for BIP340-compatible multi-signatures (KeyAgg, ApplyTweak, NonceAgg, GetSessionValues, PartialSigVerifyInternal, PartialSigAgg): https://github.com/bitcoin/bips/blob/master/bip-0327.mediawiki; BIP340 Schnorr signatures; RFC 9591 FROST (Lagrange-coefficient aggregation); secp256k1 (SEC 2); Mathlib's WeierstrassCurve.Affine group law; the signature mission's executable curve (BitcoinSig.padd, pmul, schnorrVerify)
Read-back

What the Lean code literally says, in plain math · claude-fable-5-1 (independent sub-agent, blind: Lean code + auditor instructions only)

Read-back: BitcoinMuSig.cpoint_spec

Source file: Thm_BitcoinMuSig_cpoint_spec.lean (one theorem; it builds on the MuSig definition file, which itself uses the secp256k1 signature and Taproot definition files).

Statement. For every byte string bbb and every pair P=(x,y)P = (x, y)P=(x,y) of natural numbers: if cpoint(b)\mathrm{cpoint}(b)cpoint(b) succeeds and returns (x,y)(x, y)(x,y), then

  • onCurve(x,y)\mathrm{onCurve}(x, y)onCurve(x,y) holds, i.e. (y⋅y) mod p=(x⋅x⋅x+7) mod p(y\cdot y) \bmod p = (x\cdot x\cdot x + 7) \bmod p(y⋅y)modp=(x⋅x⋅x+7)modp,
  • x<px < px<p, and
  • y<py < py<p.

Byte strings on which cpoint\mathrm{cpoint}cpoint fails (wrong length, first byte not 222 or 333, abscissa ≥p\ge p≥p, or no square root) satisfy the hypothesis for no PPP and are not constrained.

Definitions used, unfolded

Constants

  • p=2256−232−977p = 2^{256} - 2^{32} - 977p=2256−232−977 is a fixed natural number (the field modulus).
  • n=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141n = \mathtt{0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141}n=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 is a fixed natural number (written in hexadecimal).
  • Gx=0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798G_x = \mathtt{0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798}Gx​=0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798 and Gy=0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8G_y = \mathtt{0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8}Gy​=0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8 are fixed natural numbers (GyG_yGy​ is even: its last hexadecimal digit is 888).

Executable points and their arithmetic

  • An executable point is either the special value ∞\infty∞ (the code's "no coordinates" value, which it uses for the point at infinity) or a pair (x,y)(x, y)(x,y) of natural numbers of arbitrary size. Nothing in the type requires x,y<px, y < px,y<p or that the pair lies on the curve. Equality of executable points is literal equality: both ∞\infty∞, or equal pairs of natural numbers (so (x,y)(x, y)(x,y) and (x+p,y)(x+p, y)(x+p,y) are different executable points).
  • Curve test. For naturals x,yx, yx,y: onCurve(x,y)\mathrm{onCurve}(x, y)onCurve(x,y) holds iff
(y⋅y) mod p=(x⋅x⋅x+7) mod p,(y \cdot y) \bmod p = (x \cdot x \cdot x + 7) \bmod p ,(y⋅y)modp=(x⋅x⋅x+7)modp,

i.e. y2≡x3+7(modp)y^2 \equiv x^3 + 7 \pmod py2≡x3+7(modp). Pairs with unreduced coordinates (x≥px \ge px≥p or y≥py \ge py≥p) can pass this test.

  • Modular powers and inversion. powMod(b,e,m)\mathrm{powMod}(b, e, m)powMod(b,e,m) is a square-and-multiply loop; the definition file proves powMod(b,e,m)=be mod m\mathrm{powMod}(b, e, m) = b^e \bmod mpowMod(b,e,m)=bemodm for all naturals b,e,mb, e, mb,e,m. The field inverse is finv(a)=ap−2 mod p\mathrm{finv}(a) = a^{p-2} \bmod pfinv(a)=ap−2modp; in particular finv(a)=0\mathrm{finv}(a) = 0finv(a)=0 when p∣ap \mid ap∣a.
  • Addition padd(P,Q)\mathrm{padd}(P, Q)padd(P,Q):
    • padd(∞,Q)=Q\mathrm{padd}(\infty, Q) = Qpadd(∞,Q)=Q and padd(P,∞)=P\mathrm{padd}(P, \infty) = Ppadd(P,∞)=P, returned unchanged (unreduced coordinates stay unreduced).
    • For P=(x1,y1)P = (x_1, y_1)P=(x1​,y1​), Q=(x2,y2)Q = (x_2, y_2)Q=(x2​,y2​) with x1≡x2(modp)x_1 \equiv x_2 \pmod px1​≡x2​(modp):
      • if y1+y2≡0(modp)y_1 + y_2 \equiv 0 \pmod py1​+y2​≡0(modp) the result is ∞\infty∞;
      • otherwise (tangent branch, which uses only x1,y1x_1, y_1x1​,y1​):
λ=(3x12⋅finv(2y1 mod p)) mod p,x3=(λ2+2(p−x1 mod p)) mod p,\lambda = \big(3x_1^2 \cdot \mathrm{finv}(2y_1 \bmod p)\big) \bmod p,\quad x_3 = \big(\lambda^2 + 2(p - x_1 \bmod p)\big) \bmod p,λ=(3x12​⋅finv(2y1​modp))modp,x3​=(λ2+2(p−x1​modp))modp, y3=(λ⋅((x1+p−x3) mod p)+(p−y1 mod p)) mod p,y_3 = \big(\lambda \cdot ((x_1 + p - x_3) \bmod p) + (p - y_1 \bmod p)\big) \bmod p,y3​=(λ⋅((x1​+p−x3​)modp)+(p−y1​modp))modp,
and the result is $(x_3, y_3)$.
  • For P=(x1,y1)P = (x_1, y_1)P=(x1​,y1​), Q=(x2,y2)Q = (x_2, y_2)Q=(x2​,y2​) with x1≢x2(modp)x_1 \not\equiv x_2 \pmod px1​≡x2​(modp) (chord branch):
λ=(((y2+p−y1 mod p) mod p)⋅finv((x2+p−x1 mod p) mod p)) mod p,\lambda = \Big( \big((y_2 + p - y_1 \bmod p) \bmod p\big) \cdot \mathrm{finv}\big((x_2 + p - x_1 \bmod p) \bmod p\big) \Big) \bmod p,λ=(((y2​+p−y1​modp)modp)⋅finv((x2​+p−x1​modp)modp))modp, x3=(λ2+(p−x1 mod p)+(p−x2 mod p)) mod p,y3=(λ⋅((x1+p−x3) mod p)+(p−y1 mod p)) mod p,x_3 = \big(\lambda^2 + (p - x_1 \bmod p) + (p - x_2 \bmod p)\big) \bmod p,\quad y_3 = \big(\lambda \cdot ((x_1 + p - x_3) \bmod p) + (p - y_1 \bmod p)\big) \bmod p,x3​=(λ2+(p−x1​modp)+(p−x2​modp))modp,y3​=(λ⋅((x1​+p−x3​)modp)+(p−y1​modp))modp,
and the result is $(x_3, y_3)$.
  • All subtractions are of natural numbers but never truncate here (the subtracted quantity never exceeds the other). Whenever both inputs are pairs, the output is ∞\infty∞ or a pair with both coordinates <p< p<p.
  • Scalar multiplication pmul(k,P)\mathrm{pmul}(k, P)pmul(k,P) for k∈Nk \in \mathbb{N}k∈N: a least-significant-bit-first double-and-add loop with a fuel of exactly 257257257 iterations. Starting from (k,P,acc=∞)(k, P, \mathrm{acc} = \infty)(k,P,acc=∞), each iteration does: if k=0k = 0k=0, stop and return acc\mathrm{acc}acc; otherwise replace acc\mathrm{acc}acc by padd(acc,P)\mathrm{padd}(\mathrm{acc}, P)padd(acc,P) if kkk is odd (else keep it), then replace PPP by padd(P,P)\mathrm{padd}(P, P)padd(P,P) and kkk by ⌊k/2⌋\lfloor k/2 \rfloor⌊k/2⌋. When the 257257257 iterations are exhausted the current acc\mathrm{acc}acc is returned. Consequently only the 257257257 lowest bits of kkk are ever used: pmul(k,P)=pmul(k mod 2257,P)\mathrm{pmul}(k, P) = \mathrm{pmul}(k \bmod 2^{257}, P)pmul(k,P)=pmul(kmod2257,P). Also pmul(0,P)=∞\mathrm{pmul}(0, P) = \inftypmul(0,P)=∞ and pmul(k,∞)=∞\mathrm{pmul}(k, \infty) = \inftypmul(k,∞)=∞.
  • GGG denotes the executable point (Gx,Gy)(G_x, G_y)(Gx​,Gy​).

Byte strings, hashing and point encodings

  • A byte string is a finite list of bytes (values 0,…,2550, \dots, 2550,…,255). ∣b∣|b|∣b∣ is its length, ∥\Vert∥ is concatenation. takek(b)\mathrm{take}_k(b)takek​(b) is the first min⁡(k,∣b∣)\min(k, |b|)min(k,∣b∣) bytes of bbb and dropk(b)\mathrm{drop}_k(b)dropk​(b) is bbb with its first min⁡(k,∣b∣)\min(k, |b|)min(k,∣b∣) bytes removed, so a slice of a too-short string is silently shorter (possibly empty).
  • beVal(b)=∑i=0∣b∣−1bi 256 ∣b∣−1−i\mathrm{beVal}(b) = \sum_{i=0}^{|b|-1} b_i \, 256^{\,|b|-1-i}beVal(b)=∑i=0∣b∣−1​bi​256∣b∣−1−i is the big-endian value of bbb (any length; beVal\mathrm{beVal}beVal of the empty string is 000).
  • be32(x)\mathrm{be32}(x)be32(x) is the 323232-byte big-endian encoding of x mod 2256x \bmod 2^{256}xmod2256 (bits of xxx above 22562^{256}2256 are silently dropped).
  • For a pair P=(x,y)P = (x, y)P=(x,y) of naturals: xbytes(P)=be32(x)\mathrm{xbytes}(P) = \mathrm{be32}(x)xbytes(P)=be32(x); hasEvenY(P)\mathrm{hasEvenY}(P)hasEvenY(P) holds iff y mod 2=0y \bmod 2 = 0ymod2=0 (parity of the raw natural yyy, no reduction mod ppp); cbytes(P)=[c] ∥ be32(x)\mathrm{cbytes}(P) = [c] \,\Vert\, \mathrm{be32}(x)cbytes(P)=[c]∥be32(x), a 333333-byte string whose first byte ccc is 222 if hasEvenY(P)\mathrm{hasEvenY}(P)hasEvenY(P) and 333 otherwise.
  • zero33\mathrm{zero}_{33}zero33​ is the string of 333333 zero bytes. cbytesExt(∞)=zero33\mathrm{cbytesExt}(\infty) = \mathrm{zero}_{33}cbytesExt(∞)=zero33​ and cbytesExt(P)=cbytes(P)\mathrm{cbytesExt}(P) = \mathrm{cbytes}(P)cbytesExt(P)=cbytes(P) for a pair PPP.
  • SHA256\mathrm{SHA256}SHA256 is the executable SHA-256 function of the serialization definition file. ascii(s)\mathrm{ascii}(s)ascii(s) is the UTF-8 byte string of a text string sss. The tagged hash is
tagged(s,m)=SHA256(SHA256(ascii(s)) ∥ SHA256(ascii(s)) ∥ m).\mathrm{tagged}(s, m) = \mathrm{SHA256}\big(\mathrm{SHA256}(\mathrm{ascii}(s)) \,\Vert\, \mathrm{SHA256}(\mathrm{ascii}(s)) \,\Vert\, m\big).tagged(s,m)=SHA256(SHA256(ascii(s))∥SHA256(ascii(s))∥m).

Parsing compressed points

  • liftXParity(x,odd)\mathrm{liftXParity}(x, \mathit{odd})liftXParity(x,odd) for a natural xxx and a requested parity: let y=(x3+7)(p+1)/4 mod py = (x^3 + 7)^{(p+1)/4} \bmod py=(x3+7)(p+1)/4modp (computed by powMod\mathrm{powMod}powMod; (p+1)/4(p+1)/4(p+1)/4 is natural-number division). If y2 mod p=(x3+7) mod py^2 \bmod p = (x^3 + 7) \bmod py2modp=(x3+7)modp, the result is the pair (x,y∗)(x, y^\ast)(x,y∗) where y∗=yy^\ast = yy∗=y if the parity of yyy is the requested one and y∗=(p−y) mod py^\ast = (p - y) \bmod py∗=(p−y)modp otherwise (if y=0y = 0y=0 then y∗=0y^\ast = 0y∗=0 whatever parity was requested); if not, the result is a failure.
  • cpoint(b)\mathrm{cpoint}(b)cpoint(b) parses a byte string as a compressed point. If ∣b∣≠33|b| \neq 33∣b∣=33 it fails. If ∣b∣=33|b| = 33∣b∣=33, write b=[t]∥rb = [t] \Vert rb=[t]∥r with ∣r∣=32|r| = 32∣r∣=32: if t∉{2,3}t \notin \{2, 3\}t∈/{2,3} it fails; otherwise let x=beVal(r)x = \mathrm{beVal}(r)x=beVal(r); if x≥px \ge px≥p it fails, and if x<px < px<p the result is liftXParity(x,odd=(t=3))\mathrm{liftXParity}(x, \mathit{odd} = (t = 3))liftXParity(x,odd=(t=3)) (which may itself fail). A successful result is a pair (x,y)(x, y)(x,y) of naturals.
  • Important typing fact. The result of cpoint\mathrm{cpoint}cpoint has the same type as an executable point, and its failure value is literally the value ∞\infty∞. So wherever cpoint(b)\mathrm{cpoint}(b)cpoint(b) is used as an executable point, a parse failure is the point at infinity.
  • cpointExt(b)\mathrm{cpointExt}(b)cpointExt(b): if b=zero33b = \mathrm{zero}_{33}b=zero33​ the result is "success with ∞\infty∞"; otherwise it is "success with the pair cpoint(b)\mathrm{cpoint}(b)cpoint(b)" when cpoint(b)\mathrm{cpoint}(b)cpoint(b) succeeds, and failure when it fails. (Here failure and ∞\infty∞ are distinct outcomes.)
Human review
  • Endorsed by Shuze Chen · Oct 30, 2026

    Confirmed by the moderator at approval.

  • Endorsed by pitimespi · Oct 30, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me