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

v012x to dev #1820

Merged
merged 104 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
c10e59b
Fix `INACTIVITY_PENALTY_QUOTIENT`
hwwhww Apr 8, 2020
890c27d
The input parameter `index` in `compute_shuffled_index` is the positi…
hwwhww Apr 9, 2020
b2f6325
Fix `compute_committee`
hwwhww Apr 9, 2020
1e9df66
Merge pull request #1714 from ethereum/hwwhww/validator_index
djrtwo Apr 14, 2020
4a94200
Merge pull request #1712 from ethereum/hwwhww/inactivity_penalty_quot…
djrtwo Apr 14, 2020
6fdee75
Fix phase0 types
hwwhww Apr 17, 2020
cafd98b
Fix utils.hash_function typing
hwwhww Apr 17, 2020
3575b18
Fix `config_util.py` typing
hwwhww Apr 17, 2020
5b4f5c3
Merge pull request #1731 from ethereum/hwwhww/phase0_typing
djrtwo Apr 20, 2020
5929aac
Cosmetic changes from #1737
JustinDrake Apr 21, 2020
9bbac0d
Added consistency check for FFG & LMD vote in validate_on_atttestatio…
adiasg Apr 22, 2020
37abc54
Merge pull request #1740 from ethereum/JustinDrake-patch-3
djrtwo Apr 22, 2020
fde9b41
Merge pull request #1752 from ethereum/dev
djrtwo Apr 24, 2020
9acea51
Simplified by re-using get_ancestor()
adiasg Apr 25, 2020
4d980ae
Fix validator guide
hwwhww Apr 23, 2020
303d7d5
Add validator guide tests
hwwhww Apr 23, 2020
bdae27e
Add bls.AggregatePKs helper
hwwhww Apr 23, 2020
8adc15e
Add validator guide tests
hwwhww Apr 23, 2020
70bd73d
Apply PR feedback from @djrtwo
hwwhww Apr 27, 2020
d311248
Increase `EPOCHS_PER_ETH1_VOTING_PERIOD` from `2` to `4` for testing …
hwwhww Apr 27, 2020
2dbc333
Make `compute_new_state_root` a pure function
hwwhww Apr 27, 2020
f95a135
Merge pull request #1745 from ethereum/hwwhww/validator-tests
djrtwo Apr 27, 2020
553a33c
Merge pull request #1766 from ethereum/dev
djrtwo Apr 27, 2020
d128400
remove interop from header and gossip sections in network spec
djrtwo Apr 27, 2020
8758683
remove interop from phase 0 p2p specs
djrtwo Apr 27, 2020
070056b
Merge pull request #1767 from ethereum/remove-interop-fix
djrtwo Apr 30, 2020
09cae4b
Handle empty-aggregation-bits case, and add tests. See #1713
protolambda May 1, 2020
47ed5b6
Fix rewards testing for empty/weird participation cases, adding more …
protolambda May 1, 2020
b2c3611
Merge branch 'dev' into v012x
djrtwo May 5, 2020
5b3ed8a
bump VERSION.txt to 0.12.0
djrtwo May 5, 2020
38f29ba
remove PERSISTENT_COMMITTEE_PERIOD in favor of SHARD_COMMITTEE_PERIOD
djrtwo May 5, 2020
b71a0ee
Merge branch 'v012x' into ffg_lmd_vote_consistency
djrtwo May 5, 2020
5267186
Merge pull request #1783 from ethereum/fix-persistent-committee-period
protolambda May 5, 2020
b109e7d
add test for inconsistent head and target in attestation fork choice
djrtwo May 5, 2020
7625728
Merge pull request #1742 from ethereum/ffg_lmd_vote_consistency
djrtwo May 7, 2020
1e9d46d
Merge branch 'dev' into v012x
djrtwo May 7, 2020
08652f5
Merge branch 'v012x' into empty-bits-case
djrtwo May 7, 2020
12aa84f
PR feedback
djrtwo May 7, 2020
c5d0090
Merge pull request #1780 from ethereum/empty-bits-case
djrtwo May 7, 2020
3a71c6d
Merge branch 'dev' into v012x
djrtwo May 7, 2020
1137e03
move MAX_ATTESTER_SLASHINGS to 2, add multiple slashings per block tests
djrtwo May 7, 2020
01eaf6c
Clarify the response of BlocksByRange to address #1765
djrtwo May 8, 2020
fdcc6d6
gossipsub v1.1 and extended validators for gossip conditions
djrtwo May 8, 2020
cdd0ed0
Update to IETF BLS draft-irtf-cfrg-bls-signature-02
hwwhww May 9, 2020
a8e3fe7
Update p2p reqresp with explicit handling of reqresp size bounds
protolambda May 9, 2020
1636360
remove todo comment
djrtwo May 11, 2020
8fe43e1
Merge pull request #1796 from ethereum/gossipsub-v1.1
djrtwo May 11, 2020
3fb4c43
Merge pull request #1794 from ethereum/2x-attester-slashings
djrtwo May 11, 2020
b3dd99f
Loosen restrictions for aggregate propogation
paulhauner Apr 19, 2020
7d4d3e4
remove aggregate clarifiyng text that is not longer valid
djrtwo May 11, 2020
b4bc203
clarify that clients MAY stop block requests if fork choice changes
djrtwo May 11, 2020
fcf0038
remove duplicate response diagram
protolambda May 11, 2020
17f656c
Merge branch 'dev' into v012x
djrtwo May 11, 2020
65108ae
start on_block just slots test at time 0
djrtwo May 11, 2020
30ecd9b
p2p PR feedback
djrtwo May 11, 2020
396f71f
Merge pull request #1802 from ethereum/minor-forkchoice-test-fix
protolambda May 11, 2020
ca1876e
Merge pull request #1795 from ethereum/clarify-blocks-request
djrtwo May 11, 2020
ef18010
Merge pull request #1800 from ethereum/reqresp-sizes
djrtwo May 11, 2020
511f803
use all attnets across the epoch even when not max committees per slot
djrtwo May 11, 2020
78d83b6
Bump py_ecc to v3.0.0 (IETF BLS v2 + H2C v6)
hwwhww May 11, 2020
ed194de
Bump py_ecc to v4.0.0 (IETF BLS v2 + H2C v7)
hwwhww May 12, 2020
2718dcc
Update IETF standard description
hwwhww May 12, 2020
3c11a4d
Fix `AggregateVerify` param name: `message` -> `messages`
hwwhww May 13, 2020
4a246ba
Apply feedback from Danny, add a note of the hash to curve configuration
hwwhww May 13, 2020
b9e4bcc
Fix type error
hwwhww May 13, 2020
84cea96
Fix typo
hwwhww May 14, 2020
aa436d9
Use NO_SIGNATURE (0x00...) approach
hwwhww May 14, 2020
6a3241b
Remove leading space
hwwhww May 14, 2020
d27f235
Update BLS test suite to BLS standard draft v2 format
hwwhww May 14, 2020
c91e017
Merge pull request #1801 from ethereum/non-aggregator-att
djrtwo May 14, 2020
f0c4623
Apply PR feedback: add docstring
hwwhww May 14, 2020
689a695
Merge pull request #1812 from ethereum/no_signature
djrtwo May 14, 2020
9a25598
Fix typo and remove unused variable
hwwhww May 14, 2020
ea99f0a
Fix typo
hwwhww May 14, 2020
82073a4
Fix typo
hwwhww May 14, 2020
3dd1683
reformat compute_subnet_for_attestation to not use for loop
djrtwo May 14, 2020
ab3cbda
Add a note of `len(attestations) > 0`
hwwhww May 14, 2020
483f9a1
Update specs/phase0/p2p-interface.md
djrtwo May 14, 2020
96ab76d
Merge pull request #1804 from ethereum/use-all-attnets
djrtwo May 14, 2020
a9c4516
PR feedback from proto: revert configs
hwwhww May 15, 2020
d07e594
Add `Aggregate()` case
hwwhww May 15, 2020
fd3cce0
Update README
hwwhww May 15, 2020
4ffafa5
Merge pull request #1813 from ethereum/bls_v2_tests
djrtwo May 15, 2020
4a86c39
Merge pull request #1799 from ethereum/bls_v2
djrtwo May 18, 2020
ed013b1
Merge pull request #1806 from ethereum/pack_bits
djrtwo May 18, 2020
b975a92
ensure at least one validator is slashed for slashing rewards tests
djrtwo May 18, 2020
6f685a9
Merge branch 'dev' into v012x
djrtwo May 18, 2020
97b6db4
add rewards tests for validators not yet activated
djrtwo May 18, 2020
96b5733
cleanup set some new deposits helper for rewards tests
djrtwo May 18, 2020
c536729
Merge branch 'dev' into v012x
djrtwo May 18, 2020
5da4fe3
Merge pull request #1821 from ethereum/rewards-with-inactive-vals
djrtwo May 18, 2020
8060505
refactor rewards/penalties tests to use a single structure
djrtwo May 18, 2020
0f20d8a
leak state decorator, and test pre-state caching
protolambda May 18, 2020
75a0d60
cached epoch attestation preparation
protolambda May 19, 2020
97e54b8
fix cache for config change during runtime
protolambda May 19, 2020
85f6712
fix comments based on PR feedback
protolambda May 19, 2020
6d45afe
add some more random reawrds tests
djrtwo May 19, 2020
5c564f4
clean up reards generator
djrtwo May 19, 2020
65b5aa3
update test format docs
protolambda May 19, 2020
583b332
Merge pull request #1826 from ethereum/single-rewards-gen
djrtwo May 19, 2020
095b87c
Merge branch 'dev' into v012x
djrtwo May 19, 2020
724139a
change gossipsub protocol ID to /meshsub/1.1.0
djrtwo May 19, 2020
fdc7e84
remove incorrect table format
djrtwo May 19, 2020
dbb1ee6
Merge pull request #1828 from ethereum/gossipv1.1-id
djrtwo May 19, 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
14 changes: 6 additions & 8 deletions configs/mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ EPOCHS_PER_ETH1_VOTING_PERIOD: 32
SLOTS_PER_HISTORICAL_ROOT: 8192
# 2**8 (= 256) epochs ~27 hours
MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 256
# 2**11 (= 2,048) epochs 9 days
PERSISTENT_COMMITTEE_PERIOD: 2048
# 2**8 (= 256) epochs ~27 hours
SHARD_COMMITTEE_PERIOD: 256
# 2**6 (= 64) epochs ~7 hours
MAX_EPOCHS_PER_CROSSLINK: 64
# 2**2 (= 4) epochs 25.6 minutes
Expand All @@ -122,8 +122,8 @@ BASE_REWARD_FACTOR: 64
WHISTLEBLOWER_REWARD_QUOTIENT: 512
# 2**3 (= 8)
PROPOSER_REWARD_QUOTIENT: 8
# 2**25 (= 33,554,432)
INACTIVITY_PENALTY_QUOTIENT: 33554432
# 2**24 (= 16,777,216)
INACTIVITY_PENALTY_QUOTIENT: 16777216
# 2**5 (= 32)
MIN_SLASHING_PENALTY_QUOTIENT: 32

Expand All @@ -132,8 +132,8 @@ MIN_SLASHING_PENALTY_QUOTIENT: 32
# ---------------------------------------------------------------
# 2**4 (= 16)
MAX_PROPOSER_SLASHINGS: 16
# 2**0 (= 1)
MAX_ATTESTER_SLASHINGS: 1
# 2**1 (= 2)
MAX_ATTESTER_SLASHINGS: 2
# 2**7 (= 128)
MAX_ATTESTATIONS: 128
# 2**4 (= 16)
Expand Down Expand Up @@ -175,8 +175,6 @@ ONLINE_PERIOD: 8
LIGHT_CLIENT_COMMITTEE_SIZE: 128
# 2**8 (= 256) | epochs | ~27 hours
LIGHT_CLIENT_COMMITTEE_PERIOD: 256
# 2**8 (= 256) | epochs | ~27 hours
SHARD_COMMITTEE_PERIOD: 256
# 2**18 (= 262,144)
SHARD_BLOCK_CHUNK_SIZE: 262144
# 2**2 (= 4)
Expand Down
14 changes: 6 additions & 8 deletions configs/minimal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ MIN_SEED_LOOKAHEAD: 1
# 2**2 (= 4) epochs
MAX_SEED_LOOKAHEAD: 4
# [customized] higher frequency new deposits from eth1 for testing
EPOCHS_PER_ETH1_VOTING_PERIOD: 2
EPOCHS_PER_ETH1_VOTING_PERIOD: 4
# [customized] smaller state
SLOTS_PER_HISTORICAL_ROOT: 64
# 2**8 (= 256) epochs
MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 256
# [customized] higher frequency of committee turnover and faster time to acceptable voluntary exit
PERSISTENT_COMMITTEE_PERIOD: 128
SHARD_COMMITTEE_PERIOD: 64
# [customized] fast catchup crosslinks
MAX_EPOCHS_PER_CROSSLINK: 4
# 2**2 (= 4) epochs
Expand All @@ -122,8 +122,8 @@ BASE_REWARD_FACTOR: 64
WHISTLEBLOWER_REWARD_QUOTIENT: 512
# 2**3 (= 8)
PROPOSER_REWARD_QUOTIENT: 8
# 2**25 (= 33,554,432)
INACTIVITY_PENALTY_QUOTIENT: 33554432
# 2**24 (= 16,777,216)
INACTIVITY_PENALTY_QUOTIENT: 16777216
# 2**5 (= 32)
MIN_SLASHING_PENALTY_QUOTIENT: 32

Expand All @@ -132,8 +132,8 @@ MIN_SLASHING_PENALTY_QUOTIENT: 32
# ---------------------------------------------------------------
# 2**4 (= 16)
MAX_PROPOSER_SLASHINGS: 16
# 2**0 (= 1)
MAX_ATTESTER_SLASHINGS: 1
# 2**1 (= 2)
MAX_ATTESTER_SLASHINGS: 2
# 2**7 (= 128)
MAX_ATTESTATIONS: 128
# 2**4 (= 16)
Expand Down Expand Up @@ -178,8 +178,6 @@ ONLINE_PERIOD: 8
LIGHT_CLIENT_COMMITTEE_SIZE: 128
# 2**8 (= 256) | epochs
LIGHT_CLIENT_COMMITTEE_PERIOD: 256
# 2**8 (= 256) | epochs
SHARD_COMMITTEE_PERIOD: 256
# 2**18 (= 262,144)
SHARD_BLOCK_CHUNK_SIZE: 262144
# 2**2 (= 4)
Expand Down
12 changes: 8 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def get_spec(file_name: str) -> SpecObject:
PHASE1_IMPORTS = '''from eth2spec.phase0 import spec as phase0
from eth2spec.config.config_util import apply_constants_config
from typing import (
Any, Dict, Set, Sequence, NewType, Tuple, TypeVar, Callable
Any, Dict, Set, Sequence, NewType, Tuple, TypeVar, Callable, Optional
)

from dataclasses import (
Expand Down Expand Up @@ -146,8 +146,11 @@ def ceillog2(x: uint64) -> int:
hash_cache: Dict[bytes, Bytes32] = {}


def get_eth1_data(distance: uint64) -> Bytes32:
return hash(distance)
def get_eth1_data(block: Eth1Block) -> Eth1Data:
"""
A stub function return mocking Eth1Data.
"""
return Eth1Data(block_hash=hash_tree_root(block))


def hash(x: bytes) -> Bytes32: # type: ignore
Expand Down Expand Up @@ -373,6 +376,7 @@ def finalize_options(self):
self.md_doc_paths = """
specs/phase0/beacon-chain.md
specs/phase0/fork-choice.md
specs/phase0/validator.md
specs/phase1/custody-game.md
specs/phase1/beacon-chain.md
specs/phase1/shard-transition.md
Expand Down Expand Up @@ -497,7 +501,7 @@ def run(self):
"eth-utils>=1.3.0,<2",
"eth-typing>=2.1.0,<3.0.0",
"pycryptodome==3.9.4",
"py_ecc==2.0.0",
"py_ecc==4.0.0",
"dataclasses==0.6",
"remerkleable==0.1.13",
"ruamel.yaml==0.16.5",
Expand Down
54 changes: 27 additions & 27 deletions specs/phase0/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
- [`DepositMessage`](#depositmessage)
- [`DepositData`](#depositdata)
- [`BeaconBlockHeader`](#beaconblockheader)
- [`SigningRoot`](#signingroot)
- [`SigningData`](#signingdata)
- [Beacon operations](#beacon-operations)
- [`ProposerSlashing`](#proposerslashing)
- [`AttesterSlashing`](#attesterslashing)
Expand Down Expand Up @@ -195,7 +195,6 @@ The following values are (non-configurable) constants used throughout the specif
| `HYSTERESIS_DOWNWARD_MULTIPLIER` | `1` |
| `HYSTERESIS_UPWARD_MULTIPLIER` | `5` |


- For the safety of committees, `TARGET_COMMITTEE_SIZE` exceeds [the recommended minimum committee size of 111](http://web.archive.org/web/20190504131341/https://vitalik.ca/files/Ithaca201807_Sharding.pdf); with sufficient active validators (at least `SLOTS_PER_EPOCH * TARGET_COMMITTEE_SIZE`), the shuffling algorithm ensures committee sizes of at least `TARGET_COMMITTEE_SIZE`. (Unbiasable randomness with a Verifiable Delay Function (VDF) will improve committee robustness and lower the safe minimum committee size.)

### Gwei values
Expand Down Expand Up @@ -228,7 +227,8 @@ The following values are (non-configurable) constants used throughout the specif
| `EPOCHS_PER_ETH1_VOTING_PERIOD` | `2**5` (= 32) | epochs | ~3.4 hours |
| `SLOTS_PER_HISTORICAL_ROOT` | `2**13` (= 8,192) | slots | ~27 hours |
| `MIN_VALIDATOR_WITHDRAWABILITY_DELAY` | `2**8` (= 256) | epochs | ~27 hours |
| `PERSISTENT_COMMITTEE_PERIOD` | `2**11` (= 2,048) | epochs | 9 days |
| `SHARD_COMMITTEE_PERIOD` | `Epoch(2**8)` (= 256) | epochs | ~27 hours |


### State list lengths

Expand All @@ -246,17 +246,17 @@ The following values are (non-configurable) constants used throughout the specif
| `BASE_REWARD_FACTOR` | `2**6` (= 64) |
| `WHISTLEBLOWER_REWARD_QUOTIENT` | `2**9` (= 512) |
| `PROPOSER_REWARD_QUOTIENT` | `2**3` (= 8) |
| `INACTIVITY_PENALTY_QUOTIENT` | `2**25` (= 33,554,432) |
| `INACTIVITY_PENALTY_QUOTIENT` | `2**24` (= 16,777,216) |
| `MIN_SLASHING_PENALTY_QUOTIENT` | `2**5` (= 32) |

- The `INACTIVITY_PENALTY_QUOTIENT` equals `INVERSE_SQRT_E_DROP_TIME**2` where `INVERSE_SQRT_E_DROP_TIME := 2**12 epochs` (about 18 days) is the time it takes the inactivity penalty to reduce the balance of non-participating validators to about `1/sqrt(e) ~= 60.6%`. Indeed, the balance retained by offline validators after `n` epochs is about `(1 - 1/INACTIVITY_PENALTY_QUOTIENT)**(n**2/2)`; so after `INVERSE_SQRT_E_DROP_TIME` epochs, it is roughly `(1 - 1/INACTIVITY_PENALTY_QUOTIENT)**(INACTIVITY_PENALTY_QUOTIENT/2) ~= 1/sqrt(e)`.
- The `INACTIVITY_PENALTY_QUOTIENT` equals `INVERSE_SQRT_E_DROP_TIME**2` where `INVERSE_SQRT_E_DROP_TIME := 2**12` epochs (about 18 days) is the time it takes the inactivity penalty to reduce the balance of non-participating validators to about `1/sqrt(e) ~= 60.6%`. Indeed, the balance retained by offline validators after `n` epochs is about `(1 - 1/INACTIVITY_PENALTY_QUOTIENT)**(n**2/2)`; so after `INVERSE_SQRT_E_DROP_TIME` epochs, it is roughly `(1 - 1/INACTIVITY_PENALTY_QUOTIENT)**(INACTIVITY_PENALTY_QUOTIENT/2) ~= 1/sqrt(e)`.

### Max operations per block

| Name | Value |
| - | - |
| `MAX_PROPOSER_SLASHINGS` | `2**4` (= 16) |
| `MAX_ATTESTER_SLASHINGS` | `2**0` (= 1) |
| `MAX_ATTESTER_SLASHINGS` | `2**1` (= 2) |
| `MAX_ATTESTATIONS` | `2**7` (= 128) |
| `MAX_DEPOSITS` | `2**4` (= 16) |
| `MAX_VOLUNTARY_EXITS` | `2**4` (= 16) |
Expand All @@ -273,7 +273,6 @@ The following values are (non-configurable) constants used throughout the specif
| `DOMAIN_SELECTION_PROOF` | `DomainType('0x05000000')` |
| `DOMAIN_AGGREGATE_AND_PROOF` | `DomainType('0x06000000')` |


## Containers

The following types are [SimpleSerialize (SSZ)](../../ssz/simple-serialize.md) containers.
Expand Down Expand Up @@ -403,10 +402,10 @@ class BeaconBlockHeader(Container):
body_root: Root
```

#### `SigningRoot`
#### `SigningData`

```python
class SigningRoot(Container):
class SigningData(Container):
object_root: Root
domain: Domain
```
Expand Down Expand Up @@ -608,16 +607,18 @@ def bytes_to_int(data: bytes) -> uint64:

#### BLS Signatures

Eth2 makes use of BLS signatures as specified in the [IETF draft BLS specification](https://tools.ietf.org/html/draft-irtf-cfrg-bls-signature-00). Specifically, eth2 uses the `BLS_SIG_BLS12381G2-SHA256-SSWU-RO-_POP_` ciphersuite which implements the following interfaces:
Eth2 makes use of BLS signatures as specified in the [IETF draft BLS specification draft-irtf-cfrg-bls-signature-02](https://tools.ietf.org/html/draft-irtf-cfrg-bls-signature-02) but uses [Hashing to Elliptic Curves - draft-irtf-cfrg-hash-to-curve-07](https://tools.ietf.org/html/draft-irtf-cfrg-hash-to-curve-07) instead of draft-irtf-cfrg-hash-to-curve-06. Specifically, eth2 uses the `BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_` ciphersuite which implements the following interfaces:

- `def Sign(SK: int, message: Bytes) -> BLSSignature`
- `def Verify(PK: BLSPubkey, message: Bytes, signature: BLSSignature) -> bool`
- `def Aggregate(signatures: Sequence[BLSSignature]) -> BLSSignature`
- `def FastAggregateVerify(PKs: Sequence[BLSPubkey], message: Bytes, signature: BLSSignature) -> bool`
- `def AggregateVerify(pairs: Sequence[PK: BLSPubkey, message: Bytes], signature: BLSSignature) -> bool`
- `def AggregateVerify(PKs: Sequence[BLSPubkey], messages: Sequence[Bytes], signature: BLSSignature) -> bool`

Within these specifications, BLS signatures are treated as a module for notational clarity, thus to verify a signature `bls.Verify(...)` is used.

*Note*: The non-standard configuration of the BLS and hash to curve specs is temporary and will be resolved once IETF releases BLS spec draft 3.

### Predicates

#### `is_active_validator`
Expand Down Expand Up @@ -688,11 +689,11 @@ def is_slashable_attestation_data(data_1: AttestationData, data_2: AttestationDa
```python
def is_valid_indexed_attestation(state: BeaconState, indexed_attestation: IndexedAttestation) -> bool:
"""
Check if ``indexed_attestation`` has sorted and unique indices and a valid aggregate signature.
Check if ``indexed_attestation`` is not empty, has sorted and unique indices and has a valid aggregate signature.
"""
# Verify indices are sorted and unique
indices = indexed_attestation.attesting_indices
if not indices == sorted(set(indices)):
if len(indices) == 0 or not indices == sorted(set(indices)):
return False
# Verify aggregate signature
pubkeys = [state.validators[i].pubkey for i in indices]
Expand Down Expand Up @@ -722,24 +723,24 @@ def is_valid_merkle_branch(leaf: Bytes32, branch: Sequence[Bytes32], depth: uint
#### `compute_shuffled_index`

```python
def compute_shuffled_index(index: ValidatorIndex, index_count: uint64, seed: Bytes32) -> ValidatorIndex:
def compute_shuffled_index(index: uint64, index_count: uint64, seed: Bytes32) -> uint64:
"""
Return the shuffled validator index corresponding to ``seed`` (and ``index_count``).
Return the shuffled index corresponding to ``seed`` (and ``index_count``).
"""
assert index < index_count

# Swap or not (https://link.springer.com/content/pdf/10.1007%2F978-3-642-32009-5_1.pdf)
# See the 'generalized domain' algorithm on page 3
for current_round in range(SHUFFLE_ROUND_COUNT):
pivot = bytes_to_int(hash(seed + int_to_bytes(current_round, length=1))[0:8]) % index_count
flip = ValidatorIndex((pivot + index_count - index) % index_count)
flip = (pivot + index_count - index) % index_count
position = max(index, flip)
source = hash(seed + int_to_bytes(current_round, length=1) + int_to_bytes(position // 256, length=4))
byte = source[(position % 256) // 8]
bit = (byte >> (position % 8)) % 2
index = flip if bit else index

return ValidatorIndex(index)
return index
```

#### `compute_proposer_index`
Expand All @@ -753,11 +754,11 @@ def compute_proposer_index(state: BeaconState, indices: Sequence[ValidatorIndex]
MAX_RANDOM_BYTE = 2**8 - 1
i = 0
while True:
candidate_index = indices[compute_shuffled_index(ValidatorIndex(i % len(indices)), len(indices), seed)]
candidate_index = indices[compute_shuffled_index(i % len(indices), len(indices), seed)]
random_byte = hash(seed + int_to_bytes(i // 32, length=8))[i % 32]
effective_balance = state.validators[candidate_index].effective_balance
if effective_balance * MAX_RANDOM_BYTE >= MAX_EFFECTIVE_BALANCE * random_byte:
return ValidatorIndex(candidate_index)
return candidate_index
i += 1
```

Expand All @@ -773,7 +774,7 @@ def compute_committee(indices: Sequence[ValidatorIndex],
"""
start = (len(indices) * index) // count
end = (len(indices) * (index + 1)) // count
return [indices[compute_shuffled_index(ValidatorIndex(i), len(indices), seed)] for i in range(start, end)]
return [indices[compute_shuffled_index(i, len(indices), seed)] for i in range(start, end)]
```

#### `compute_epoch_at_slot`
Expand Down Expand Up @@ -852,13 +853,12 @@ def compute_domain(domain_type: DomainType, fork_version: Version=None, genesis_
```python
def compute_signing_root(ssz_object: SSZObject, domain: Domain) -> Root:
"""
Return the signing root of an object by calculating the root of the object-domain tree.
Return the signing root for the corresponding signing data.
"""
domain_wrapped_object = SigningRoot(
return hash_tree_root(SigningData(
object_root=hash_tree_root(ssz_object),
domain=domain,
)
return hash_tree_root(domain_wrapped_object)
))
```

### Beacon state accessors
Expand Down Expand Up @@ -1125,7 +1125,7 @@ def slash_validator(state: BeaconState,
whistleblower_reward = Gwei(validator.effective_balance // WHISTLEBLOWER_REWARD_QUOTIENT)
proposer_reward = Gwei(whistleblower_reward // PROPOSER_REWARD_QUOTIENT)
increase_balance(state, proposer_index, proposer_reward)
increase_balance(state, whistleblower_index, whistleblower_reward - proposer_reward)
increase_balance(state, whistleblower_index, Gwei(whistleblower_reward - proposer_reward))
```

## Genesis
Expand Down Expand Up @@ -1231,7 +1231,7 @@ def process_slots(state: BeaconState, slot: Slot) -> None:
# Process epoch on the start slot of the next epoch
if (state.slot + 1) % SLOTS_PER_EPOCH == 0:
process_epoch(state)
state.slot += Slot(1)
state.slot = Slot(state.slot + 1)
```

```python
Expand Down Expand Up @@ -1781,7 +1781,7 @@ def process_voluntary_exit(state: BeaconState, signed_voluntary_exit: SignedVolu
# Exits must specify an epoch when they become valid; they are not valid before then
assert get_current_epoch(state) >= voluntary_exit.epoch
# Verify the validator has been active long enough
assert get_current_epoch(state) >= validator.activation_epoch + PERSISTENT_COMMITTEE_PERIOD
assert get_current_epoch(state) >= validator.activation_epoch + SHARD_COMMITTEE_PERIOD
# Verify signature
domain = get_domain(state, DOMAIN_VOLUNTARY_EXIT, voluntary_exit.epoch)
signing_root = compute_signing_root(voluntary_exit, domain)
Expand Down
6 changes: 5 additions & 1 deletion specs/phase0/fork-choice.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def get_latest_attesting_balance(store: Store, root: Root) -> Gwei:
active_indices = get_active_validator_indices(state, get_current_epoch(state))
return Gwei(sum(
state.validators[i].effective_balance for i in active_indices
if (i in store.latest_messages
if (i in store.latest_messages
and get_ancestor(store, store.latest_messages[i].root, store.blocks[root].slot) == root)
))
```
Expand Down Expand Up @@ -285,6 +285,10 @@ def validate_on_attestation(store: Store, attestation: Attestation) -> None:
# Attestations must not be for blocks in the future. If not, the attestation should not be considered
assert store.blocks[attestation.data.beacon_block_root].slot <= attestation.data.slot

# FFG and LMD vote must be consistent with each other
target_slot = compute_start_slot_at_epoch(target.epoch)
assert target.root == get_ancestor(store, attestation.data.beacon_block_root, target_slot)

# Attestations can only affect the fork choice of subsequent slots.
# Delay consideration in the fork choice until their slot is in the past.
assert get_current_slot(store) >= attestation.data.slot + 1
Expand Down
Loading