From 7aad3f28e6a2809680a28f6d320d1c5457930af4 Mon Sep 17 00:00:00 2001 From: tersec Date: Wed, 28 Feb 2024 04:34:11 +0000 Subject: [PATCH] rm constructTestBloomFilter --- beacon_chain/bloomfilter.nim | 6 ------ nfuzz/libnfuzz.nim | 7 +++++-- .../consensus_spec/altair/test_fixture_operations.nim | 5 +++-- .../bellatrix/test_fixture_operations.nim | 5 +++-- .../consensus_spec/capella/test_fixture_operations.nim | 5 +++-- tests/consensus_spec/deneb/test_fixture_operations.nim | 5 +++-- .../consensus_spec/phase0/test_fixture_operations.nim | 6 +++--- tests/teststateutil.nim | 10 ++++++---- 8 files changed, 26 insertions(+), 23 deletions(-) diff --git a/beacon_chain/bloomfilter.nim b/beacon_chain/bloomfilter.nim index 383e5bf879..ba37bba029 100644 --- a/beacon_chain/bloomfilter.nim +++ b/beacon_chain/bloomfilter.nim @@ -20,7 +20,6 @@ type PubkeyBloomFilter* = object bloomFilter: array[1 shl pubkeyBloomFilterScale, byte] -from std/algorithm import fill from stew/bitops2 import getBit, setBit iterator bloomFilterHashes(pubkey: ValidatorPubKey): auto = @@ -38,11 +37,6 @@ func constructBloomFilter*(x: openArray[Validator]): auto = setBit(res[].bloomFilter, bloomFilterHash) res -func constructTestBloomFilter*(): auto = - let res = new PubkeyBloomFilter - res[].bloomFilter.fill(high(byte)) - res - func mightContain*(bf: PubkeyBloomFilter, pubkey: ValidatorPubKey): bool = # Might return false positive, but never false negative for bloomFilterHash in bloomFilterHashes(pubkey): diff --git a/nfuzz/libnfuzz.nim b/nfuzz/libnfuzz.nim index 2506018bb8..bfc558922f 100644 --- a/nfuzz/libnfuzz.nim +++ b/nfuzz/libnfuzz.nim @@ -8,6 +8,8 @@ # Required for deserialisation of ValidatorSig in Attestation due to # https://github.com/nim-lang/Nim/issues/11225 +{.push raises: [].} + import stew/ptrops, chronicles, ../beacon_chain/networking/network_metadata, @@ -137,14 +139,15 @@ func nfuzz_block_header(input: openArray[byte], xoutput: ptr byte, decodeAndProcess(BlockHeaderInput): process_block_header(data.state, data.beaconBlock.message, flags, cache).isOk -from ".."/beacon_chain/bloomfilter import constructTestBloomFilter +from ".."/beacon_chain/bloomfilter import constructBloomFilter proc nfuzz_deposit(input: openArray[byte], xoutput: ptr byte, xoutput_size: ptr uint, disable_bls: bool): bool {.exportc, raises: [FuzzCrashError].} = decodeAndProcess(DepositInput): process_deposit( getRuntimeConfig(some "mainnet"), data.state, - constructTestBloomFilter()[], data.deposit, flags).isOk + constructBloomFilter(data.state.validators.asSeq)[], data.deposit, + flags).isOk proc nfuzz_proposer_slashing(input: openArray[byte], xoutput: ptr byte, xoutput_size: ptr uint, disable_bls: bool): bool {.exportc, raises: [FuzzCrashError].} = diff --git a/tests/consensus_spec/altair/test_fixture_operations.nim b/tests/consensus_spec/altair/test_fixture_operations.nim index bb6493e910..fc058c3d8d 100644 --- a/tests/consensus_spec/altair/test_fixture_operations.nim +++ b/tests/consensus_spec/altair/test_fixture_operations.nim @@ -110,14 +110,15 @@ suite baseDescription & "Block Header " & preset(): runTest[altair.BeaconBlock, typeof applyBlockHeader]( OpBlockHeaderDir, suiteName, "Block Header", "block", applyBlockHeader, path) -from ".."/".."/".."/beacon_chain/bloomfilter import constructTestBloomFilter +from ".."/".."/".."/beacon_chain/bloomfilter import constructBloomFilter suite baseDescription & "Deposit " & preset(): proc applyDeposit( preState: var altair.BeaconState, deposit: Deposit): Result[void, cstring] = process_deposit( - defaultRuntimeConfig, preState, constructTestBloomFilter()[], deposit, {}) + defaultRuntimeConfig, preState, + constructBloomFilter(preState.validators.asSeq)[], deposit, {}) for path in walkTests(OpDepositsDir): runTest[Deposit, typeof applyDeposit]( diff --git a/tests/consensus_spec/bellatrix/test_fixture_operations.nim b/tests/consensus_spec/bellatrix/test_fixture_operations.nim index 944801bf7a..58d7a5bf39 100644 --- a/tests/consensus_spec/bellatrix/test_fixture_operations.nim +++ b/tests/consensus_spec/bellatrix/test_fixture_operations.nim @@ -116,14 +116,15 @@ suite baseDescription & "Block Header " & preset(): OpBlockHeaderDir, suiteName, "Block Header", "block", applyBlockHeader, path) -from ".."/".."/".."/beacon_chain/bloomfilter import constructTestBloomFilter +from ".."/".."/".."/beacon_chain/bloomfilter import constructBloomFilter suite baseDescription & "Deposit " & preset(): proc applyDeposit( preState: var bellatrix.BeaconState, deposit: Deposit): Result[void, cstring] = process_deposit( - defaultRuntimeConfig, preState, constructTestBloomFilter()[], deposit, {}) + defaultRuntimeConfig, preState, + constructBloomFilter(preState.validators.asSeq)[], deposit, {}) for path in walkTests(OpDepositsDir): runTest[Deposit, typeof applyDeposit]( diff --git a/tests/consensus_spec/capella/test_fixture_operations.nim b/tests/consensus_spec/capella/test_fixture_operations.nim index 7bed06f78f..dce2f28522 100644 --- a/tests/consensus_spec/capella/test_fixture_operations.nim +++ b/tests/consensus_spec/capella/test_fixture_operations.nim @@ -133,14 +133,15 @@ suite baseDescription & "BLS to execution change " & preset(): OpBlsToExecutionChangeDir, suiteName, "BLS to execution change", "address_change", applyBlsToExecutionChange, path) -from ".."/".."/".."/beacon_chain/bloomfilter import constructTestBloomFilter +from ".."/".."/".."/beacon_chain/bloomfilter import constructBloomFilter suite baseDescription & "Deposit " & preset(): proc applyDeposit( preState: var capella.BeaconState, deposit: Deposit): Result[void, cstring] = process_deposit( - defaultRuntimeConfig, preState, constructTestBloomFilter()[], deposit, {}) + defaultRuntimeConfig, preState, + constructBloomFilter(preState.validators.asSeq)[], deposit, {}) for path in walkTests(OpDepositsDir): runTest[Deposit, typeof applyDeposit]( diff --git a/tests/consensus_spec/deneb/test_fixture_operations.nim b/tests/consensus_spec/deneb/test_fixture_operations.nim index e36d151e78..cd2c11a905 100644 --- a/tests/consensus_spec/deneb/test_fixture_operations.nim +++ b/tests/consensus_spec/deneb/test_fixture_operations.nim @@ -136,14 +136,15 @@ suite baseDescription & "BLS to execution change " & preset(): OpBlsToExecutionChangeDir, suiteName, "BLS to execution change", "address_change", applyBlsToExecutionChange, path) -from ".."/".."/".."/beacon_chain/bloomfilter import constructTestBloomFilter +from ".."/".."/".."/beacon_chain/bloomfilter import constructBloomFilter suite baseDescription & "Deposit " & preset(): proc applyDeposit( preState: var deneb.BeaconState, deposit: Deposit): Result[void, cstring] = process_deposit( - defaultRuntimeConfig, preState, constructTestBloomFilter()[], deposit, {}) + defaultRuntimeConfig, preState, + constructBloomFilter(preState.validators.asSeq)[], deposit, {}) for path in walkTests(OpDepositsDir): runTest[Deposit, typeof applyDeposit]( diff --git a/tests/consensus_spec/phase0/test_fixture_operations.nim b/tests/consensus_spec/phase0/test_fixture_operations.nim index d8befbf167..9dccaf8170 100644 --- a/tests/consensus_spec/phase0/test_fixture_operations.nim +++ b/tests/consensus_spec/phase0/test_fixture_operations.nim @@ -103,15 +103,15 @@ suite baseDescription & "Block Header " & preset(): OpBlockHeaderDir, suiteName, "Block Header", "block", applyBlockHeader, path) -from ".."/".."/".."/beacon_chain/bloomfilter import constructTestBloomFilter +from ".."/".."/".."/beacon_chain/bloomfilter import constructBloomFilter suite baseDescription & "Deposit " & preset(): proc applyDeposit( preState: var phase0.BeaconState, deposit: Deposit): Result[void, cstring] = process_deposit( - defaultRuntimeConfig, preState, constructTestBloomFilter()[], deposit, - {}) + defaultRuntimeConfig, preState, + constructBloomFilter(preState.validators.asSeq)[], deposit, {}) for path in walkTests(OpDepositsDir): runTest[Deposit, typeof applyDeposit]( diff --git a/tests/teststateutil.nim b/tests/teststateutil.nim index 84ba1fb242..e0dbac71b5 100644 --- a/tests/teststateutil.nim +++ b/tests/teststateutil.nim @@ -10,9 +10,11 @@ import chronicles, ./mocking/mock_deposits, - ./helpers/math_helpers, ../beacon_chain/spec/[ - forks, helpers, state_transition, state_transition_block] + forks, state_transition, state_transition_block] + +from "."/helpers/math_helpers import round_multiple_down +from ".."/beacon_chain/bloomfilter import constructBloomFilter proc valid_deposit(state: var ForkyHashedBeaconState) = const deposit_amount = MAX_EFFECTIVE_BALANCE @@ -30,8 +32,8 @@ proc valid_deposit(state: var ForkyHashedBeaconState) = else: 0 doAssert process_deposit( - defaultRuntimeConfig, state.data, constructTestBloomFilter()[], deposit, - {}).isOk + defaultRuntimeConfig, state.data, + constructBloomFilter(state.data.validators.asSeq)[], deposit, {}).isOk doAssert state.data.validators.len == pre_val_count + 1 doAssert state.data.balances.len == pre_val_count + 1 doAssert state.data.balances.item(validator_index) == pre_balance + deposit.data.amount