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

v1.0 release #2082

Merged
merged 76 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
3cb1580
Update p2p-interface.md
ralexstokes Sep 12, 2020
8ad0865
Use gossip signing policy in p2p spec, see libp2p/specs#294
protolambda Sep 14, 2020
7a46181
Merge pull request #2077 from ethereum/master
protolambda Sep 21, 2020
104b83a
use integer division (//) instead of non-integer (/)
ericsson49 Sep 22, 2020
d7cb570
Merge pull request #2078 from ericsson49/ericsson49/fix_compute_weak_…
djrtwo Sep 22, 2020
a232efb
revert incorrect type fix
djrtwo Sep 22, 2020
8c9c943
Merge pull request #2054 from ethereum/ralexstokes-patch-1
djrtwo Sep 22, 2020
7088274
cleanup phase1 TOC contents
protolambda Sep 23, 2020
6a1813b
Merge pull request #2079 from ethereum/toc-cleanup
djrtwo Sep 23, 2020
19d6c83
Add IETF BLS draft 04 edge cases test vectors
hwwhww Sep 25, 2020
bdbd2aa
Aggregate G2 point at infinity
hwwhww Sep 25, 2020
ad4ad2d
Bump IETF BLS spec version draft 03 -> draft 04
hwwhww Sep 25, 2020
b43f62d
Fix encoding
hwwhww Sep 25, 2020
62d596a
update signature policy link
protolambda Sep 25, 2020
157f7e8
upgrade config to mainnet values
djrtwo Sep 28, 2020
4e2c7d2
add additional genesis initialization tests
djrtwo Sep 28, 2020
76d6926
use better rng practice for reproducibility
djrtwo Sep 29, 2020
0e2e494
fix function signature calls on deposit helpers
djrtwo Sep 29, 2020
9f36fd6
PR feedback. thanks @hwwhww
djrtwo Sep 29, 2020
122d34a
Merge pull request #2083 from ethereum/init-tests
djrtwo Sep 29, 2020
4613c6b
Bump py_ecc to 5.0.0
hwwhww Sep 30, 2020
5f9e659
Merge pull request #2060 from protolambda/signing-policy
djrtwo Sep 30, 2020
4d3ac72
Bump milagro_bls_binding to `1.4.0`, handle the exception cases
hwwhww Oct 5, 2020
d264ad8
Merge pull request #2080 from ethereum/bls_v4
hwwhww Oct 5, 2020
00a19e5
Bump milagro_bls_binding to 1.5.0
hwwhww Oct 6, 2020
29b5efd
Merge pull request #2087 from ethereum/bls_v4_milagro_patch
djrtwo Oct 6, 2020
2e09c91
fix test generators for mainnet max slashing penalties
djrtwo Oct 6, 2020
df23a95
Merge pull request #2088 from ethereum/fix-test
djrtwo Oct 6, 2020
a365fcb
fix message-id issues
djrtwo Oct 6, 2020
6287875
use domain byte to isolate message-id domains
djrtwo Oct 7, 2020
8cda237
note v5.1 in discv5 p2p spec
djrtwo Oct 7, 2020
3bf6b00
Merge pull request #2090 from ethereum/dv5.1
djrtwo Oct 7, 2020
64b34b5
Merge pull request #2089 from ethereum/fix-message-id
djrtwo Oct 7, 2020
45de819
Merge branch 'dev' into v1.0-candidate
djrtwo Oct 7, 2020
d3d9bbd
add note about coming gs v1.1 params
djrtwo Oct 7, 2020
d0cf4e7
Simplify fork choice spec
ralexstokes Oct 7, 2020
663af77
Clean up unused variable for linter
ralexstokes Oct 8, 2020
d0fd65c
Merge pull request #2091 from ethereum/gs-v1.1
djrtwo Oct 8, 2020
91deacb
double eth1data params
djrtwo Oct 8, 2020
a64ae81
Merge pull request #2093 from ethereum/eth1data-params
djrtwo Oct 8, 2020
427c7bb
fix minor typo in validator guide
djrtwo Oct 8, 2020
8fa3efe
Update simple-serialize.md
Oct 8, 2020
ddfb74c
Merge pull request #2095 from ethereum/val-typo
protolambda Oct 8, 2020
0f2fcac
Merge pull request #2096 from androolloyd/master
djrtwo Oct 12, 2020
d6ccbd5
Fix typo, `messages` -> `message`
hwwhww Oct 13, 2020
1782983
Merge pull request #2099 from ethereum/fix_bls_testgen_typo
djrtwo Oct 13, 2020
a61c56a
add a few rewards tests for duplicate style attestations
djrtwo Oct 13, 2020
032a933
Merge pull request #2102 from ethereum/add-rewards-tests
djrtwo Oct 14, 2020
c17a95a
add note about how slashings and exits can interact. add test
djrtwo Oct 14, 2020
aab58e4
update sanity generators to generate the oepration block tests as well
djrtwo Oct 14, 2020
7fb9226
Make `state_transition` not return post state; the given pre state sh…
hwwhww Oct 15, 2020
f1e4b3c
Refactor shard_state_transition
hwwhww Oct 15, 2020
a34970f
move op tests to test_blocks
djrtwo Oct 16, 2020
2c337d6
Merge pull request #2103 from ethereum/slash-exit
djrtwo Oct 16, 2020
73cd1a8
added best practices section according to https://github.com/ethereum…
alonmuroch Oct 20, 2020
fe5e2f6
table of content
alonmuroch Oct 20, 2020
f7a9493
multi-op tests
djrtwo Oct 20, 2020
0835c78
Apply suggestions from Dankrad's code review
alonmuroch Oct 27, 2020
b356f52
ensure aggregate attestation's slot and target are consistent
djrtwo Oct 28, 2020
b1c2a20
Merge pull request #2115 from ethereum/agg-target-validation
protolambda Oct 29, 2020
bdd1077
Merge pull request #2110 from ethereum/multi-op-tests
djrtwo Nov 2, 2020
bfaef68
Merge pull request #2092 from ethereum/ralexstokes-patch-1
djrtwo Nov 3, 2020
6b44f63
Merge pull request #2104 from ethereum/state_transition_patch
djrtwo Nov 3, 2020
a8c1d21
add attestation test for off by one committee index
djrtwo Nov 3, 2020
276ca6d
pr feedback
djrtwo Nov 3, 2020
a3e023a
Merge pull request #2119 from ethereum/att-test
protolambda Nov 3, 2020
c4ccdc9
Merge branch 'dev' into v1.0-candidate
djrtwo Nov 3, 2020
15270b7
bump VERSION.txt to 1.0.0
djrtwo Nov 3, 2020
0d8d9e7
Merge pull request #2120 from ethereum/bump-version
djrtwo Nov 3, 2020
82cdbba
Increase mesh degree
AgeManning Nov 4, 2020
cfc91cd
Merge pull request #2121 from AgeManning/gossipsub-mesh
djrtwo Nov 4, 2020
5b95219
Apply suggestions from code review
alonmuroch Nov 4, 2020
6996a89
Apply suggestions from code review
alonmuroch Nov 4, 2020
2aa827c
Merge pull request #2107 from bloxapp/honest_val_time_attack
djrtwo Nov 4, 2020
cd7b105
add mainnet deposit contract address and min genesis time
djrtwo Nov 4, 2020
7589af8
remove wip notice on phase 0 specs
djrtwo Nov 4, 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
18 changes: 8 additions & 10 deletions configs/mainnet/phase0.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Mainnet preset
# Note: the intention of this file (for now) is to illustrate what a mainnet configuration could look like.
# Some of these constants may still change before the launch of Phase 0.

CONFIG_NAME: "mainnet"

Expand Down Expand Up @@ -28,8 +26,6 @@ HYSTERESIS_QUOTIENT: 4
HYSTERESIS_DOWNWARD_MULTIPLIER: 1
# 5 (plus 1.25)
HYSTERESIS_UPWARD_MULTIPLIER: 5
# 3
PROPORTIONAL_SLASHING_MULTIPLIER: 3


# Fork Choice
Expand Down Expand Up @@ -82,8 +78,8 @@ BLS_WITHDRAWAL_PREFIX: 0x00

# Time parameters
# ---------------------------------------------------------------
# 172800 seconds (2 days)
GENESIS_DELAY: 172800
# 604800 seconds (7 days)
GENESIS_DELAY: 604800
# 12 seconds
SECONDS_PER_SLOT: 12
# 2**0 (= 1) slots 12 seconds
Expand Down Expand Up @@ -126,10 +122,12 @@ BASE_REWARD_FACTOR: 64
WHISTLEBLOWER_REWARD_QUOTIENT: 512
# 2**3 (= 8)
PROPOSER_REWARD_QUOTIENT: 8
# 2**24 (= 16,777,216)
INACTIVITY_PENALTY_QUOTIENT: 16777216
# 2**5 (= 32)
MIN_SLASHING_PENALTY_QUOTIENT: 32
# 2**26 (= 67,108,864)
INACTIVITY_PENALTY_QUOTIENT: 67108864
# 2**7 (= 128) (lower safety margin at Phase 0 genesis)
MIN_SLASHING_PENALTY_QUOTIENT: 128
# 1 (lower safety margin at Phase 0 genesis)
PROPORTIONAL_SLASHING_MULTIPLIER: 1


# Max operations per block
Expand Down
12 changes: 6 additions & 6 deletions configs/minimal/phase0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ HYSTERESIS_QUOTIENT: 4
HYSTERESIS_DOWNWARD_MULTIPLIER: 1
# 5 (plus 1.25)
HYSTERESIS_UPWARD_MULTIPLIER: 5
# 3
PROPORTIONAL_SLASHING_MULTIPLIER: 3


# Fork Choice
Expand Down Expand Up @@ -125,10 +123,12 @@ BASE_REWARD_FACTOR: 64
WHISTLEBLOWER_REWARD_QUOTIENT: 512
# 2**3 (= 8)
PROPOSER_REWARD_QUOTIENT: 8
# 2**24 (= 16,777,216)
INACTIVITY_PENALTY_QUOTIENT: 16777216
# 2**5 (= 32)
MIN_SLASHING_PENALTY_QUOTIENT: 32
# [customized] 2**25 (= 33,554,432)
INACTIVITY_PENALTY_QUOTIENT: 33554432
# [customized] 2**6 (= 64)
MIN_SLASHING_PENALTY_QUOTIENT: 64
# [customized] 2 (lower safety margin than Phase 0 genesis but different than mainnet config for testing)
PROPORTIONAL_SLASHING_MULTIPLIER: 2


# Max operations per block
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,8 @@ def run(self):
"eth-utils>=1.3.0,<2",
"eth-typing>=2.1.0,<3.0.0",
"pycryptodome==3.9.4",
"py_ecc==4.0.0",
"milagro_bls_binding==1.3.0",
"py_ecc==5.0.0",
"milagro_bls_binding==1.5.0",
"dataclasses==0.6",
"remerkleable==0.1.17",
"ruamel.yaml==0.16.5",
Expand Down
14 changes: 8 additions & 6 deletions specs/phase0/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ The following values are (non-configurable) constants used throughout the specif
| `HYSTERESIS_QUOTIENT` | `uint64(4)` |
| `HYSTERESIS_DOWNWARD_MULTIPLIER` | `uint64(1)` |
| `HYSTERESIS_UPWARD_MULTIPLIER` | `uint64(5)` |
| `PROPORTIONAL_SLASHING_MULTIPLIER` | `uint64(3)` |

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

Expand All @@ -219,7 +218,7 @@ The following values are (non-configurable) constants used throughout the specif

| Name | Value | Unit | Duration |
| - | - | :-: | :-: |
| `GENESIS_DELAY` | `uint64(172800)` | seconds | 2 days |
| `GENESIS_DELAY` | `uint64(604800)` | seconds | 7 days |
| `SECONDS_PER_SLOT` | `uint64(12)` | seconds | 12 seconds |
| `SECONDS_PER_ETH1_BLOCK` | `uint64(14)` | seconds | 14 seconds |
| `MIN_ATTESTATION_INCLUSION_DELAY` | `uint64(2**0)` (= 1) | slots | 12 seconds |
Expand Down Expand Up @@ -248,10 +247,13 @@ The following values are (non-configurable) constants used throughout the specif
| `BASE_REWARD_FACTOR` | `uint64(2**6)` (= 64) |
| `WHISTLEBLOWER_REWARD_QUOTIENT` | `uint64(2**9)` (= 512) |
| `PROPOSER_REWARD_QUOTIENT` | `uint64(2**3)` (= 8) |
| `INACTIVITY_PENALTY_QUOTIENT` | `uint64(2**24)` (= 16,777,216) |
| `MIN_SLASHING_PENALTY_QUOTIENT` | `uint64(2**5)` (= 32) |
| `INACTIVITY_PENALTY_QUOTIENT` | `uint64(2**26)` (= 67,108,864) |
| `MIN_SLASHING_PENALTY_QUOTIENT` | `uint64(2**7)` (=128) |
| `PROPORTIONAL_SLASHING_MULTIPLIER` | `uint64(1)` |

- 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**13` epochs (about 36 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)`. Note this value will be upgraded to `2**24` after Phase 0 mainnet stabilizes to provide a faster recovery in the event of an inactivity leak.

- The `PROPORTIONAL_SLASHING_MULTIPLIER` is set to `1` at initial mainnet launch, resulting in one-third of the minimum accountable safety margin in the event of a finality attack. After Phase 0 mainnet stablizes, this value will be upgraded to `3` to provide the maximal minimum accoutable safety margin.

### Max operations per block

Expand Down Expand Up @@ -603,7 +605,7 @@ def bytes_to_uint64(data: bytes) -> uint64:

#### BLS Signatures

Eth2 makes use of BLS signatures as specified in the [IETF draft BLS specification draft-irtf-cfrg-bls-signature-03](https://tools.ietf.org/html/draft-irtf-cfrg-bls-signature-03). Specifically, eth2 uses the `BLS_SIG_BLS12381G2_XMD:SHA-256_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-04](https://tools.ietf.org/html/draft-irtf-cfrg-bls-signature-04). 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`
Expand Down
4 changes: 2 additions & 2 deletions specs/phase0/p2p-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ and MUST support serving requests of blocks up to their own `head_block_root`.

Clients MUST respond with at least the first block that exists in the range, if they have it, and no more than `MAX_REQUEST_BLOCKS` blocks.

The following blocks, where they exist, MUST be send in consecutive order.
The following blocks, where they exist, MUST be sent in consecutive order.

Clients MAY limit the number of blocks in the response.

Expand Down Expand Up @@ -1444,7 +1444,7 @@ ENRs contain `fork_digest` which utilizes the `genesis_validators_root` for a cl
so prior to knowing genesis, we cannot use `fork_digest` to cleanly find peers on our intended chain.
Once genesis data is known, we can then form ENRs and safely find peers.

When using an eth1 deposit contract for deposits, `fork_digest` will be known `GENESIS_DELAY` (48hours in mainnet configuration) before `genesis_time`,
When using an eth1 deposit contract for deposits, `fork_digest` will be known `GENESIS_DELAY` (7 days in mainnet configuration) before `genesis_time`,
providing ample time to find peers and form initial connections and gossip subnets prior to genesis.

## Compression/Encoding
Expand Down
4 changes: 2 additions & 2 deletions specs/phase0/weak-subjectivity.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def compute_weak_subjectivity_period(state: BeaconState) -> uint64:
weak_subjectivity_period = MIN_VALIDATOR_WITHDRAWABILITY_DELAY
validator_count = len(get_active_validator_indices(state, get_current_epoch(state)))
if validator_count >= MIN_PER_EPOCH_CHURN_LIMIT * CHURN_LIMIT_QUOTIENT:
weak_subjectivity_period += SAFETY_DECAY * CHURN_LIMIT_QUOTIENT / (2 * 100)
weak_subjectivity_period += SAFETY_DECAY * CHURN_LIMIT_QUOTIENT // (2 * 100)
else:
weak_subjectivity_period += SAFETY_DECAY * validator_count / (2 * 100 * MIN_PER_EPOCH_CHURN_LIMIT)
weak_subjectivity_period += SAFETY_DECAY * validator_count // (2 * 100 * MIN_PER_EPOCH_CHURN_LIMIT)
return weak_subjectivity_period
```

Expand Down
2 changes: 1 addition & 1 deletion specs/phase1/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**


- [Introduction](#introduction)
- [Custom types](#custom-types)
Expand Down
26 changes: 9 additions & 17 deletions specs/phase1/phase1-fork.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*

- [Ethereum 2.0 Phase 1 -- From Phase 0 to Phase 1](#ethereum-20-phase-1----from-phase-0-to-phase-1)
- [Table of contents](#table-of-contents)
- [Introduction](#introduction)
- [Configuration](#configuration)
- [Fork to Phase 1](#fork-to-phase-1)
- [Fork trigger](#fork-trigger)
- [Upgrading the state](#upgrading-the-state)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

# Ethereum 2.0 Phase 1 -- From Phase 0 to Phase 1

**Notice**: This document is a work-in-progress for researchers and implementers.

## Table of contents

<!-- TOC -->
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

TODO

<!-- /TOC -->
- [Introduction](#introduction)
- [Configuration](#configuration)
- [Fork to Phase 1](#fork-to-phase-1)
- [Fork trigger](#fork-trigger)
- [Upgrading the state](#upgrading-the-state)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Introduction

Expand Down
2 changes: 1 addition & 1 deletion specs/phase1/shard-transition.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*


- [Introduction](#introduction)
- [Helper functions](#helper-functions)
Expand Down
62 changes: 52 additions & 10 deletions tests/core/pyspec/eth2spec/test/helpers/deposits.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from random import Random

from eth2spec.test.helpers.keys import pubkeys, privkeys
from eth2spec.utils import bls
from eth2spec.utils.merkle_minimal import calc_merkle_tree_from_leaves, get_merkle_proof
Expand Down Expand Up @@ -62,29 +64,69 @@ def deposit_from_context(spec, deposit_data_list, index):
return deposit, root, deposit_data_list


def prepare_genesis_deposits(spec, genesis_validator_count, amount, signed=False, deposit_data_list=None):
def prepare_full_genesis_deposits(spec,
amount,
deposit_count,
min_pubkey_index=0,
signed=False,
deposit_data_list=None):
if deposit_data_list is None:
deposit_data_list = []
genesis_deposits = []
for validator_index in range(genesis_validator_count):
pubkey = pubkeys[validator_index]
privkey = privkeys[validator_index]
for pubkey_index in range(min_pubkey_index, min_pubkey_index + deposit_count):
pubkey = pubkeys[pubkey_index]
privkey = privkeys[pubkey_index]
# insecurely use pubkey as withdrawal key if no credentials provided
withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(pubkey)[1:]
deposit, root, deposit_data_list = build_deposit(
spec,
deposit_data_list,
pubkey,
privkey,
amount,
withdrawal_credentials,
signed,
deposit_data_list=deposit_data_list,
pubkey=pubkey,
privkey=privkey,
amount=amount,
withdrawal_credentials=withdrawal_credentials,
signed=signed,
)
genesis_deposits.append(deposit)

return genesis_deposits, root, deposit_data_list


def prepare_random_genesis_deposits(spec,
deposit_count,
max_pubkey_index,
min_pubkey_index=0,
max_amount=None,
min_amount=None,
deposit_data_list=None,
rng=Random(3131)):
if max_amount is None:
max_amount = spec.MAX_EFFECTIVE_BALANCE
if min_amount is None:
min_amount = spec.MIN_DEPOSIT_AMOUNT
if deposit_data_list is None:
deposit_data_list = []
deposits = []
for _ in range(deposit_count):
pubkey_index = rng.randint(min_pubkey_index, max_pubkey_index)
pubkey = pubkeys[pubkey_index]
privkey = privkeys[pubkey_index]
amount = rng.randint(min_amount, max_amount)
random_byte = bytes([rng.randint(0, 255)])
withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(random_byte)[1:]
deposit, root, deposit_data_list = build_deposit(
spec,
deposit_data_list=deposit_data_list,
pubkey=pubkey,
privkey=privkey,
amount=amount,
withdrawal_credentials=withdrawal_credentials,
signed=True,
)
deposits.append(deposit)
return deposits, root, deposit_data_list


def prepare_state_and_deposit(spec, state, validator_index, amount, withdrawal_credentials=None, signed=False):
"""
Prepare the state for the deposit, and create a deposit for the given validator, depositing the given amount.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ def slash_validators(spec, state, indices, out_epochs):
@with_all_phases
@spec_state_test
def test_max_penalties(spec, state):
slashed_count = (len(state.validators) // 3) + 1
# Slashed count to ensure that enough validators are slashed to induce maximum penalties
slashed_count = min(
(len(state.validators) // spec.PROPORTIONAL_SLASHING_MULTIPLIER) + 1,
# Can't slash more than validator count!
len(state.validators)
)
out_epoch = spec.get_current_epoch(state) + (spec.EPOCHS_PER_SLASHINGS_VECTOR // 2)

slashed_indices = list(range(slashed_count))
Expand All @@ -35,7 +40,7 @@ def test_max_penalties(spec, state):
total_balance = spec.get_total_active_balance(state)
total_penalties = sum(state.slashings)

assert total_balance // 3 <= total_penalties
assert total_balance // spec.PROPORTIONAL_SLASHING_MULTIPLIER <= total_penalties

yield from run_process_slashings(spec, state)

Expand Down Expand Up @@ -91,12 +96,12 @@ def test_scaled_penalties(spec, state):
state.slashings[5] = base + (incr * 6)
state.slashings[spec.EPOCHS_PER_SLASHINGS_VECTOR - 1] = base + (incr * 7)

slashed_count = len(state.validators) // 4
slashed_count = len(state.validators) // (spec.PROPORTIONAL_SLASHING_MULTIPLIER + 1)

assert slashed_count > 10

# make the balances non-uniform.
# Otherwise it would just be a simple 3/4 balance slashing. Test the per-validator scaled penalties.
# Otherwise it would just be a simple balance slashing. Test the per-validator scaled penalties.
diff = spec.MAX_EFFECTIVE_BALANCE - base
increments = diff // incr
for i in range(10):
Expand Down Expand Up @@ -129,7 +134,7 @@ def test_scaled_penalties(spec, state):
v = state.validators[i]
expected_penalty = (
v.effective_balance // spec.EFFECTIVE_BALANCE_INCREMENT
* (3 * total_penalties)
* (spec.PROPORTIONAL_SLASHING_MULTIPLIER * total_penalties)
// (total_balance)
* spec.EFFECTIVE_BALANCE_INCREMENT
)
Expand Down
Loading