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