Skip to content

perf: canonicalize internal equality assertions#1776

Open
Kuhai9801 wants to merge 3 commits into
Consensys:masterfrom
Kuhai9801:issue-555-internal-equality-aliases
Open

perf: canonicalize internal equality assertions#1776
Kuhai9801 wants to merge 3 commits into
Consensys:masterfrom
Kuhai9801:issue-555-internal-equality-aliases

Conversation

@Kuhai9801

@Kuhai9801 Kuhai9801 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

Medium Risk
Touches core compile/solve paths (instruction tree, witness assignment, serialization); safety relies on correct no-alias escapes for hints, commitments, and stored wire IDs.

Overview
Adds internal wire aliasing so AssertIsEqual between two unit-coefficient internal wires can record a union instead of emitting a - b == 0, cutting redundant constraints (issue #555).

R1CS and SCS builders track aliases via wirealias.Set (internal-only unions, MarkNoAlias for public/secret, hints, commitments, custom instruction outputs). During Compile, applyWireAliases calls System.ApplyWireAliases to rewrite constraint/hint calldata to canonical wire IDs, rebuild instruction levels, reset lookup-hint level caches, and append a BlueprintWireAliases solver instruction (no proof constraints) so eliminated wires get witness values from their representative.

Serialization registers the new blueprint type; stats reflect slightly lower Plonk constraint counts on several benchmarks.

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

@Kuhai9801 Kuhai9801 marked this pull request as ready for review June 8, 2026 10:51
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