Skip to content

Commit

Permalink
refactor: compactify commitment tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tabaie committed Jun 20, 2023
1 parent aa46799 commit 97045ee
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 57 deletions.
2 changes: 1 addition & 1 deletion backend/groth16/bls12-377/setup.go

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

2 changes: 1 addition & 1 deletion backend/groth16/bls12-381/setup.go

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

2 changes: 1 addition & 1 deletion backend/groth16/bls24-315/setup.go

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

2 changes: 1 addition & 1 deletion backend/groth16/bls24-317/setup.go

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

2 changes: 1 addition & 1 deletion backend/groth16/bn254/setup.go

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

2 changes: 1 addition & 1 deletion backend/groth16/bw6-633/setup.go

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

2 changes: 1 addition & 1 deletion backend/groth16/bw6-761/setup.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ func (pk *ProvingKey) NbG2() int {
return 2 + len(pk.G2.B)
}

// bitRerverse permutation as in fft.BitReverse , but with []curve.G1Affine
// bitReverse permutation as in fft.BitReverse , but with []curve.G1Affine
func bitReverse(a []curve.G1Affine) {
n := uint(len(a))
nn := uint(bits.UintSize - bits.TrailingZeros(n))
Expand Down
74 changes: 25 additions & 49 deletions test/commitments_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package test

import (
"github.com/consensys/gnark/backend"
"reflect"
"testing"

Expand All @@ -20,10 +21,6 @@ func (c *noCommitmentCircuit) Define(api frontend.API) error {
return nil
}

func TestNoCommitmentCircuit(t *testing.T) {
testAll(t, &noCommitmentCircuit{1})
}

type commitmentCircuit struct {
Public []frontend.Variable `gnark:",public"`
X []frontend.Variable
Expand All @@ -46,31 +43,6 @@ func (c *commitmentCircuit) Define(api frontend.API) error {
return nil
}

func TestSingleCommitment(t *testing.T) {
assignment := &commitmentCircuit{X: []frontend.Variable{1}, Public: []frontend.Variable{}}
testAll(t, assignment)
}

func TestTwoCommitments(t *testing.T) {
assignment := &commitmentCircuit{X: []frontend.Variable{1, 2}, Public: []frontend.Variable{}}
testAll(t, assignment)
}

func TestFiveCommitments(t *testing.T) {
assignment := &commitmentCircuit{X: []frontend.Variable{1, 2, 3, 4, 5}, Public: []frontend.Variable{}}
testAll(t, assignment)
}

func TestSingleCommitmentSinglePublic(t *testing.T) {
assignment := &commitmentCircuit{X: []frontend.Variable{0}, Public: []frontend.Variable{1}}
testAll(t, assignment)
}

func TestFiveCommitmentsFivePublic(t *testing.T) {
assignment := &commitmentCircuit{X: []frontend.Variable{0, 1, 2, 3, 4}, Public: []frontend.Variable{1, 2, 3, 4, 5}}
testAll(t, assignment)
}

type committedConstantCircuit struct {
X frontend.Variable
}
Expand All @@ -84,10 +56,6 @@ func (c *committedConstantCircuit) Define(api frontend.API) error {
return nil
}

func TestCommittedConstant(t *testing.T) {
testAll(t, &committedConstantCircuit{1})
}

type committedPublicCircuit struct {
X frontend.Variable `gnark:",public"`
}
Expand All @@ -101,10 +69,6 @@ func (c *committedPublicCircuit) Define(api frontend.API) error {
return nil
}

func TestCommittedPublic(t *testing.T) {
testAll(t, &committedPublicCircuit{1})
}

type independentCommitsCircuit struct {
X []frontend.Variable
}
Expand All @@ -121,10 +85,6 @@ func (c *independentCommitsCircuit) Define(api frontend.API) error {
return nil
}

func TestTwoIndependentCommits(t *testing.T) {
testAll(t, &independentCommitsCircuit{X: []frontend.Variable{1, 1}})
}

type twoCommitCircuit struct {
X []frontend.Variable
Y frontend.Variable
Expand All @@ -143,10 +103,6 @@ func (c *twoCommitCircuit) Define(api frontend.API) error {
return nil
}

func TestTwoCommit(t *testing.T) {
testAll(t, &twoCommitCircuit{X: []frontend.Variable{1, 2}, Y: 3})
}

type doubleCommitCircuit struct {
X, Y frontend.Variable
}
Expand All @@ -164,10 +120,6 @@ func (c *doubleCommitCircuit) Define(api frontend.API) error {
return nil
}

func TestDoubleCommit(t *testing.T) {
testAll(t, &doubleCommitCircuit{X: 1, Y: 2})
}

func TestHollow(t *testing.T) {

run := func(c, expected frontend.Circuit) func(t *testing.T) {
Expand Down Expand Up @@ -222,3 +174,27 @@ func TestCommitUniquenessZerosScs(t *testing.T) { // TODO @Tabaie Randomize Grot
_, err = ccs.Solve(w)
assert.NoError(t, err)
}

var commitmentTestCircuits []frontend.Circuit

func init() {
commitmentTestCircuits = []frontend.Circuit{
&noCommitmentCircuit{1},
&commitmentCircuit{X: []frontend.Variable{1}, Public: []frontend.Variable{}}, // single commitment
&commitmentCircuit{X: []frontend.Variable{1, 2}, Public: []frontend.Variable{}}, // two commitments
&commitmentCircuit{X: []frontend.Variable{1, 2, 3, 4, 5}, Public: []frontend.Variable{}}, // five commitments
&commitmentCircuit{X: []frontend.Variable{0}, Public: []frontend.Variable{1}}, // single commitment single public
&commitmentCircuit{X: []frontend.Variable{0, 1, 2, 3, 4}, Public: []frontend.Variable{1, 2, 3, 4, 5}}, // five commitments five public
&committedConstantCircuit{1}, // single committed constant
&committedPublicCircuit{1}, // single committed public
&independentCommitsCircuit{X: []frontend.Variable{1, 1}}, // two independent commitments
&twoCommitCircuit{X: []frontend.Variable{1, 2}, Y: 3}, // two commitments, second depending on first
&doubleCommitCircuit{X: 1, Y: 2}, // double committing to the same variable
}
}

func TestCommitment(t *testing.T) {
for _, assignment := range commitmentTestCircuits {
NewAssert(t).ProverSucceeded(hollow(assignment), assignment, WithBackends(backend.GROTH16, backend.PLONK))
}
}

0 comments on commit 97045ee

Please sign in to comment.