align `MockPrivKeys` with EF keys (#4866)

Back then, Milagro interop used offset 1000 for mock BLS keys.
Meanwhile, interop code was removed and multi client testnets are there.
EF tests use an offset of 1 for mock BLS keys. This patch aligns our
implementation to also use offset of 1, potentially making debugging of
state differences a bit easier (but, ultimately, low impact).

Furthermore, simulation files are now emitted into a subdirectory
to have less chunk in the repo root directory, and to avoid conflicts
where a cached file with offset 1000 runs against tests expecting 1.

See https://github.com/status-im/nimbus-eth2/pull/2928/files#r719266863
This commit is contained in:
Etan Kissling 2023-04-27 14:17:19 +02:00 committed by GitHub
parent dd1ffa5ded
commit 445ece1157
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 8 deletions

1
.gitignore vendored
View File

@ -49,6 +49,7 @@ build/
/local_testnet*_data*/
test_keymanager_api
test_sim
/libnfuzz_linkerArgs.txt

View File

@ -1,5 +1,5 @@
# beacon_chain
# Copyright (c) 2020-2022 Status Research & Development GmbH
# Copyright (c) 2020-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).
@ -8,7 +8,7 @@
import
stats, strformat, times,
../tests/testblockutil, ../tests/consensus_spec/os_ops,
../beacon_chain/beacon_chain_db,
../beacon_chain/[beacon_chain_db, filepath],
../beacon_chain/spec/datatypes/[phase0, altair],
../beacon_chain/spec/[beaconstate, deposit_snapshots, forks, helpers],
../beacon_chain/consensus_object_pools/[blockchain_dag, block_pools_types]
@ -68,10 +68,16 @@ func verifyConsensus*(state: ForkedHashedBeaconState, attesterRatio: auto) =
proc loadGenesis*(validators: Natural, validate: bool):
(ref ForkedHashedBeaconState, DepositTreeSnapshot) =
const genesisDir = "test_sim"
if (let res = secureCreatePath(genesisDir); res.isErr):
fatal "Could not create directory",
path = genesisDir, err = ioErrorMsg(res.error)
quit 1
let
genesisFn =
genesisFn = genesisDir /
&"genesis_{const_preset}_{validators}_{SPEC_VERSION}.ssz"
contractSnapshotFn =
contractSnapshotFn = genesisDir /
&"deposit_contract_snapshot_{const_preset}_{validators}_{SPEC_VERSION}.ssz"
cfg = defaultRuntimeConfig
@ -89,7 +95,7 @@ proc loadGenesis*(validators: Natural, validate: bool):
echo &"Loaded {genesisFn}..."
# TODO check that the private keys are interop keys
# TODO check that the private keys are EF test keys
let contractSnapshot = SSZ.loadFile(contractSnapshotFn,
DepositTreeSnapshot)

View File

@ -30,9 +30,7 @@ const
# https://github.com/ethereum/consensus-specs/blob/v1.3.0/tests/core/pyspec/eth2spec/test/helpers/keys.py
func `[]`*(_: MockPrivKeysT, index: ValidatorIndex|uint64): ValidatorPrivKey =
# 0 is not a valid BLS private key - 1000 helps interop with rust BLS library,
# lighthouse. EF tests use 1 instead of 1000.
var bytes = (index.uint64 + 1000'u64).toBytesLE()
var bytes = (index.uint64 + 1'u64).toBytesLE() # Consistent with EF tests
static: doAssert sizeof(bytes) <= sizeof(result)
copyMem(addr result, addr bytes, sizeof(bytes))