-
Notifications
You must be signed in to change notification settings - Fork 5
/
commitment_test.go
61 lines (50 loc) · 1.15 KB
/
commitment_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
package ozcoin
import (
"math/big"
"testing"
)
type rangeSignInput struct {
Amt uint64
Actual uint64
}
var rangeSignInputs = []rangeSignInput{
rangeSignInput{0, 0},
rangeSignInput{1, 1},
rangeSignInput{5000000000, 5000000000},
rangeSignInput{17179869184, 0},
}
func TestRangeCommit(t *testing.T) {
for i, inp := range rangeSignInputs {
r := &big.Int{}
rp := RangeCommit(inp.Amt, r)
// Expected commit
actualBytes := UIntBytes(inp.Actual)
exp := PedersenSum(r.Bytes(), actualBytes)
// Subtract expected from commit
exp.Y.Neg(exp.Y)
exp.X, exp.Y = CURVE.Params().Add(rp.X, rp.Y, exp.X, exp.Y)
// Should be 0's
zero := &big.Int{}
if zero.Cmp(exp.X) != 0 || zero.Cmp(exp.Y) != 0 {
t.Error("Actual commit different from expected commit")
}
// Should always verify
if !rp.Verify() {
t.Error("Range proof", i, " failed to verify unexpectedly")
}
}
}
func BenchmarkRangeCommit(b *testing.B) {
for i := 0; i < b.N; i++ {
r := &big.Int{}
_ = RangeCommit(50, r)
}
}
func BenchmarkRangeCommitVerify(b *testing.B) {
r := &big.Int{}
rp := RangeCommit(50, r)
b.ResetTimer()
for i := 0; i < b.N; i++ {
rp.Verify()
}
}