Skip to content

Commit

Permalink
remove skipMerkleValidation and skipBlockParentRootValidation (status…
Browse files Browse the repository at this point in the history
  • Loading branch information
tersec authored Jun 18, 2020
1 parent a9c7e19 commit ee9f4a2
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
16 changes: 12 additions & 4 deletions beacon_chain/beacon_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import
# Standard library
os, tables, random, strutils, times, math,
algorithm, os, tables, random, strutils, times, math,

# Nimble packages
stew/[objects, byteutils], stew/shims/macros,
Expand Down Expand Up @@ -1005,8 +1005,10 @@ programMain:

case config.cmd
of createTestnet:
var deposits: seq[Deposit]
var i = -1
var
depositDirs: seq[string]
deposits: seq[Deposit]
i = -1
for kind, dir in walkDir(config.testnetDepositsDir.string):
if kind != pcDir:
continue
Expand All @@ -1015,6 +1017,12 @@ programMain:
if i < config.firstValidator.int:
continue

depositDirs.add dir

# Add deposits, in order, to pass Merkle validation
sort(depositDirs, system.cmp)

for dir in depositDirs:
let depositFile = dir / "deposit.json"
try:
deposits.add Json.loadFile(depositFile, Deposit)
Expand All @@ -1031,7 +1039,7 @@ programMain:
else: waitFor getLatestEth1BlockHash(config.web3Url)
var
initialState = initialize_beacon_state_from_eth1(
eth1Hash, startTime, deposits, {skipBlsValidation, skipMerkleValidation})
eth1Hash, startTime, deposits, {skipBlsValidation})

# https://github.com/ethereum/eth2.0-pm/tree/6e41fcf383ebeb5125938850d8e9b4e9888389b4/interop/mocked_start#create-genesis-state
initialState.genesis_time = startTime
Expand Down
5 changes: 0 additions & 5 deletions beacon_chain/extras.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,12 @@

type
UpdateFlag* = enum
skipMerkleValidation ##\
## When processing deposits, skip verifying the Merkle proof trees of each
## deposit.
skipBlsValidation ##\
## Skip verification of BLS signatures in block processing.
## Predominantly intended for use in testing, e.g. to allow extra coverage.
## Also useful to avoid unnecessary work when replaying known, good blocks.
skipStateRootValidation ##\
## Skip verification of block state root.
skipBlockParentRootValidation ##\
## Skip verification that the block's parent root matches the previous block header.
verifyFinalization

UpdateFlags* = set[UpdateFlag]
2 changes: 1 addition & 1 deletion beacon_chain/keystore_management.nim
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ proc generateDeposits*(totalValidators: int,
let credentials = generateCredentials(password = password)

let
keyName = $(credentials.signingKey.toPubKey)
keyName = intToStr(i, 6) & "_" & $(credentials.signingKey.toPubKey)
validatorDir = validatorsDir / keyName
passphraseFile = secretsDir / keyName
depositFile = validatorDir / depositFileName
Expand Down
4 changes: 2 additions & 2 deletions beacon_chain/spec/beaconstate.nim
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ proc process_deposit*(
# Process an Eth1 deposit, registering a validator or increasing its balance.

# Verify the Merkle branch
if skipMerkleValidation notin flags and not is_valid_merkle_branch(
if not is_valid_merkle_branch(
hash_tree_root(deposit.data),
deposit.proof,
DEPOSIT_CONTRACT_TREE_DEPTH + 1, # Add 1 for the `List` length mix-in
state.eth1_deposit_index,
state.eth1_data.deposit_root,
):
notice "Deposit merkle validation failed",
notice "Deposit Merkle validation failed",
proof = deposit.proof, deposit_root = state.eth1_data.deposit_root,
deposit_index = state.eth1_deposit_index
return false
Expand Down
3 changes: 1 addition & 2 deletions beacon_chain/spec/state_transition_block.nim
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ proc process_block_header*(
return false

# Verify that the parent matches
if skipBlockParentRootValidation notin flags and not (blck.parent_root ==
hash_tree_root(state.latest_block_header)):
if not (blck.parent_root == hash_tree_root(state.latest_block_header)):
notice "Block header: previous block root mismatch",
latest_block_header = state.latest_block_header,
blck = shortLog(blck),
Expand Down
2 changes: 1 addition & 1 deletion tests/simulation/vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ cd - &>/dev/null

# When changing these, also update the readme section on running simulation
# so that the run_node example is correct!
NUM_VALIDATORS=${VALIDATORS:-192}
NUM_VALIDATORS=${VALIDATORS:-128}
TOTAL_NODES=${NODES:-4}
TOTAL_USER_NODES=${USER_NODES:-0}
TOTAL_SYSTEM_NODES=$(( TOTAL_NODES - TOTAL_USER_NODES ))
Expand Down

0 comments on commit ee9f4a2

Please sign in to comment.