Skip to content

refactor(poseidon1): build circulant MDS via np.roll#738

Open
tcoratger wants to merge 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/poseidon1-mds-roll
Open

refactor(poseidon1): build circulant MDS via np.roll#738
tcoratger wants to merge 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/poseidon1-mds-roll

Conversation

@tcoratger
Copy link
Copy Markdown
Collaborator

Summary

  • Replace the nested Python loop in _build_circulant_mds with a single numpy comprehension: row i of a circulant matrix is just the first row rolled right by i positions.
  • Modulo reduction is applied once on the assembled matrix instead of per element.
  • Added one sentence to the docstring explaining the row-i = first-row-rolled-by-i identity.

Test plan

  • Element-wise equality check against the original implementation for the width-16 spec row, the width-24 spec row, and a value crossing the modulus.
  • uv run pytest tests/ -k poseidon1 — 8 tests pass.

🤖 Generated with Claude Code

Replace the nested Python loop in _build_circulant_mds with a single
numpy comprehension. Row i of a circulant matrix is the first row
rolled right by i positions, so the matrix is built as a stack of
rolled rows reduced mod p.

Verified element-wise equivalent against the width-16 and width-24
spec rows and a value crossing the modulus.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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