@@ -611,9 +611,43 @@ def test_invalid_different_credentials(spec, state):
611611
612612
613613@with_electra_and_later
614- @spec_state_test
614+ @with_presets ([MINIMAL ], "need sufficient consolidation churn limit" )
615+ @with_custom_state (
616+ balances_fn = scaled_churn_balances_exceed_activation_exit_churn_limit ,
617+ threshold_fn = default_activation_threshold ,
618+ )
619+ @spec_test
620+ @single_phase
615621@always_bls
616622def test_invalid_source_signature (spec , state ):
623+ # This state has 256 validators each with 32 ETH in MINIMAL preset, 128 ETH consolidation churn
624+ current_epoch = spec .get_current_epoch (state )
625+ source_index = spec .get_active_validator_indices (state , current_epoch )[0 ]
626+ target_index = spec .get_active_validator_indices (state , current_epoch )[1 ]
627+ source_privkey = pubkey_to_privkey [state .validators [source_index ].pubkey ]
628+ target_privkey = pubkey_to_privkey [state .validators [target_index ].pubkey ]
629+
630+ # Set source and target withdrawal credentials to the same eth1 credential
631+ set_eth1_withdrawal_credential_with_balance (spec , state , source_index )
632+ set_eth1_withdrawal_credential_with_balance (spec , state , target_index )
633+
634+ signed_consolidation = sign_consolidation (
635+ spec ,
636+ state ,
637+ spec .Consolidation (
638+ epoch = current_epoch , source_index = source_index , target_index = target_index
639+ ),
640+ source_privkey ,
641+ target_privkey ,
642+ )
643+
644+ # Set earliest consolidation epoch to the expected exit epoch
645+ expected_exit_epoch = spec .compute_activation_exit_epoch (current_epoch )
646+ state .earliest_consolidation_epoch = expected_exit_epoch
647+ consolidation_churn_limit = spec .get_consolidation_churn_limit (state )
648+ # Set the consolidation balance to consume equal to churn limit
649+ state .consolidation_balance_to_consume = consolidation_churn_limit
650+
617651 current_epoch = spec .get_current_epoch (state )
618652 source_privkey = pubkey_to_privkey [state .validators [0 ].pubkey ]
619653 target_privkey = pubkey_to_privkey [state .validators [1 ].pubkey ]
@@ -627,17 +661,53 @@ def test_invalid_source_signature(spec, state):
627661 source_privkey ,
628662 target_privkey ,
629663 )
664+
630665 # Change the pubkey of the source validator, invalidating its signature
631666 state .validators [0 ].pubkey = state .validators [1 ].pubkey
667+
632668 yield from run_consolidation_processing (
633669 spec , state , signed_consolidation , valid = False
634670 )
635671
636672
637673@with_electra_and_later
638- @spec_state_test
674+ @with_presets ([MINIMAL ], "need sufficient consolidation churn limit" )
675+ @with_custom_state (
676+ balances_fn = scaled_churn_balances_exceed_activation_exit_churn_limit ,
677+ threshold_fn = default_activation_threshold ,
678+ )
679+ @spec_test
680+ @single_phase
639681@always_bls
640682def test_invalid_target_signature (spec , state ):
683+ # This state has 256 validators each with 32 ETH in MINIMAL preset, 128 ETH consolidation churn
684+ current_epoch = spec .get_current_epoch (state )
685+ source_index = spec .get_active_validator_indices (state , current_epoch )[0 ]
686+ target_index = spec .get_active_validator_indices (state , current_epoch )[1 ]
687+ source_privkey = pubkey_to_privkey [state .validators [source_index ].pubkey ]
688+ target_privkey = pubkey_to_privkey [state .validators [target_index ].pubkey ]
689+
690+ # Set source and target withdrawal credentials to the same eth1 credential
691+ set_eth1_withdrawal_credential_with_balance (spec , state , source_index )
692+ set_eth1_withdrawal_credential_with_balance (spec , state , target_index )
693+
694+ signed_consolidation = sign_consolidation (
695+ spec ,
696+ state ,
697+ spec .Consolidation (
698+ epoch = current_epoch , source_index = source_index , target_index = target_index
699+ ),
700+ source_privkey ,
701+ target_privkey ,
702+ )
703+
704+ # Set earliest consolidation epoch to the expected exit epoch
705+ expected_exit_epoch = spec .compute_activation_exit_epoch (current_epoch )
706+ state .earliest_consolidation_epoch = expected_exit_epoch
707+ consolidation_churn_limit = spec .get_consolidation_churn_limit (state )
708+ # Set the consolidation balance to consume equal to churn limit
709+ state .consolidation_balance_to_consume = consolidation_churn_limit
710+
641711 current_epoch = spec .get_current_epoch (state )
642712 source_privkey = pubkey_to_privkey [state .validators [0 ].pubkey ]
643713 target_privkey = pubkey_to_privkey [state .validators [1 ].pubkey ]
@@ -651,8 +721,10 @@ def test_invalid_target_signature(spec, state):
651721 source_privkey ,
652722 target_privkey ,
653723 )
724+
654725 # Change the pubkey of the target validator, invalidating its signature
655726 state .validators [1 ].pubkey = state .validators [2 ].pubkey
727+
656728 yield from run_consolidation_processing (
657729 spec , state , signed_consolidation , valid = False
658730 )
0 commit comments