-
Notifications
You must be signed in to change notification settings - Fork 25
/
randao.go
35 lines (27 loc) · 843 Bytes
/
randao.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
package common
import (
"encoding/binary"
. "github.com/protolambda/zrnt/eth2/util/hashing"
)
// Prepare the randao mix for the given epoch by copying over the mix from the previous epoch.
func PrepareRandao(mixes RandaoMixes, epoch Epoch) error {
prev, err := mixes.GetRandomMix(epoch.Previous())
if err != nil {
return err
}
return mixes.SetRandomMix(epoch, prev)
}
func GetSeed(spec *Spec, mixes RandaoMixes, epoch Epoch, domainType BLSDomainType) (Root, error) {
buf := make([]byte, 4+8+32)
// domain type
copy(buf[0:4], domainType[:])
// epoch
binary.LittleEndian.PutUint64(buf[4:4+8], uint64(epoch))
// Avoid underflow
mix, err := mixes.GetRandomMix(epoch + spec.EPOCHS_PER_HISTORICAL_VECTOR - spec.MIN_SEED_LOOKAHEAD - 1)
if err != nil {
return Root{}, err
}
copy(buf[4+8:], mix[:])
return Hash(buf), nil
}