arnaucube
arnaucube/gnark-plonky2-verifierPublic Self-hosted repository
gnark-plonky2-verifier/sha512/sha_test.go
sha512/sha_test.goRaw
 1package sha512
 2
 3import (
 4	"math/big"
 5	"testing"
 6
 7	"github.com/consensys/gnark/frontend"
 8	"github.com/consensys/gnark/test"
 9)
10
11type Sha512Circuit struct {
12	in []frontend.Variable `gnark:"in"`
13	out []frontend.Variable `gnark:"out"`
14}
15
16func (circuit *Sha512Circuit) Define(api frontend.API) error {
17	res := Sha512(api, circuit.in)
18	for i := 0; i < 512; i++ {
19		api.AssertIsEqual(res[i], circuit.out[i])
20	}
21	return nil
22}
23
24func TestSha512(t *testing.T) {
25	assert := test.NewAssert(t)
26	circuit := OnCurveTest[Ed25519, Ed25519Scalars]{}
27	witness := OnCurveTest[Ed25519, Ed25519Scalars]{
28		P: AffinePoint[Ed25519]{
29			X: emulated.NewElement[Ed25519](newBigInt("216936D3CD6E53FEC0A4E231FDD6DC5C692CC7609525A7B2C9562D608F25D51A")),
30			Y: emulated.NewElement[Ed25519](newBigInt("6666666666666666666666666666666666666666666666666666666666666658")),
31		},
32	}
33	err := test.IsSolved(&circuit, &witness, testCurve.ScalarField())
34	assert.NoError(err)
35}
36
37var testCurve = ecc.BN254