Poseidon hash function#1777
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a Poseidon hash benchmark/test suite for the zkc DSL, including u32-emulated and native felt implementations, and updates compiler support needed for felt-typed memory/static constants. It also performs a repository-wide spelling rename from flattern to flatten.
Changes:
- Adds Poseidon constants, MDS matrices, result tables, implementations, documentation, and zkc benchmark tests.
- Adds felt memory unit tests and compiler/codegen changes for felt memory and constants.
- Renames
flatternidentifiers/comments toflattenacross compiler, IR, and corset packages.
Reviewed changes
Copilot reviewed 95 out of 95 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
pkg/zkc/compiler/codegen/evaluate.go |
Adds field-aware constant evaluation paths. |
pkg/zkc/compiler/codegen/statement.go |
Allows felt data lines for writable memories. |
pkg/zkc/compiler/codegen/flatten.go |
Renames codegen flatten helper. |
pkg/zkc/compiler/codegen/compile.go |
Updates callers to renamed flatten helper. |
pkg/zkc/compiler/incremental_compiler.go |
Defaults incremental compiler field. |
pkg/zkc/compiler/parser/parser.go |
Fixes error propagation and comment spelling. |
pkg/test/zkc_bench_test.go |
Wires Poseidon benchmark tests. |
pkg/test/zkc_unit_test.go |
Wires felt memory unit tests. |
testdata/zkc/unit/*felt_memory* |
Adds felt memory/static table test cases. |
testdata/zkc/bench/poseidon/** |
Adds Poseidon implementations, constants, docs, and test fixtures. |
pkg/corset/**, pkg/ir/**, pkg/zkc/vm/**, pkg/asm/** |
Applies flattern → flatten spelling/identifier cleanup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| case *expr.Cast[symbol.Resolved]: | ||
| return p.Eval(e.Expr, definition) |
d61d2e9 to
f7a9222
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit faba60a. Configure here.
8261f8b to
a11a4fa
Compare
DavePearce
left a comment
There was a problem hiding this comment.
Ok, there are some problems here. We do not want 70 odd files for a single benchmark!! You need to tidy this up and remove all of the various debugging / test harness stuff. I want these files only:
testdata/zkc/benchmark/poseidon_felt.zkc <-- contains complete benchmark for felt
testdata/zkc/benchmark/poseidon_felt.accepts
testdata/zkc/benchmark/poseidon_u32.zkc. <-- contains complete benchmark for u32
testdata/zkc/benchmark/poseidon_u32.accepts
The fact that a README.md is needed to explain what is going on tells me that something is seriously off.
Poseidon of - range(k) with k = 7, 16, 256 - [0]*k, with k = 1, 16, 256 more tests (65k u32 and 65k felt) added large test (262k felt and u32 Poseidon) Signed-off-by: DavePearce <dave01001110@gmail.com>
a11a4fa to
c35200f
Compare

Note
Medium Risk
Compiler and constant-evaluation changes for 𝔽 casts and memory layout affect correctness of generated code; the large Poseidon surface is mostly testdata but increases CI runtime and maintenance burden.
Overview
Adds a Poseidon sponge hash in ZKC (Koalabear, width 16) with parallel u32 and native 𝔽 implementations, static MDS/round constants, and extensive bench/unit/invalid coverage under
testdata/zkc/bench/poseidon/.Strengthens field-element handling: casts and constants are checked against the field modulus in typing and constant evaluation; memory codegen uses native registers for
𝔽data lines;IncrementalCompilerdefaults toKOALABEAR_16; tests gainKOALABEAR_CONFIGplus felt memory/casting and overflow invalid cases.Renames
Flattern→Flattenacross Corset source maps, ZKC types/codegen/lowering, and IR term simplifiers (mechanical API spelling fix). Small codegen/parser fixes (e.g. unwritable memory panic text, function AST comment).Reviewed by Cursor Bugbot for commit 24b460a. Bugbot is set up for automated code reviews on this repo. Configure here.