mark is_valid_merkle_branch(...), process_justification_and_finalization(...), and process_rewards_and_penalties(...) as 0.9.0; update check_attestation(...) to 0.9.0; add 11 working test fixtures, having updated SSZ fixture directory to 0.9.0

This commit is contained in:
Dustin Brody 2019-11-08 12:31:48 +01:00
parent 275fb22c00
commit e984b2c932
5 changed files with 40 additions and 28 deletions

View File

@ -57,6 +57,9 @@ task test, "Run all tests":
#buildBinary "test_fixture_ssz_static", "tests/official/", "-r -d:release -d:chronicles_log_level=DEBUG -d:const_preset=minimal" #buildBinary "test_fixture_ssz_static", "tests/official/", "-r -d:release -d:chronicles_log_level=DEBUG -d:const_preset=minimal"
#buildBinary "test_fixture_ssz_static", "tests/official/", "-r -d:release -d:chronicles_log_level=DEBUG -d:const_preset=mainnet" #buildBinary "test_fixture_ssz_static", "tests/official/", "-r -d:release -d:chronicles_log_level=DEBUG -d:const_preset=mainnet"
buildBinary "working_tests", "tests/", "-r -d:release -d:chronicles_log_level=DEBUG -d:const_preset=minimal"
buildBinary "working_tests", "tests/", "-r -d:release -d:chronicles_log_level=DEBUG -d:const_preset=mainnet"
#buildBinary "all_fixtures_require_ssz", "tests/official/", "-r -d:release -d:chronicles_log_level=DEBUG -d:const_preset=minimal" #buildBinary "all_fixtures_require_ssz", "tests/official/", "-r -d:release -d:chronicles_log_level=DEBUG -d:const_preset=minimal"
#buildBinary "all_fixtures_require_ssz", "tests/official/", "-r -d:release -d:chronicles_log_level=DEBUG -d:const_preset=mainnet" #buildBinary "all_fixtures_require_ssz", "tests/official/", "-r -d:release -d:chronicles_log_level=DEBUG -d:const_preset=mainnet"

View File

@ -11,7 +11,7 @@ import
../extras, ../ssz, ../extras, ../ssz,
./crypto, ./datatypes, ./digest, ./helpers, ./validator ./crypto, ./datatypes, ./digest, ./helpers, ./validator
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.4/specs/core/0_beacon-chain.md#is_valid_merkle_branch # https://github.com/ethereum/eth2.0-specs/blob/v0.9.0/specs/core/0_beacon-chain.md#is_valid_merkle_branch
func is_valid_merkle_branch(leaf: Eth2Digest, branch: openarray[Eth2Digest], depth: uint64, index: uint64, root: Eth2Digest): bool = func is_valid_merkle_branch(leaf: Eth2Digest, branch: openarray[Eth2Digest], depth: uint64, index: uint64, root: Eth2Digest): bool =
## Check if ``leaf`` at ``index`` verifies against the Merkle ``root`` and ## Check if ``leaf`` at ``index`` verifies against the Merkle ``root`` and
## ``branch``. ## ``branch``.
@ -489,7 +489,7 @@ func get_indexed_attestation*(state: BeaconState, attestation: Attestation,
signature: attestation.signature, signature: attestation.signature,
) )
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.4/specs/core/0_beacon-chain.md#attestations # https://github.com/ethereum/eth2.0-specs/blob/v0.9.0/specs/core/0_beacon-chain.md#attestations
proc check_attestation*( proc check_attestation*(
state: BeaconState, attestation: Attestation, flags: UpdateFlags, state: BeaconState, attestation: Attestation, flags: UpdateFlags,
stateCache: var StateCache): bool = stateCache: var StateCache): bool =
@ -511,35 +511,32 @@ proc check_attestation*(
warn("Target epoch not current or previous epoch") warn("Target epoch not current or previous epoch")
return return
let attestation_slot = get_attestation_data_slot(state, attestation.data) if not (data.slot + MIN_ATTESTATION_INCLUSION_DELAY <= stateSlot):
if not (attestation_slot + MIN_ATTESTATION_INCLUSION_DELAY <= stateSlot):
warn("Attestation too new", warn("Attestation too new",
attestation_slot = shortLog(attestation_slot), attestation_slot = shortLog(data.slot),
state_slot = shortLog(stateSlot)) state_slot = shortLog(stateSlot))
return return
if not (stateSlot <= attestation_slot + SLOTS_PER_EPOCH): if not (stateSlot <= data.slot + SLOTS_PER_EPOCH):
warn("Attestation too old", warn("Attestation too old",
attestation_slot = shortLog(attestation_slot), attestation_slot = shortLog(data.slot),
state_slot = shortLog(stateSlot)) state_slot = shortLog(stateSlot))
return return
#let committee = get_crosslink_committee(state, data.target.epoch, data.crosslink.shard, stateCache) let committee = get_beacon_committee(state, data.slot, data.index, stateCache)
#if attestation.aggregation_bits.len != attestation.custody_bits.len: if attestation.aggregation_bits.len != attestation.custody_bits.len:
# warn("Inconsistent aggregation and custody bits", warn("Inconsistent aggregation and custody bits",
# aggregation_bits_len = attestation.aggregation_bits.len, aggregation_bits_len = attestation.aggregation_bits.len,
# custody_bits_len = attestation.custody_bits.len custody_bits_len = attestation.custody_bits.len
# ) )
# return return
#if attestation.aggregation_bits.len != committee.len: if attestation.aggregation_bits.len != committee.len:
# warn("Inconsistent aggregation and committee length", warn("Inconsistent aggregation and committee length",
# aggregation_bits_len = attestation.aggregation_bits.len, aggregation_bits_len = attestation.aggregation_bits.len,
# committee_len = committee.len committee_len = committee.len
# ) )
# return return
# Check FFG data, crosslink data, and signature
let ffg_check_data = (data.source.epoch, data.source.root, data.target.epoch) let ffg_check_data = (data.source.epoch, data.source.root, data.target.epoch)
if data.target.epoch == get_current_epoch(state): if data.target.epoch == get_current_epoch(state):
@ -553,7 +550,6 @@ proc check_attestation*(
warn("FFG data not matching current justified epoch") warn("FFG data not matching current justified epoch")
return return
# Check signature
if not is_valid_indexed_attestation( if not is_valid_indexed_attestation(
state, get_indexed_attestation(state, attestation, stateCache)): state, get_indexed_attestation(state, attestation, stateCache)):
warn("process_attestation: signature or bitfields incorrect") warn("process_attestation: signature or bitfields incorrect")

View File

@ -22,19 +22,21 @@ const
# --------------------------------------------------------------- # ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.4/configs/minimal.yaml#L4 # https://github.com/ethereum/eth2.0-specs/blob/v0.8.4/configs/minimal.yaml#L4
# Changed # TODO remove
SHARD_COUNT* {.intdefine.} = 8 SHARD_COUNT* {.intdefine.} = 8
# Changed
MAX_COMMITTEES_PER_SLOT* = 4 MAX_COMMITTEES_PER_SLOT* = 4
TARGET_COMMITTEE_SIZE* = 4 TARGET_COMMITTEE_SIZE* = 4
# Unchanged # Unchanged
MAX_VALIDATORS_PER_COMMITTEE* = 4096 MAX_VALIDATORS_PER_COMMITTEE* = 2048
MIN_PER_EPOCH_CHURN_LIMIT* = 4 MIN_PER_EPOCH_CHURN_LIMIT* = 4
CHURN_LIMIT_QUOTIENT* = 2^16 CHURN_LIMIT_QUOTIENT* = 2^16
# Changed # Changed
SHUFFLE_ROUND_COUNT* = 10 SHUFFLE_ROUND_COUNT* = 10
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT* {.intdefine.} = 99 MIN_GENESIS_ACTIVE_VALIDATOR_COUNT* {.intdefine.} = 64
MIN_GENESIS_TIME* {.intdefine.} = 0 MIN_GENESIS_TIME* {.intdefine.} = 0
# Constants # Constants

View File

@ -92,7 +92,7 @@ func get_attesting_balance(
get_total_balance(state, get_unslashed_attesting_indices( get_total_balance(state, get_unslashed_attesting_indices(
state, attestations, stateCache)) state, attestations, stateCache))
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.4/specs/core/0_beacon-chain.md#justification-and-finalization # https://github.com/ethereum/eth2.0-specs/blob/v0.9.0/specs/core/0_beacon-chain.md#justification-and-finalization
proc process_justification_and_finalization*( proc process_justification_and_finalization*(
state: var BeaconState, stateCache: var StateCache) = state: var BeaconState, stateCache: var StateCache) =
@ -326,7 +326,7 @@ func get_attestation_deltas(state: BeaconState, stateCache: var StateCache):
(rewards, penalties) (rewards, penalties)
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.4/specs/core/0_beacon-chain.md#rewards-and-penalties-1 # https://github.com/ethereum/eth2.0-specs/blob/v0.9.0/specs/core/0_beacon-chain.md#rewards-and-penalties-1
func process_rewards_and_penalties( func process_rewards_and_penalties(
state: var BeaconState, cache: var StateCache) = state: var BeaconState, cache: var StateCache) =
if get_current_epoch(state) == GENESIS_EPOCH: if get_current_epoch(state) == GENESIS_EPOCH:

11
tests/working_tests.nim Normal file
View File

@ -0,0 +1,11 @@
import
official/test_fixture_bls,
official/test_fixture_shuffling,
official/test_fixture_ssz_generic_types,
official/test_fixture_sanity_slots,
official/test_fixture_operations_voluntary_exit,
official/test_fixture_ssz_uint,
official/test_fixture_operations_deposits,
spec_block_processing/test_process_attestation.nim,
spec_block_processing/test_process_deposits.nim,
spec_epoch_processing/test_process_justification_and_finalization