diff --git a/beacon_chain.nimble b/beacon_chain.nimble index 055b0a302..e9dd79323 100644 --- a/beacon_chain.nimble +++ b/beacon_chain.nimble @@ -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=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=mainnet" diff --git a/beacon_chain/spec/beaconstate.nim b/beacon_chain/spec/beaconstate.nim index ad1b6146f..3053ad8ae 100644 --- a/beacon_chain/spec/beaconstate.nim +++ b/beacon_chain/spec/beaconstate.nim @@ -11,7 +11,7 @@ import ../extras, ../ssz, ./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 = ## Check if ``leaf`` at ``index`` verifies against the Merkle ``root`` and ## ``branch``. @@ -489,7 +489,7 @@ func get_indexed_attestation*(state: BeaconState, attestation: Attestation, 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*( state: BeaconState, attestation: Attestation, flags: UpdateFlags, stateCache: var StateCache): bool = @@ -511,35 +511,32 @@ proc check_attestation*( warn("Target epoch not current or previous epoch") return - let attestation_slot = get_attestation_data_slot(state, attestation.data) - - if not (attestation_slot + MIN_ATTESTATION_INCLUSION_DELAY <= stateSlot): + if not (data.slot + MIN_ATTESTATION_INCLUSION_DELAY <= stateSlot): warn("Attestation too new", - attestation_slot = shortLog(attestation_slot), + attestation_slot = shortLog(data.slot), state_slot = shortLog(stateSlot)) return - if not (stateSlot <= attestation_slot + SLOTS_PER_EPOCH): + if not (stateSlot <= data.slot + SLOTS_PER_EPOCH): warn("Attestation too old", - attestation_slot = shortLog(attestation_slot), + attestation_slot = shortLog(data.slot), state_slot = shortLog(stateSlot)) return - #let committee = get_crosslink_committee(state, data.target.epoch, data.crosslink.shard, stateCache) - #if attestation.aggregation_bits.len != attestation.custody_bits.len: - # warn("Inconsistent aggregation and custody bits", - # aggregation_bits_len = attestation.aggregation_bits.len, - # custody_bits_len = attestation.custody_bits.len - # ) - # return - #if attestation.aggregation_bits.len != committee.len: - # warn("Inconsistent aggregation and committee length", - # aggregation_bits_len = attestation.aggregation_bits.len, - # committee_len = committee.len - # ) - # return + let committee = get_beacon_committee(state, data.slot, data.index, stateCache) + if attestation.aggregation_bits.len != attestation.custody_bits.len: + warn("Inconsistent aggregation and custody bits", + aggregation_bits_len = attestation.aggregation_bits.len, + custody_bits_len = attestation.custody_bits.len + ) + return + if attestation.aggregation_bits.len != committee.len: + warn("Inconsistent aggregation and committee length", + aggregation_bits_len = attestation.aggregation_bits.len, + committee_len = committee.len + ) + return - # Check FFG data, crosslink data, and signature let ffg_check_data = (data.source.epoch, data.source.root, data.target.epoch) if data.target.epoch == get_current_epoch(state): @@ -553,7 +550,6 @@ proc check_attestation*( warn("FFG data not matching current justified epoch") return - # Check signature if not is_valid_indexed_attestation( state, get_indexed_attestation(state, attestation, stateCache)): warn("process_attestation: signature or bitfields incorrect") diff --git a/beacon_chain/spec/presets/minimal.nim b/beacon_chain/spec/presets/minimal.nim index 71b6623aa..da6f9bf1c 100644 --- a/beacon_chain/spec/presets/minimal.nim +++ b/beacon_chain/spec/presets/minimal.nim @@ -22,19 +22,21 @@ const # --------------------------------------------------------------- # https://github.com/ethereum/eth2.0-specs/blob/v0.8.4/configs/minimal.yaml#L4 - # Changed + # TODO remove SHARD_COUNT* {.intdefine.} = 8 + + # Changed MAX_COMMITTEES_PER_SLOT* = 4 TARGET_COMMITTEE_SIZE* = 4 # Unchanged - MAX_VALIDATORS_PER_COMMITTEE* = 4096 + MAX_VALIDATORS_PER_COMMITTEE* = 2048 MIN_PER_EPOCH_CHURN_LIMIT* = 4 CHURN_LIMIT_QUOTIENT* = 2^16 # Changed SHUFFLE_ROUND_COUNT* = 10 - MIN_GENESIS_ACTIVE_VALIDATOR_COUNT* {.intdefine.} = 99 + MIN_GENESIS_ACTIVE_VALIDATOR_COUNT* {.intdefine.} = 64 MIN_GENESIS_TIME* {.intdefine.} = 0 # Constants diff --git a/beacon_chain/spec/state_transition_epoch.nim b/beacon_chain/spec/state_transition_epoch.nim index 8d08d7cd1..6ea9eee3b 100644 --- a/beacon_chain/spec/state_transition_epoch.nim +++ b/beacon_chain/spec/state_transition_epoch.nim @@ -92,7 +92,7 @@ func get_attesting_balance( get_total_balance(state, get_unslashed_attesting_indices( 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*( state: var BeaconState, stateCache: var StateCache) = @@ -326,7 +326,7 @@ func get_attestation_deltas(state: BeaconState, stateCache: var StateCache): (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( state: var BeaconState, cache: var StateCache) = if get_current_epoch(state) == GENESIS_EPOCH: diff --git a/tests/working_tests.nim b/tests/working_tests.nim new file mode 100644 index 000000000..30bbc6357 --- /dev/null +++ b/tests/working_tests.nim @@ -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