Skip to content

Commit

Permalink
rm constructTestBloomFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
tersec committed Feb 28, 2024
1 parent 9c31a26 commit 7aad3f2
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 23 deletions.
6 changes: 0 additions & 6 deletions beacon_chain/bloomfilter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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):
Expand Down
7 changes: 5 additions & 2 deletions nfuzz/libnfuzz.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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].} =
Expand Down
5 changes: 3 additions & 2 deletions tests/consensus_spec/altair/test_fixture_operations.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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](
Expand Down
5 changes: 3 additions & 2 deletions tests/consensus_spec/bellatrix/test_fixture_operations.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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](
Expand Down
5 changes: 3 additions & 2 deletions tests/consensus_spec/capella/test_fixture_operations.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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](
Expand Down
5 changes: 3 additions & 2 deletions tests/consensus_spec/deneb/test_fixture_operations.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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](
Expand Down
6 changes: 3 additions & 3 deletions tests/consensus_spec/phase0/test_fixture_operations.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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](
Expand Down
10 changes: 6 additions & 4 deletions tests/teststateutil.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 7aad3f2

Please sign in to comment.