-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add external range checker interface * feat: add optional FrontendType method to the builders In range checking gadget we try to estimate the number of constraints given different parameters. But for estimating we need to know the costs of operations. And the costs of the operations depend on the way we arithmetize the circuit. Added an internal interface which allows to query the arithmetization method and implement this in existing builders. * feat: implement range checking * feat: use range checking in field emulation * test: update circuit statistics * test: update stats * test: update stats
- Loading branch information
Showing
13 changed files
with
399 additions
and
50 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Package frontendtype allows to assert frontend type. | ||
package frontendtype | ||
|
||
type Type int | ||
|
||
const ( | ||
R1CS Type = iota | ||
SCS | ||
) | ||
|
||
type FrontendTyper interface { | ||
FrontendType() Type | ||
} |
Binary file not shown.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Package rangecheck implements range checking gadget | ||
// | ||
// This package chooses the most optimal path for performing range checks: | ||
// - if the backend supports native range checking and the frontend exports the variables in the proprietary format by implementing [frontend.Rangechecker], then use it directly; | ||
// - if the backend supports creating a commitment of variables by implementing [frontend.Committer], then we use the product argument as in [BCG+18]. [r1cs.NewBuilder] returns a builder which implements this interface; | ||
// - lacking these, we perform binary decomposition of variable into bits. | ||
// | ||
// [BCG+18]: https://eprint.iacr.org/2018/380 | ||
package rangecheck | ||
|
||
import ( | ||
"github.com/consensys/gnark/frontend" | ||
"github.com/consensys/gnark/frontend/cs/r1cs" | ||
) | ||
|
||
// only for documentation purposes. If we import the package then godoc knows | ||
// how to refer to package r1cs and we get nice links in godoc. We import the | ||
// package anyway in test. | ||
var _ = r1cs.NewBuilder | ||
|
||
// New returns a new range checker depending on the frontend capabilities. | ||
func New(api frontend.API) frontend.Rangechecker { | ||
if rc, ok := api.(frontend.Rangechecker); ok { | ||
return rc | ||
} | ||
if _, ok := api.(frontend.Committer); ok { | ||
return newCommitRangechecker(api) | ||
} | ||
return plainChecker{api: api} | ||
} |
Oops, something went wrong.