forked from ssvlabs/ssv-spec
/
alea_msgs.go
145 lines (139 loc) · 3.7 KB
/
alea_msgs.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package testingutils
import (
"github.com/MatheusFranco99/ssv-spec-AleaBFT/alea"
"github.com/MatheusFranco99/ssv-spec-AleaBFT/types"
"github.com/herumi/bls-eth-go-binary/bls"
)
var MultiSignAleaMsg = func(sks []*bls.SecretKey, ids []types.OperatorID, msg *alea.Message) *alea.SignedMessage {
if len(sks) == 0 || len(ids) != len(sks) {
panic("sks != ids")
}
var signed *alea.SignedMessage
for i, sk := range sks {
if signed == nil {
signed = SignAleaMsg(sk, ids[i], msg)
} else {
if err := signed.Aggregate(SignAleaMsg(sk, ids[i], msg)); err != nil {
panic(err.Error())
}
}
}
return signed
}
var SignAleaMsg = func(sk *bls.SecretKey, id types.OperatorID, msg *alea.Message) *alea.SignedMessage {
domain := types.PrimusTestnet
sigType := types.QBFTSignatureType
r, _ := types.ComputeSigningRoot(msg, types.ComputeSignatureDomain(domain, sigType))
sig := sk.SignByte(r)
return &alea.SignedMessage{
Message: msg,
Signers: []types.OperatorID{id},
Signature: sig.Serialize(),
}
}
var ProposalDataBytesAlea = func(data []byte) []byte {
d := &alea.ProposalData{
Data: data,
}
ret, _ := d.Encode()
return ret
}
var FillGapDataBytes = func(operatorID types.OperatorID, priority alea.Priority) []byte {
d := &alea.FillGapData{
OperatorID: operatorID,
Priority: priority,
}
ret, _ := d.Encode()
return ret
}
var FillerDataBytes = func(entries [][]*alea.ProposalData, priorities []alea.Priority, aggregatedMsgs [][]byte, operatorID types.OperatorID) []byte {
d := &alea.FillerData{
Entries: entries,
Priorities: priorities,
AggregatedMsgs: aggregatedMsgs,
OperatorID: operatorID,
}
ret, _ := d.Encode()
return ret
}
var ABAInitDataBytes = func(vote byte, round alea.Round, acRound alea.ACRound) []byte {
d := &alea.ABAInitData{
Vote: vote,
Round: round,
ACRound: acRound,
}
ret, _ := d.Encode()
return ret
}
var ABAAuxDataBytes = func(vote byte, round alea.Round, acRound alea.ACRound) []byte {
d := &alea.ABAAuxData{
Vote: vote,
Round: round,
ACRound: acRound,
}
ret, _ := d.Encode()
return ret
}
var ABAConfDataBytes = func(votes []byte, round alea.Round, acRound alea.ACRound) []byte {
d := &alea.ABAConfData{
Votes: votes,
Round: round,
ACRound: acRound,
}
ret, _ := d.Encode()
return ret
}
var ABAFinishDataBytes = func(vote byte, acRound alea.ACRound) []byte {
d := &alea.ABAFinishData{
Vote: vote,
ACRound: acRound,
}
ret, _ := d.Encode()
return ret
}
var VCBCSendDataBytes = func(proposals []*alea.ProposalData, priority alea.Priority, author types.OperatorID) []byte {
d := &alea.VCBCSendData{
Proposals: proposals,
Priority: priority,
Author: author,
}
ret, _ := d.Encode()
return ret
}
var VCBCReadyDataBytes = func(hash []byte, priority alea.Priority, author types.OperatorID) []byte {
d := &alea.VCBCReadyData{
Hash: hash,
Priority: priority,
Author: author,
}
ret, _ := d.Encode()
return ret
}
var VCBCFinalDataBytes = func(hash []byte, priority alea.Priority, aggregatedMsg []byte, author types.OperatorID) []byte {
d := &alea.VCBCFinalData{
Hash: hash,
Priority: priority,
AggregatedMsg: aggregatedMsg,
Author: author,
}
ret, _ := d.Encode()
return ret
}
var VCBCRequestDataBytes = func(priority alea.Priority, author types.OperatorID) []byte {
d := &alea.VCBCRequestData{
Priority: priority,
Author: author,
}
ret, _ := d.Encode()
return ret
}
var VCBCAnswerDataBytes = func(proposals []*alea.ProposalData, priority alea.Priority, aggregatedMsg []byte, author types.OperatorID) []byte {
d := &alea.VCBCAnswerData{
Proposals: proposals,
Priority: priority,
AggregatedMsg: aggregatedMsg,
Author: author,
}
ret, _ := d.Encode()
return ret
}