Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds a constraint counter api #176

Merged
merged 7 commits into from
Nov 18, 2021
Merged

Conversation

gbotrel
Copy link
Collaborator

@gbotrel gbotrel commented Nov 16, 2021

Usage, inside a circuit:

	start := api.Tag("start_mulfp2")

	l1 := api.Add(e1.A0, e1.A1)
	l2 := api.Add(e2.A0, e2.A1)
	// ... etc

	end := api.Tag("end_mulfp2")
	api.AddCounter(start, end)

Then access through CompiledConstraintSystem with

ccs, _ := frontend.Compile(...)
counters := ccs.GetCounters()

// in a test file
assert.SolvingSucceeded(&circuit, &witness, test.WithCurves(ecc.BW6_761))
counters := assert.GetCounters(&circuit)

for _, c := range counters {
t.Log(c)
}

Counter struct:

// Counter contains measurements of useful statistics between two Tag
type Counter struct {
	From, To      string
	NbVariables   int
	NbConstraints int
	CurveID       ecc.ID
	BackendID     backend.ID
}

displays as:

groth16[bn254] start[g1.go:210] - end[g1.go:220]: 2277 variables, 2508 constraints

Notes:

  • measurement for PlonK is contextual, since linear expression reduction may use previously reduced expression (ie measuring two repeating piece of circuit may yield a smaller number of constraint the second time)
  • api naming is not definitive

Also, first steps for #174

@gbotrel gbotrel requested a review from ivokub November 17, 2021 19:58
@gbotrel gbotrel marked this pull request as draft November 17, 2021 22:18
@gbotrel gbotrel marked this pull request as ready for review November 18, 2021 04:14
@gbotrel
Copy link
Collaborator Author

gbotrel commented Nov 18, 2021

  • need a better way to identify Counter objects. From / To will (currently) include line number, bad idea if we want to compare counters across branches for non-regression for example.
  • figure out feature-wise, if maybe we want to have a default counter (englobing the whole circuit). What other stats we want to put in there. If we want to make that available only with a build tag.

@gbotrel gbotrel merged commit 0652866 into develop Nov 18, 2021
@gbotrel gbotrel deleted the feat-constraint-counter branch November 18, 2021 16:31
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.

1 participant