perf: canonicalize internal equality assertions#1776
Draft
1sgtpepper wants to merge 11 commits into
Draft
Conversation
1sgtpepper
marked this pull request as ready for review
June 8, 2026 10:51
1sgtpepper
marked this pull request as draft
July 1, 2026 13:41
1sgtpepper
force-pushed
the
issue-555-internal-equality-aliases
branch
from
July 15, 2026 06:07
f2b9795 to
33cd10f
Compare
1sgtpepper
force-pushed
the
issue-555-internal-equality-aliases
branch
from
July 15, 2026 07:55
b18635c to
affe723
Compare
1sgtpepper
force-pushed
the
issue-555-internal-equality-aliases
branch
from
July 15, 2026 08:23
ddf86fc to
f63a54f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Canonicalize internal-variable equality assertions so equivalent wires share a representative instead of emitting an extra
a - b == 0constraint.This reduces the issue #555 equality-heavy case by removing redundant equality constraints and internal wires where aliasing is valid.
Fixes #555
Type of change
How has this been tested?
api.AssertIsEqual(...)#555 regression coverage.issue555-proof: changed-surface tests and benchmark passed.issue555-full-proof: upstream short test block passed.pull_request/staticcheck:gofmt,goimports, generated-file check, andgolangci-lintpassed.How has this been benchmarked?
go test ./internal/regression_tests/issue555 -run '^$' -bench BenchmarkInternalEqualityCanonicalizationCompile -benchtime=100x -count=3Benchmark result: R1CS and SCS equality-heavy paths match the baseline at
2048 constraints/opand2048 internal_variables/op; aliasing adds one instruction.Checklist:
golangci-lintdoes not output errors locallyNote
High Risk
Changes compile-time constraint generation and post-compile wire rewriting/solving across R1CS and SCS; incorrect alias eligibility could weaken soundness, though extensive regression tests target escape cases.
Overview
R1CS and SCS builders now track safe internal-wire equalities with a union-find
wirealias.Setinstead of always emittinga - b == 0.AssertIsEqualon two pure unit terms callsUnionand skips the constraint when aliasing is allowed; witness/public/secret equalities and wires that escape (hints, commitments, custom instructions,ToCanonicalVariable, etc.) stay explicitly constrained viaMarkNoAlias/MarkInternal.At compile,
applyWireAliasesrewrites constraint calldata to canonical wire IDs and appends aBlueprintWireAliasessolver instruction so eliminated wires copy their representative’s value.System.ApplyWireAliasesrebuilds the instruction tree and resets lookup-hint level caches when aliases change.Constraint layer adds
BlueprintWireAliases, marshaling registration, and tests for serialization, lookup-hint rewrite, and level-cache reset.Tests and stats: issue #555 regression suite, builder/unit tests, and updated Plonk constraint counts in
latest_stats.csvwhere redundant equalities dropped.Reviewed by Cursor Bugbot for commit c458205. Bugbot is set up for automated code reviews on this repo. Configure here.