-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathreshare.go
52 lines (46 loc) · 1.36 KB
/
reshare.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
package spec
import (
"bytes"
"fmt"
"sort"
"github.com/attestantio/go-eth2-client/spec/phase0"
)
// ValidateReshareMessage returns nil if re-share message is valid
func ValidateReshareMessage(
reshare *Reshare,
operator *Operator,
proof *SignedProof,
) error {
if !UniqueAndOrderedOperators(reshare.OldOperators) {
return fmt.Errorf("old operators are not unique and ordered")
}
// verify owner address
if !bytes.Equal(reshare.Owner[:], proof.Proof.Owner[:]) {
return fmt.Errorf("invalid owner address")
}
if err := ValidateCeremonyProof(reshare.ValidatorPubKey, operator, *proof); err != nil {
return err
}
if !UniqueAndOrderedOperators(reshare.NewOperators) {
return fmt.Errorf("new operators are not unique and ordered")
}
if EqualOperators(reshare.OldOperators, reshare.NewOperators) {
return fmt.Errorf("old and new operators are the same")
}
if !ValidThresholdSet(reshare.OldT, reshare.OldOperators) {
return fmt.Errorf("old threshold set is invalid")
}
if !ValidThresholdSet(reshare.NewT, reshare.NewOperators) {
return fmt.Errorf("new threshold set is invalid")
}
if !ValidAmountSet(phase0.Gwei(reshare.Amount)) {
return fmt.Errorf("amount should be in range between 32 ETH and 2048 ETH")
}
return nil
}
func OrderOperators(in []*Operator) []*Operator {
sort.Slice(in, func(i, j int) bool {
return in[i].ID < in[j].ID
})
return in
}