update process_deposit() to actually check is_valid_merkle_branch() unless skipValidation specified
This commit is contained in:
parent
659c24a476
commit
45dd12cf3f
|
@ -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
|
||||
|
|
|
@ -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..."
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue