perf: canonicalize internal equality assertions#1776
Open
Kuhai9801 wants to merge 3 commits into
Open
Conversation
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
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
AssertIsEqualbetween two unit-coefficient internal wires can record a union instead of emittinga - b == 0, cutting redundant constraints (issue #555).R1CS and SCS builders track aliases via
wirealias.Set(internal-only unions,MarkNoAliasfor public/secret, hints, commitments, custom instruction outputs). DuringCompile,applyWireAliasescallsSystem.ApplyWireAliasesto rewrite constraint/hint calldata to canonical wire IDs, rebuild instruction levels, reset lookup-hint level caches, and append aBlueprintWireAliasessolver 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.