diff --git a/chain/consensus/filcns/filecoin.go b/chain/consensus/filcns/filecoin.go index fd49f1c9a..b5ec13a60 100644 --- a/chain/consensus/filcns/filecoin.go +++ b/chain/consensus/filcns/filecoin.go @@ -201,7 +201,7 @@ func (filec *FilecoinEC) ValidateBlock(ctx context.Context, b *types.FullBlock) return xerrors.Errorf("failed to marshal miner address to cbor: %w", err) } - vrfBase, err := rand.DrawRandomness(rBeacon.Data, crypto.DomainSeparationTag_ElectionProofProduction, h.Height, buf.Bytes()) + vrfBase, err := rand.DrawRandomnessFromBase(rBeacon.Data, crypto.DomainSeparationTag_ElectionProofProduction, h.Height, buf.Bytes()) if err != nil { return xerrors.Errorf("could not draw randomness: %w", err) } @@ -267,7 +267,7 @@ func (filec *FilecoinEC) ValidateBlock(ctx context.Context, b *types.FullBlock) beaconBase = h.BeaconEntries[len(h.BeaconEntries)-1] } - vrfBase, err := rand.DrawRandomness(beaconBase.Data, crypto.DomainSeparationTag_TicketProduction, h.Height-build.TicketRandomnessLookback, buf.Bytes()) + vrfBase, err := rand.DrawRandomnessFromBase(beaconBase.Data, crypto.DomainSeparationTag_TicketProduction, h.Height-build.TicketRandomnessLookback, buf.Bytes()) if err != nil { return xerrors.Errorf("failed to compute vrf base for ticket: %w", err) } @@ -345,7 +345,7 @@ func (filec *FilecoinEC) VerifyWinningPoStProof(ctx context.Context, nv network. rbase = h.BeaconEntries[len(h.BeaconEntries)-1] } - rand, err := rand.DrawRandomness(rbase.Data, crypto.DomainSeparationTag_WinningPoStChallengeSeed, h.Height, buf.Bytes()) + rand, err := rand.DrawRandomnessFromBase(rbase.Data, crypto.DomainSeparationTag_WinningPoStChallengeSeed, h.Height, buf.Bytes()) if err != nil { return xerrors.Errorf("failed to get randomness for verifying winning post proof: %w", err) } diff --git a/chain/gen/gen.go b/chain/gen/gen.go index 2e5f5e7f7..087f0e00c 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -376,7 +376,7 @@ func (cg *ChainGen) nextBlockProof(ctx context.Context, pts *types.TipSet, m add buf.Write(pts.MinTicket().VRFProof) } - ticketRand, err := rand.DrawRandomness(rbase.Data, crypto.DomainSeparationTag_TicketProduction, round-build.TicketRandomnessLookback, buf.Bytes()) + ticketRand, err := rand.DrawRandomnessFromBase(rbase.Data, crypto.DomainSeparationTag_TicketProduction, round-build.TicketRandomnessLookback, buf.Bytes()) if err != nil { return nil, nil, nil, err } @@ -636,7 +636,7 @@ func IsRoundWinner(ctx context.Context, ts *types.TipSet, round abi.ChainEpoch, return nil, xerrors.Errorf("failed to cbor marshal address: %w", err) } - electionRand, err := rand.DrawRandomness(brand.Data, crypto.DomainSeparationTag_ElectionProofProduction, round, buf.Bytes()) + electionRand, err := rand.DrawRandomnessFromBase(brand.Data, crypto.DomainSeparationTag_ElectionProofProduction, round, buf.Bytes()) if err != nil { return nil, xerrors.Errorf("failed to draw randomness: %w", err) } diff --git a/chain/rand/rand.go b/chain/rand/rand.go index dce4231e2..8ff6300c9 100644 --- a/chain/rand/rand.go +++ b/chain/rand/rand.go @@ -21,7 +21,7 @@ import ( var log = logging.Logger("rand") -func DrawRandomness(rbase []byte, pers crypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte) ([]byte, error) { +func DrawRandomnessFromBase(rbase []byte, pers crypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte) ([]byte, error) { h := blake2b.New256() if err := binary.Write(h, binary.BigEndian, int64(pers)); err != nil { return nil, xerrors.Errorf("deriving randomness: %w", err) @@ -188,7 +188,7 @@ func (sr *stateRand) DrawChainRandomness(ctx context.Context, pers crypto.Domain return nil, xerrors.Errorf("failed to get chain randomness: %w", err) } - ret, err := DrawRandomness(rbase, pers, filecoinEpoch, entropy) + ret, err := DrawRandomnessFromBase(rbase, pers, filecoinEpoch, entropy) if err != nil { return nil, xerrors.Errorf("failed to draw chain randomness: %w", err) } @@ -203,7 +203,7 @@ func (sr *stateRand) DrawBeaconRandomness(ctx context.Context, pers crypto.Domai return nil, xerrors.Errorf("failed to get chain randomness: %w", err) } - ret, err := DrawRandomness(rbase, pers, filecoinEpoch, entropy) + ret, err := DrawRandomnessFromBase(rbase, pers, filecoinEpoch, entropy) if err != nil { return nil, xerrors.Errorf("failed to draw chain randomness: %w", err) } diff --git a/chain/rand/rand_test.go b/chain/rand/rand_test.go index acd928854..e2e722165 100644 --- a/chain/rand/rand_test.go +++ b/chain/rand/rand_test.go @@ -69,7 +69,7 @@ func TestNullRandomnessV1(t *testing.T) { } //stm: @BLOCKCHAIN_RAND_DRAW_RANDOMNESS_01 - rand2, err := rand.DrawRandomness(resp.Entry.Data, pers, randEpoch, entropy) + rand2, err := rand.DrawRandomnessFromBase(resp.Entry.Data, pers, randEpoch, entropy) if err != nil { t.Fatal(err) } @@ -148,8 +148,8 @@ func TestNullRandomnessV2(t *testing.T) { } //stm: @BLOCKCHAIN_RAND_DRAW_RANDOMNESS_01, @BLOCKCHAIN_RAND_EXTRACT_BEACON_ENTRY_FOR_EPOCH_01, @BLOCKCHAIN_RAND_GET_BEACON_RANDOMNESS_TIPSET_03 - // note that the randEpoch passed to DrawRandomness is still randEpoch (not the latest ts height) - rand2, err := rand.DrawRandomness(resp.Entry.Data, pers, randEpoch, entropy) + // note that the randEpoch passed to DrawRandomnessFromBase is still randEpoch (not the latest ts height) + rand2, err := rand.DrawRandomnessFromBase(resp.Entry.Data, pers, randEpoch, entropy) if err != nil { t.Fatal(err) } @@ -232,7 +232,7 @@ func TestNullRandomnessV3(t *testing.T) { } //stm: @BLOCKCHAIN_RAND_DRAW_RANDOMNESS_01 - rand2, err := rand.DrawRandomness(resp.Entry.Data, pers, randEpoch, entropy) + rand2, err := rand.DrawRandomnessFromBase(resp.Entry.Data, pers, randEpoch, entropy) if err != nil { t.Fatal(err) } diff --git a/chain/stmgr/actors.go b/chain/stmgr/actors.go index 4de39c7f1..56744fa74 100644 --- a/chain/stmgr/actors.go +++ b/chain/stmgr/actors.go @@ -355,7 +355,7 @@ func MinerGetBaseInfo(ctx context.Context, sm *StateManager, bcs beacon.Schedule return nil, xerrors.Errorf("failed to marshal miner address: %w", err) } - prand, err := rand.DrawRandomness(rbase.Data, crypto.DomainSeparationTag_WinningPoStChallengeSeed, round, buf.Bytes()) + prand, err := rand.DrawRandomnessFromBase(rbase.Data, crypto.DomainSeparationTag_WinningPoStChallengeSeed, round, buf.Bytes()) if err != nil { return nil, xerrors.Errorf("failed to get randomness for winning post: %w", err) } diff --git a/chain/vm/runtime.go b/chain/vm/runtime.go index f647918e9..031c3d6ca 100644 --- a/chain/vm/runtime.go +++ b/chain/vm/runtime.go @@ -237,7 +237,7 @@ func (rt *Runtime) GetRandomnessFromTickets(personalization crypto.DomainSeparat panic(aerrors.Fatalf("could not get ticket randomness: %s", err)) } - ret, err := rand.DrawRandomness(randomnessBase, personalization, randEpoch, entropy) + ret, err := rand.DrawRandomnessFromBase(randomnessBase, personalization, randEpoch, entropy) if err != nil { panic(aerrors.Fatalf("could not draw ticket randomness: %s", err)) @@ -253,7 +253,7 @@ func (rt *Runtime) GetRandomnessFromBeacon(personalization crypto.DomainSeparati panic(aerrors.Fatalf("could not get ticket randomness: %s", err)) } - ret, err := rand.DrawRandomness(randomnessBase, personalization, randEpoch, entropy) + ret, err := rand.DrawRandomnessFromBase(randomnessBase, personalization, randEpoch, entropy) if err != nil { panic(aerrors.Fatalf("could not draw ticket randomness: %s", err)) diff --git a/chain/vm/vmi.go b/chain/vm/vmi.go index 749d38d44..924f54738 100644 --- a/chain/vm/vmi.go +++ b/chain/vm/vmi.go @@ -72,6 +72,6 @@ func NewVM(ctx context.Context, opts *VMOpts) (Interface, error) { } type Rand interface { - GetChainRandomness(ctx context.Context, round abi.ChainEpoch) ([]byte, error) - GetBeaconRandomness(ctx context.Context, round abi.ChainEpoch) ([]byte, error) + GetChainRandomness(ctx context.Context, round abi.ChainEpoch) ([32]byte, error) + GetBeaconRandomness(ctx context.Context, round abi.ChainEpoch) ([32]byte, error) } diff --git a/miner/miner.go b/miner/miner.go index 9281854d7..2d802e2cf 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -531,7 +531,7 @@ func (m *Miner) mineOne(ctx context.Context, base *MiningBase) (minedBlock *type return nil, err } - rand, err := lrand.DrawRandomness(rbase.Data, crypto.DomainSeparationTag_WinningPoStChallengeSeed, round, buf.Bytes()) + rand, err := lrand.DrawRandomnessFromBase(rbase.Data, crypto.DomainSeparationTag_WinningPoStChallengeSeed, round, buf.Bytes()) if err != nil { err = xerrors.Errorf("failed to get randomness for winning post: %w", err) return nil, err @@ -600,7 +600,7 @@ func (m *Miner) computeTicket(ctx context.Context, brand *types.BeaconEntry, bas buf.Write(base.TipSet.MinTicket().VRFProof) } - input, err := lrand.DrawRandomness(brand.Data, crypto.DomainSeparationTag_TicketProduction, round-build.TicketRandomnessLookback, buf.Bytes()) + input, err := lrand.DrawRandomnessFromBase(brand.Data, crypto.DomainSeparationTag_TicketProduction, round-build.TicketRandomnessLookback, buf.Bytes()) if err != nil { return nil, err }