Skip to content
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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Review casper_v2.1.md #1

wants to merge 11 commits into from

Conversation

hwwhww
Copy link
Owner

@hwwhww hwwhww commented Jul 21, 2018

No description provided.

* **MAX_VALIDATOR_COUNT** - `ETH_SUPPLY_CAP / DEPOSIT_SIZE = 4194304`
* **EPOCH_LENGTH** - 64 blocks
* **SLOT_DURATION** - 8 seconds
* **MIN_COMMITTEE_SIZE** - 128
Copy link
Owner Author

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?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skumbag

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nichebiche

* **MIN_COMMITTEE_SIZE** - 128
* **END_EPOCH_GRACE_PERIOD** - 8 blocks

### Main chain changes
Copy link
Owner Author

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree.

# cross-links what shard in this epoch
'current_epoch_shuffling': ['int24'],
# The current epoch
'current_epoch': 'int64',
Copy link
Owner Author

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?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


### 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.
Copy link
Owner Author

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)"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nichebiche


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
Copy link
Owner Author

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?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! Fixed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Live


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
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

64 -> EPOCH_LENGTH

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nichebiche

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.
Copy link
Owner Author

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?

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".

* 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`.
Copy link
Owner Author

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_COUNTto 2^15, where MAX_VALIDATOR_COUNT / MIN_COMMITTEE_SIZE = 2^15?

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.


### 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.
Copy link
Owner Author

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -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.
Copy link
Owner Author

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
```

Here's the crystallized state:
Copy link
Owner Author

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


The beacon chain state is split into two parts, _active state_ and _crystallized state_.

Here's the active state:
Copy link
Owner Author

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* 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.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ith

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 😄

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funny


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)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

latest justified checkpoint (LJC)

# Randao commitment reveal
'randao_reveal': 'hash32',
# Attestation votes
'attestation_votes': [AttestationVote],
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AttestationVote is not defined.

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)

* 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]`
Copy link
Owner Author

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


* 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`
Copy link
Owner Author

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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
Copy link
Owner Author

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?

# Reference to main chain block
'main_chain_ref': 'hash32',
# Attestations
'attestations': [AttestationRecord],
Copy link
Owner Author

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.


```python
fields = {
'height': 'int16',
'slot': 'int64',
Copy link
Owner Author

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.

* 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

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add: Full RNG process


```python
def get_shuffling(seed, validator_count):
assert validator_count <= 16777216
Copy link
Owner Author

@hwwhww hwwhww Jul 27, 2018

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?

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.

'current_epoch': 'int64',
# The permutation of the validators that
# determines who participates in what
# committee and at what height
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

height -> slot


Here's a depiction of what is going on with reduced parameters for simplicity of exposition:

![](http://vitalik.ca/files/ShuffleAndAssign.png)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

height -> slot


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)
Copy link
Owner Author

@hwwhww hwwhww Jul 27, 2018

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 shard s in the attestations; call this set roots

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
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Take root in roots such that the total deposit size of the subset of validators that have voted for shard_block_hash and shard s is maximal; call this best_root


* 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}`
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BESTROOT -> best_root

* 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`
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

best_root

Copy link

@Nichebiche Nichebiche left a 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

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

* **MAX_VALIDATOR_COUNT** - `ETH_SUPPLY_CAP / DEPOSIT_SIZE = 4194304`
* **EPOCH_LENGTH** - 64 blocks
* **SLOT_DURATION** - 8 seconds
* **MIN_COMMITTEE_SIZE** - 128

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nichebiche


### 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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nichebiche


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nichebiche


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Live

@@ -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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@Nichebiche Nichebiche left a 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',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0x9320BceD0068fdF72C278Fc5721aB776ef0Cc6B9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants