Merge branch 'devel' of github.com:status-im/nim-beacon-chain into devel

This commit is contained in:
Ștefan Talpalaru 2020-01-30 22:54:01 +01:00
commit 5be8a66d53
No known key found for this signature in database
GPG Key ID: CBF7934204F1B6F9
8 changed files with 52 additions and 42 deletions

View File

@ -47,27 +47,20 @@ func decrease_balance*(
else:
state.balances[index] - delta
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.4/specs/core/0_beacon-chain.md#deposits
func process_deposit*(
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#deposits
proc process_deposit*(
state: var BeaconState, deposit: Deposit, flags: UpdateFlags = {}): bool {.nbench.}=
# Process an Eth1 deposit, registering a validator or increasing its balance.
# Verify the Merkle branch
# TODO enable this check, but don't use doAssert
if not is_valid_merkle_branch(
hash_tree_root(deposit.getDepositMessage),
if skipValidation notin flags and not is_valid_merkle_branch(
hash_tree_root(deposit.data),
deposit.proof,
DEPOSIT_CONTRACT_TREE_DEPTH,
DEPOSIT_CONTRACT_TREE_DEPTH + 1,
state.eth1_deposit_index,
state.eth1_data.deposit_root,
):
## TODO: a notice-like mechanism which works in a func
## here and elsewhere, one minimal approach is a check-if-true
## and return false iff so.
## obviously, better/more principled ones exist, but
## generally require broader rearchitecting, and this is what
## mostly happens now, just haphazardly.
discard
return false
# Deposits must be processed in order
state.eth1_deposit_index += 1

View File

@ -1,5 +1,5 @@
# beacon_chain
# Copyright (c) 2019 Status Research & Development GmbH
# Copyright (c) 2019-2020 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@ -78,7 +78,8 @@ cli do(slots = SLOTS_PER_EPOCH * 6,
let
genesisState =
initialize_beacon_state_from_eth1(Eth2Digest(), 0, deposits, flags)
initialize_beacon_state_from_eth1(
Eth2Digest(), 0, deposits, {skipValidation})
genesisBlock = get_initial_beacon_block(genesisState)
echo "Starting simulation..."

View File

@ -66,18 +66,27 @@ template runTest(testName: string, identifier: untyped) =
`testImpl _ operations_attestations _ identifier`()
suite "Official - Operations - Attestations " & preset():
runTest("success", success)
runTest("success previous epoch", success_previous_epoch)
runTest("invalid attestation signature", invalid_attestation_signature)
runTest("before inclusion delay", before_inclusion_delay)
# https://github.com/ethereum/eth2.0-spec-tests/tree/v0.10.1/tests/minimal/phase0/operations/attestation/pyspec_tests
# https://github.com/ethereum/eth2.0-spec-tests/tree/v0.10.1/tests/mainnet/phase0/operations/attestation/pyspec_tests
runTest("after_epoch_slots", after_epoch_slots)
runTest("bad source root", bad_source_root)
runTest("before inclusion delay", before_inclusion_delay)
runTest("empty aggregation bits", empty_aggregation_bits)
runTest("future target epoch", future_target_epoch)
runTest("invalid attestation signature", invalid_attestation_signature)
runTest("invalid current source root", invalid_current_source_root)
runTest("invalid index", invalid_index)
runTest("mismatched target and slot", mismatched_target_and_slot)
runTest("new source epoch", new_source_epoch)
runTest("old source epoch", old_source_epoch)
runTest("old target epoch", old_target_epoch)
runTest("future target epoch", future_target_epoch)
runTest("new source epoch", new_source_epoch)
runTest("source root is target root", source_root_is_target_root)
runTest("invalid current source root", invalid_current_source_root)
runTest("bad source root", bad_source_root)
runTest("empty aggregation bits", empty_aggregation_bits)
runTest("too many aggregation bits", too_many_aggregation_bits)
runTest("success", success)
runTest("success multi-proposer index interations",
success_multi_proposer_index_iterations)
runTest("success previous epoch", success_previous_epoch)
runTest("too few aggregation bits", too_few_aggregation_bits)
runTest("too many aggregation bits", too_many_aggregation_bits)
runTest("wrong index for committee signature",
wrong_index_for_committee_signature)
runTest("wrong index for slot", wrong_index_for_slot)

View File

@ -66,13 +66,15 @@ template runTest(identifier: untyped) =
`testImpl_proposer_slashing _ identifier`()
suite "Official - Operations - Proposer slashing " & preset():
runTest(success)
runTest(invalid_sig_1)
runTest(invalid_sig_2)
runTest(invalid_sig_1_and_2)
runTest(invalid_proposer_index)
# https://github.com/ethereum/eth2.0-spec-tests/tree/v0.10.1/tests/minimal/phase0/operations/proposer_slashing/pyspec_tests
# https://github.com/ethereum/eth2.0-spec-tests/tree/v0.10.1/tests/mainnet/phase0/operations/proposer_slashing/pyspec_tests
runTest(epochs_are_different)
runTest(headers_are_same)
runTest(invalid_proposer_index)
runTest(invalid_sig_1)
runTest(invalid_sig_1_and_2)
runTest(invalid_sig_2)
runTest(proposer_is_not_activated)
runTest(proposer_is_slashed)
runTest(proposer_is_withdrawn)
runTest(success)

View File

@ -64,16 +64,18 @@ template runTest(identifier: untyped) =
`testImpl _ voluntary_exit _ identifier`()
suite "Official - Operations - Voluntary exit " & preset():
# https://github.com/ethereum/eth2.0-spec-tests/tree/v0.10.1/tests/minimal/phase0/operations/voluntary_exit/pyspec_tests
# https://github.com/ethereum/eth2.0-spec-tests/tree/v0.10.1/tests/mainnet/phase0/operations/voluntary_exit/pyspec_tests
runTest(success)
when false:
# TODO not sure how this particularly could falsely succeed
runTest(invalid_signature)
runTest(validator_invalid_validator_index)
runTest(validator_already_exited)
runTest(success_exit_queue)
runTest(validator_exit_in_future)
runTest(validator_invalid_validator_index)
runTest(validator_not_active)
runTest(validator_already_exited)
runTest(default_exit_epoch_subsequent_exit)
runTest(validator_not_active_long_enough)
runTest(validator_not_active)

View File

@ -47,6 +47,8 @@ template runTest(testName: string, identifier: untyped, num_slots: uint64): unty
# ---------------------------------------------------------------
suite "Official - Sanity - Slots " & preset():
# https://github.com/ethereum/eth2.0-spec-tests/tree/v0.10.1/tests/minimal/phase0/sanity/slots/pyspec_tests
# https://github.com/ethereum/eth2.0-spec-tests/tree/v0.10.1/tests/mainnet/phase0/sanity/slots/pyspec_tests
runTest("Advance 1 slot", slots_1, 1)
runTest("Advance 2 slots", slots_2, 2)
runTest("Advance an empty epoch", empty_epoch, SLOTS_PER_EPOCH)

View File

@ -1,5 +1,5 @@
# beacon_chain
# Copyright (c) 2018 Status Research & Development GmbH
# Copyright (c) 2018-2020 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@ -10,11 +10,12 @@
import
times, unittest,
./testutil, ./testblockutil,
../beacon_chain/spec/[beaconstate, datatypes, digest]
../beacon_chain/spec/[beaconstate, datatypes, digest],
../beacon_chain/extras
suite "Beacon state" & preset():
timedTest "Smoke test initialize_beacon_state_from_eth1" & preset():
let state = initialize_beacon_state_from_eth1(
Eth2Digest(), 0,
makeInitialDeposits(SLOTS_PER_EPOCH, {}), {})
makeInitialDeposits(SLOTS_PER_EPOCH, {}), {skipValidation})
check: state.validators.len == SLOTS_PER_EPOCH

View File

@ -1,5 +1,5 @@
# beacon_chain
# Copyright (c) 2018 Status Research & Development GmbH
# Copyright (c) 2018-2020 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@ -11,7 +11,7 @@ import
unittest,
./testutil, ./testblockutil,
../beacon_chain/spec/[beaconstate, datatypes, digest, validator],
../beacon_chain/[state_transition, ssz]
../beacon_chain/[extras, state_transition, ssz]
suite "Block processing" & preset():
## For now just test that we can compile and execute block processing with
@ -22,7 +22,7 @@ suite "Block processing" & preset():
# TODO bls verification is a bit of a bottleneck here
genesisState = initialize_beacon_state_from_eth1(
Eth2Digest(), 0,
makeInitialDeposits(), {})
makeInitialDeposits(), {skipValidation})
genesisBlock = get_initial_beacon_block(genesisState)
genesisRoot = hash_tree_root(genesisBlock.message)