-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
78 lines (69 loc) · 1.94 KB
/
utils_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package chainark
import (
"math/big"
"testing"
"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/std/algebra/emulated/sw_bn254"
"github.com/consensys/gnark/std/math/emulated"
"github.com/consensys/gnark/test"
)
type idTestCircuit struct {
Eles [2]emulated.Element[sw_bn254.ScalarField]
Id LinkageID
Expected frontend.Variable
}
func (c *idTestCircuit) Define(api frontend.API) error {
t := TestIDWitness[sw_bn254.ScalarField](api, c.Id, c.Eles[:], 128)
api.AssertIsEqual(t, c.Expected)
return nil
}
func TestIdVSWitness(t *testing.T) {
limbs1 := [4]uint64{0x012345, 0x6789ab, 0, 0}
limbs2 := [4]uint64{0xaa, 0xbb, 0, 0}
ele1 := emulated.Element[sw_bn254.ScalarField]{
Limbs: []frontend.Variable{
frontend.Variable(limbs1[0]),
frontend.Variable(limbs1[1]),
frontend.Variable(limbs1[2]),
frontend.Variable(limbs1[3]),
},
}
ele2 := emulated.Element[sw_bn254.ScalarField]{
Limbs: []frontend.Variable{
frontend.Variable(limbs2[0]),
frontend.Variable(limbs2[1]),
frontend.Variable(limbs2[2]),
frontend.Variable(limbs2[3]),
},
}
eles := [2]emulated.Element[sw_bn254.ScalarField]{ele1, ele2}
bi1, ok := big.NewInt(0).SetString("6789ab0000000000012345", 16)
if !ok {
panic("bi1")
}
bi2, ok := big.NewInt(0).SetString("bb00000000000000aa", 16)
if !ok {
panic("bi2")
}
id := LinkageID{Vals: []frontend.Variable{frontend.Variable(bi1), frontend.Variable(bi2)}, BitsPerVar: 128}
circuit := &idTestCircuit{
Id: PlaceholderLinkageID(2, 128),
}
assignment := &idTestCircuit{
Eles: eles,
Id: id,
Expected: 1,
}
err := test.IsSolved(circuit, assignment, ecc.BN254.ScalarField())
assert := test.NewAssert(t)
assert.NoError(err)
eles[0].Limbs[1] = frontend.Variable(100)
assignment2 := &idTestCircuit{
Eles: eles,
Id: id,
Expected: 0,
}
err = test.IsSolved(circuit, assignment2, ecc.BN254.ScalarField())
assert.NoError(err)
}