-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathfuzz_core_test.go
More file actions
91 lines (76 loc) · 2 KB
/
Copy pathfuzz_core_test.go
File metadata and controls
91 lines (76 loc) · 2 KB
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
package ecvrf
import (
"testing"
)
func FuzzDecodeProofSecp256k1(f *testing.F) {
f.Add([]byte{0x00})
f.Add([]byte{0x02, 0x01})
f.Fuzz(func(t *testing.T, pi []byte) {
// Retrieve core config from the preconfigured VRF
temp := Secp256k1Sha256Tai.(*vrf)
c := &core{Config: &temp.cfg}
// Ensure no panic occurs during decoding
defer func() {
if r := recover(); r != nil {
t.Fatalf("DecodeProof panicked: %v", r)
}
}()
_, _, _, _ = c.DecodeProof(pi)
})
}
func FuzzDecodeProofP256(f *testing.F) {
f.Add([]byte{0x00})
f.Add([]byte{0x02, 0x01})
f.Fuzz(func(t *testing.T, pi []byte) {
temp := P256Sha256Tai.(*vrf)
c := &core{Config: &temp.cfg}
defer func() {
if r := recover(); r != nil {
t.Fatalf("DecodeProof panicked: %v", r)
}
}()
_, _, _, _ = c.DecodeProof(pi)
})
}
func FuzzHashToCurveTryAndIncrementSecp256k1(f *testing.F) {
f.Add([]byte("Hello"), []byte{1})
f.Add([]byte{0x01, 0x02, 0x03}, []byte{0xFF})
f.Fuzz(func(t *testing.T, alpha []byte, skSeed []byte) {
sk := deriveSecp256k1Key(skSeed)
if sk == nil {
t.Skip()
}
temp := Secp256k1Sha256Tai.(*vrf)
c := &core{Config: &temp.cfg}
H, err := c.HashToCurveTryAndIncrement(&point{sk.PublicKey.X, sk.PublicKey.Y}, alpha)
if err != nil {
// No guarantee that a valid point is found for all inputs; just ensure no panic.
return
}
if c.Unmarshal(c.Marshal(H)) == nil {
t.Fatalf("returned point is not on curve")
}
})
}
func FuzzHashToCurveTryAndIncrementP256(f *testing.F) {
f.Add([]byte("Hello"), []byte{2})
f.Add([]byte{0x01, 0x02, 0x03}, []byte{0x01, 0x02})
f.Fuzz(func(t *testing.T, alpha []byte, skSeed []byte) {
if len(skSeed) == 0 {
t.Skip()
}
temp := P256Sha256Tai.(*vrf)
c := &core{Config: &temp.cfg}
sk := deriveP256Key(skSeed)
if sk == nil {
t.Skip()
}
H, err := c.HashToCurveTryAndIncrement(&point{sk.PublicKey.X, sk.PublicKey.Y}, alpha)
if err != nil {
return
}
if c.Unmarshal(c.Marshal(H)) == nil {
t.Fatalf("returned point is not on curve")
}
})
}