mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-20 15:38:55 +00:00
FIx tests with rebase
This commit is contained in:
parent
7f9a0264ce
commit
cf975c6b86
@ -17,7 +17,7 @@ from py_ecc.bls.g2_primitives import (
|
||||
G1_to_pubkey as py_ecc_G1_to_bytes48,
|
||||
pubkey_to_G1 as py_ecc_bytes48_to_G1,
|
||||
)
|
||||
from eth2spec.test.helpers.whisk import get_whisk_tracker_and_commitment
|
||||
from eth2spec.test.helpers.whisk import get_whisk_tracker_and_commitment, is_first_proposal
|
||||
|
||||
PointProjective = Optimized_Point3D[Optimized_Field]
|
||||
|
||||
@ -126,7 +126,7 @@ def build_empty_block(spec, state, slot=None, proposer_index=None):
|
||||
k_initial = whisk_ks_initial[proposer_index]
|
||||
|
||||
# Sanity check proposer is correct
|
||||
proposer_k_commitment = state.validators[proposer_index].whisk_k_commitment
|
||||
proposer_k_commitment = state.whisk_k_commitments[proposer_index]
|
||||
k_commitment = py_ecc_G1_to_bytes48(multiply(G1, int(k_initial)))
|
||||
if proposer_k_commitment != k_commitment:
|
||||
raise Exception("k proposer_index not eq proposer_k_commitment", proposer_k_commitment, k_commitment)
|
||||
@ -174,8 +174,7 @@ def build_empty_block(spec, state, slot=None, proposer_index=None):
|
||||
#######
|
||||
|
||||
# Branching logic depending if first proposal or not
|
||||
is_first_proposal = state.validators[proposer_index].whisk_tracker.r_G == spec.BLS_G1_GENERATOR
|
||||
if is_first_proposal:
|
||||
if is_first_proposal(spec, state, proposer_index):
|
||||
# Register new tracker
|
||||
k_final = whisk_ks_final[proposer_index]
|
||||
# TODO: Actual logic should pick a random r, but may need to do something fancy to locate trackers quickly
|
||||
|
@ -5,7 +5,7 @@ from eth2spec.test.helpers.execution_payload import (
|
||||
compute_el_header_block_hash,
|
||||
)
|
||||
from eth2spec.test.helpers.forks import (
|
||||
is_post_altair, is_post_bellatrix, is_post_capella, is_post_eip6110,
|
||||
is_post_altair, is_post_bellatrix, is_post_capella, is_post_eip6110, is_post_whisk
|
||||
)
|
||||
from eth2spec.test.helpers.keys import pubkeys
|
||||
|
||||
@ -141,4 +141,11 @@ def create_genesis_state(spec, validator_balances, activation_threshold):
|
||||
if is_post_eip6110(spec):
|
||||
state.deposit_receipts_start_index = spec.UNSET_DEPOSIT_RECEIPTS_START_INDEX
|
||||
|
||||
if is_post_whisk(spec):
|
||||
zero_commitment = spec.BLSPubkey()
|
||||
zero_tracker = spec.WhiskTracker()
|
||||
for _ in range(len(state.validators)):
|
||||
state.whisk_k_commitments.append(zero_commitment)
|
||||
state.whisk_trackers.append(zero_tracker)
|
||||
|
||||
return state
|
||||
|
@ -27,12 +27,12 @@ def get_whisk_tracker_and_commitment(k: int, r: int) -> Tuple[WhiskTracker, BLSP
|
||||
# Trigger condition for first proposal
|
||||
def set_as_first_proposal(spec, state, proposer_index: int):
|
||||
# Ensure tracker is empty to prevent breaking it
|
||||
assert state.validators[proposer_index].whisk_tracker.r_G == spec.BLSG1Point()
|
||||
state.validators[proposer_index].whisk_tracker.r_G = spec.BLS_G1_GENERATOR
|
||||
assert state.whisk_trackers[proposer_index].r_G == spec.BLSG1Point()
|
||||
state.whisk_trackers[proposer_index].r_G = spec.BLS_G1_GENERATOR
|
||||
|
||||
|
||||
def is_first_proposal(spec, state, proposer_index: int) -> bool:
|
||||
return state.validators[proposer_index].whisk_tracker.r_G == spec.BLS_G1_GENERATOR
|
||||
return state.whisk_trackers[proposer_index].r_G == spec.BLS_G1_GENERATOR
|
||||
|
||||
|
||||
def set_registration(body, k: int, r: int):
|
||||
@ -45,6 +45,6 @@ def set_registration(body, k: int, r: int):
|
||||
def set_opening_proof(spec, state, block, proposer_index: int, k: int, r: int):
|
||||
tracker, k_commitment = get_whisk_tracker_and_commitment(k, r)
|
||||
state.whisk_proposer_trackers[state.slot % spec.WHISK_PROPOSER_TRACKERS_COUNT] = tracker
|
||||
state.validators[proposer_index].whisk_k_commitment = k_commitment
|
||||
state.whisk_k_commitments[proposer_index] = k_commitment
|
||||
block.proposer_index = proposer_index
|
||||
block.body.whisk_opening_proof = GenerateWhiskTrackerProof(tracker, k)
|
||||
|
@ -44,7 +44,7 @@ def test_valid_proof(spec, state):
|
||||
def test_wrong_commitment(spec, state):
|
||||
block = empty_block(spec)
|
||||
set_opening_proof(spec, state, block, PROPOSER_INDEX, K_OK, R_OK)
|
||||
state.validators[PROPOSER_INDEX].whisk_k_commitment = get_whisk_k_commitment(K_WRONG)
|
||||
state.whisk_k_commitments[PROPOSER_INDEX] = get_whisk_k_commitment(K_WRONG)
|
||||
run_process_whisk_opening_proof(spec, state, block, valid=False)
|
||||
|
||||
|
||||
|
@ -57,7 +57,7 @@ def test_first_proposal_indentity_tracker(spec, state):
|
||||
def test_first_proposal_non_unique_k_other(spec, state):
|
||||
body = empty_block_body(spec)
|
||||
set_as_first_proposal_and_proposer(spec, state, PROPOSER_INDEX)
|
||||
state.validators[OTHER_INDEX].whisk_k_commitment = get_whisk_k_commitment(OTHER_K)
|
||||
state.whisk_k_commitments[OTHER_INDEX] = get_whisk_k_commitment(OTHER_K)
|
||||
set_registration(body, OTHER_K, OTHER_R)
|
||||
yield from run_process_whisk_registration(spec, state, body, valid=False)
|
||||
|
||||
@ -67,7 +67,7 @@ def test_first_proposal_non_unique_k_other(spec, state):
|
||||
def test_first_proposal_non_unique_k_self(spec, state):
|
||||
body = empty_block_body(spec)
|
||||
set_as_first_proposal_and_proposer(spec, state, PROPOSER_INDEX)
|
||||
state.validators[PROPOSER_INDEX].whisk_k_commitment = get_whisk_k_commitment(OTHER_K)
|
||||
state.whisk_k_commitments[PROPOSER_INDEX] = get_whisk_k_commitment(OTHER_K)
|
||||
set_registration(body, OTHER_K, OTHER_R)
|
||||
yield from run_process_whisk_registration(spec, state, body, valid=False)
|
||||
|
||||
|
@ -14,10 +14,10 @@ def assign_proposer_at_slot(state, slot: int):
|
||||
|
||||
def initialize_whisk_full(spec, state):
|
||||
# TODO: De-duplicate code from whisk/fork.md
|
||||
for index, validator in enumerate(state.validators):
|
||||
for index in range(len(state.validators)):
|
||||
whisk_k_commitment, whisk_tracker = spec.get_initial_commitments(whisk_ks_initial[index])
|
||||
validator.whisk_k_commitment = whisk_k_commitment
|
||||
validator.whisk_tracker = whisk_tracker
|
||||
state.whisk_k_commitments[index] = whisk_k_commitment
|
||||
state.whisk_trackers[index] = whisk_tracker
|
||||
|
||||
# Do a candidate selection followed by a proposer selection so that we have proposers for the upcoming day
|
||||
# Use an old epoch when selecting candidates so that we don't get the same seed as in the next candidate selection
|
||||
@ -37,7 +37,7 @@ def test_whisk__process_block_single_initial(spec, state):
|
||||
assert state.slot == 0
|
||||
proposer_slot_1 = 0
|
||||
tracker_slot_1, k_commitment = get_whisk_tracker_and_commitment(whisk_ks_initial[proposer_slot_1], 1)
|
||||
state.validators[proposer_slot_1].whisk_k_commitment = k_commitment
|
||||
state.whisk_k_commitments[proposer_slot_1] = k_commitment
|
||||
state.whisk_proposer_trackers[1] = tracker_slot_1
|
||||
fill_candidate_trackers(spec, state, tracker_slot_1)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user