Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
295 commits
Select commit Hold shift + click to select a range
1894cfa
feat: gkrmimc for sbox degree 5
Tabaie Jun 9, 2025
241d645
mimc length 1 works
Tabaie Jun 10, 2025
bb36459
fix final layer
Tabaie Jun 10, 2025
311d9d9
chore generify Println changes
Tabaie Jun 10, 2025
b3d1af8
fix: use multicommitter
Tabaie Jun 10, 2025
815adc7
feat: use kvstore for caching instances
Tabaie Jun 10, 2025
85d6aaa
Merge branch 'feat/gkr/add-instance' into feat/gkr/hashes
Tabaie Jun 10, 2025
7ab8702
feat: merkledamgard hasher as statestorer
Tabaie Jun 11, 2025
2fb7daa
test: SetState
Tabaie Jun 11, 2025
de55a27
feat: mimc.New to return StateStorer
Tabaie Jun 11, 2025
31a0a59
fix: single instance and no instance edge cases
Tabaie Jun 11, 2025
bb0eca0
Merge branch 'feat/gkr/add-instance' into feat/gkr/hashes
Tabaie Jun 11, 2025
db56157
fix: single-instance, circuit with depth
Tabaie Jun 11, 2025
7e4b954
Merge branch 'feat/gkr/add-instance' into feat/gkr/hashes
Tabaie Jun 11, 2025
b4544d6
Merge branch 'master' into feat/gkr/add-instance
Tabaie Jun 15, 2025
bdd01fd
Merge branch 'master' into feat/gkr/add-instance
Tabaie Jun 23, 2025
c170695
Merge branch 'master' into feat/gkr/add-instance
Tabaie Jul 2, 2025
70802ea
Merge branch 'master' into feat/gkr/add-instance
Tabaie Jul 7, 2025
4ca453c
docs: address cursor comments
Tabaie Jul 8, 2025
f2b1122
Merge branch 'master' into feat/gkr/add-instance
Tabaie Jul 9, 2025
b9c01be
Merge branch 'master' into feat/gkr/add-instance
Tabaie Jul 28, 2025
8e92d99
Merge branch 'feat/gkr/add-instance' into feat/gkr/hashes
Tabaie Jul 28, 2025
893ba91
Merge branch 'master' into feat/gkr/add-instance
Tabaie Aug 6, 2025
a13ac27
Merge branch 'master' into feat/gkr/add-instance
Tabaie Aug 19, 2025
8947d9f
refactor: remove MapRange
Tabaie Aug 19, 2025
4a09fd1
Merge branch 'master' into feat/gkr/add-instance
Tabaie Aug 28, 2025
929d732
Merge branch 'master' into feat/gkr/add-instance
Tabaie Sep 17, 2025
3ec0778
Merge branch 'feat/gkr/add-instance' into feat/gkr/hashes
Tabaie Sep 17, 2025
8c37435
fix: bad merge
Tabaie Sep 17, 2025
1e20850
perf: single-elem pool for bls12-377
Tabaie Sep 17, 2025
4c69b65
build: generify changes
Tabaie Sep 17, 2025
b12c0ee
fix: api pointer receiver
Tabaie Sep 17, 2025
e6a64bc
bench: gkr mimc permutations
Tabaie Sep 17, 2025
d55dbf4
bench: gkr-mimc permutations
Tabaie Sep 17, 2025
b26f33c
Merge branch 'feat/gkr/hashes' into perf/mem/gkr
Tabaie Sep 17, 2025
466f16b
refactor: remove loadCs
Tabaie Sep 17, 2025
57e95bc
perf: reset api in gkr solver
Tabaie Sep 17, 2025
6755e03
build: generify api reset
Tabaie Sep 17, 2025
b1de735
`hashTree` -> `merkleTree`
Tabaie Sep 17, 2025
6c4c5c6
docs: copilot-inspired explanation for `freeElements`
Tabaie Sep 17, 2025
8d0b353
perf: more pool freeing
Tabaie Sep 17, 2025
5a048b6
perf: dedicated exp function
Tabaie Sep 22, 2025
c6b830c
build: generify exp changes
Tabaie Sep 22, 2025
7bb78e7
fix: test for all curves
Tabaie Sep 22, 2025
58a0fdb
perf: fastpath for ^17
Tabaie Sep 22, 2025
4b2c102
fix: exp
Tabaie Sep 22, 2025
30c39b4
fix: exp. really
Tabaie Sep 22, 2025
6c7a7fc
test: modernize benchmark
Tabaie Sep 22, 2025
266c5f6
Revert "build: generify exp changes"
Tabaie Sep 22, 2025
5dd1d61
revert: exp func
Tabaie Sep 22, 2025
1374bab
refactor: modulus name
Tabaie Sep 22, 2025
9959f8a
revert: remove FrontendApiWrapper
Tabaie Sep 22, 2025
271cff9
perf: dedicated exp17 func
Tabaie Sep 23, 2025
1519d52
perf: SumExp17
Tabaie Sep 24, 2025
2e3be9f
perf: cache key as fr.Element
Tabaie Sep 24, 2025
a05f8d6
build: generify
Tabaie Sep 24, 2025
f6613ce
perf: store keys as fr.Elements instead of big.Int
Tabaie Sep 30, 2025
d7eec96
Merge branch 'master' into feat/gkr/hashes
Tabaie Jan 7, 2026
610d49c
fix: match api changes
Tabaie Jan 7, 2026
8549a0b
fix: api use
Tabaie Jan 7, 2026
8bcce8f
remove engine_hints
Tabaie Jan 7, 2026
a045f11
revert change to engine.go
Tabaie Jan 7, 2026
9c35fd7
fix: mimc tests
Tabaie Jan 7, 2026
dd4e36a
fix: error message
Tabaie Jan 7, 2026
f2d2c2f
Merge branch 'master' into feat/gkr/hashes
Tabaie Jan 8, 2026
560e80e
fix: error on empty list
Tabaie Jan 8, 2026
bc1750c
Merge branch 'master' into feat/gkr/hashes
Tabaie Jan 9, 2026
543905e
Merge branch 'feat/gkr/hashes' into perf/mem/gkr-exp17
Tabaie Jan 9, 2026
c80eff5
revert: api in the solve hint
Tabaie Jan 11, 2026
17f7285
feat: first pass at compiled gates
Tabaie Jan 12, 2026
c4b73d0
refactor: clean up gate compilation
Tabaie Jan 12, 2026
5e9239e
fix: gkr.go and gkr_testing.go for bn254
Tabaie Jan 12, 2026
82aad28
build: generify gate_testing
Tabaie Jan 12, 2026
2a854dc
build: generify changes to gkr.go
Tabaie Jan 12, 2026
c11be57
Merge branch 'master' into feat/gkr/compiled-gates
Tabaie Jan 12, 2026
9830c6b
fix: gate registry
Tabaie Jan 13, 2026
c1b4062
revert: bring back Evaluate
Tabaie Jan 13, 2026
c70ae4d
fix: gkr_test
Tabaie Jan 13, 2026
d7f365c
feat: circuit evaluator pool in Solve Hint
Tabaie Jan 13, 2026
f0668e5
fix: not reading variables bug
Tabaie Jan 13, 2026
fd88aed
fix: Complete() bug
Tabaie Jan 13, 2026
8548102
fix: startup frame size
Tabaie Jan 13, 2026
53e6e8e
fix: error on empty gates
Tabaie Jan 13, 2026
1b961f5
perf: take executors outside
Tabaie Jan 13, 2026
a38d67b
fix: don't copy async things
Tabaie Jan 13, 2026
2aa3720
perf: gate evaluator pools
Tabaie Jan 14, 2026
3801200
build: generify
Tabaie Jan 14, 2026
40d43c5
perf: use switch instead of func ptr
Tabaie Jan 14, 2026
bbc0b59
build: generify and get rid of Println
Tabaie Jan 14, 2026
c8b3da3
fix: AI feedback
Tabaie Jan 14, 2026
1651b4f
minor cleanups
Tabaie Jan 14, 2026
a2fa8b3
fix: AI suggestions
Tabaie Jan 14, 2026
0fadf54
Merge branch 'master' into feat/gkr/compiled-gates
Tabaie Jan 16, 2026
6857066
bench: merkle tree
Tabaie Jan 16, 2026
c6de241
perf: universal gate evaluators
Tabaie Jan 21, 2026
b2e17d0
bench: modernize the gkr mimc benchmark
Tabaie Jan 21, 2026
7bd8382
revert: universal gates
Tabaie Jan 21, 2026
4f28b07
Merge branch 'master' into feat/gkr/compiled-gates
Tabaie Jan 21, 2026
d31afd6
Merge branch 'master' into feat/gkr/compiled-gates
Tabaie Jan 21, 2026
e3ea981
Merge branch 'master' into feat/gkr/compiled-gates
Tabaie Jan 21, 2026
ae8f5e1
feat: blueprint for bn254
Tabaie Jan 22, 2026
7d86c47
build: generify
Tabaie Jan 23, 2026
f74a6cb
refactor: remove unnecessary size parameters from instruction input
Tabaie Jan 23, 2026
0bc2b79
fix: runtime pool initialization
Tabaie Jan 23, 2026
487cf7d
fix: montgomery conversion
Tabaie Jan 23, 2026
66e3d1f
fix: make metadata private
Tabaie Jan 23, 2026
a2dae18
fix: solve blueprint
Tabaie Jan 23, 2026
b449e1c
feat: get value blueprint
Tabaie Jan 23, 2026
9aaa533
fix: interface issues
Tabaie Jan 23, 2026
52007aa
feat: blueprints for all curves
Tabaie Jan 23, 2026
04e502b
refactor: generify circuit types
Tabaie Jan 23, 2026
60a167b
chore: some cleanup
Tabaie Jan 23, 2026
73d6d92
fix: json friendly circuit type
Tabaie Jan 23, 2026
e075fcc
fix: small things
Tabaie Jan 23, 2026
bdb7b7d
fix: test compile
Tabaie Jan 23, 2026
d621873
fix: add identity gates to test inputs
Tabaie Jan 23, 2026
9593052
fix: initialize blueprint
Tabaie Jan 23, 2026
33d6692
fix: panic with test engine
Tabaie Jan 23, 2026
5c33812
fix: circuit outs
Tabaie Jan 23, 2026
3ec214e
Merge branch 'master' into refactor/gkr/blueprints
Tabaie Jan 30, 2026
f68fae7
style: formatting
Tabaie Jan 30, 2026
c85d576
fix: remove re-added test engine funcs
Tabaie Jan 30, 2026
0c6dd9c
Revert "fix: remove re-added test engine funcs"
Tabaie Jan 30, 2026
ae408dc
revert: reinstate GetBlueprint mechanism
Tabaie Jan 30, 2026
837ca48
Merge branch 'master' into refactor/gkr/blueprints
Tabaie Feb 6, 2026
67edcf6
fix: calldata prepended by its own size
Tabaie Feb 6, 2026
65539ce
feat: first attempt at mismatch function
Tabaie Feb 8, 2026
2dd4d25
fix: Solve blueprint nondeterminism for bn254
Tabaie Feb 8, 2026
96edfaf
build: generify
Tabaie Feb 8, 2026
fa8c6c6
fix: codegen
Tabaie Feb 8, 2026
1945d67
fix: Prove dependence on Solve
Tabaie Feb 8, 2026
59ea748
remove unused field
Tabaie Feb 8, 2026
5aa15d5
fix: padding issues
Tabaie Feb 8, 2026
3fdb62a
fix: solving race condition
Tabaie Feb 8, 2026
efae0d7
refactor: proof.Flatten
Tabaie Feb 9, 2026
3f3dcf0
refactor: proof iterator
Tabaie Feb 9, 2026
761a6ee
fix: early termination bug
Tabaie Feb 9, 2026
4375623
refactor: use Reset to initialize
Tabaie Feb 9, 2026
5fc5a48
build: generify
Tabaie Feb 9, 2026
db9b2da
fix: Test engine to run reset
Tabaie Feb 10, 2026
d235209
Merge branch 'master' into refactor/gkr/blueprints
Tabaie Feb 11, 2026
14b592b
fix: remove decommissioned curves
Tabaie Feb 11, 2026
339668e
fix: remove newWitness out of bench loop
Tabaie Feb 11, 2026
d892646
remove unused field
Tabaie Feb 11, 2026
207b16f
refactor: stub API changes
Tabaie Feb 11, 2026
c7629d6
refactor: move gate registry to API
Tabaie Feb 11, 2026
f77393e
fix minor bugs
Tabaie Feb 11, 2026
2154298
build: generify gate testing changes
Tabaie Feb 11, 2026
7bc6d17
fix static degree detection bug
Tabaie Feb 11, 2026
f38d074
fix compilation
Tabaie Feb 11, 2026
b156730
refactor: serializable circuits for blueprints
Tabaie Feb 11, 2026
f91a9fb
build: generify
Tabaie Feb 11, 2026
9948b29
revert: blueprint to use executable circuit
Tabaie Feb 11, 2026
d3992f7
remove registry test
Tabaie Feb 11, 2026
8f4c207
fix conversion bug
Tabaie Feb 11, 2026
3ef6c99
decriminalize no solvable vars
Tabaie Feb 11, 2026
a0bf975
Merge remote-tracking branch 'origin/refactor/gkr/rm-global-gateregis…
Tabaie Feb 13, 2026
021a1e5
revert reverting blueprints
Tabaie Feb 13, 2026
387cd70
revert: executable -> serializable
Tabaie Feb 13, 2026
2455eff
snapshot: insoluble import cycle
Tabaie Feb 13, 2026
1443d0a
refactor: isAdditive
Tabaie Feb 13, 2026
158bb94
feat: big.Int based gate testing
Tabaie Feb 13, 2026
1412941
remove per curve gate testing
Tabaie Feb 13, 2026
ca19a84
fix: degree detection
Tabaie Feb 13, 2026
ce8b9c2
fix: remove TestIsAdditive in curve package
Tabaie Feb 13, 2026
f445071
build: generify
Tabaie Feb 13, 2026
0eac4e6
build: generify
Tabaie Feb 13, 2026
e1ed95a
feat: toSerializableCircuit for tests
Tabaie Feb 13, 2026
16bc2bb
refactor: remove pointer types
Tabaie Feb 13, 2026
becb46a
fix: gate compilation bug in ToSerializableCircuit
Tabaie Feb 13, 2026
88a5f8c
fix: strange git behavior
Tabaie Feb 13, 2026
a4801df
propagate changes
Tabaie Feb 13, 2026
7cf2786
remove id gates in test circuits
Tabaie Feb 13, 2026
079e61e
fix circuit compilation bug
Tabaie Feb 13, 2026
00b1a9d
fix: bn254 tests pass
Tabaie Feb 13, 2026
108464a
fix strange git behavior
Tabaie Feb 13, 2026
c493a92
build: generify
Tabaie Feb 13, 2026
417e72f
fix: input gate degree
Tabaie Feb 14, 2026
181c537
feat: cache to return both circuits
Tabaie Feb 14, 2026
e8d15e6
all tests pass
Tabaie Feb 14, 2026
b81bad2
Merge branch 'master' into refactor/gkr/no-gatereg
Tabaie Feb 14, 2026
e2a0aa3
remove topological sort
Tabaie Feb 14, 2026
8f44c44
Merge branch 'refactor/gkr/no-gatereg' of https://github.com/Consensy…
Tabaie Feb 14, 2026
b30cab7
minor naming improvements
Tabaie Feb 14, 2026
fa7acf2
simplify gateEvaluator
Tabaie Feb 14, 2026
5233918
build: go generate
Tabaie Feb 14, 2026
138c5fa
remove empty file
Tabaie Feb 14, 2026
de288b1
Merge branch 'refactor/gkr/no-gatereg' of https://github.com/Consensy…
Tabaie Feb 14, 2026
3d8f697
Merge branch 'master' into refactor/gkr/no-gatereg
Tabaie Feb 17, 2026
89aa7d0
Merge branch 'master' into refactor/gkr/no-gatereg
Tabaie Feb 18, 2026
466daa3
Merge branch 'master' into refactor/gkr/no-gatereg
Tabaie Feb 18, 2026
52abacd
refactor: better name for ProofPolyLength
Tabaie Feb 18, 2026
e3cb77b
Merge branch 'refactor/gkr/no-gatereg' of https://github.com/Consensy…
Tabaie Feb 18, 2026
47aa744
refactor: name changes for bn254
Tabaie Feb 18, 2026
64b496f
refactor: name changes in the gadget package
Tabaie Feb 18, 2026
84467fa
build: generify
Tabaie Feb 18, 2026
8a5acff
refactor: remove permutations
Tabaie Feb 18, 2026
a8be3ad
style: remove unnecessary space
Tabaie Feb 18, 2026
c141874
fix: improved error message for "constant" gate
Tabaie Feb 19, 2026
15e8b2a
feat: Can now export intermediate wires as output
Tabaie Feb 19, 2026
f853c3b
Merge branch 'master' into refactor/gkr/no-gatereg
Tabaie Feb 19, 2026
7972627
fix: unused import
Tabaie Feb 19, 2026
1e12091
fix: regen constraint testdata
Tabaie Feb 19, 2026
3bbfa73
fix: address cursor comment: do not modify circuit in backend
Tabaie Feb 20, 2026
08f6c4d
feat: shim for the old gate registry
Tabaie Feb 20, 2026
3617964
fix: commit all changes
Tabaie Feb 20, 2026
2771002
fix: lint errors
Tabaie Feb 20, 2026
a540ffe
test: r1cs roundtrip for gkr
Tabaie Feb 20, 2026
9f6257f
style: concise
Tabaie Feb 20, 2026
16c01a3
fix: blueprint comparison
Tabaie Feb 23, 2026
658cf25
test: U64Only option
Tabaie Feb 23, 2026
b58e0c1
bench: gkrposeidon2
Tabaie Feb 26, 2026
dc47db2
refactor: rawcircuit
Tabaie Feb 26, 2026
64f73f9
feat: basic schedule objects
Tabaie Mar 3, 2026
03ad0f4
refactor: gkrtypes -> gkrcore
Tabaie Mar 3, 2026
30447e5
feat: schedule builder
Tabaie Mar 5, 2026
c1e3be4
feat: functions for level based scheduling
Tabaie Mar 10, 2026
eb3a0b6
refactor: remove use of the fiatshamir package
Tabaie Mar 10, 2026
5e878c7
feat: levels for bn254
Tabaie Mar 10, 2026
6e4a9e5
Merge master into perf/gkr/levels
Tabaie Mar 10, 2026
8d8c282
test: sumcheck
Tabaie Mar 10, 2026
68c7cdd
most tests passing
Tabaie Mar 11, 2026
95aa3d0
non-vector tests pass
Tabaie Mar 11, 2026
e795d2d
build: generify
Tabaie Mar 11, 2026
db27299
mostly fix gadget package
Tabaie Mar 11, 2026
2766c39
feat: claimSource with extra claim index field
Tabaie Mar 13, 2026
3bda3bc
proof size as method
Tabaie Mar 13, 2026
63c141c
refactor: serialization
Tabaie Mar 15, 2026
f65cc96
refactor: extra dimension for outgoingEvalPoints
Tabaie Mar 15, 2026
63af77f
feat: UniqueInputIndices func
Tabaie Mar 16, 2026
955b157
feat: use uniqueInputIndices in the resources struct
Tabaie Mar 16, 2026
b0fc1ec
feat: proveSkipLevel
Tabaie Mar 16, 2026
715176d
feat: verifySkipLevel
Tabaie Mar 16, 2026
3f46589
feat: proveSumcheckLevel
Tabaie Mar 16, 2026
5510550
feat: verifySumcheckLevel
Tabaie Mar 16, 2026
ad463dc
feat: prove/verify
Tabaie Mar 16, 2026
90afede
gkr tests
Tabaie Mar 16, 2026
4e03a98
test: more rigorous
Tabaie Mar 16, 2026
23cf32e
generify for gadget, remove impossible sentinel logic
Tabaie Mar 16, 2026
e634ee1
generification
Tabaie Mar 16, 2026
6a6e88d
fix: verifySkipLevel gadget
Tabaie Mar 16, 2026
7962e41
build generify
Tabaie Mar 16, 2026
f29b7f9
fix: index bug
Tabaie Mar 16, 2026
1bb1f99
serialization changes
Tabaie Mar 16, 2026
8624cc8
fix: Outputs
Tabaie Mar 16, 2026
875d0d9
import hashes in gkr itself
Tabaie Mar 16, 2026
73738ab
Merge branch 'master' into perf/gkr/levels
Tabaie Mar 16, 2026
b730f0d
build: regenerate serialization circuit
Tabaie Mar 16, 2026
c82730d
feat: mandatorily add circuit and schedule hash to initial challenges
Tabaie Mar 16, 2026
3026237
Merge branch 'master' into perf/gkr/levels
Tabaie Mar 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions constraint/gkr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package constraint

type (
// GkrClaimSource identifies an incoming evaluation claim for a wire.
// Level is the level that produced the claim.
// OutgoingClaimIndex selects which of that level's outgoing evaluation points is referenced;
// always 0 for SumcheckLevels, 0..M-1 for SkipLevels with M inherited evaluation points.
// The initial verifier challenge is represented as {Level: len(schedule), OutgoingClaimIndex: 0}.
GkrClaimSource struct {
Level int `json:"level"`
OutgoingClaimIndex int `json:"outgoingClaimIndex"`
}

// GkrClaimGroup represents a set of wires sharing identical claim sources.
// finalEvalProof index = pos(wire, srcLevel) * NbOutgoingEvalPoints(srcLevel) + ClaimSources[claimI].OutgoingClaimIndex,
// where pos(wire, srcLevel) is the wire's position in srcLevel's UniqueGateInputs list.
GkrClaimGroup struct {
Wires []int `json:"wires"`
ClaimSources []GkrClaimSource `json:"claimSources"`
}

// GkrProvingLevel is a single level in the proving schedule.
GkrProvingLevel interface {
NbOutgoingEvalPoints() int
// NbClaims returns the total number of claims at this level.
NbClaims() int
ClaimGroups() []GkrClaimGroup
// FinalEvalProofIndex returns where to find the evaluationPointI'th evaluation claim for the wireI'th input wire to the layer,
// in the layer's final evaluation proof.
FinalEvalProofIndex(wireI, evaluationPointI int) int
}

// GkrSkipLevel represents a level where zerocheck is skipped.
// Claims propagate through at their existing evaluation points.
GkrSkipLevel GkrClaimGroup

// GkrSumcheckLevel represents a level where one or more zerochecks are batched
// together in a single sumcheck. Each GkrClaimGroup within may have different
// claim sources (sumcheck-level batching), or the same source (enabling
// zerocheck-level batching with shared eq tables).
GkrSumcheckLevel []GkrClaimGroup

// GkrProvingSchedule is a sequence of levels defining how to prove a GKR circuit.
GkrProvingSchedule []GkrProvingLevel
)

func (g GkrClaimGroup) NbClaims() int { return len(g.Wires) * len(g.ClaimSources) }

func (l GkrSumcheckLevel) NbOutgoingEvalPoints() int { return 1 }
func (l GkrSumcheckLevel) NbClaims() int {
n := 0
for _, g := range l {
n += len(g.Wires) * len(g.ClaimSources)
}
return n
}
func (l GkrSumcheckLevel) ClaimGroups() []GkrClaimGroup { return l }
func (l GkrSumcheckLevel) FinalEvalProofIndex(wireI, _ int) int { return wireI }

func (l GkrSkipLevel) NbOutgoingEvalPoints() int { return len(l.ClaimSources) }
func (l GkrSkipLevel) NbClaims() int {
return GkrClaimGroup(l).NbClaims()
}
func (l GkrSkipLevel) ClaimGroups() []GkrClaimGroup { return []GkrClaimGroup{GkrClaimGroup(l)} }
func (l GkrSkipLevel) FinalEvalProofIndex(wireI, evaluationPointI int) int {
return wireI*l.NbOutgoingEvalPoints() + evaluationPointI
}

// BindGkrFinalEvalProof binds the non-input-wire entries of finalEvalProof into the transcript.
// Input-wire evaluations are fully determined by the public assignment (and by evaluation points
// already committed to the transcript), so hashing them contributes nothing to Fiat-Shamir security.
// uniqueGateInputs is the deduplicated list of gate-input wire indices for the level in the same
// order as the finalEvalProof entries (i.e. the order returned by UniqueGateInputs).
func BindGkrFinalEvalProof[F any](transcript interface{ Bind(...F) }, finalEvalProof []F, uniqueGateInputs []int, isInput func(wireI int) bool, level GkrProvingLevel) {
for i, inputWireI := range uniqueGateInputs {
if !isInput(inputWireI) {
transcript.Bind(finalEvalProof[level.FinalEvalProofIndex(i, 0):level.FinalEvalProofIndex(i+1, 0)]...)
}
}
}
3 changes: 3 additions & 0 deletions constraint/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ func getTagSet() cbor.TagSet {
addType(reflect.TypeOf(BlueprintBatchInverse[U32]{}))
addType(reflect.TypeOf(BlueprintBatchInverse[U64]{}))

addType(reflect.TypeOf(GkrSkipLevel{}))
addType(reflect.TypeOf(GkrSumcheckLevel{}))

// Add types registered by external packages (e.g., GKR blueprints)
// These use explicit tag numbers to ensure stability regardless of init() order
for _, rt := range registeredBlueprintTypes {
Expand Down
4 changes: 2 additions & 2 deletions constraint/solver/gkrgates/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"runtime"

"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark/internal/gkr/gkrtypes"
"github.com/consensys/gnark/internal/gkr/gkrcore"
"github.com/consensys/gnark/std/gkrapi/gkr"
)

Expand Down Expand Up @@ -119,7 +119,7 @@ func Register(f gkr.GateFunction, nbIn int, options ...RegisterOption) error {
}

for _, curve := range s.curves {
compiled, err := gkrtypes.CompileGateFunction(f, nbIn, curve.ScalarField())
compiled, err := gkrcore.CompileGateFunction(f, nbIn, curve.ScalarField())
if err != nil {
return err
}
Expand Down
55 changes: 32 additions & 23 deletions internal/generator/backend/template/gkr/blueprint.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import (
"github.com/consensys/gnark-crypto/ecc"
"{{ .FieldPackagePath }}"
"{{ .FieldPackagePath }}/polynomial"
fiatshamir "github.com/consensys/gnark-crypto/fiat-shamir"
"github.com/consensys/gnark-crypto/hash"
"github.com/consensys/gnark/constraint"
"github.com/consensys/gnark/internal/gkr/gkrtypes"
"github.com/consensys/gnark/internal/gkr/gkrcore"
)

func init() {
Expand All @@ -27,7 +26,7 @@ type circuitEvaluator struct {
// BlueprintSolve is a {{.FieldID}}-specific blueprint for solving GKR circuit instances.
type BlueprintSolve struct {
// Circuit structure (serialized)
Circuit gkrtypes.SerializableCircuit
Circuit gkrcore.SerializableCircuit
NbInstances uint32

// Not serialized - recreated lazily at solve time
Expand All @@ -41,10 +40,13 @@ type BlueprintSolve struct {

// Ensures BlueprintSolve implements BlueprintStateful
var _ constraint.BlueprintStateful[constraint.U64] = (*BlueprintSolve)(nil)

// Equal returns true if the serialized fields of two BlueprintSolve are equal.
// Used for testing serialization round-trips.
func (b *BlueprintSolve) Equal(other constraint.BlueprintComparable) bool {
if other == nil { return false }
if other == nil {
return false
}
o, ok := other.(*BlueprintSolve)
if !ok {
return false
Expand Down Expand Up @@ -107,7 +109,7 @@ func (b *BlueprintSolve) Solve(s constraint.Solver[constraint.U64], inst constra
if w.IsInput() {
val, delta := s.Read(calldata)
calldata = calldata[delta:]
// Copy directly from constraint.U64 to fr.Element (both in Montgomery form)
// Copy directly from constraint.U64 to {{ .ElementType }} (both in Montgomery form)
copy(b.assignments[wI][instanceI][:], val[:])
} else {
// Get evaluator for this wire from the circuit evaluator
Expand All @@ -123,7 +125,7 @@ func (b *BlueprintSolve) Solve(s constraint.Solver[constraint.U64], inst constra
}
}

// Set output wires (copy fr.Element to U64 in Montgomery form)
// Set output wires (copy {{ .ElementType }} to U64 in Montgomery form)
for outI, outWI := range b.outputWires {
var val constraint.U64
copy(val[:], b.assignments[outWI][instanceI][:])
Expand All @@ -150,9 +152,9 @@ func (b *BlueprintSolve) NbConstraints() int {

// NbOutputs implements Blueprint
func (b *BlueprintSolve) NbOutputs(inst constraint.Instruction) int {
if b.outputWires == nil {
b.outputWires = b.Circuit.Outputs()
}
if b.outputWires == nil {
b.outputWires = b.Circuit.Outputs()
}
return len(b.outputWires)
}

Expand Down Expand Up @@ -194,16 +196,20 @@ func (b *BlueprintSolve) UpdateInstructionTree(inst constraint.Instruction, tree
type BlueprintProve struct {
SolveBlueprintID constraint.BlueprintID
SolveBlueprint *BlueprintSolve `cbor:"-"` // not serialized, set at compile time
Schedule constraint.GkrProvingSchedule
HashName string

lock sync.Mutex
}

// Ensures BlueprintProve implements BlueprintSolvable
var _ constraint.BlueprintSolvable[constraint.U64] = (*BlueprintProve)(nil)

// Equal returns true if the serialized fields of two BlueprintProve are equal.
func (b *BlueprintProve) Equal(other constraint.BlueprintComparable) bool {
if other == nil { return false }
if other == nil {
return false
}
o, ok := other.(*BlueprintProve)
if !ok {
return false
Expand Down Expand Up @@ -243,28 +249,27 @@ func (b *BlueprintProve) Solve(s constraint.Solver[constraint.U64], inst constra
}
}

// Create hasher and write base challenges
hsh := hash.NewHash(b.HashName + "_{{.FieldID}}")

// Read initial challenges from instruction calldata (parse dynamically, no metadata)
// Format: [0]=totalSize, [1...]=challenge linear expressions
insBytes := make([][]byte, 0) // first challenges
calldata := inst.Calldata[1:] // skip size prefix
for len(calldata) != 0 {
val, delta := s.Read(calldata)
calldata = calldata[delta:]

// Copy directly from constraint.U64 to fr.Element (both in Montgomery form)
// Copy directly from constraint.U64 to {{ .ElementType }} (both in Montgomery form)
var challenge {{ .ElementType }}
copy(challenge[:], val[:])
insBytes = append(insBytes, challenge.Marshal())
challengeBytes := challenge.Bytes()
hsh.Write(challengeBytes[:])
}

// Create Fiat-Shamir settings
hsh := hash.NewHash(b.HashName + "_{{.FieldID}}")
fsSettings := fiatshamir.WithHash(hsh, insBytes...)

// Call the {{.FieldID}}-specific Prove function (assignments already WireAssignment type)
proof, err := Prove(solveBlueprint.Circuit, assignments, fsSettings)
proof, err := Prove(solveBlueprint.Circuit, b.Schedule, assignments, hsh)
if err != nil {
return fmt.Errorf("{{toLower .FieldID}} prove failed: %w", err)
return fmt.Errorf("{{.FieldID}} prove failed: %w", err)
}

for i, elem := range proof.flatten() {
Expand Down Expand Up @@ -292,7 +297,7 @@ func (b *BlueprintProve) proofSize() int {
}
nbPaddedInstances := ecc.NextPowerOfTwo(uint64(b.SolveBlueprint.NbInstances))
logNbInstances := bits.TrailingZeros64(nbPaddedInstances)
return b.SolveBlueprint.Circuit.ProofSize(logNbInstances)
return b.SolveBlueprint.Circuit.ProofSize(b.Schedule, logNbInstances)
}

// NbOutputs implements Blueprint
Expand Down Expand Up @@ -344,9 +349,12 @@ type BlueprintGetAssignment struct {

// Ensures BlueprintGetAssignment implements BlueprintSolvable
var _ constraint.BlueprintSolvable[constraint.U64] = (*BlueprintGetAssignment)(nil)

// Equal returns true if the serialized fields of two BlueprintGetAssignment are equal.
func (b *BlueprintGetAssignment) Equal(other constraint.BlueprintComparable) bool {
if other == nil { return false }
if other == nil {
return false
}
o, ok := other.(*BlueprintGetAssignment)
if !ok {
return false
Expand Down Expand Up @@ -418,7 +426,7 @@ func (b *BlueprintGetAssignment) UpdateInstructionTree(inst constraint.Instructi
}

// NewBlueprints creates and registers all GKR blueprints for {{.FieldID}}
func NewBlueprints(circuit gkrtypes.SerializableCircuit, hashName string, compiler constraint.CustomizableSystem) gkrtypes.Blueprints {
func NewBlueprints(circuit gkrcore.SerializableCircuit, schedule constraint.GkrProvingSchedule, hashName string, compiler constraint.CustomizableSystem) gkrcore.Blueprints {
// Create and register solve blueprint
solve := &BlueprintSolve{Circuit: circuit}
solveID := compiler.AddBlueprint(solve)
Expand All @@ -427,6 +435,7 @@ func NewBlueprints(circuit gkrtypes.SerializableCircuit, hashName string, compil
prove := &BlueprintProve{
SolveBlueprintID: solveID,
SolveBlueprint: solve,
Schedule: schedule,
HashName: hashName,
}
proveID := compiler.AddBlueprint(prove)
Expand All @@ -437,7 +446,7 @@ func NewBlueprints(circuit gkrtypes.SerializableCircuit, hashName string, compil
}
getAssignmentID := compiler.AddBlueprint(getAssignment)

return gkrtypes.Blueprints{
return gkrcore.Blueprints{
SolveID: solveID,
Solve: solve,
ProveID: proveID,
Expand Down
Loading
Loading