/
rounds.go
146 lines (130 loc) · 3.35 KB
/
rounds.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
146
// Copyright © 2019 Binance
//
// This file is part of Binance. The full Binance copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.
package signing
import (
"errors"
"math/big"
"github.com/bnb-chain/tss-lib/v2/common"
"github.com/bnb-chain/tss-lib/v2/crypto"
"github.com/bnb-chain/tss-lib/v2/ecdsa/keygen"
"github.com/bnb-chain/tss-lib/v2/tss"
)
const (
TaskName = "signing"
)
type (
base struct {
*tss.Parameters
key *keygen.LocalPartySaveData
data *common.SignatureData
temp *localTempData
out chan<- tss.Message
end chan<- *common.SignatureData
ok []bool // `ok` tracks parties which have been verified by Update()
started bool
number int
}
round1 struct {
*base
}
round2 struct {
*round1
}
round3 struct {
*round2
}
round4 struct {
*round3
}
round5 struct {
*round4
}
round6 struct {
*round5
}
round7 struct {
*round6
}
round8 struct {
*round7
}
round9 struct {
*round8
}
finalization struct {
*round9
}
)
var (
_ tss.Round = (*round1)(nil)
_ tss.Round = (*round2)(nil)
_ tss.Round = (*round3)(nil)
_ tss.Round = (*round4)(nil)
_ tss.Round = (*round5)(nil)
_ tss.Round = (*round6)(nil)
_ tss.Round = (*round7)(nil)
_ tss.Round = (*round8)(nil)
_ tss.Round = (*round9)(nil)
_ tss.Round = (*finalization)(nil)
)
// ----- //
func (round *base) Params() *tss.Parameters {
return round.Parameters
}
func (round *base) RoundNumber() int {
return round.number
}
// CanProceed is inherited by other rounds
func (round *base) CanProceed() bool {
if !round.started {
return false
}
for _, ok := range round.ok {
if !ok {
return false
}
}
return true
}
// WaitingFor is called by a Party for reporting back to the caller
func (round *base) WaitingFor() []*tss.PartyID {
Ps := round.Parties().IDs()
ids := make([]*tss.PartyID, 0, len(round.ok))
for j, ok := range round.ok {
if ok {
continue
}
ids = append(ids, Ps[j])
}
return ids
}
func (round *base) WrapError(err error, culprits ...*tss.PartyID) *tss.Error {
return tss.NewError(err, TaskName, round.number, round.PartyID(), culprits...)
}
// ----- //
// `ok` tracks parties which have been verified by Update()
func (round *base) resetOK() {
for j := range round.ok {
round.ok[j] = false
}
}
// get ssid from local params
func (round *base) getSSID() ([]byte, error) {
ssidList := []*big.Int{round.EC().Params().P, round.EC().Params().N, round.EC().Params().B, round.EC().Params().Gx, round.EC().Params().Gy} // ec curve
ssidList = append(ssidList, round.Parties().IDs().Keys()...) // parties
BigXjList, err := crypto.FlattenECPoints(round.key.BigXj)
if err != nil {
return nil, round.WrapError(errors.New("read BigXj failed"), round.PartyID())
}
ssidList = append(ssidList, BigXjList...) // BigXj
ssidList = append(ssidList, round.key.NTildej...) // NTilde
ssidList = append(ssidList, round.key.H1j...) // h1
ssidList = append(ssidList, round.key.H2j...) // h2
ssidList = append(ssidList, big.NewInt(int64(round.number))) // round number
ssidList = append(ssidList, round.temp.ssidNonce)
ssid := common.SHA512_256i(ssidList...).Bytes()
return ssid, nil
}