8000 Follow up on #939 (leader election and drand) by nicola · Pull Request #967 · filecoin-project/specs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Follow up on #939 (leader election and drand) #967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d79c677
update finality number
sternhenri May 15, 2020
b48f9e4
a whole lot of consensus stuff
sternhenri May 16, 2020
d90301c
fix labels, and update drand entry to fit more general beacon data type
sternhenri May 17, 2020
6d37868
revise per @nikkolasg and @zixuanzh notes
sternhenri May 22, 2020
7e98b21
touch up per zx note
sternhenri May 29, 2020
f128c31
changes made a couple weeks ago
sternhenri Jun 18, 2020
409e71e
fixed errors, missing GetRandomnessFromVRFChain still
sternhenri Jun 25, 2020
1454d59
add back ticket and vrf chain content for sealing
sternhenri Jun 25, 2020
d99d5ba
fix edge case for beaconEntries retrieval and genesis
sternhenri Jun 25, 2020
bf923fb
typeError
sternhenri Jun 25, 2020
75e78ec
fix per Kubuxu comment
sternhenri Jun 25, 2020
48a87f0
@nikkolasg fix
sternhenri Jun 25, 2020
f4ba3b5
drand enpoints
nikkolasg Jun 30, 2020
2289dd3
extract randomness from chain
nikkolasg Jun 30, 2020
5f88251
adding block entries on block creation
nikkolasg Jun 30, 2020
32ca09f
adding drand entry to block semantic validatioN
nikkolasg Jun 30, 2020
85fcc3e
fixing lint error on block.id
nikkolasg Jun 30, 2020
96004df
adding election proof definition
nikkolasg Jun 30, 2020
0779bfe
not implemented RadnomnessSeedAtEpoch for the moment
nikkolasg Jun 30, 2020
b5206df
linting pass
nikkolasg Jun 30, 2020
c10a1fe
rewrote GetRandomnessSeed without election period
nikkolasg Jun 30, 2020
a35e2f1
henri PR + getRandomness with argument
nikkolasg Jul 7, 2020
812fd22
rephrase vrf-chain seal need
sternhenri Jul 12, 2020
6fae017
Apply suggestions from code review
nicola Jul 13, 2020
0022b7c
Update src/systems/filecoin_blockchain/storage_power_consensus/_index.md
nicola Jul 23, 2020
e384483
changed method name adopted in specs-actors
nicola Jul 23, 2020
d95e92a
Update src/systems/filecoin_blockchain/storage_power_consensus/_index.md
nicola Jul 23, 2020
f06f9e8
grammatical error
nicola Jul 23, 2020
ccc0f20
adapted comment
nikkolasg Aug 3, 2020
3284d4d
remove getbeaconentryforepoch
nikkolasg Aug 5, 2020
08a6e5d
put back again exception for genesis
nikkolasg Aug 6, 2020
b2aa4d0
Merge branch 'beta' into rework/consensus
olizilla Aug 13, 2020
fddb585
chore: fix links and shortcodes
olizilla Aug 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 55 additions & 43 deletions content/algorithms/crypto/randomness.md
8000
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,27 @@ dashboardTests: 0
---

# Randomness
---

TODO: clean up stale .id/.go files

Randomness is used throughout the protocol in order to generate values and extend the blockchain.
Random values are drawn from the [Ticket Chain](storage_power_consensus#the-ticket-chain-and-drawing-randomness) and appropriately formatted for usage.
Random values are drawn from a (drand)[drand] beacon and appropriately formatted for usage.
We describe this formatting below.

## Encoding On-chain data for randomness
## Encoding Random Beacon randomness for on-chain use

Entropy from the drand beacon can be harvested into a more general data structure: a `BeaconEntry`, defined as follows:

```go
type BeaconEntry struct {
// Drand Round for the given randomness
Round uint64
// Drand Signature for the given Randomness, named Data as a more general name for random beacon output
Data []byte
}
```

Entropy from the ticket-chain can be combined with other values to generate necessary randomness that can be
The BeaconEntry is then combined with other values to generate necessary randomness that can be
specific to (eg) a given miner address or epoch. To be used as part of entropy, these values are combined in
objects that can then be CBOR-serialized according to their algebraic datatypes.

Expand All @@ -27,58 +39,25 @@ Further, we define Domain Separation Tags with which we prepend random inputs wh
All randomness used in the protocol must be generated in conjunction with a unique DST, as well as
certain [Signatures](signatures) and [Verifiable Random Function](vrf) usage.

## Drawing tickets for randomness from the chain

Tickets are used as a source of on-chain randomness, generated with each new block created (see [Tickets](storage_power_consensus#tickets)).

A ticket is drawn from the chain for randomness as follows, for a given epoch `n`, and ticket sought at epoch `e`:
```text
RandomnessSeedAtEpoch(e):
While ticket is not set:
Set wantedTipsetHeight = e
if wantedTipsetHeight <= genesis:
Set ticket = genesis ticket
else if blocks were mined at wantedTipsetHeight:
ReferenceTipset = TipsetAtHeight(wantedTipsetHeight)
Set ticket = minTicket in ReferenceTipset
If no blocks were mined at wantedTipsetHeight:
wantedTipsetHeight--
(Repeat)
return ticket.Digest()
```

In plain language, this means:

- Choose the smallest ticket in the Tipset if it contains multiple blocks.
- When sampling a ticket from an epoch with no blocks, draw the min ticket from the prior epoch with blocks

This ticket is then combined with a Domain Separation Tag, the round number sought and appropriate entropy to form randomness for various uses in the protocol.

See the `RandomnessSeedAtEpoch` method below:
{{<embed src="/systems/filecoin_blockchain/struct/chain/chain.go" lang="go">}}

## Forming Randomness Seeds

The drawn ticket digest is combined with a few elements to make up randomness for use as part of the protocol.
The beacon entry is combined with a few elements for use as part of the protocol as follows:

- a DST (domain separation tag)
- Different uses of randomness are distinguished by this type of personalization which ensures that randomness used for different purposes will not conflict with randomness used elsewhere in the protocol
- the epoch number, ensuring
- liveness for leader election -- in the case of null rounds, the new epoch number will output new randomness for LE
- distinct values for randomness sought before genesis -- where the genesis ticket will be returned
- For instance, if in epoch `curr`, a miner wants randomness from `lookback` epochs back where `curr - lookback <= genesis`, the ticket randomness drawn would be based on `genesisTicket.digest` where the `genesisTicket` is the randomness included in the genesis block. Using the epoch as part of randomness composition ensures that randomness drawn at various epochs prior to genesis has different values.
- other entropy,
- ensuring that randomness is modified as needed by other context-dependent entropy (e.g. a miner address if we want the randomness to be different for each miner).
- liveness for leader election -- in the case no one is elected in a round and no new beacon entry has appeared (i.e. if the beacon frequency is slower than that of block production in Filecoin), the new epoch number will output new randomness for LE (note that Filecoin uses liveness during a beacon outage).
- other entropy, ensuring that randomness is modified as needed by other context-dependent entropy (e.g. a miner address if we want the randomness to be different for each miner).

While all elements are not needed for every use of entropy (e.g. the inclusion of the round number is not necessary prior to genesis or outside of leader election, other entropy is only used sometimes, etc), we draw randomness as follows for the sake of uniformity/simplicity in the overall protocol.

In all cases, a ticket is used as the base of randomness (see [Tickets](storage_power_consensus#tickets)). In order to make randomness seed creation uniform, the protocol derives all such seeds in the same way, using blake2b as a hash function to generate a 256-bit output as follows:
In all cases, a (drand)[drand] signature is used as the base of randomness: it is hashed using blake2b in order to obtain a usable randomness seed. In order to make randomness seed creation uniform, the protocol derives all such seeds in the same way, using blake2b as a hash function to generate a 256-bit output as follows:

In round `n`, for a given randomness lookback `l`, and serialized entropy `s`:

```text
GetRandomness(dst, l, s):
ticketDigest = RandomnessSeedAtEpoch(n-l)
ticketDigest = beacon.GetRandomnessFromBeacon(n-l)

buffer = Bytes{}
buffer.append(IntToBigEndianBytes(dst))
Expand All @@ -92,6 +71,37 @@ GetRandomness(dst, l, s):
{{<embed src="/modules/actors/crypto/randomness.go" lang="go">}}
{{<embed src="/systems/filecoin_blockchain/struct/chain/chain.go" lang="go">}}

## Drawing tickets from the VRF-chain for proof inclusion

In some places, the protocol needs randomness drawn from the Filecoin blockchain's VRF-chain (which generates [tickets](storage_power_consensus#tickets) with each new block) rather than from the random beacon, in order to tie certain proofs to a particular set of Filecoin blocks (i.e. a given chain or fork).
In particular, `SealRandomness` must be taken from the VRF chain, in order to ensure that no other fork can replay the Seal (see [sealing](sealing) for more).

A ticket is drawn from the chain for randomness as follows, for a given epoch `n`, and ticket sought at epoch `e`:
```text
GetRandomnessFromVRFChain(e):
While ticket is not set:
Set wantedTipsetHeight = e
if wantedTipsetHeight <= genesis:
Set ticket = genesis ticket
else if blocks were mined at wantedTipsetHeight:
ReferenceTipset = TipsetAtHeight(wantedTipsetHeight)
Set ticket = minTicket in ReferenceTipset
If no blocks were mined at wantedTipsetHeight:
wantedTipsetHeight--
(Repeat)
return ticket.Digest()
```

In plain language, this means:

- Choose the smallest ticket in the Tipset if it contains multiple blocks.
- When sampling a ticket from an epoch with no blocks, draw the min ticket from the prior epoch with blocks

This ticket is then combined with a Domain Separation Tag, the round number sought and appropriate entropy to form randomness for various uses in the protocol.

See the `GetRandomnessFromVRFChain` method below:
{{<embed src="/systems/filecoin_blockchain/struct/chain/chain.go" lang="go">}}

## Entropy to be used with randomness

As stated above, different uses of randomness may require added entropy. The CBOR-serialization of the inputs to this entropy must be used.
Expand All @@ -108,8 +118,10 @@ type baz struct {
Currently, we distinguish the following entropy needs in the Filecoin protocol (this list is not exhaustive):

- TicketProduction: requires MinerIDAddress
- ElectionPoStChallengeSeed: requires current epoch and MinerIDAddress -- epoch is already mixed in from ticket drawing so in practice is the same as just adding MinerIDAddress as entropy
- ElectionProofProduction: requires current epoch and MinerIDAddress -- epoch is already mixed in from ticket drawing so in practice is the same as just adding MinerIDAddress as entropy
- WinningPoStChallengeSeed: requires MinerIDAddress
- WindowedPoStChallengeSeed: requires MinerIDAddress
- WindowedPoStDeadlineAssignment: TODO @jake
- SealRandomness: requires MinerIDAddress
- InteractiveSealChallengeSeed: requires MinerIDAddress

Expand Down
Loading
0