-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrangeproof_test.go
64 lines (56 loc) · 1.81 KB
/
rangeproof_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
package zksigma
import (
"crypto/rand"
"math/big"
"testing"
)
// Copy-pasted from original apl implementation by Willy (github.com/wrv)
func TestRangeProver_Verify(t *testing.T) {
value, _ := rand.Int(rand.Reader, big.NewInt(1099511627775))
proof, rp, err := NewRangeProof(TestCurve, value)
if err != nil {
t.Fatalf("TestRangeProver_Verify failed to generate proof\n")
}
comm := PedCommitR(TestCurve, value, rp)
if !comm.Equal(proof.ProofAggregate) {
t.Error("Error computing the randomnesses used -- commitments did not check out when supposed to")
} else {
ok, err := proof.Verify(TestCurve, comm)
if !ok {
t.Errorf("** Range proof failed: %s", err)
} else {
}
}
}
func TestRangeProverSerialization(t *testing.T) {
value, _ := rand.Int(rand.Reader, big.NewInt(1099511627775))
proof, rp, err := NewRangeProof(TestCurve, value)
if err != nil {
t.Fatalf("TestRangeProverSerialization failed to generate proof\n")
}
proof, err = NewRangeProofFromBytes(proof.Bytes())
if err != nil {
t.Fatalf("TestRangeProverSerialization failed to deserialize\n")
}
comm := PedCommitR(TestCurve, value, rp)
if !comm.Equal(proof.ProofAggregate) {
t.Error("Error computing the randomnesses used -- commitments did not check out when supposed to")
} else {
ok, err := proof.Verify(TestCurve, comm)
if !ok {
t.Errorf("** Range proof failed: %s", err)
} else {
}
}
}
func TestOutOfRangeRangeProver_Verify(t *testing.T) {
min := new(big.Int).Exp(new(big.Int).SetInt64(2), new(big.Int).SetInt64(64), nil)
value, err := rand.Int(rand.Reader, new(big.Int).Add(new(big.Int).Sub(TestCurve.C.Params().N, min), min)) // want to make sure it's out of range
if err != nil {
t.Error(err)
}
_, _, err = NewRangeProof(TestCurve, value)
if err == nil {
t.Error("Computing the range proof shouldn't work but it did")
}
}