-
Notifications
You must be signed in to change notification settings - Fork 13
/
poetcore_test.go
111 lines (93 loc) · 2.54 KB
/
poetcore_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"context"
"crypto/rand"
"fmt"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/spacemeshos/poet/hash"
"github.com/spacemeshos/poet/prover"
"github.com/spacemeshos/poet/shared"
"github.com/spacemeshos/poet/verifier"
)
func BenchmarkProverAndVerifierBig(b *testing.B) {
r := require.New(b)
challenge := make([]byte, 32)
_, err := rand.Read(challenge)
r.NoError(err)
securityParam := shared.T
b.Log("Computing dag...")
t1 := time.Now()
numLeaves, merkleProof, err := prover.GenerateProofWithoutPersistency(
context.Background(),
prover.TreeConfig{Datadir: b.TempDir()},
hash.GenLabelHashFunc(challenge),
hash.GenMerkleHashFunc(challenge),
time.Now(),
securityParam,
)
r.NoError(err, "Failed to generate proof")
e := time.Since(t1)
b.Logf("Proof generated in %s (%f) \n", e, e.Seconds())
b.Logf("Dag root label: %x\n", merkleProof.Root)
err = verifier.Validate(
*merkleProof,
hash.GenLabelHashFunc(challenge),
hash.GenMerkleHashFunc(challenge),
numLeaves,
securityParam,
)
r.NoError(err, "Failed to verify NIP")
e1 := time.Since(t1)
b.Logf("Proof verified in %s (%f)\n", e1-e, (e1 - e).Seconds())
}
func TestNip(t *testing.T) {
challenge := []byte("Spacemesh launched its mainnet")
securityParam := shared.T
numLeaves, merkleProof, err := prover.GenerateProofWithoutPersistency(
context.Background(),
prover.TreeConfig{Datadir: t.TempDir()},
hash.GenLabelHashFunc(challenge),
hash.GenMerkleHashFunc(challenge),
time.Now(),
securityParam,
)
require.NoError(t, err)
fmt.Printf("Dag root label: %x\n", merkleProof.Root)
err = verifier.Validate(
*merkleProof,
hash.GenLabelHashFunc(challenge),
hash.GenMerkleHashFunc(challenge),
numLeaves,
securityParam,
)
require.NoError(t, err, "failed to verify proof")
}
func BenchmarkProofEx(t *testing.B) {
for j := 0; j < 10; j++ {
// generate random commitment
challenge := make([]byte, 32)
_, err := rand.Read(challenge)
require.NoError(t, err)
securityParam := shared.T
numLeaves, merkleProof, err := prover.GenerateProofWithoutPersistency(
context.Background(),
prover.TreeConfig{Datadir: t.TempDir()},
hash.GenLabelHashFunc(challenge),
hash.GenMerkleHashFunc(challenge),
time.Now(),
securityParam,
)
require.NoError(t, err)
fmt.Printf("Dag root label: %x\n", merkleProof.Root)
err = verifier.Validate(
*merkleProof,
hash.GenLabelHashFunc(challenge),
hash.GenMerkleHashFunc(challenge),
numLeaves,
securityParam,
)
require.NoError(t, err, "failed to verify proof")
}
}