Skip to content

perf: canonicalize internal equality assertions#1776

Draft
1sgtpepper wants to merge 11 commits into
Consensys:masterfrom
1sgtpepper:issue-555-internal-equality-aliases
Draft

perf: canonicalize internal equality assertions#1776
1sgtpepper wants to merge 11 commits into
Consensys:masterfrom
1sgtpepper:issue-555-internal-equality-aliases

Conversation

@1sgtpepper

@1sgtpepper 1sgtpepper commented Jun 8, 2026

Copy link
Copy Markdown

Description

Canonicalize internal-variable equality assertions so equivalent wires share a representative instead of emitting an extra a - b == 0 constraint.

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

  • Optimization / performance improvement

How has this been tested?

  • Added unit, frontend builder, and issue reduce constraint generated with api.AssertIsEqual(...) #555 regression coverage.
  • Refreshed affected stats fixtures.
  • Fork Actions issue555-proof: changed-surface tests and benchmark passed.
  • Fork Actions issue555-full-proof: upstream short test block passed.
  • Fork Actions pull_request/staticcheck: gofmt, goimports, generated-file check, and golangci-lint passed.

How has this been benchmarked?

  • go test ./internal/regression_tests/issue555 -run '^$' -bench BenchmarkInternalEqualityCanonicalizationCompile -benchtime=100x -count=3

Benchmark result: R1CS and SCS equality-heavy paths match the baseline at 2048 constraints/op and 2048 internal_variables/op; aliasing adds one instruction.

Checklist:

  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or that my feature works
  • I did not modify files generated from templates
  • golangci-lint does not output errors locally
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Note

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.Set instead of always emitting a - b == 0. AssertIsEqual on two pure unit terms calls Union and skips the constraint when aliasing is allowed; witness/public/secret equalities and wires that escape (hints, commitments, custom instructions, ToCanonicalVariable, etc.) stay explicitly constrained via MarkNoAlias / MarkInternal.

At compile, applyWireAliases rewrites constraint calldata to canonical wire IDs and appends a BlueprintWireAliases solver instruction so eliminated wires copy their representative’s value. System.ApplyWireAliases rebuilds 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.csv where redundant equalities dropped.

Reviewed by Cursor Bugbot for commit c458205. Bugbot is set up for automated code reviews on this repo. Configure here.

@1sgtpepper
1sgtpepper marked this pull request as ready for review June 8, 2026 10:51
@1sgtpepper
1sgtpepper marked this pull request as draft July 1, 2026 13:41
@1sgtpepper
1sgtpepper force-pushed the issue-555-internal-equality-aliases branch from f2b9795 to 33cd10f Compare July 15, 2026 06:07
@1sgtpepper
1sgtpepper force-pushed the issue-555-internal-equality-aliases branch from b18635c to affe723 Compare July 15, 2026 07:55
@1sgtpepper
1sgtpepper force-pushed the issue-555-internal-equality-aliases branch from ddf86fc to f63a54f Compare July 15, 2026 08:23
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.

reduce constraint generated with api.AssertIsEqual(...)

1 participant