Skip to content

feat(xmss): validate XmssConfig fields at construction - #1123

Merged
tcoratger merged 2 commits into
leanEthereum:mainfrom
tcoratger:crypto/xmss-config-validation
Jun 17, 2026
Merged

feat(xmss): validate XmssConfig fields at construction#1123
tcoratger merged 2 commits into
leanEthereum:mainfrom
tcoratger:crypto/xmss-config-validation

Conversation

@tcoratger

Copy link
Copy Markdown
Collaborator

Problem

XmssConfig declared its numeric fields as bare int with no positivity constraints, unlike PoseidonParams which uses Field(gt=0, ...). In addition, LOG_LIFETIME must be even (the key splits into a top tree and bottom trees that each cover LOG_LIFETIME / 2 levels), but evenness was only enforced deep in tree-building. A misconfigured XmssConfig therefore failed late and cryptically.

Fix

  • Add Field(gt=0) to every logically positive numeric XmssConfig field (LOG_LIFETIME, DIMENSION, BASE, Z, Q, TARGET_SUM, MAX_TRIES, PARAMETER_LENGTH, the field-element lengths, and CAPACITY).
  • Extend the existing model validator to reject an odd LOG_LIFETIME with a clear full-sentence message, consistent with the existing decomposition check.
  • No default values, numeric behavior, wire format, or algorithm changed. PROD_CONFIG, TEST_CONFIG, and TARGET_CONFIG all still construct unchanged.
  • Add unit tests covering rejection of a non-positive field and rejection of an odd LOG_LIFETIME, asserting the full exception message.

🤖 Generated with Claude Code

tcoratger and others added 2 commits June 17, 2026 16:03
Add Field(gt=0) positivity constraints to every numeric XmssConfig
field, matching the style used by PoseidonParams. Extend the existing
model validator to reject an odd LOG_LIFETIME, since the key splits into
a top tree and bottom trees that each cover LOG_LIFETIME / 2 levels.

Previously a non-positive field or an odd lifetime exponent only failed
deep in tree-building with a cryptic error. Now misconfiguration is
caught at construction with a clear message. Defaults are unchanged and
all three shipped configs still construct.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
# Conflicts:
#	src/lean_spec/spec/crypto/xmss/constants.py
@tcoratger
tcoratger merged commit 27a28c1 into leanEthereum:main Jun 17, 2026
13 of 14 checks passed
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