-
Notifications
You must be signed in to change notification settings - Fork 3
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
Review casper_v2.1.md #1
base: master
Are you sure you want to change the base?
Conversation
sharding/review/casper_v2.1.md
Outdated
* **MAX_VALIDATOR_COUNT** - `ETH_SUPPLY_CAP / DEPOSIT_SIZE = 4194304` | ||
* **EPOCH_LENGTH** - 64 blocks | ||
* **SLOT_DURATION** - 8 seconds | ||
* **MIN_COMMITTEE_SIZE** - 128 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about elaborating why we use MIN_COMMITTEE_SIZE = 128
from the view of security model?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Search for "111" here: https://vitalik.ca/files/Ithaca201807_Sharding.pdf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skumbag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nichebiche
sharding/review/casper_v2.1.md
Outdated
* **MIN_COMMITTEE_SIZE** - 128 | ||
* **END_EPOCH_GRACE_PERIOD** - 8 blocks | ||
|
||
### Main chain changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: we can call the legacy chain the PoW main chain
for differentiating its role.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree.
sharding/review/casper_v2.1.md
Outdated
# cross-links what shard in this epoch | ||
'current_epoch_shuffling': ['int24'], | ||
# The current epoch | ||
'current_epoch': 'int64', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: put current_epoch
before current_epoch_shuffling
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
sharding/review/casper_v2.1.md
Outdated
|
||
### Beacon chain fork choice rule | ||
|
||
The beacon chain uses the Casper FFG fork choice rule of "favor the chain containing the highest-epoch justified checkpoint". To choose between chains that are all descended from the same justified checkpoint, the chain uses "recursive proximity to justification" to choose a checkpoint, then uses GHOST within an epoch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: "recursive proximity to justification (RPJ)"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nichebiche
sharding/review/casper_v2.1.md
Outdated
|
||
We now define the state transition function. At the high level, the state transition is made up of two parts: | ||
|
||
1. The epoch transition, which happens only if `slot_count // 64 > epoch_number`, and affects the crystallized state and active state |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be consistent, slot_count
-> slot_number
? Or it's a different parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right! Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Live
sharding/review/casper_v2.1.md
Outdated
|
||
We now define the state transition function. At the high level, the state transition is made up of two parts: | ||
|
||
1. The epoch transition, which happens only if `slot_count // 64 > epoch_number`, and affects the crystallized state and active state |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
64
-> EPOCH_LENGTH
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nichebiche
sharding/review/casper_v2.1.md
Outdated
1. It attests to some parent block in the beacon chain | ||
2. It attests to a block hash in a shard (a sufficient number of such attestations create a "cross-link", confirming that shard block into the main chain). | ||
|
||
Every shard (e.g. there might be 1024 shards in total) is itself a PoS chain, and the shard chains are where the transactions and accounts will be stored. The cross-links serve to "confirm" segments of the shard chains into the main chain, and are also the primary way through which the different shards will be able to talk to each other. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there might be 1024 shards in total
-> there might be 1024 shards initially
to imply that the shards may grow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The number of shards is constant within the scope of the mechanism (ie. adding more would require a hard fork). So IMO better to keep the emphasis of "it's 1024, deal with it".
sharding/review/casper_v2.1.md
Outdated
* Verify that `height <= slot_number` | ||
* Use `get_cutoffs` above to get the index cutoffs for the heights and the shards. | ||
* If `height_in_epoch < EPOCH_LENGTH - END_EPOCH_GRACE_PERIOD`, verify that `si = (shard_id - next_shard) % SHARD_COUNT` is a valid shard index for that height (ie. check `height_cutoffs[height_in_epoch] <= shard_cutoffs[si] < height_cutoffs[height_in_epoch + 1])`). | ||
* Otherwise, verify `shard_id == 65535` and `shard_block_hash == 0`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shard_id == 65535
implies that MAX_SHARD_COUNT
is 2^16
. Why not set MAX_SHARD_COUNT
to 2^15
, where MAX_VALIDATOR_COUNT / MIN_COMMITTEE_SIZE = 2^15
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point is to have an "out of the way" shard ID that doesn't represent any shard.
sharding/review/casper_v2.1.md
Outdated
|
||
### Epoch transitions | ||
|
||
When the current block height (ie. the height in the active state) is 0 mod SHARD_COUNT, we execute an epoch transition, which breaks down into several parts. Note that all validator balance changes only take effect after all of these parts finish. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: formatting 0 mod SHARD_COUNT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
sharding/review/casper_v2.1.md
Outdated
@@ -246,9 +247,9 @@ def get_cutoffs(validator_count): | |||
|
|||
# For the validators assigned to each height, split them up | |||
# into committees for different shards. Do not assign the | |||
# last 8 heights in an epoch to any shards. | |||
# last END_EPOCH_GRACE_PERIOD heights in an epoch to any shards. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
END_EPOCH_GRACE_PERIOD
should be defined in Constants
section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sharding/review/casper_v2.1.md
Outdated
} | ||
``` | ||
|
||
Here's the crystallized state: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to use CrystallizedState
for consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
sharding/review/casper_v2.1.md
Outdated
|
||
The beacon chain state is split into two parts, _active state_ and _crystallized state_. | ||
|
||
Here's the active state: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to use ActiveState
for consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
sharding/review/casper_v2.1.md
Outdated
* Otherwise, verify `shard_id == 65535` and `shard_block_hash == 0`. | ||
* If `height_in_epoch < EPOCH_LENGTH - 8`, let `start = shard_cutoffs[si]` and `end = shard_cutoffs[si+1]`. Otherwise, let `start = height_cutoffs[height_in_epoch]` and `end = height_cutoffs[height_in_epoch + 1]` | ||
* Verify that `len(attester_bitfield) == ceil_div8(end - start)`, where `ceil_div8 = (x + 7) // 8`. Verify that bits `end-start....` and higher, if present (ie. `end-start` is not a multiple of 8), are all zero | ||
* Take all indices `0 <= i < end-start` where the ith bit of `attester_bitfield` equals 1, take `current_epoch_shuffling[start+i]` as the indices of those validators, extract their pubkeys, and add them all together to generate the group pubkey. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i
th
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, don't really care 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Funny
sharding/review/casper_v2.1.md
Outdated
|
||
The beacon chain uses the Casper FFG fork choice rule of "favor the chain containing the highest-epoch justified checkpoint". To choose between chains that are all descended from the same justified checkpoint, the chain uses "recursive proximity to justification" to choose a checkpoint, then uses GHOST within an epoch. | ||
|
||
RPJ works as follows. First, start at the latest justified checkpoint. Then, choose the descendant checkpoint that has the most attestations supporting it. Repeat until you get to a checkpoint with no children (in this phase, only checkpoints whose epochs are completed, ie. epoch N where the timeslots for epoch N+1 have already begun, are admissible) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
latest justified checkpoint (LJC)
sharding/review/casper_v2.1.md
Outdated
# Randao commitment reveal | ||
'randao_reveal': 'hash32', | ||
# Attestation votes | ||
'attestation_votes': [AttestationVote], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AttestationVote
is not defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed (changed AggregateVote to AttestationVote later)
sharding/review/casper_v2.1.md
Outdated
* Use `get_cutoffs` above to get the index cutoffs for the heights and the shards. | ||
* If `height_in_epoch < EPOCH_LENGTH - END_EPOCH_GRACE_PERIOD`, verify that `si = (shard_id - next_shard) % SHARD_COUNT` is a valid shard index for that height (ie. check `height_cutoffs[height_in_epoch] <= shard_cutoffs[si] < height_cutoffs[height_in_epoch + 1])`). | ||
* Otherwise, verify `shard_id == 65535` and `shard_block_hash == 0`. | ||
* If `height_in_epoch < EPOCH_LENGTH - 8`, let `start = shard_cutoffs[si]` and `end = shard_cutoffs[si+1]`. Otherwise, let `start = height_cutoffs[height_in_epoch]` and `end = height_cutoffs[height_in_epoch + 1]` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should replace 8
with END_EPOCH_GRACE_PERIOD
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
sharding/review/casper_v2.1.md
Outdated
|
||
* Take the set of `shard_block_hash` values that have been proposed for S in the attestations (call this set ROOTS) | ||
* Take the ROOT in ROOTS such that the total deposit size of the subset of validators that have voted for `shard_block_hash` ROOT and `shard_id` S is maximal; call this BESTROOT | ||
* For every validator that voted for BESTROOT, increment their balance by `online_crosslink_reward`. For everyone else who was assigned to a shard (ie. not the proposers of the last 8 blocks), decrement their balance by `offline_crosslink_penalty` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should replace 8
with END_EPOCH_GRACE_PERIOD
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
sharding/review/casper_v2.1.md
Outdated
For a block on the beacon chain to be processed by a node, three conditions have to be met: | ||
|
||
* The parent pointed to by the `parent_hash` has already been processed and accepted | ||
* The main chain block pointed to by the `main_chain_ref` has already been processed and accepted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any in-protocol condition of main_chain_ref
? e.g., the main chain block number should within head_main_chain_block_number - X
?
sharding/review/casper_v2.1.md
Outdated
# Reference to main chain block | ||
'main_chain_ref': 'hash32', | ||
# Attestations | ||
'attestations': [AttestationRecord], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AttestationRecord
can be renamed to Attestation
, more concise.
sharding/review/casper_v2.1.md
Outdated
|
||
```python | ||
fields = { | ||
'height': 'int16', | ||
'slot': 'int64', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Block
, the slot number is slot_number
; it would be nice to use the same name for the same property.
sharding/review/casper_v2.1.md
Outdated
* Logic for inducting queued validators from the main chain | ||
* Penalties for signing or attesting to non-canonical-chain blocks (update: may not be necessary, see https://ethresear.ch/t/attestation-committee-based-full-pos-chains/2259) | ||
* Slashing conditions | ||
* Logic for withdrawing deposits to shards | ||
* Per-validator proofs of custody | ||
* Full rewards and penalties | ||
* Versioning and upgrades | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add: Full RNG process
sharding/review/casper_v2.1.md
Outdated
|
||
```python | ||
def get_shuffling(seed, validator_count): | ||
assert validator_count <= 16777216 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why using 16777216
(2^24) while MAX_VALIDATOR_COUNT
is defined as 2^22 = 4194304?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The algorithm very directly depends on the number of validators being less than 2^24 because of how it gets indices three bytes at a time.
sharding/review/casper_v2.1.md
Outdated
'current_epoch': 'int64', | ||
# The permutation of the validators that | ||
# determines who participates in what | ||
# committee and at what height |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
height
-> slot
sharding/review/casper_v2.1.md
Outdated
|
||
Here's a depiction of what is going on with reduced parameters for simplicity of exposition: | ||
|
||
![](http://vitalik.ca/files/ShuffleAndAssign.png) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
height
-> slot
sharding/review/casper_v2.1.md
Outdated
|
||
Repeat for every shard S: | ||
|
||
* Take the set of `shard_block_hash` values that have been proposed for S in the attestations (call this set ROOTS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The writing style of this paragraph is quite different from the others; IMO it's more readable if:
Repeat for every shard s
:
- Take the set of
shard_block_hash
values that have been proposed for shards
in the attestations; call this setroots
sharding/review/casper_v2.1.md
Outdated
Repeat for every shard S: | ||
|
||
* Take the set of `shard_block_hash` values that have been proposed for S in the attestations (call this set ROOTS) | ||
* Take the ROOT in ROOTS such that the total deposit size of the subset of validators that have voted for `shard_block_hash` ROOT and `shard_id` S is maximal; call this BESTROOT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Take
root
inroots
such that the total deposit size of the subset of validators that have voted forshard_block_hash
and shards
is maximal; call thisbest_root
sharding/review/casper_v2.1.md
Outdated
|
||
* Take the set of `shard_block_hash` values that have been proposed for S in the attestations (call this set ROOTS) | ||
* Take the ROOT in ROOTS such that the total deposit size of the subset of validators that have voted for `shard_block_hash` ROOT and `shard_id` S is maximal; call this BESTROOT | ||
* If the size of the subset that voted * 3 >= `total_deposits * 2`, and `crosslink_records[shard_id].epoch < last_finalized_epoch`, set `crosslink_records[shard_id]` to `{epoch: current_epoch, hash: BESTROOT}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BESTROOT
-> best_root
sharding/review/casper_v2.1.md
Outdated
* Take the set of `shard_block_hash` values that have been proposed for S in the attestations (call this set ROOTS) | ||
* Take the ROOT in ROOTS such that the total deposit size of the subset of validators that have voted for `shard_block_hash` ROOT and `shard_id` S is maximal; call this BESTROOT | ||
* If the size of the subset that voted * 3 >= `total_deposits * 2`, and `crosslink_records[shard_id].epoch < last_finalized_epoch`, set `crosslink_records[shard_id]` to `{epoch: current_epoch, hash: BESTROOT}` | ||
* If the crosslink was saved, for every validator that voted for BESTROOT, increment their balance by `online_crosslink_reward`. For everyone else who was assigned to a shard (ie. not the proposers of the last `END_EPOCH_GRACE_PERIOD` blocks), decrement their balance by `offline_crosslink_penalty` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
best_root
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
@@ -0,0 +1,446 @@ | |||
# Casper+Sharding chain v2.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ethereum community shall be blessed by Nichebiche love
sharding/review/casper_v2.1.md
Outdated
* **MAX_VALIDATOR_COUNT** - `ETH_SUPPLY_CAP / DEPOSIT_SIZE = 4194304` | ||
* **EPOCH_LENGTH** - 64 blocks | ||
* **SLOT_DURATION** - 8 seconds | ||
* **MIN_COMMITTEE_SIZE** - 128 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nichebiche
sharding/review/casper_v2.1.md
Outdated
|
||
### Beacon chain fork choice rule | ||
|
||
The beacon chain uses the Casper FFG fork choice rule of "favor the chain containing the highest-epoch justified checkpoint". To choose between chains that are all descended from the same justified checkpoint, the chain uses "recursive proximity to justification" to choose a checkpoint, then uses GHOST within an epoch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nichebiche
sharding/review/casper_v2.1.md
Outdated
|
||
We now define the state transition function. At the high level, the state transition is made up of two parts: | ||
|
||
1. The epoch transition, which happens only if `slot_count // 64 > epoch_number`, and affects the crystallized state and active state |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nichebiche
sharding/review/casper_v2.1.md
Outdated
|
||
We now define the state transition function. At the high level, the state transition is made up of two parts: | ||
|
||
1. The epoch transition, which happens only if `slot_count // 64 > epoch_number`, and affects the crystallized state and active state |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Live
sharding/review/casper_v2.1.md
Outdated
@@ -246,9 +247,9 @@ def get_cutoffs(validator_count): | |||
|
|||
# For the validators assigned to each height, split them up | |||
# into committees for different shards. Do not assign the | |||
# last 8 heights in an epoch to any shards. | |||
# last END_EPOCH_GRACE_PERIOD heights in an epoch to any shards. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome
# after withdrawal | ||
'withdrawal_shard': 'int16', | ||
# And what address | ||
'withdrawal_address': 'address', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0x9320BceD0068fdF72C278Fc5721aB776ef0Cc6B9
No description provided.