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

test: add test/solver_test.go #329

Merged
merged 26 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8e789a7
build: update to latest gnark-crypto
gbotrel May 26, 2022
f823f8a
refactor: frontend.Compile(ecc.ID) -> frontend.Compile(field.Field)
gbotrel Jun 1, 2022
74dce97
refactor: field.Field -> *big.Int
gbotrel Jun 3, 2022
3ad1821
build: update to latest gnark-crypto
gbotrel Jun 3, 2022
e491b94
feat: added internal/tinyfield
gbotrel Jun 3, 2022
5da5c19
refactor: NewWitness(ecc.ID) -> NewWitness(field big.Int)
gbotrel Jun 6, 2022
f7f8b7c
feat: build R1CS with tinyfield
gbotrel Jun 6, 2022
f594b31
Merge branch 'develop' into test/fuzz_small_field
gbotrel Jun 6, 2022
473d2e9
test: ignore range circuit for tinyfield r1cs serialization
gbotrel Jun 6, 2022
968de4a
refactor: hint now takes *big.Int scalar field instead of curveID
gbotrel Jun 6, 2022
a9651df
refactor: remove Backend() in Builder / Api interfaces
gbotrel Jun 6, 2022
c0bfbfb
feat: added R1CSSolver test against tinyfield
gbotrel Jun 7, 2022
0069c90
refactor: add utils.ByteLen(*big.Int) method
gbotrel Jun 7, 2022
8e49d8f
feat: SetScalarField returns error with unsupported modulus
gbotrel Jun 7, 2022
564d77a
feat: added Compiler.FieldBitLen()
gbotrel Jun 7, 2022
c588a08
style: clean code generator
gbotrel Jun 7, 2022
ae2e777
Merge branch 'test/fuzz_small_field' into test/fuzz_small
gbotrel Jun 7, 2022
8cc8573
refactor: get rid of Curve() API
gbotrel Jun 7, 2022
f7f9cf6
refactor: remove more curve dependencies in frontend
gbotrel Jun 7, 2022
273d14e
fix: remove solver_test from previous commit
gbotrel Jun 7, 2022
88783fb
test: added test/solver_test.go
gbotrel Jun 7, 2022
ea6ab85
Merge branch 'develop' into test/fuzz_small_field
gbotrel Jun 7, 2022
d1eaf9b
style: code cleaning
gbotrel Jun 8, 2022
f5009cd
test: modify internal/circuits/range_constant bound
gbotrel Jun 8, 2022
58ff4b4
fix: scs.Xor didn't boolean constraint inputs
gbotrel Jun 8, 2022
2d89de3
fix,test: restore witness between test engine runs
gbotrel Jun 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions frontend/cs/scs/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,16 @@ func (system *scs) FromBinary(b ...frontend.Variable) frontend.Variable {
// Xor returns a ^ b
// a and b must be 0 or 1
func (system *scs) Xor(a, b frontend.Variable) frontend.Variable {
system.AssertIsBoolean(a)
system.AssertIsBoolean(b)
_a, aConstant := system.ConstantValue(a)
_b, bConstant := system.ConstantValue(b)

if aConstant && bConstant {
_a.Xor(_a, _b)
return _a
}

res := system.newInternalVariable()
if aConstant {
a, b = b, a
Expand All @@ -224,6 +227,10 @@ func (system *scs) Xor(a, b frontend.Variable) frontend.Variable {
// Or returns a | b
// a and b must be 0 or 1
func (system *scs) Or(a, b frontend.Variable) frontend.Variable {

system.AssertIsBoolean(a)
system.AssertIsBoolean(b)

_a, aConstant := system.ConstantValue(a)
_b, bConstant := system.ConstantValue(b)

Expand All @@ -241,11 +248,6 @@ func (system *scs) Or(a, b frontend.Variable) frontend.Variable {
l := a.(compiled.Term)
r := l

if !(_b.IsUint64() && (_b.Uint64() <= 1)) {
panic(fmt.Sprintf("%s should be 0 or 1", _b.String()))
}
system.AssertIsBoolean(a)

one := big.NewInt(1)
_b.Sub(_b, one)
idl := system.st.CoeffID(_b)
Expand All @@ -254,8 +256,6 @@ func (system *scs) Or(a, b frontend.Variable) frontend.Variable {
}
l := a.(compiled.Term)
r := b.(compiled.Term)
system.AssertIsBoolean(l)
system.AssertIsBoolean(r)
system.addPlonkConstraint(l, r, res, compiled.CoeffIdMinusOne, compiled.CoeffIdMinusOne, compiled.CoeffIdOne, compiled.CoeffIdOne, compiled.CoeffIdOne, compiled.CoeffIdZero)
return res
}
Expand Down
2 changes: 1 addition & 1 deletion internal/backend/bls12-377/cs/r1cs_sparse.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/backend/bls12-381/cs/r1cs_sparse.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/backend/bls24-315/cs/r1cs_sparse.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/backend/bn254/cs/r1cs_sparse.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/backend/bw6-633/cs/r1cs_sparse.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/backend/bw6-761/cs/r1cs_sparse.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions internal/backend/circuits/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/consensys/gnark/frontend"
)

const bound = 161
const bound = 44

type rangeCheckConstantCircuit struct {
X frontend.Variable
Expand All @@ -24,8 +24,8 @@ func (circuit *rangeCheckConstantCircuit) Define(api frontend.API) error {
func rangeCheckConstant() {
var circuit, good, bad rangeCheckConstantCircuit

good.X = (10)
good.Y = (4)
good.X = (4)
good.Y = (2)

bad.X = (11)
bad.Y = (4)
Expand All @@ -52,8 +52,8 @@ func rangeCheck() {

var circuit, good, bad rangeCheckCircuit

good.X = (10)
good.Y = (4)
good.X = (4)
good.Y = (2)
good.Bound = (bound)

bad.X = (11)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewSparseR1CS(ccs compiled.SparseR1CS, coefficients []big.Int) *SparseR1CS
// witness: contains the input variables
// it returns the full slice of wires
func (cs *SparseR1CS) Solve(witness []fr.Element, opt backend.ProverConfig) ([]fr.Element, error) {
log := logger.Logger().With().Str("curve", cs.CurveID().String()).Int("nbConstraints", len(cs.Constraints)).Str("backend", "plonk").Logger()
log := logger.Logger().With().Int("nbConstraints", len(cs.Constraints)).Str("backend", "plonk").Logger()

// set the slices holding the solution.values and monitoring which variables have been solved
nbVariables := cs.NbInternalVariables + cs.NbSecretVariables + cs.NbPublicVariables
Expand Down
2 changes: 1 addition & 1 deletion internal/tinyfield/cs/r1cs_sparse.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading