gnark-plonky2-verifier/sha512/binsum_test.go
sha512/binsum_test.goRaw
1package sha512
2
3import (
4 "testing"
5 "fmt"
6
7 "github.com/consensys/gnark-crypto/ecc"
8 "github.com/consensys/gnark/frontend"
9 "github.com/consensys/gnark/test"
10 // "github.com/ethereum/go-ethereum/crypto/secp256k1"
11)
12
13type BinsumTest struct {
14 A []frontend.Variable
15 B []frontend.Variable
16 C []frontend.Variable
17}
18
19func (c *BinsumTest) Define(api frontend.API) error {
20 sum := BinSum(api, c.A, c.B)
21 for i := 0; i < len(sum) || i < len(c.C); i++ {
22 fmt.Println(i, c.C)
23 if i < len(sum) && i < len(c.C) {
24 api.Println(sum[i])
25 api.AssertIsEqual(sum[i], c.C[i])
26 } else if i < len(sum) {
27 api.AssertIsEqual(sum[i], 0)
28 } else {
29 fmt.Println(i, c.C[i])
30 api.AssertIsEqual(c.C[i], 0)
31 }
32 }
33 return nil
34}
35
36func TestBinsum(t *testing.T) {
37 assert := test.NewAssert(t)
38 circuit := BinsumTest{
39 A: []frontend.Variable{0, 0, 0},
40 B: []frontend.Variable{0, 0, 0},
41 C: []frontend.Variable{0, 0, 0, 0},
42 }
43 witness := BinsumTest{
44 A: []frontend.Variable{1, 0, 1},
45 B: []frontend.Variable{1, 1, 1},
46 C: []frontend.Variable{0, 0, 1, 1},
47 }
48 err := test.IsSolved(&circuit, &witness, testCurve.ScalarField())
49 assert.NoError(err)
50}
51
52var testCurve = ecc.BN254