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

256-bit custody atoms for better alignment with rest of the spec and greater efficiency #1705

Merged
merged 53 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
ca6af0c
256-bit custody atoms for better alignment with rest of the spec and …
dankrad Apr 5, 2020
bf34fdf
Fix ToC
dankrad Apr 5, 2020
c3c24b4
Fix lint
dankrad Apr 5, 2020
907c56d
Fix ToC
dankrad Apr 5, 2020
ab2ee0e
Restoring chunk challenges and testing
dankrad Apr 24, 2020
2449db1
Phase 1 block tests are working
dankrad Apr 27, 2020
0e2931b
All tests passed
dankrad Apr 28, 2020
d58d762
Fix toc
dankrad Apr 30, 2020
d30f11a
Fix lint
dankrad Apr 30, 2020
b82496f
Rename file
dankrad Apr 30, 2020
964bf42
Fix type
dankrad Apr 30, 2020
ee4c866
Merge branch 'dev' into dankrad-custody-256bit-merging
hwwhww May 5, 2020
f4334d1
Delete outdated helper
hwwhww May 5, 2020
3851a26
add phase 1 custody objects to custody-game.md
djrtwo May 19, 2020
3f0e58a
add chunk challenge and response to block and operations
djrtwo May 19, 2020
7fc9dbf
clarify comment for ShardTransition.shard_data_roots
djrtwo May 19, 2020
1623086
make get_validator_from_deposit for better code reuse across phase 0 …
djrtwo May 19, 2020
7894754
add process_challenge_deadlines to process_epoch
djrtwo May 19, 2020
de03ebb
many custody game formatting cleanups
djrtwo May 19, 2020
3a4db69
Merge branch 'dev' into dankrad-custody-256bit
djrtwo May 31, 2020
d6435d0
Merge branch 'dev' into dankrad-custody-256bit
djrtwo Jun 2, 2020
41cfa7f
Merge branch 'dev' into dankrad-custody-256bit
hwwhww Jun 8, 2020
e46d5ef
Add test for slashing after failing to respond to custody chunk chall…
dankrad Jun 10, 2020
bcfaa1b
Fix tests
dankrad Jun 12, 2020
7c6280a
Update specs/phase1/custody-game.md
dankrad Jun 12, 2020
31654d8
Update specs/phase1/custody-game.md
dankrad Jun 12, 2020
d41b6a5
Update specs/phase1/custody-game.md
dankrad Jun 12, 2020
0e8bba2
Update specs/phase1/custody-game.md
dankrad Jun 12, 2020
7bf491d
Update specs/phase1/custody-game.md
dankrad Jun 12, 2020
65c3417
Fix replace_empty_or_append, remove assert False & test
dankrad Jun 12, 2020
59b35af
Refactor universal hash function
dankrad Jun 12, 2020
398fc83
Fix TOC
dankrad Jun 12, 2020
29c1569
Merge branch 'dev' into dankrad-custody-256bit
dankrad Jun 12, 2020
04fb992
Remove custody bits from phase 1 and tests
dankrad Jun 12, 2020
f857dbf
Custody tests
dankrad Jun 12, 2020
42a9f1a
Fix Legendre bit computations
dankrad Jun 12, 2020
f6d7dac
Change to 2**14 epoch (73 day) custody periods as per #1888
dankrad Jun 13, 2020
e80f672
Merge branch 'dev' into dankrad-custody-256bit
hwwhww Jun 15, 2020
8697b30
Fix configuration
hwwhww Jun 15, 2020
97d50b3
minor fixes in config comments
djrtwo Jun 15, 2020
01a6928
custody 0.01 testing cleanup
djrtwo Jun 15, 2020
a0175ca
Merge branch 'dankrad-custody-256bit' into dankrad-custody-0.01bit
djrtwo Jun 16, 2020
eec323c
Merge pull request #1889 from ethereum/dankrad-custody-0.01bit
djrtwo Jun 16, 2020
1135631
Updated .gitignore
dankrad Jun 16, 2020
2dee432
Refactor getting Merkle root of data part of ByteList
dankrad Jun 16, 2020
a4c2950
Phase 1 validator guide stub. This is to start collecting important d…
dankrad Jun 16, 2020
8186594
Rename to get_sample_shard_transition
dankrad Jun 16, 2020
4b8b3f2
Update specs/phase1/custody-game.md
dankrad Jun 16, 2020
4bc849b
Update specs/phase1/custody-game.md
dankrad Jun 16, 2020
df1a932
Rename misleading variable all_secrets_are_revealed
dankrad Jun 16, 2020
5e5a951
Fix conflicts
hwwhww Jun 16, 2020
58935c1
Move constant
dankrad Jun 16, 2020
e6e694f
Fix toc
dankrad Jun 16, 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
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,13 @@ tests/core/pyspec/test-reports
tests/core/pyspec/eth2spec/test_results.xml

*.egg-info

# flake8 config
tox.ini

# VS code files
.vscode
*.code-workspace

# npm (for doctoc)
package-lock.json
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pyspec:

# installs the packages to run pyspec tests
install_test:
python3 -m venv venv; . venv/bin/activate; pip3 install .[test] .[lint]
python3.8 -m venv venv; . venv/bin/activate; pip3 install .[lint]; pip3 install -e .[test]

test: pyspec
. venv/bin/activate; cd $(PY_SPEC_DIR); \
Expand Down Expand Up @@ -101,7 +101,7 @@ codespell:

lint: pyspec
. venv/bin/activate; cd $(PY_SPEC_DIR); \
flake8 --ignore=E252,W504,W503 --max-line-length=120 ./eth2spec \
flake8 --ignore=E252,W504,W503,E128,C901 --max-line-length=120 ./eth2spec \
&& cd ./eth2spec && mypy --follow-imports=silent --warn-unused-ignores --ignore-missing-imports --check-untyped-defs --disallow-incomplete-defs --disallow-untyped-defs -p phase0 \
&& mypy --follow-imports=silent --warn-unused-ignores --ignore-missing-imports --check-untyped-defs --disallow-incomplete-defs --disallow-untyped-defs -p phase1;

Expand Down
37 changes: 32 additions & 5 deletions configs/mainnet/phase1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ TARGET_SHARD_BLOCK_SIZE: 262144
SHARD_BLOCK_OFFSETS: [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233]
# len(SHARD_BLOCK_OFFSETS)
MAX_SHARD_BLOCKS_PER_ATTESTATION: 12
# 2**12 (= 4,096)
BYTES_PER_CUSTODY_CHUNK: 4096
# ceillog2(MAX_SHARD_BLOCK_SIZE // BYTES_PER_CUSTODY_CHUNK)
CUSTODY_RESPONSE_DEPTH: 8

# Gwei values
# 2**14 (= 16,384) Gwei
Expand All @@ -41,10 +45,15 @@ ONLINE_PERIOD: 8
# 2**8 (= 256) | epochs
LIGHT_CLIENT_COMMITTEE_PERIOD: 256

# Max operations per block
# 2**20 (= 1,048,576)
MAX_CUSTODY_CHUNK_CHALLENGE_RECORDS: 1048576

# Domain types
DOMAIN_SHARD_PROPOSAL: 0x80000000
DOMAIN_SHARD_COMMITTEE: 0x81000000
DOMAIN_LIGHT_CLIENT: 0x82000000
# custody-game spec
DOMAIN_CUSTODY_BIT_SLASHING: 0x83000000


Expand All @@ -53,19 +62,37 @@ DOMAIN_CUSTODY_BIT_SLASHING: 0x83000000
# Time parameters
# 2**1 (= 2) epochs, 12.8 minutes
RANDAO_PENALTY_EPOCHS: 2
# 2**15 (= 32,768) epochs, ~146 days
EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS: 32768
# 2**14 (= 16,384) epochs ~73 days
EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS: 16384
# 2**11 (= 2,048) epochs, ~9 days
EPOCHS_PER_CUSTODY_PERIOD: 2048
EPOCHS_PER_CUSTODY_PERIOD: 16384
# 2**11 (= 2,048) epochs, ~9 days
CUSTODY_PERIOD_TO_RANDAO_PADDING: 2048
# 2**7 (= 128) epochs, ~14 hours
MAX_REVEAL_LATENESS_DECREMENT: 128
# 2**14 (= 16,384) epochs
CUSTODY_RESPONSE_DEADLINE: 16384
# 2**15 (= 32,768) epochs, ~146 days
MAX_CHUNK_CHALLENGE_DELAY: 32768

# Misc parameters
# 2**256 - 189
CUSTODY_PRIME: 115792089237316195423570985008687907853269984665640564039457584007913129639747
# 3
CUSTODY_SECRETS: 3
# 2**5 (= 32) bytes
BYTES_PER_CUSTODY_ATOM: 32
# 1/1024 chance of custody bit 1
CUSTODY_PROBABILITY_EXPONENT: 10

# Max operations
# 2**8 (= 256)
MAX_CUSTODY_KEY_REVEALS: 256
# 2**0 (= 1)
MAX_EARLY_DERIVED_SECRET_REVEALS: 1
# 2**2 (= 2)
MAX_CUSTODY_CHUNK_CHALLENGES: 4
# 2** 4 (= 16)
MAX_CUSTODY_CHUNK_CHALLENGE_RESP: 16
# 2**0 (= 1)
MAX_CUSTODY_SLASHINGS: 1

# Reward and penalty quotients
Expand Down
43 changes: 36 additions & 7 deletions configs/minimal/phase1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ TARGET_SHARD_BLOCK_SIZE: 262144
SHARD_BLOCK_OFFSETS: [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233]
# len(SHARD_BLOCK_OFFSETS)
MAX_SHARD_BLOCKS_PER_ATTESTATION: 12
# 2**12 (= 4,096)
BYTES_PER_CUSTODY_CHUNK: 4096
# ceillog2(MAX_SHARD_BLOCK_SIZE // BYTES_PER_CUSTODY_CHUNK)
CUSTODY_RESPONSE_DEPTH: 8

# Gwei values
# 2**14 (= 16,384) Gwei
Expand All @@ -43,10 +47,15 @@ ONLINE_PERIOD: 8
# 2**8 (= 256) | epochs
LIGHT_CLIENT_COMMITTEE_PERIOD: 256

# Max operations per block
# 2**20 (= 1,048,576)
MAX_CUSTODY_CHUNK_CHALLENGE_RECORDS: 1048576

# Domain types
DOMAIN_SHARD_PROPOSAL: 0x80000000
DOMAIN_SHARD_COMMITTEE: 0x81000000
DOMAIN_LIGHT_CLIENT: 0x82000000
# custody-game spec
DOMAIN_CUSTODY_BIT_SLASHING: 0x83000000


Expand All @@ -56,18 +65,38 @@ DOMAIN_CUSTODY_BIT_SLASHING: 0x83000000
# 2**1 (= 2) epochs
RANDAO_PENALTY_EPOCHS: 2
# [customized] quicker for testing
EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS: 4096
# 2**11 (= 2,048) epochs
EPOCHS_PER_CUSTODY_PERIOD: 2048
# 2**11 (= 2,048) epochs
CUSTODY_PERIOD_TO_RANDAO_PADDING: 2048
# 2**7 (= 128) epochs
MAX_REVEAL_LATENESS_DECREMENT: 128
EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS: 128
# [customized] quicker for testing
EPOCHS_PER_CUSTODY_PERIOD: 64
# [customized] quicker for testing
CUSTODY_PERIOD_TO_RANDAO_PADDING: 8
# [customized] quicker for testing
CUSTODY_RESPONSE_DEADLINE: 128
# [customize for faster testing]
MAX_CHUNK_CHALLENGE_DELAY: 128


# Misc parameters
# 2**256 - 189
CUSTODY_PRIME: 115792089237316195423570985008687907853269984665640564039457584007913129639747
# 3
CUSTODY_SECRETS: 3
# 2**5 (= 32) bytes
BYTES_PER_CUSTODY_ATOM: 32
# 1/4 chance of custody bit 1 [customized for faster testing]
CUSTODY_PROBABILITY_EXPONENT: 2


# Max operations
# 2**8 (= 256)
MAX_CUSTODY_KEY_REVEALS: 256
# 2**0 (= 1)
MAX_EARLY_DERIVED_SECRET_REVEALS: 1
# [customized]
MAX_CUSTODY_CHUNK_CHALLENGES: 2
# [customized]
MAX_CUSTODY_CHUNK_CHALLENGE_RESP: 8
# 2**0 (= 1)
MAX_CUSTODY_SLASHINGS: 1

# Reward and penalty quotients
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def get_spec(file_name: str) -> SpecObject:
from eth2spec.utils.ssz.ssz_impl import hash_tree_root
from eth2spec.utils.ssz.ssz_typing import (
View, boolean, Container, List, Vector, uint64, uint8, bit,
ByteList, Bytes1, Bytes4, Bytes32, Bytes48, Bytes96, Bitlist, Bitvector,
ByteList, ByteVector, Bytes1, Bytes4, Bytes32, Bytes48, Bytes96, Bitlist, Bitvector,
)
from eth2spec.utils import bls

Expand Down
26 changes: 17 additions & 9 deletions specs/phase0/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -1748,6 +1748,22 @@ def process_attestation(state: BeaconState, attestation: Attestation) -> None:

##### Deposits

```python
def get_validator_from_deposit(state: BeaconState, deposit: Deposit) -> Validator:
amount = deposit.data.amount
effective_balance = min(amount - amount % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE)

return Validator(
pubkey=deposit.data.pubkey,
withdrawal_credentials=deposit.data.withdrawal_credentials,
activation_eligibility_epoch=FAR_FUTURE_EPOCH,
activation_epoch=FAR_FUTURE_EPOCH,
exit_epoch=FAR_FUTURE_EPOCH,
withdrawable_epoch=FAR_FUTURE_EPOCH,
effective_balance=effective_balance,
)
```

```python
def process_deposit(state: BeaconState, deposit: Deposit) -> None:
# Verify the Merkle branch
Expand Down Expand Up @@ -1778,15 +1794,7 @@ def process_deposit(state: BeaconState, deposit: Deposit) -> None:
return

# Add validator and balance entries
state.validators.append(Validator(
pubkey=pubkey,
withdrawal_credentials=deposit.data.withdrawal_credentials,
activation_eligibility_epoch=FAR_FUTURE_EPOCH,
activation_epoch=FAR_FUTURE_EPOCH,
exit_epoch=FAR_FUTURE_EPOCH,
withdrawable_epoch=FAR_FUTURE_EPOCH,
effective_balance=min(amount - amount % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE),
))
state.validators.append(get_validator_from_deposit(state, deposit))
state.balances.append(amount)
else:
# Increase balance by deposit amount
Expand Down
Loading