reduce nim-eth dependencies just for RNG (#5099)

We have several modules that import `nim-eth` for the sole purpose of
its `keys.newRng` function. This function is meanwhile a simple wrapper
around `nim-bearssl`'s `HmacDrbgContext.new()`, so the import doesn't
really serve a use anymore. Replace `keys.newRng` with the direct call
to reduce `nim-eth` imports.
This commit is contained in:
Etan Kissling
2023-06-20 00:43:50 +02:00
committed by GitHub
parent 3dd256b686
commit 2722778ce5
27 changed files with 112 additions and 82 deletions

View File

@@ -202,7 +202,7 @@ proc main() {.async.} =
except Exception as exc: # TODO fix confutils except Exception as exc: # TODO fix confutils
raiseAssert exc.msg raiseAssert exc.msg
let rng = keys.newRng() let rng = HmacDrbgContext.new()
if conf.cmd == StartUpCommand.generateSimulationDeposits: if conf.cmd == StartUpCommand.generateSimulationDeposits:
let let

View File

@@ -8,7 +8,7 @@ import
std/os, std/os,
chronicles, chronicles,
stew/results, snappy, taskpools, stew/results, snappy, taskpools,
../ncli/e2store, eth/keys, ../ncli/e2store,
./spec/datatypes/[altair, bellatrix, phase0], ./spec/datatypes/[altair, bellatrix, phase0],
./spec/[beaconstate, forks, signatures_batch], ./spec/[beaconstate, forks, signatures_batch],
./consensus_object_pools/block_dag # TODO move to somewhere else to avoid circular deps ./consensus_object_pools/block_dag # TODO move to somewhere else to avoid circular deps
@@ -167,9 +167,9 @@ proc verify*(f: EraFile, cfg: RuntimeConfig): Result[Eth2Digest, string] =
startSlot = f.stateIdx.startSlot startSlot = f.stateIdx.startSlot
era = startSlot.era era = startSlot.era
var rng = HmacDrbgContext.new()
taskpool = Taskpool.new() taskpool = Taskpool.new()
verifier = BatchVerifier(rng: keys.newRng(), taskpool: taskpool) var verifier = BatchVerifier(rng: rng, taskpool: taskpool)
var tmp: seq[byte] var tmp: seq[byte]
? f.getStateSSZ(startSlot, tmp) ? f.getStateSSZ(startSlot, tmp)

View File

@@ -9,7 +9,6 @@
import import
chronicles, chronicles,
eth/keys,
./gossip_processing/light_client_processor, ./gossip_processing/light_client_processor,
./networking/[eth2_network, topic_params], ./networking/[eth2_network, topic_params],
./spec/datatypes/altair, ./spec/datatypes/altair,

View File

@@ -10,10 +10,10 @@
import import
std/[os, strutils], std/[os, strutils],
chronicles, stew/shims/net, stew/results, chronicles, stew/shims/net, stew/results,
eth/keys, eth/p2p/discoveryv5/[enr, protocol, node], eth/p2p/discoveryv5/[enr, protocol, node],
".."/[conf, conf_light_client] ".."/[conf, conf_light_client]
export protocol, keys export protocol
type type
Eth2DiscoveryProtocol* = protocol.Protocol Eth2DiscoveryProtocol* = protocol.Protocol

View File

@@ -13,7 +13,6 @@ import
metrics, metrics/chronos_httpserver, metrics, metrics/chronos_httpserver,
stew/[byteutils, io2], stew/[byteutils, io2],
eth/p2p/discoveryv5/[enr, random2], eth/p2p/discoveryv5/[enr, random2],
eth/keys,
./consensus_object_pools/blob_quarantine, ./consensus_object_pools/blob_quarantine,
./consensus_object_pools/vanity_logs/vanity_logs, ./consensus_object_pools/vanity_logs/vanity_logs,
./networking/topic_params, ./networking/topic_params,
@@ -2008,7 +2007,7 @@ proc doSlashingInterchange(conf: BeaconNodeConf) {.raises: [Defect, CatchableErr
proc handleStartUpCmd(config: var BeaconNodeConf) {.raises: [Defect, CatchableError].} = proc handleStartUpCmd(config: var BeaconNodeConf) {.raises: [Defect, CatchableError].} =
# Single RNG instance for the application - will be seeded on construction # Single RNG instance for the application - will be seeded on construction
# and avoid using system resources (such as urandom) after that # and avoid using system resources (such as urandom) after that
let rng = keys.newRng() let rng = HmacDrbgContext.new()
case config.cmd case config.cmd
of BNStartUpCmd.noCommand: doRunBeaconNode(config, rng) of BNStartUpCmd.noCommand: doRunBeaconNode(config, rng)

View File

@@ -8,7 +8,7 @@
import import
std/os, std/os,
chronicles, chronos, stew/io2, chronicles, chronos, stew/io2,
eth/db/kvstore_sqlite3, eth/keys, eth/db/kvstore_sqlite3,
./el/el_manager, ./el/el_manager,
./gossip_processing/optimistic_processor, ./gossip_processing/optimistic_processor,
./networking/[topic_params, network_metadata], ./networking/[topic_params, network_metadata],
@@ -79,7 +79,7 @@ programMain:
genesisBlockRoot = get_initial_beacon_block(genesisState[]).root genesisBlockRoot = get_initial_beacon_block(genesisState[]).root
rng = keys.newRng() rng = HmacDrbgContext.new()
netKeys = getRandomNetKeys(rng[]) netKeys = getRandomNetKeys(rng[])
network = createEth2Node( network = createEth2Node(
rng, config, netKeys, cfg, rng, config, netKeys, cfg,

View File

@@ -6,7 +6,6 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms. # at your option. This file may not be copied, modified, or distributed except according to those terms.
import import
stew/io2, presto, metrics, metrics/chronos_httpserver, stew/io2, presto, metrics, metrics/chronos_httpserver,
libp2p/crypto/crypto,
./rpc/rest_key_management_api, ./rpc/rest_key_management_api,
./validator_client/[ ./validator_client/[
common, fallback_service, duties_service, fork_service, block_service, common, fallback_service, duties_service, fork_service, block_service,
@@ -512,7 +511,7 @@ programMain:
# Single RNG instance for the application - will be seeded on construction # Single RNG instance for the application - will be seeded on construction
# and avoid using system resources (such as urandom) after that # and avoid using system resources (such as urandom) after that
rng = crypto.newRng() rng = HmacDrbgContext.new()
setupLogging(config.logLevel, config.logStdout, config.logFile) setupLogging(config.logLevel, config.logStdout, config.logFile)
waitFor runValidatorClient(config, rng) waitFor runValidatorClient(config, rng)

View File

@@ -11,7 +11,7 @@ import
std/[os, strutils, terminal, wordwrap, unicode], std/[os, strutils, terminal, wordwrap, unicode],
chronicles, chronos, json_serialization, zxcvbn, chronicles, chronos, json_serialization, zxcvbn,
bearssl/rand, bearssl/rand,
serialization, blscurve, eth/common/eth_types, eth/keys, confutils, serialization, blscurve, eth/common/eth_types, confutils,
nimbus_security_resources, nimbus_security_resources,
".."/spec/[eth2_merkleization, keystore, crypto], ".."/spec/[eth2_merkleization, keystore, crypto],
".."/spec/datatypes/base, ".."/spec/datatypes/base,

View File

@@ -21,7 +21,7 @@ import
chronicles, chronicles/timings, chronicles, chronicles/timings,
json_serialization/std/[options, sets, net], json_serialization/std/[options, sets, net],
eth/db/kvstore, eth/db/kvstore,
eth/keys, eth/p2p/discoveryv5/[protocol, enr], eth/p2p/discoveryv5/[protocol, enr],
web3/ethtypes, web3/ethtypes,
# Local modules # Local modules

View File

@@ -1,6 +1,13 @@
# beacon_chain
# Copyright (c) 2022-2023 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).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import import
std/os, std/os,
confutils, eth/keys, confutils,
../beacon_chain/validators/keystore_management, ../beacon_chain/validators/keystore_management,
../beacon_chain/spec/[keystore, crypto], ../beacon_chain/spec/[keystore, crypto],
../beacon_chain/conf ../beacon_chain/conf
@@ -58,9 +65,8 @@ proc main =
error "The specified treshold must be lower or equal to the number of signers" error "The specified treshold must be lower or equal to the number of signers"
quit 1 quit 1
var let rng = HmacDrbgContext.new()
rng = keys.newRng() template rngCtx: untyped = rng[]
rngCtx = rng[]
let let
validatorsDir = conf.validatorsDir validatorsDir = conf.validatorsDir

View File

@@ -523,7 +523,7 @@ proc main() {.async.} =
except Exception as exc: # TODO fix confutils except Exception as exc: # TODO fix confutils
raiseAssert exc.msg raiseAssert exc.msg
let rng = keys.newRng() let rng = HmacDrbgContext.new()
if conf.cmd == StartUpCommand.generateDeposits: if conf.cmd == StartUpCommand.generateDeposits:
let let
@@ -589,7 +589,7 @@ proc main() {.async.} =
case conf.cmd case conf.cmd
of StartUpCommand.createTestnet: of StartUpCommand.createTestnet:
let rng = keys.newRng() let rng = HmacDrbgContext.new()
doCreateTestnet(conf, rng[]) doCreateTestnet(conf, rng[])
of StartUpCommand.deployDepositContract: of StartUpCommand.deployDepositContract:

View File

@@ -16,7 +16,7 @@
import import
confutils, chronicles, eth/db/kvstore_sqlite3, confutils, chronicles, eth/db/kvstore_sqlite3,
chronos/timer, eth/keys, taskpools, chronos/timer, taskpools,
../tests/testblockutil, ../tests/testblockutil,
../beacon_chain/spec/[forks, state_transition], ../beacon_chain/spec/[forks, state_transition],
../beacon_chain/spec/datatypes/[phase0, altair, bellatrix, deneb], ../beacon_chain/spec/datatypes/[phase0, altair, bellatrix, deneb],
@@ -313,19 +313,20 @@ cli do(slots = SLOTS_PER_EPOCH * 6,
ChainDAGRef.preInit(db, genesisState[]) ChainDAGRef.preInit(db, genesisState[])
db.putDepositTreeSnapshot(depositTreeSnapshot) db.putDepositTreeSnapshot(depositTreeSnapshot)
let rng = HmacDrbgContext.new()
var var
validatorMonitor = newClone(ValidatorMonitor.init()) validatorMonitor = newClone(ValidatorMonitor.init())
dag = ChainDAGRef.init(cfg, db, validatorMonitor, {}) dag = ChainDAGRef.init(cfg, db, validatorMonitor, {})
eth1Chain = Eth1Chain.init(cfg, db, 0, default Eth2Digest) eth1Chain = Eth1Chain.init(cfg, db, 0, default Eth2Digest)
merkleizer = DepositsMerkleizer.init(depositTreeSnapshot.depositContractState) merkleizer = DepositsMerkleizer.init(depositTreeSnapshot.depositContractState)
taskpool = Taskpool.new() taskpool = Taskpool.new()
verifier = BatchVerifier(rng: keys.newRng(), taskpool: taskpool) verifier = BatchVerifier(rng: rng, taskpool: taskpool)
quarantine = newClone(Quarantine.init()) quarantine = newClone(Quarantine.init())
attPool = AttestationPool.init(dag, quarantine) attPool = AttestationPool.init(dag, quarantine)
batchCrypto = BatchCrypto.new( batchCrypto = BatchCrypto.new(
keys.newRng(), eager = func(): bool = true, rng, eager = func(): bool = true,
genesis_validators_root = dag.genesis_validators_root, taskpool) genesis_validators_root = dag.genesis_validators_root, taskpool)
syncCommitteePool = newClone SyncCommitteeMsgPool.init(keys.newRng(), cfg) syncCommitteePool = newClone SyncCommitteeMsgPool.init(rng, cfg)
timers: array[Timers, RunningStat] timers: array[Timers, RunningStat]
attesters: RunningStat attesters: RunningStat
r = initRand(1) r = initRand(1)

View File

@@ -10,7 +10,7 @@
import import
# Status libraries # Status libraries
stew/results, chronicles, stew/results, chronicles,
eth/keys, taskpools, taskpools,
# Internals # Internals
../../beacon_chain/spec/[helpers, forks, state_transition_block], ../../beacon_chain/spec/[helpers, forks, state_transition_block],
../../beacon_chain/spec/datatypes/[ ../../beacon_chain/spec/datatypes/[
@@ -348,9 +348,10 @@ proc doRunTest(path: string, fork: ConsensusFork) =
of ConsensusFork.Phase0: of ConsensusFork.Phase0:
initialLoad(path, db, phase0.BeaconState, phase0.BeaconBlock) initialLoad(path, db, phase0.BeaconState, phase0.BeaconBlock)
var let
rng = HmacDrbgContext.new()
taskpool = Taskpool.new() taskpool = Taskpool.new()
verifier = BatchVerifier(rng: keys.newRng(), taskpool: taskpool) var verifier = BatchVerifier(rng: rng, taskpool: taskpool)
let steps = loadOps(path, fork) let steps = loadOps(path, fork)
var time = stores.fkChoice.checkpoints.time var time = stores.fkChoice.checkpoints.time

View File

@@ -1,13 +1,19 @@
# beacon_chain
# Copyright (c) 2021-2023 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).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
{.used.} {.used.}
import import
unittest2, unittest2,
eth/keys,
../beacon_chain/validators/action_tracker ../beacon_chain/validators/action_tracker
suite "subnet tracker": suite "subnet tracker":
setup: setup:
let rng = keys.newRng() let rng = HmacDrbgContext.new()
test "should register stability subnets on attester duties": test "should register stability subnets on attester duties":
var tracker = ActionTracker.init(rng, false) var tracker = ActionTracker.init(rng, false)

View File

@@ -13,7 +13,7 @@ import
unittest2, unittest2,
chronicles, chronos, chronicles, chronos,
stew/byteutils, stew/byteutils,
eth/keys, taskpools, taskpools,
# Internal # Internal
../beacon_chain/gossip_processing/[gossip_validation], ../beacon_chain/gossip_processing/[gossip_validation],
../beacon_chain/fork_choice/[fork_choice_types, fork_choice], ../beacon_chain/fork_choice/[fork_choice_types, fork_choice],
@@ -58,13 +58,14 @@ suite "Attestation pool processing" & preset():
setup: setup:
# Genesis state that results in 6 members per committee # Genesis state that results in 6 members per committee
let rng = HmacDrbgContext.new()
var var
validatorMonitor = newClone(ValidatorMonitor.init()) validatorMonitor = newClone(ValidatorMonitor.init())
dag = init( dag = init(
ChainDAGRef, defaultRuntimeConfig, makeTestDB(SLOTS_PER_EPOCH * 6), ChainDAGRef, defaultRuntimeConfig, makeTestDB(SLOTS_PER_EPOCH * 6),
validatorMonitor, {}) validatorMonitor, {})
taskpool = Taskpool.new() taskpool = Taskpool.new()
verifier = BatchVerifier(rng: keys.newRng(), taskpool: taskpool) verifier = BatchVerifier(rng: rng, taskpool: taskpool)
quarantine = newClone(Quarantine.init()) quarantine = newClone(Quarantine.init())
pool = newClone(AttestationPool.init(dag, quarantine)) pool = newClone(AttestationPool.init(dag, quarantine))
state = newClone(dag.headState) state = newClone(dag.headState)

View File

@@ -11,7 +11,7 @@ import
chronos, chronos,
std/sequtils, std/sequtils,
unittest2, unittest2,
eth/keys, taskpools, taskpools,
../beacon_chain/[conf, beacon_clock], ../beacon_chain/[conf, beacon_clock],
../beacon_chain/spec/[beaconstate, forks, helpers, state_transition], ../beacon_chain/spec/[beaconstate, forks, helpers, state_transition],
../beacon_chain/spec/datatypes/deneb, ../beacon_chain/spec/datatypes/deneb,
@@ -34,12 +34,13 @@ proc pruneAtFinalization(dag: ChainDAGRef) =
suite "Block processor" & preset(): suite "Block processor" & preset():
setup: setup:
let rng = HmacDrbgContext.new()
var var
db = makeTestDB(SLOTS_PER_EPOCH) db = makeTestDB(SLOTS_PER_EPOCH)
validatorMonitor = newClone(ValidatorMonitor.init()) validatorMonitor = newClone(ValidatorMonitor.init())
dag = init(ChainDAGRef, defaultRuntimeConfig, db, validatorMonitor, {}) dag = init(ChainDAGRef, defaultRuntimeConfig, db, validatorMonitor, {})
taskpool = Taskpool.new() taskpool = Taskpool.new()
verifier = BatchVerifier(rng: keys.newRng(), taskpool: taskpool) verifier = BatchVerifier(rng: rng, taskpool: taskpool)
quarantine = newClone(Quarantine.init()) quarantine = newClone(Quarantine.init())
blobQuarantine = newClone(BlobQuarantine()) blobQuarantine = newClone(BlobQuarantine())
attestationPool = newClone(AttestationPool.init(dag, quarantine)) attestationPool = newClone(AttestationPool.init(dag, quarantine))
@@ -56,7 +57,7 @@ suite "Block processor" & preset():
b2 = addTestBlock(state[], cache).phase0Data b2 = addTestBlock(state[], cache).phase0Data
getTimeFn = proc(): BeaconTime = b2.message.slot.start_beacon_time() getTimeFn = proc(): BeaconTime = b2.message.slot.start_beacon_time()
processor = BlockProcessor.new( processor = BlockProcessor.new(
false, "", "", keys.newRng(), taskpool, consensusManager, false, "", "", rng, taskpool, consensusManager,
validatorMonitor, blobQuarantine, getTimeFn) validatorMonitor, blobQuarantine, getTimeFn)
asyncTest "Reverse order block add & get" & preset(): asyncTest "Reverse order block add & get" & preset():

View File

@@ -10,7 +10,7 @@
import import
std/[random, sequtils], std/[random, sequtils],
unittest2, unittest2,
eth/keys, taskpools, taskpools,
../beacon_chain/el/merkle_minimal, ../beacon_chain/el/merkle_minimal,
../beacon_chain/spec/datatypes/base, ../beacon_chain/spec/datatypes/base,
../beacon_chain/spec/[beaconstate, forks, helpers, signatures, state_transition], ../beacon_chain/spec/[beaconstate, forks, helpers, signatures, state_transition],
@@ -39,11 +39,12 @@ type
suite "Block pool processing" & preset(): suite "Block pool processing" & preset():
setup: setup:
let rng = HmacDrbgContext.new()
var var
db = makeTestDB(SLOTS_PER_EPOCH) db = makeTestDB(SLOTS_PER_EPOCH)
validatorMonitor = newClone(ValidatorMonitor.init()) validatorMonitor = newClone(ValidatorMonitor.init())
dag = init(ChainDAGRef, defaultRuntimeConfig, db, validatorMonitor, {}) dag = init(ChainDAGRef, defaultRuntimeConfig, db, validatorMonitor, {})
verifier = BatchVerifier(rng: keys.newRng(), taskpool: Taskpool.new()) verifier = BatchVerifier(rng: rng, taskpool: Taskpool.new())
quarantine = Quarantine.init() quarantine = Quarantine.init()
state = newClone(dag.headState) state = newClone(dag.headState)
cache = StateCache() cache = StateCache()
@@ -282,6 +283,8 @@ when declared(GC_fullCollect): # i386 test machines seem to run low..
suite "Block pool altair processing" & preset(): suite "Block pool altair processing" & preset():
setup: setup:
let rng = HmacDrbgContext.new()
var var
cfg = defaultRuntimeConfig cfg = defaultRuntimeConfig
cfg.ALTAIR_FORK_EPOCH = Epoch(1) cfg.ALTAIR_FORK_EPOCH = Epoch(1)
@@ -290,7 +293,7 @@ suite "Block pool altair processing" & preset():
db = makeTestDB(SLOTS_PER_EPOCH) db = makeTestDB(SLOTS_PER_EPOCH)
validatorMonitor = newClone(ValidatorMonitor.init()) validatorMonitor = newClone(ValidatorMonitor.init())
dag = init(ChainDAGRef, cfg, db, validatorMonitor, {}) dag = init(ChainDAGRef, cfg, db, validatorMonitor, {})
verifier = BatchVerifier(rng: keys.newRng(), taskpool: Taskpool.new()) verifier = BatchVerifier(rng: rng, taskpool: Taskpool.new())
quarantine = Quarantine.init() quarantine = Quarantine.init()
state = newClone(dag.headState) state = newClone(dag.headState)
cache = StateCache() cache = StateCache()
@@ -361,11 +364,12 @@ suite "Block pool altair processing" & preset():
suite "chain DAG finalization tests" & preset(): suite "chain DAG finalization tests" & preset():
setup: setup:
let rng = HmacDrbgContext.new()
var var
db = makeTestDB(SLOTS_PER_EPOCH) db = makeTestDB(SLOTS_PER_EPOCH)
validatorMonitor = newClone(ValidatorMonitor.init()) validatorMonitor = newClone(ValidatorMonitor.init())
dag = init(ChainDAGRef, defaultRuntimeConfig, db, validatorMonitor, {}) dag = init(ChainDAGRef, defaultRuntimeConfig, db, validatorMonitor, {})
verifier = BatchVerifier(rng: keys.newRng(), taskpool: Taskpool.new()) verifier = BatchVerifier(rng: rng, taskpool: Taskpool.new())
quarantine = Quarantine.init() quarantine = Quarantine.init()
cache = StateCache() cache = StateCache()
info = ForkedEpochInfo() info = ForkedEpochInfo()
@@ -628,13 +632,14 @@ suite "chain DAG finalization tests" & preset():
suite "Old database versions" & preset(): suite "Old database versions" & preset():
setup: setup:
let let
rng = HmacDrbgContext.new()
genState = newClone(initialize_hashed_beacon_state_from_eth1( genState = newClone(initialize_hashed_beacon_state_from_eth1(
defaultRuntimeConfig, ZERO_HASH, 0, defaultRuntimeConfig, ZERO_HASH, 0,
makeInitialDeposits(SLOTS_PER_EPOCH.uint64, flags = {skipBlsValidation}), makeInitialDeposits(SLOTS_PER_EPOCH.uint64, flags = {skipBlsValidation}),
{skipBlsValidation})) {skipBlsValidation}))
genBlock = get_initial_beacon_block(genState[]) genBlock = get_initial_beacon_block(genState[])
var var
verifier = BatchVerifier(rng: keys.newRng(), taskpool: Taskpool.new()) verifier = BatchVerifier(rng: rng, taskpool: Taskpool.new())
quarantine = Quarantine.init() quarantine = Quarantine.init()
test "pre-1.1.0": test "pre-1.1.0":
@@ -669,6 +674,8 @@ suite "Old database versions" & preset():
suite "Diverging hardforks": suite "Diverging hardforks":
setup: setup:
let rng = HmacDrbgContext.new()
var var
phase0RuntimeConfig = defaultRuntimeConfig phase0RuntimeConfig = defaultRuntimeConfig
altairRuntimeConfig = defaultRuntimeConfig altairRuntimeConfig = defaultRuntimeConfig
@@ -680,7 +687,7 @@ suite "Diverging hardforks":
db = makeTestDB(SLOTS_PER_EPOCH) db = makeTestDB(SLOTS_PER_EPOCH)
validatorMonitor = newClone(ValidatorMonitor.init()) validatorMonitor = newClone(ValidatorMonitor.init())
dag = init(ChainDAGRef, phase0RuntimeConfig, db, validatorMonitor, {}) dag = init(ChainDAGRef, phase0RuntimeConfig, db, validatorMonitor, {})
verifier = BatchVerifier(rng: keys.newRng(), taskpool: Taskpool.new()) verifier = BatchVerifier(rng: rng, taskpool: Taskpool.new())
quarantine = newClone(Quarantine.init()) quarantine = newClone(Quarantine.init())
cache = StateCache() cache = StateCache()
info = ForkedEpochInfo() info = ForkedEpochInfo()
@@ -917,9 +924,12 @@ suite "Backfill":
dag.addBackfillBlock( dag.addBackfillBlock(
genBlock.phase0Data.asSigned) == AddBackRes.err VerifierError.Duplicate genBlock.phase0Data.asSigned) == AddBackRes.err VerifierError.Duplicate
let
rng = HmacDrbgContext.new()
taskpool = Taskpool.new()
var var
cache: StateCache cache: StateCache
verifier = BatchVerifier(rng: keys.newRng(), taskpool: Taskpool.new()) verifier = BatchVerifier(rng: rng, taskpool: taskpool)
quarantine = newClone(Quarantine.init()) quarantine = newClone(Quarantine.init())
let let
@@ -1050,6 +1060,8 @@ suite "Starting states":
suite "Latest valid hash" & preset(): suite "Latest valid hash" & preset():
setup: setup:
let rng = HmacDrbgContext.new()
var runtimeConfig = defaultRuntimeConfig var runtimeConfig = defaultRuntimeConfig
runtimeConfig.ALTAIR_FORK_EPOCH = 1.Epoch runtimeConfig.ALTAIR_FORK_EPOCH = 1.Epoch
runtimeConfig.BELLATRIX_FORK_EPOCH = 2.Epoch runtimeConfig.BELLATRIX_FORK_EPOCH = 2.Epoch
@@ -1058,7 +1070,7 @@ suite "Latest valid hash" & preset():
db = makeTestDB(SLOTS_PER_EPOCH) db = makeTestDB(SLOTS_PER_EPOCH)
validatorMonitor = newClone(ValidatorMonitor.init()) validatorMonitor = newClone(ValidatorMonitor.init())
dag = init(ChainDAGRef, runtimeConfig, db, validatorMonitor, {}) dag = init(ChainDAGRef, runtimeConfig, db, validatorMonitor, {})
verifier = BatchVerifier(rng: keys.newRng(), taskpool: Taskpool.new()) verifier = BatchVerifier(rng: rng, taskpool: Taskpool.new())
quarantine = newClone(Quarantine.init()) quarantine = newClone(Quarantine.init())
cache = StateCache() cache = StateCache()
info = ForkedEpochInfo() info = ForkedEpochInfo()
@@ -1114,6 +1126,7 @@ suite "Latest valid hash" & preset():
suite "Pruning": suite "Pruning":
setup: setup:
let let
rng = HmacDrbgContext.new()
cfg = block: cfg = block:
var res = defaultRuntimeConfig var res = defaultRuntimeConfig
res.MIN_VALIDATOR_WITHDRAWABILITY_DELAY = 4 res.MIN_VALIDATOR_WITHDRAWABILITY_DELAY = 4
@@ -1126,7 +1139,7 @@ suite "Pruning":
tmpState = assignClone(dag.headState) tmpState = assignClone(dag.headState)
var var
verifier = BatchVerifier(rng: keys.newRng(), taskpool: Taskpool.new()) verifier = BatchVerifier(rng: rng, taskpool: Taskpool.new())
quarantine = Quarantine.init() quarantine = Quarantine.init()
cache = StateCache() cache = StateCache()
blocks = @[dag.head] blocks = @[dag.head]
@@ -1186,10 +1199,11 @@ suite "Shufflings":
flags = {}, cfg = cfg), flags = {}, cfg = cfg),
validatorMonitor, {}) validatorMonitor, {})
quarantine = newClone(Quarantine.init()) quarantine = newClone(Quarantine.init())
rng = HmacDrbgContext.new()
taskpool = Taskpool.new() taskpool = Taskpool.new()
var var
verifier = BatchVerifier(rng: keys.newRng(), taskpool: taskpool) verifier = BatchVerifier(rng: rng, taskpool: taskpool)
graffiti: GraffitiBytes graffiti: GraffitiBytes
proc addBlocks(blocks: uint64, attested: bool, cache: var StateCache) = proc addBlocks(blocks: uint64, attested: bool, cache: var StateCache) =
inc distinctBase(graffiti)[0] # Avoid duplicate blocks across branches inc distinctBase(graffiti)[0] # Avoid duplicate blocks across branches

View File

@@ -1,5 +1,5 @@
# beacon_chain # beacon_chain
# Copyright (c) 2021-2022 Status Research & Development GmbH # Copyright (c) 2021-2023 Status Research & Development GmbH
# Licensed and distributed under either of # Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * 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). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@@ -36,7 +36,7 @@ const noSyncnetsPreference = SyncnetBits()
procSuite "Eth2 specific discovery tests": procSuite "Eth2 specific discovery tests":
let let
rng = keys.newRng() rng = HmacDrbgContext.new()
enrForkId = ENRForkID( enrForkId = ENRForkID(
fork_digest: ForkDigest([byte 0, 1, 2, 3]), fork_digest: ForkDigest([byte 0, 1, 2, 3]),
next_fork_version: Version([byte 0, 0, 0, 0]), next_fork_version: Version([byte 0, 0, 0, 0]),

View File

@@ -13,7 +13,7 @@ import
# Status lib # Status lib
unittest2, unittest2,
chronos, chronos,
eth/keys, taskpools, taskpools,
# Internal # Internal
../beacon_chain/[beacon_clock], ../beacon_chain/[beacon_clock],
../beacon_chain/gossip_processing/[gossip_validation, batch_validation], ../beacon_chain/gossip_processing/[gossip_validation, batch_validation],
@@ -36,20 +36,21 @@ proc pruneAtFinalization(dag: ChainDAGRef, attPool: AttestationPool) =
suite "Gossip validation " & preset(): suite "Gossip validation " & preset():
setup: setup:
# Genesis state that results in 3 members per committee # Genesis state that results in 3 members per committee
let rng = HmacDrbgContext.new()
var var
validatorMonitor = newClone(ValidatorMonitor.init()) validatorMonitor = newClone(ValidatorMonitor.init())
dag = init( dag = init(
ChainDAGRef, defaultRuntimeConfig, makeTestDB(SLOTS_PER_EPOCH * 3), ChainDAGRef, defaultRuntimeConfig, makeTestDB(SLOTS_PER_EPOCH * 3),
validatorMonitor, {}) validatorMonitor, {})
taskpool = Taskpool.new() taskpool = Taskpool.new()
verifier = BatchVerifier(rng: keys.newRng(), taskpool: taskpool) verifier = BatchVerifier(rng: rng, taskpool: taskpool)
quarantine = newClone(Quarantine.init()) quarantine = newClone(Quarantine.init())
pool = newClone(AttestationPool.init(dag, quarantine)) pool = newClone(AttestationPool.init(dag, quarantine))
state = newClone(dag.headState) state = newClone(dag.headState)
cache = StateCache() cache = StateCache()
info = ForkedEpochInfo() info = ForkedEpochInfo()
batchCrypto = BatchCrypto.new( batchCrypto = BatchCrypto.new(
keys.newRng(), eager = proc(): bool = false, rng, eager = proc(): bool = false,
genesis_validators_root = dag.genesis_validators_root, taskpool) genesis_validators_root = dag.genesis_validators_root, taskpool)
# Slot 0 is a finalized slot - won't be making attestations for it.. # Slot 0 is a finalized slot - won't be making attestations for it..
check: check:
@@ -187,8 +188,9 @@ suite "Gossip validation - Extra": # Not based on preset config
cfg cfg
taskpool = Taskpool.new() taskpool = Taskpool.new()
quarantine = newClone(Quarantine.init()) quarantine = newClone(Quarantine.init())
rng = HmacDrbgContext.new()
var var
verifier = BatchVerifier(rng: keys.newRng(), taskpool: Taskpool.new()) verifier = BatchVerifier(rng: rng, taskpool: Taskpool.new())
dag = block: dag = block:
let let
validatorMonitor = newClone(ValidatorMonitor.init()) validatorMonitor = newClone(ValidatorMonitor.init())
@@ -220,7 +222,7 @@ suite "Gossip validation - Extra": # Not based on preset config
dag dag
let batchCrypto = BatchCrypto.new( let batchCrypto = BatchCrypto.new(
keys.newRng(), eager = proc(): bool = false, rng, eager = proc(): bool = false,
genesis_validators_root = dag.genesis_validators_root, taskpool) genesis_validators_root = dag.genesis_validators_root, taskpool)
var var
@@ -243,8 +245,7 @@ suite "Gossip validation - Extra": # Not based on preset config
slot, state[].latest_block_root) slot, state[].latest_block_root)
msg = resMsg.get() msg = resMsg.get()
syncCommitteePool = newClone( syncCommitteePool = newClone(SyncCommitteeMsgPool.init(rng, cfg))
SyncCommitteeMsgPool.init(keys.newRng(), cfg))
res = waitFor validateSyncCommitteeMessage( res = waitFor validateSyncCommitteeMessage(
dag, quarantine, batchCrypto, syncCommitteePool, dag, quarantine, batchCrypto, syncCommitteePool,
msg, subcommitteeIdx, slot.start_beacon_time(), true) msg, subcommitteeIdx, slot.start_beacon_time(), true)

View File

@@ -1,5 +1,5 @@
# beacon_chain # beacon_chain
# Copyright (c) 2022 Status Research & Development GmbH # Copyright (c) 2022-2023 Status Research & Development GmbH
# Licensed and distributed under either of # Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * 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). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@@ -9,7 +9,7 @@
import import
std/[typetraits, sequtils], std/[typetraits, sequtils],
unittest2, eth/keys, stew/byteutils, unittest2, stew/byteutils,
../beacon_chain/spec/[crypto, keystore], ../beacon_chain/spec/[crypto, keystore],
./testutil ./testutil
@@ -24,7 +24,7 @@ suite "Key spliting":
password = string.fromBytes hexToSeqByte("7465737470617373776f7264f09f9491") password = string.fromBytes hexToSeqByte("7465737470617373776f7264f09f9491")
salt = hexToSeqByte "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3" salt = hexToSeqByte "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"
iv = hexToSeqByte "264daa3f303d7259501c93d997d84fe6" iv = hexToSeqByte "264daa3f303d7259501c93d997d84fe6"
rng = keys.newRng() rng = HmacDrbgContext.new()
msg = rng[].generateBytes(32) msg = rng[].generateBytes(32)
test "single share": test "single share":

View File

@@ -10,7 +10,7 @@
import import
std/[typetraits, os, options, json, sequtils, uri, algorithm], std/[typetraits, os, options, json, sequtils, uri, algorithm],
testutils/unittests, chronicles, stint, json_serialization, confutils, testutils/unittests, chronicles, stint, json_serialization, confutils,
chronos, eth/keys, blscurve, libp2p/crypto/crypto as lcrypto, chronos, blscurve, libp2p/crypto/crypto as lcrypto,
stew/[byteutils, io2], stew/shims/net, stew/[byteutils, io2], stew/shims/net,
../beacon_chain/spec/[crypto, keystore, eth2_merkleization], ../beacon_chain/spec/[crypto, keystore, eth2_merkleization],
@@ -121,7 +121,7 @@ func contains*(keylist: openArray[KeystoreInfo], key: string): bool =
proc prepareNetwork = proc prepareNetwork =
let let
rng = keys.newRng() rng = HmacDrbgContext.new()
mnemonic = generateMnemonic(rng[]) mnemonic = generateMnemonic(rng[])
seed = getSeed(mnemonic, KeystorePass.init "") seed = getSeed(mnemonic, KeystorePass.init "")
cfg = defaultRuntimeConfig cfg = defaultRuntimeConfig
@@ -271,7 +271,7 @@ proc addPreTestRemoteKeystores(validatorsDir: string) =
quit 1 quit 1
proc startBeaconNode(basePort: int) {.raises: [Defect, CatchableError].} = proc startBeaconNode(basePort: int) {.raises: [Defect, CatchableError].} =
let rng = keys.newRng() let rng = HmacDrbgContext.new()
copyHalfValidators(nodeDataDir, true) copyHalfValidators(nodeDataDir, true)
addPreTestRemoteKeystores(nodeValidatorsDir) addPreTestRemoteKeystores(nodeValidatorsDir)
@@ -309,7 +309,7 @@ proc startBeaconNode(basePort: int) {.raises: [Defect, CatchableError].} =
# os.removeDir dataDir # os.removeDir dataDir
proc startValidatorClient(basePort: int) {.async, thread.} = proc startValidatorClient(basePort: int) {.async, thread.} =
let rng = keys.newRng() let rng = HmacDrbgContext.new()
copyHalfValidators(vcDataDir, false) copyHalfValidators(vcDataDir, false)
addPreTestRemoteKeystores(vcValidatorsDir) addPreTestRemoteKeystores(vcValidatorsDir)
@@ -390,7 +390,7 @@ func `==`(a: seq[ValidatorPubKey],
proc runTests(keymanager: KeymanagerToTest) {.async.} = proc runTests(keymanager: KeymanagerToTest) {.async.} =
let let
client = RestClientRef.new(initTAddress("127.0.0.1", keymanager.port)) client = RestClientRef.new(initTAddress("127.0.0.1", keymanager.port))
rng = keys.newRng() rng = HmacDrbgContext.new()
privateKey = ValidatorPrivKey.fromRaw(secretBytes).get privateKey = ValidatorPrivKey.fromRaw(secretBytes).get
allValidators = listLocalValidators( allValidators = listLocalValidators(

View File

@@ -1,5 +1,5 @@
# beacon_chain # beacon_chain
# Copyright (c) 2018-2022 Status Research & Development GmbH # Copyright (c) 2018-2023 Status Research & Development GmbH
# Licensed and distributed under either of # Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * 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). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@@ -10,7 +10,7 @@
import import
std/[json, typetraits], std/[json, typetraits],
unittest2, unittest2,
stew/byteutils, blscurve, eth/keys, json_serialization, stew/byteutils, blscurve, json_serialization,
libp2p/crypto/crypto as lcrypto, libp2p/crypto/crypto as lcrypto,
../beacon_chain/spec/[crypto, keystore], ../beacon_chain/spec/[crypto, keystore],
./testutil ./testutil
@@ -268,7 +268,7 @@ const
iv = hexToSeqByte "264daa3f303d7259501c93d997d84fe6" iv = hexToSeqByte "264daa3f303d7259501c93d997d84fe6"
let let
rng = keys.newRng() rng = HmacDrbgContext.new()
suite "KeyStorage testing suite": suite "KeyStorage testing suite":
setup: setup:
@@ -472,4 +472,3 @@ suite "eth2.0-deposits-cli compatibility":
v3SK.toHex == "1445cec3861d7cbf80e409d79aeee131622dcb0c815ff97ceab2515e14c41a1a" v3SK.toHex == "1445cec3861d7cbf80e409d79aeee131622dcb0c815ff97ceab2515e14c41a1a"
v3WK.toHex == "1ccd5dce4c842bd3f65bbd59a382662e689fcf01ddc39aaaf2dcc7d073f11a93" v3WK.toHex == "1ccd5dce4c842bd3f65bbd59a382662e689fcf01ddc39aaaf2dcc7d073f11a93"

View File

@@ -1,5 +1,5 @@
# beacon_chain # beacon_chain
# Copyright (c) 2021-2022 Status Research & Development GmbH # Copyright (c) 2021-2023 Status Research & Development GmbH
# Licensed and distributed under either of # Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * 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). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@@ -10,7 +10,7 @@
import import
std/[os, options, json, typetraits, uri, algorithm], std/[os, options, json, typetraits, uri, algorithm],
unittest2, chronos, chronicles, stint, json_serialization, unittest2, chronos, chronicles, stint, json_serialization,
blscurve, eth/keys, blscurve,
libp2p/crypto/crypto as lcrypto, libp2p/crypto/crypto as lcrypto,
stew/[io2, byteutils], stew/[io2, byteutils],
../beacon_chain/filepath, ../beacon_chain/filepath,
@@ -44,7 +44,7 @@ proc contentEquals(filePath, expectedContent: string): bool =
expectedContent == readAll(file) expectedContent == readAll(file)
let let
rng = keys.newRng() rng = HmacDrbgContext.new()
mnemonic = generateMnemonic(rng[]) mnemonic = generateMnemonic(rng[])
seed = getSeed(mnemonic, KeystorePass.init "") seed = getSeed(mnemonic, KeystorePass.init "")
cfg = defaultRuntimeConfig cfg = defaultRuntimeConfig

View File

@@ -9,7 +9,7 @@
import import
# Status libraries # Status libraries
eth/keys, taskpools, taskpools,
# Beacon chain internals # Beacon chain internals
../beacon_chain/consensus_object_pools/ ../beacon_chain/consensus_object_pools/
[block_clearance, block_quarantine, blockchain_dag], [block_clearance, block_quarantine, blockchain_dag],
@@ -94,8 +94,9 @@ suite "Light client" & preset():
serve: true, serve: true,
importMode: LightClientDataImportMode.OnlyNew)) importMode: LightClientDataImportMode.OnlyNew))
quarantine = newClone(Quarantine.init()) quarantine = newClone(Quarantine.init())
rng = HmacDrbgContext.new()
taskpool = Taskpool.new() taskpool = Taskpool.new()
var verifier = BatchVerifier(rng: keys.newRng(), taskpool: taskpool) var verifier = BatchVerifier(rng: rng, taskpool: taskpool)
test "Pre-Altair": test "Pre-Altair":
# Genesis # Genesis

View File

@@ -9,7 +9,7 @@
import import
# Status libraries # Status libraries
chronos, eth/keys, chronos,
# Beacon chain internals # Beacon chain internals
../beacon_chain/consensus_object_pools/ ../beacon_chain/consensus_object_pools/
[block_clearance, block_quarantine, blockchain_dag], [block_clearance, block_quarantine, blockchain_dag],
@@ -42,8 +42,9 @@ suite "Light client processor" & preset():
serve: true, serve: true,
importMode: LightClientDataImportMode.OnlyNew)) importMode: LightClientDataImportMode.OnlyNew))
quarantine = newClone(Quarantine.init()) quarantine = newClone(Quarantine.init())
rng = HmacDrbgContext.new()
taskpool = Taskpool.new() taskpool = Taskpool.new()
var verifier = BatchVerifier(rng: keys.newRng(), taskpool: taskpool) var verifier = BatchVerifier(rng: rng, taskpool: taskpool)
var cache: StateCache var cache: StateCache
proc addBlocks(blocks: uint64, syncCommitteeRatio: float) = proc addBlocks(blocks: uint64, syncCommitteeRatio: float) =

View File

@@ -9,7 +9,6 @@
import import
unittest2, unittest2,
eth/keys,
../beacon_chain/spec/[beaconstate, helpers, signatures], ../beacon_chain/spec/[beaconstate, helpers, signatures],
../beacon_chain/consensus_object_pools/sync_committee_msg_pool, ../beacon_chain/consensus_object_pools/sync_committee_msg_pool,
./testblockutil ./testblockutil
@@ -23,12 +22,14 @@ func aggregate(sigs: openArray[CookedSig]): CookedSig =
suite "Sync committee pool": suite "Sync committee pool":
setup: setup:
let cfg = block: let
var res = defaultRuntimeConfig rng = HmacDrbgContext.new()
res.ALTAIR_FORK_EPOCH = 0.Epoch cfg = block:
res.BELLATRIX_FORK_EPOCH = 20.Epoch var res = defaultRuntimeConfig
res res.ALTAIR_FORK_EPOCH = 0.Epoch
var pool = SyncCommitteeMsgPool.init(keys.newRng(), cfg) res.BELLATRIX_FORK_EPOCH = 20.Epoch
res
var pool = SyncCommitteeMsgPool.init(rng, cfg)
test "An empty pool is safe to use": test "An empty pool is safe to use":
let headBid = let headBid =

View File

@@ -7,7 +7,6 @@
import import
chronicles, chronicles,
eth/keys,
stew/endians2, stew/endians2,
../beacon_chain/consensus_object_pools/sync_committee_msg_pool, ../beacon_chain/consensus_object_pools/sync_committee_msg_pool,
../beacon_chain/spec/datatypes/bellatrix, ../beacon_chain/spec/datatypes/bellatrix,
@@ -423,7 +422,8 @@ proc makeSyncAggregate(
getStateField(state, slot) getStateField(state, slot)
latest_block_id = latest_block_id =
withState(state): forkyState.latest_block_id withState(state): forkyState.latest_block_id
syncCommitteePool = newClone(SyncCommitteeMsgPool.init(keys.newRng(), cfg)) rng = HmacDrbgContext.new()
syncCommitteePool = newClone(SyncCommitteeMsgPool.init(rng, cfg))
type type
Aggregator = object Aggregator = object