Skip to content

share Winternitz and target-sum encoding instances - #1125

Open
mmtobs wants to merge 1 commit into
Verified-zkEVM:mainfrom
mmtobs:codex/pr1050-draft-e3-20261113
Open

mmtobs wants to merge 1 commit into
Verified-zkEVM:mainfrom
mmtobs:codex/pr1050-draft-e3-20261113

Conversation

@mmtobs

@mmtobs mmtobs commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Winternitz and target-sum encodings instantiate the generic incomparable-code interface. Their checksum, acceptance-count and collision results remain separate from general GXMSS.

Dependent contribution from the PR #1050 review. Depends on E1 #1123, E2 #1124, A3 #1116.

This PR contains contribution E3's touched files against upstream main at 0e67181a176e241956c073a214a1eb7d76b99aa9. Prerequisite source trees are omitted. Standalone CI can fail on missing prerequisite modules until this branch is restacked after those dependencies land. The dependency links define integration order; this contribution is available for maintainer review.

Original contribution commits: 7a4af218a1694c1c3e6ba6c34e3124dcc709c191. The exact original change range and published reference history remain preserved.

Validation

The complete reconciled stack is the integration source. Its focused native build passes (189 changed owner/test modules, 3,639 reported jobs); all 68 retained hypertree consumer sources, four conformance fixtures and the complete owner audit pass without warnings. Combining the 34 contribution trees, including the distributed final import cleanup, exactly reproduces reconciled tree 7cabc9101bfe37331bd8aefbe578ed69dd642bc3.

bash scripts/validate.sh --lint --test --axioms passes on the complete reconciled stack: six proof libraries (5,474 reported jobs), test build (10,937 jobs), default executable tests/CSV, source/docs/boundary/style/initialization gates, the unchanged 156-entry lint baseline and zero axiom/sorry taint over 34,760 declarations/1,426 modules. The public API consumer and all-owner audit were refreshed after the umbrella rebuilt; all other consumer bindings were verified unchanged. Prior original-stack and A1 evidence remains preserved. No standalone full-suite pass is claimed for this dependent head, and no separate full suite or dedicated review is repeated per slice. Lean 4.35.0 and locked dependencies are unchanged; local uv is 0.12.5 versus hosted CI's 0.13.6. No independent clean install or optional native FFI/nightly result is claimed.

Owner regressions included: VCVioTest/IncomparableEncoding/Instances.lean.

Dependent draft E3 against fixed upstream 0e67181.
Original contribution commits: 7a4af21.
Only this contribution touched paths and its import cleanup are included; prerequisite source trees are omitted.
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

🤖 PR Summary

⚠️ PR title does not follow conventional commit format type[(scope)]: subject. Got: share Winternitz and target-sum encoding instances

Mathematical Formalization

  • TargetSum encoding (TargetSum/Basic.lean): Defines Parameters (wrapping a TweakableHash and epoch-to-tweak map), the code code v w target as the set of codewords whose digit sum equals target, proves code_incomparable, implements the IncomparableEncoding returning the hash output exactly when the digit sum matches the target and none otherwise, and provides characterization theorems (value_eq_some_iff, value_eq_none_iff, success_mem_code).
  • Winternitz encoding (Winternitz/Encoding.lean): Defines Parameters (with payloadLengthPositive, digitWidthPositive, thf, epochToTweak), sets code to checksumWordCode, and implements an IncomparableEncoding that always returns some. Proves code_incomparable, failureMass_zero, uniformErrorAtMost_zero, canonicalErrorAtMost_zero, and probComp_uniformErrorAtMost_zero.
  • Winternitz code construction (Winternitz/Code.lean): Defines checksumWidth, payloadSum, complement, checksum, word, and checksumWordCode. Proves payloadSum_le_maximum, complement_lt_pow_width, checksum_eq_padded_digits, checksum_reconstruct, and the main result checksumWordCode_incomparable via word_eq_of_le.
  • TargetSum counting (TargetSum/Counting.lean): Defines acceptedWords, acceptedCount, coefficient (via generating polynomial), uniformEventMass, uniformRejectionMass. Proves coefficient_eq_acceptedCount, rejected_add_accepted_count, and a lower bound two_codewords_of_small_target. Connections to Lemma 7 of ePrint 2025/055.
  • TargetSum collision bridge (TargetSum/Collision.lean): Defines accepts (digit-sum equals target), bridge (instantiation of the shared Bridge structure using TargetSum.encoding with injectivity proof for epochToTweak), UniformSeedLaw, and advantage_le_hash (bound via TargetCollisionReduction.advantage_le_hash).
  • Winternitz collision bridge (Winternitz/Collision.lean): Defines word_injective (full checksum word injective for w>0), bridge (instantiates Bridge with accepts constant true), UniformSeedLaw, and advantage_le_hash (transfer to SM-DT-rTCR game).
  • Error analysis for TargetSum (TargetSum/Error.lean): Defines outputEventMass, EpsilonUniform. Proves failureMass_eq_rejectedEventMass, failureMass_le, uniformErrorAtMost, canonicalErrorAtMost, probComp_uniformErrorAtMost. Connects per-event statistical-distance premise to encoding failure probability bounds.

Testing / Concrete Instances

  • VCVioTest/IncomparableEncoding/Instances.lean: Defines three concrete codewords (oneOne, oneTwo, zeroZero), verifies checksum width, carry, incomparability, target-sum acceptance/rejection. Provides toy parameters for both encodings, several bounds bridging to TargetCollisionResistance, edge-case counts for impossible targets, empty words, zero-width words, and a check that single-digit target-sum rejects a zero word.

Infrastructure

  • VCVio.lean: Adds public import statements for IncomparableEncoding.TargetSum (with Basic, Collision, Counting, Error) and IncomparableEncoding.Winternitz (with Code, Collision, Encoding), integrating the new modules into the project’s public API.
  • VCVioTest.lean: Adds public import VCVioTest.IncomparableEncoding.Instances.
  • TargetSum.lean and Winternitz.lean: Top-level aggregation files that publicly re-export their respective submodules with docstrings.

All proofs are complete; no sorry or admit placeholders are introduced.


Statistics

Metric Count
📝 Files Changed 12
✅ Lines Added 1096
❌ Lines Removed 0

Lean Declarations

✏️ Added: 91 declaration(s)

VCVio/CryptoFoundations/IncomparableEncoding/TargetSum/Basic.lean (6)

  • @[expose] def code (v w target : ℕ) : Set (Codeword v (2 ^ w))
  • @[expose] def encoding (p : Parameters PP M R E Tweak v w target) :
  • theorem code_incomparable (v w target : ℕ) :
  • theorem success_mem_code (p : Parameters PP M R E Tweak v w target)
  • theorem value_eq_none_iff (p : Parameters PP M R E Tweak v w target)
  • theorem value_eq_some_iff (p : Parameters PP M R E Tweak v w target)

VCVio/CryptoFoundations/IncomparableEncoding/TargetSum/Collision.lean (4)

  • @[expose] def UniformSeedLaw [Fintype PP]
  • @[expose] def accepts (word : Codeword v (2 ^ w)) : Bool
  • @[expose] def bridge (params : TargetSum.Parameters PP M R E Tweak v w target)
  • theorem advantage_le_hash [SampleableType R]

VCVio/CryptoFoundations/IncomparableEncoding/TargetSum/Counting.lean (17)

  • @[expose] def acceptedCount (v w target : ℕ) : ℕ
  • @[expose] def acceptedWords (v w target : ℕ) : Finset (Codeword v (2 ^ w))
  • @[expose] def rejectedWords (v w target : ℕ) : Finset (Codeword v (2 ^ w))
  • @[expose] noncomputable def coefficient (v w target : ℕ) : ℕ
  • @[expose] noncomputable def digitPolynomial (w : ℕ) : Polynomial ℕ
  • @[expose] noncomputable def uniformEventMass (v w : ℕ)
  • @[expose] noncomputable def uniformRejectionMass (v w target : ℕ) : ℝ≥0∞
  • private noncomputable def wordPolynomial (v w : ℕ) : Polynomial ℕ
  • private theorem coeff_wordPolynomial (v w target : ℕ) :
  • private theorem wordPolynomial_eq_pow (v w : ℕ) :
  • theorem acceptedCount_two_le_of_small_target (v w target : ℕ)
  • theorem card_output (v w : ℕ) :
  • theorem coefficient_eq_acceptedCount (v w target : ℕ) :
  • theorem rejected_add_accepted_count (v w target : ℕ) :
  • theorem two_codewords_of_acceptedCount (v w target : ℕ)
  • theorem two_codewords_of_small_target (v w target : ℕ)
  • theorem uniformRejected_eq_uniformRejectionMass (v w target : ℕ) :

VCVio/CryptoFoundations/IncomparableEncoding/TargetSum/Error.lean (7)

  • @[expose] def EpsilonUniform {m : Type → Type} [Monad m]
  • @[expose] noncomputable def outputEventMass {m : Type → Type} [Monad m]
  • theorem canonicalErrorAtMost
  • theorem failureMass_eq_rejectedEventMass {m : Type → Type} [Monad m]
  • theorem failureMass_le {m : Type → Type} [Monad m]
  • theorem probComp_uniformErrorAtMost
  • theorem uniformErrorAtMost {m : Type → Type} [Monad m]

VCVio/CryptoFoundations/IncomparableEncoding/Winternitz/Code.lean (15)

  • @[expose] def checksum {n₀ w : ℕ} (_hw : 0 < w)
  • @[expose] def checksumWidth (n₀ w : ℕ) : ℕ
  • @[expose] def checksumWordCode (n₀ w : ℕ) (hw : 0 < w) :
  • @[expose] def complement {n₀ w : ℕ} (payload : Codeword n₀ (2 ^ w)) : ℕ
  • @[expose] def maximum (n₀ w : ℕ) : ℕ
  • @[expose] def payloadSum {n₀ w : ℕ} (payload : Codeword n₀ (2 ^ w)) : ℕ
  • @[expose] def word {n₀ w : ℕ} (hw : 0 < w)
  • theorem checksumWordCode_incomparable (n₀ w : ℕ) (hw : 0 < w) :
  • theorem checksum_eq_padded_digits {n₀ w : ℕ} (hw : 0 < w)
  • theorem checksum_reconstruct {n₀ w : ℕ} (hw : 0 < w)
  • theorem complement_lt_pow_width {n₀ w : ℕ} (hw : 0 < w)
  • theorem maximum_lt_pow_width (n₀ w : ℕ) (hw : 0 < w) :
  • theorem one_lt_radix {w : ℕ} (hw : 0 < w) : 1 < 2 ^ w
  • theorem payloadSum_le_maximum {n₀ w : ℕ} (payload : Codeword n₀ (2 ^ w)) :
  • theorem word_eq_of_le {n₀ w : ℕ} (hw : 0 < w)

VCVio/CryptoFoundations/IncomparableEncoding/Winternitz/Collision.lean (4)

  • @[expose] def UniformSeedLaw [Fintype PP]
  • @[expose] def bridge (params : Winternitz.Parameters PP M R E Tweak n₀ w)
  • theorem advantage_le_hash [SampleableType R]
  • theorem word_injective (hw : 0 < w) :

VCVio/CryptoFoundations/IncomparableEncoding/Winternitz/Encoding.lean (10)

  • @[expose] def code {PP M R E Tweak : Type} {n₀ w : ℕ}
  • @[expose] def encoding {PP M R E Tweak : Type} {n₀ w : ℕ}
  • theorem canonicalErrorAtMost_zero
  • theorem code_incomparable {PP M R E Tweak : Type} {n₀ w : ℕ}
  • theorem failureMass_zero {m : Type → Type} [Monad m]
  • theorem probComp_uniformErrorAtMost_zero
  • theorem two_codewords {PP M R E Tweak : Type} {n₀ w : ℕ}
  • theorem uniformErrorAtMost_zero {m : Type → Type} [Monad m]
  • theorem value_eq_some {PP M R E Tweak : Type} {n₀ w : ℕ}
  • theorem value_ne_none {PP M R E Tweak : Type} {n₀ w : ℕ}

VCVioTest/IncomparableEncoding/Instances.lean (28)

  • @[expose] def oneOne : Codeword 2 4
  • @[expose] def oneTwo : Codeword 2 4
  • @[expose] def toyTargetParameters :
  • @[expose] def toyWinternitzParameters :
  • @[expose] def zeroZero : Codeword 2 4
  • theorem checksum_bridge_bound (p K : ℕ)
  • theorem checksum_bridge_parameters (p K : ℕ) :
  • theorem checksum_canonical_error :
  • theorem checksum_carry :
  • theorem checksum_nonmaximum :
  • theorem checksum_width_two_two : Winternitz.checksumWidth 2 2 = 2
  • theorem distinct_checksum_words :
  • theorem distinct_checksum_words_incomparable :
  • theorem empty_word_count : TargetSum.acceptedCount 0 0 0 = 1
  • theorem empty_word_impossible : TargetSum.acceptedCount 0 0 1 = 0
  • theorem impossible_target_coefficient : TargetSum.coefficient 2 2 7 = 0
  • theorem impossible_target_count : TargetSum.acceptedCount 2 2 7 = 0
  • theorem target_bridge_bound (p K : ℕ)
  • theorem target_coefficient_four : TargetSum.coefficient 2 2 3 = 4
  • theorem target_count_four : TargetSum.acceptedCount 2 2 3 = 4
  • theorem target_encoding_accepts :
  • theorem target_encoding_rejects :
  • theorem target_nonmaximum : (TargetSum.encoding toyTargetParameters).NoMaximumOutput
  • theorem target_single_digit_rejected :
  • theorem target_sum_accepts :
  • theorem target_sum_rejects :
  • theorem target_two_codewords :
  • theorem zero_width_count : TargetSum.acceptedCount 2 0 0 = 1

sorry Tracking

  • No sorrys were added, removed, or affected.

📋 **Additional Analysis**

The diff adds 10 new files for IncomparableEncoding (TargetSum, Winternitz, and tests). Overall it adheres well to the project's style guide, module system, and documentation expectations. A few minor violations are noted below.


📄 **Per-File Summaries**
  • VCVio.lean: The diff adds nine public import statements for the new IncomparableEncoding subdirectory, specifically exposing the TargetSum module (with its Basic, Collision, Counting, and Error submodules) and the Winternitz module (with its Code, Collision, and Encoding submodules). This makes these cryptographic encoding and collision‑resistance definitions available to any file that imports VCVio.lean, thereby integrating the new IncomparableEncoding component into the project’s public API surface.
  • VCVio/CryptoFoundations/IncomparableEncoding/TargetSum.lean: This is a new top-level aggregation file for the TargetSum module, publicly re-exporting the Basic, Counting, Error, and Collision submodules. It provides a single module-level docstring describing the file as containing the code family, encoding observations, and the target-collision bridge. Because this is a new file, there are no sorry or admit statements to report.
  • VCVio/CryptoFoundations/IncomparableEncoding/TargetSum/Basic.lean: Added a new file Basic.lean that defines a target-sum incomparable encoding. It introduces a Parameters structure wrapping a TweakableHash and an epoch-to-tweak map; defines the global target-sum code code v w target as the set of codewords whose digit sum equals target; proves code_incomparable; implements the encoding as a IncomparableEncoding that returns the hash output exactly when its digit sum matches the target, and none otherwise; and provides three characterization theorems (value_eq_some_iff, value_eq_none_iff, success_mem_code) that relate the encoding's output to the target-sum condition. No sorry or admit are present.
  • VCVio/CryptoFoundations/IncomparableEncoding/TargetSum/Collision.lean: This new file introduces the module IncomparableEncoding.TargetSumCollision in the Lean 4 formal verification project, defining key components for transporting collision resistance from a target-sum encoding to a tweakable hash. It defines accepts (a predicate checking if the digit-sum of a codeword equals the target), bridge (an instantiation of the shared Bridge structure using TargetSum.encoding and the given parameters, with an injectivity proof for epochToTweak), UniformSeedLaw (a proposition asserting uniform sampling of the seed generator), and advantage_le_hash (a theorem, fully proved via TargetCollisionReduction.advantage_le_hash, stating that the target-collision-resistance advantage is bounded by the SM-DT-rTCR advantage of a reduced adversary). The file serves as the concrete encoding bridge for the generic reduction, preserving the message-hash seed sampler, target cap, and retry cap, and contains no sorry or admit declarations.
  • VCVio/CryptoFoundations/IncomparableEncoding/TargetSum/Counting.lean: The new file Counting.lean adds definitions and theorems for counting codewords whose digit sum equals a given target, including the generating polynomial approach and a bound on the number of codewords. It introduces acceptedWords, acceptedCount, rejectedWords, and the polynomial coefficient, with theorems linking them (e.g., coefficient_eq_acceptedCount, rejected_add_accepted_count). Two explicit constructions (two_codewords_of_small_target) give a lower bound on acceptedCount under mild conditions on v,w,target. The file also defines uniform event mass and rejection mass, uniformEventMass and uniformRejectionMass, and proves uniformRejected_eq_uniformRejectionMass connecting them to coefficient, as used in Lemma 7 of ePrint 2025/055. No sorry or admit appear.
  • VCVio/CryptoFoundations/IncomparableEncoding/TargetSum/Error.lean: This new file Error.lean defines outputEventMass and EpsilonUniform, and proves four theorems (failureMass_eq_rejectedEventMass, failureMass_le, uniformErrorAtMost, canonicalErrorAtMost, probComp_uniformErrorAtMost) that connect a per-event hash-output statistical-distance premise (EpsilonUniform) to error bounds on the encoding failure probability. outputEventMass computes the probability that a hash output lands in a given event set under an arbitrary sampler; EpsilonUniform states that this mass is within ε (in ENNReal.absDiff) of the corresponding uniform event mass for all pp/tweak/message/events. Theorems show that the encoding's failureMass for a rejected-word event equals outputEventMass on that event, that it is bounded by ε + uniformRejectionMass v w target, and use this to derive the UniformErrorAtMost and CanonicalErrorAtMost bounds for uniform and canonical samplers respectively. No sorry or admit are present.
  • VCVio/CryptoFoundations/IncomparableEncoding/Winternitz.lean: This new file Winternitz.lean defines the top-level module for the Winternitz encoding section of the incomparable‑encoding library. It publicly re‑exports three submodules: Winternitz.Code (the code family), Winternitz.Encoding (encoding observations), and Winternitz.Collision (target‑collision bridge). The docstring provides a brief orientation: “The code family, encoding observations and target‑collision bridge.”
  • VCVio/CryptoFoundations/IncomparableEncoding/Winternitz/Code.lean: This new file defines the Winternitz checksum word construction: checksumWidth, maximum, payloadSum, complement, checksum, word, and checksumWordCode. It proves that the payload sum is bounded (payloadSum_le_maximum), that the complementary checksum fits in the chosen digit width (complement_lt_pow_width), and that the explicit checksum digits agree with padded base‑2^w digits (checksum_eq_padded_digits, checksum_reconstruct). The main result (checksumWordCode_incomparable) shows that the resulting set of codewords is an incomparable code, leveraging the lemma word_eq_of_le which deduces equality of payloads from componentwise inequality. No sorry or admit appear.
  • VCVio/CryptoFoundations/IncomparableEncoding/Winternitz/Collision.lean: This new file Collision.lean adds three declarations. word_injective proves that the full checksum word (the concatenation of message digits and checksum digits) is injective for w > 0. bridge instantiates the shared Bridge structure using the Winternitz encoding, setting the failure predicate accepts to the constant true and wiring the injectivity lemma as the required word_injective field. UniformSeedLaw defines a proposition stating that params.thf.seedGen is uniformly sampled under ProbCompRuntime. advantage_le_hash (a theorem) transfers a checksum-word collision adversary into the SM-DT-rTCR game at the same capacities, giving a bound on TargetCollisionResistance.advantage source by TweakableHash.SM_DT_RTCR_Advantage of the reduced adversary, using the generic TargetCollisionReduction lemma. The file contains no sorry or admit.
  • VCVio/CryptoFoundations/IncomparableEncoding/Winternitz/Encoding.lean: This file introduces the module IncomparableEncoding.Winternitz.Encoding, which defines the encoding for a Winternitz-style incomparable encoding. It defines the Parameters structure (with fields payloadLengthPositive, digitWidthPositive, thf (a tweakable hash), and epochToTweak), the code definition (set to checksumWordCode), and the encoding definition (an IncomparableEncoding that always returns some). It also provides the theorems code_incomparable, two_codewords, value_eq_some, value_ne_none, failureMass_zero, uniformErrorAtMost_zero, canonicalErrorAtMost_zero, and probComp_uniformErrorAtMost_zero, proving that the encoding never fails and has zero error under various conditions. No sorry or admit are present.
  • VCVioTest.lean: Added public import VCVioTest.IncomparableEncoding.Instances to the module's public imports, making the instances defined in that file available to downstream consumers of VCVioTest.
  • VCVioTest/IncomparableEncoding/Instances.lean: Adds the file VCVioTest/IncomparableEncoding/Instances.lean, which defines three concrete codewords (oneOne, oneTwo, zeroZero), a set of theorems verifying checksum width, checksum carry, and incomparability, target-sum acceptance/rejection for oneTwo and zeroZero, toy parameters for both the target-sum and Winternitz encodings, and several bounds bridging these instances to the generic TargetCollisionResistance security reduction. Also includes edge-case counts for impossible targets, empty words, and zero-width words, and checks that the single-digit target-sum predicate rejects a zero word.

Last updated: 2026-11-13 15:51 UTC.

@mmtobs
mmtobs marked this pull request as ready for review November 13, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant