Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EIP-6110: Supply validator deposits on chain #13944

Merged
merged 92 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
5ad0a86
wip changes
james-prysm May 1, 2024
3572a53
wip changes refactoring deposit functions
james-prysm May 1, 2024
be6e19c
Merge branch 'develop' into eip6110
james-prysm May 2, 2024
bd3a92e
wip on deposit functions
james-prysm May 2, 2024
7666f65
wip changes to fix deposit processing
james-prysm May 2, 2024
51a2282
more wip function logic
james-prysm May 3, 2024
db031bd
gaz
james-prysm May 3, 2024
393e1a8
Merge branch 'develop' into eip6110
james-prysm May 6, 2024
9ccbaca
Merge branch 'develop' into eip6110
james-prysm May 6, 2024
ee0ad99
Merge branch 'develop' into eip6110
james-prysm May 7, 2024
550d366
Merge branch 'develop' into eip6110
james-prysm May 7, 2024
7f2bdf5
Merge branch 'develop' into eip6110
james-prysm May 7, 2024
c24e80c
wip refactoring deposit changes
james-prysm May 7, 2024
6287e3c
Merge branch 'develop' into eip6110
james-prysm May 7, 2024
be66a2d
Merge branch 'develop' into eip6110
james-prysm May 7, 2024
e3f50e9
removing circlular dependency and other small fix
james-prysm May 7, 2024
560ef11
Merge branch 'develop' into eip6110
james-prysm May 8, 2024
822cf02
fixing circular dependencies
james-prysm May 8, 2024
91eadef
fixing validators file
james-prysm May 8, 2024
8ffcb16
fixing more tests
james-prysm May 8, 2024
e4efcab
fixing unit tests
james-prysm May 8, 2024
babebea
Merge branch 'develop' into eip6110
james-prysm May 8, 2024
3469f6b
wip deposit packing
james-prysm May 9, 2024
d000211
refactoring packing
james-prysm May 9, 2024
4ba45f0
changing packing code some more
james-prysm May 9, 2024
c5189a7
fixing packing change
james-prysm May 9, 2024
935baca
updating more tests
james-prysm May 9, 2024
210a129
Merge branch 'develop' into eip6110
james-prysm May 9, 2024
d884737
removing comment
james-prysm May 9, 2024
b659925
fixing transition code for eip6110
james-prysm May 9, 2024
db5743f
Merge branch 'develop' into eip6110
james-prysm May 9, 2024
358ae04
including inserts for validator index cache
james-prysm May 9, 2024
1843ee5
Merge branch 'develop' into eip6110
james-prysm May 10, 2024
ade6c30
Merge branch 'develop' into eip6110
james-prysm May 12, 2024
32bc6b4
adding tests and placeholder test
james-prysm May 12, 2024
dd24d42
Merge branch 'develop' into eip6110
james-prysm May 13, 2024
ee52e22
moving deposit related unit tests over
james-prysm May 13, 2024
d8608d1
adding in test for electra proposer packing
james-prysm May 13, 2024
ef10964
Merge branch 'develop' into eip6110
james-prysm May 13, 2024
918ca0e
spec test wip
james-prysm May 14, 2024
e2af855
moving cache saving to the correct spot
james-prysm May 14, 2024
b6c1c37
eip-6110: deposit spectests
prestonvanloon May 14, 2024
8f554db
adding deposit receipt spec tests
james-prysm May 15, 2024
d08900f
Merge branch 'develop' into eip6110
james-prysm May 15, 2024
2c02712
reverting altair operations in this pr and will be handled separately
james-prysm May 15, 2024
ae4d911
Merge branch 'develop' into eip6110
james-prysm May 16, 2024
edc7198
Merge branch 'develop' into eip6110
james-prysm May 21, 2024
99a0aff
Merge branch 'develop' into eip6110
james-prysm May 24, 2024
f9b56d1
Merge branch 'develop' into eip6110
james-prysm Jun 5, 2024
261809b
Merge branch 'develop' into eip6110
james-prysm Jun 10, 2024
7a0a7a4
Merge branch 'develop' into eip6110
james-prysm Jun 12, 2024
c322c09
Merge branch 'develop' into eip6110
james-prysm Jun 12, 2024
3200781
fixing renames but need to refactor process deposits
james-prysm Jun 12, 2024
e0ae765
gaz
james-prysm Jun 12, 2024
fa3a689
fixing names
james-prysm Jun 13, 2024
278d80c
fixing linting
james-prysm Jun 13, 2024
69f77e7
Merge branch 'develop' into eip6110
james-prysm Jun 13, 2024
a39e014
fixing unit test
james-prysm Jun 13, 2024
56f0728
fixing a test and updating test util
james-prysm Jun 13, 2024
ffe5260
bal never used
james-prysm Jun 13, 2024
12fe34c
fixing more tests
james-prysm Jun 13, 2024
212ef50
fixing one more test
james-prysm Jun 14, 2024
644f938
Merge branch 'develop' into eip6110
james-prysm Jun 14, 2024
afc037b
Merge branch 'develop' into eip6110
james-prysm Jun 14, 2024
575ae4c
addressing feedback
james-prysm Jun 17, 2024
940d8e3
refactoring process deposits to be part of their own fork instead of …
james-prysm Jun 20, 2024
e34cd2f
adding new tests to cover functions and removing redundancies
james-prysm Jun 20, 2024
83eacc0
Merge branch 'develop' into eip6110
james-prysm Jun 20, 2024
a45c7e7
removing comment based on feedback
james-prysm Jun 20, 2024
f919a8d
Merge branch 'develop' into eip6110
james-prysm Jun 20, 2024
c819897
resolving easy deepsource issue
james-prysm Jun 20, 2024
d7bd167
Merge branch 'develop' into eip6110
james-prysm Jun 21, 2024
3cb4c5f
refactoring for appropriate aliasing and readability
james-prysm Jun 21, 2024
1582be9
Merge branch 'develop' into eip6110
james-prysm Jun 24, 2024
c09cd25
reverting some changes to simplify diff
james-prysm Jun 24, 2024
dc38405
Merge branch 'develop' into eip6110
james-prysm Jun 24, 2024
9b5a925
Merge branch 'develop' into eip6110
james-prysm Jun 25, 2024
bccfa0b
small edit to comment
james-prysm Jun 25, 2024
aff2231
fixing linting
james-prysm Jun 25, 2024
04372f5
Merge branch 'develop' into eip6110
james-prysm Jun 26, 2024
a9a7aed
Merge branch 'develop' into eip6110
james-prysm Jun 26, 2024
f2be21f
Merge branch 'develop' into eip6110
james-prysm Jun 26, 2024
502a721
Merge branch 'develop' into eip6110
james-prysm Jun 27, 2024
43912e9
Merge branch 'develop' into eip6110
james-prysm Jun 27, 2024
7fa467a
fixing merge changes and review comments
james-prysm Jun 27, 2024
3e5f08b
Merge branch 'develop' into eip6110
james-prysm Jun 28, 2024
2bb28d3
Update beacon-chain/rpc/prysm/v1alpha1/validator/proposer_deposits.go
james-prysm Jun 28, 2024
7fa48d1
Merge branch 'develop' into eip6110
james-prysm Jun 28, 2024
45e9eb2
partial review comments
james-prysm Jun 28, 2024
0dc3473
addressing slack feedback
james-prysm Jun 28, 2024
649e94b
moving function from deposits to validator.go
james-prysm Jun 28, 2024
f2da526
adding in batch verification and improving logs
james-prysm Jun 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 1 addition & 22 deletions beacon-chain/core/altair/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,10 @@ func ProcessDeposits(
if deposit == nil || deposit.Data == nil {
return nil, errors.New("got a nil deposit in block")
}
beaconState, err = ProcessDeposit(beaconState, deposit, batchVerified)
beaconState, err = blocks.ProcessDeposit(beaconState, deposit, batchVerified)
if err != nil {
return nil, errors.Wrapf(err, "could not process deposit from %#x", bytesutil.Trunc(deposit.Data.PublicKey))
}
}
return beaconState, nil
}

// ProcessDeposit processes validator deposit for beacon state Altair.
func ProcessDeposit(beaconState state.BeaconState, deposit *ethpb.Deposit, verifySignature bool) (state.BeaconState, error) {
beaconState, isNewValidator, err := blocks.ProcessDeposit(beaconState, deposit, verifySignature)
if err != nil {
return nil, err
}
if isNewValidator {
if err := beaconState.AppendInactivityScore(0); err != nil {
return nil, err
}
if err := beaconState.AppendPreviousParticipationBits(0); err != nil {
return nil, err
}
if err := beaconState.AppendCurrentParticipationBits(0); err != nil {
return nil, err
}
}

return beaconState, nil
}
233 changes: 168 additions & 65 deletions beacon-chain/core/blocks/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v5/math"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
)

// ProcessPreGenesisDeposits processes a deposit for the beacon state before chainstart.
Expand Down Expand Up @@ -90,7 +91,7 @@ func ProcessDeposits(
if d == nil || d.Data == nil {
return nil, errors.New("got a nil deposit in block")
}
beaconState, _, err = ProcessDeposit(beaconState, d, batchVerified)
beaconState, err = ProcessDeposit(beaconState, d, batchVerified)
if err != nil {
return nil, errors.Wrapf(err, "could not process deposit from %#x", bytesutil.Trunc(d.Data.PublicKey))
}
Expand Down Expand Up @@ -122,91 +123,193 @@ func BatchVerifyDepositsSignatures(ctx context.Context, deposits []*ethpb.Deposi
// Spec pseudocode definition:
// def process_deposit(state: BeaconState, deposit: Deposit) -> None:
//
// # Verify the Merkle branch
// assert is_valid_merkle_branch(
// leaf=hash_tree_root(deposit.data),
// branch=deposit.proof,
// depth=DEPOSIT_CONTRACT_TREE_DEPTH + 1, # Add 1 for the List length mix-in
// index=state.eth1_deposit_index,
// root=state.eth1_data.deposit_root,
// )
// # Verify the Merkle branch
// assert is_valid_merkle_branch(
// leaf=hash_tree_root(deposit.data),
// branch=deposit.proof,
// depth=DEPOSIT_CONTRACT_TREE_DEPTH + 1, # Add 1 for the List length mix-in
// index=state.eth1_deposit_index,
// root=state.eth1_data.deposit_root,
// )
james-prysm marked this conversation as resolved.
Show resolved Hide resolved
//
// # Deposits must be processed in order
// state.eth1_deposit_index += 1
// # Deposits must be processed in order
// state.eth1_deposit_index += 1
//
// pubkey = deposit.data.pubkey
// amount = deposit.data.amount
// validator_pubkeys = [v.pubkey for v in state.validators]
// if pubkey not in validator_pubkeys:
// # Verify the deposit signature (proof of possession) which is not checked by the deposit contract
// deposit_message = DepositMessage(
// pubkey=deposit.data.pubkey,
// withdrawal_credentials=deposit.data.withdrawal_credentials,
// amount=deposit.data.amount,
// )
// domain = compute_domain(DOMAIN_DEPOSIT) # Fork-agnostic domain since deposits are valid across forks
// signing_root = compute_signing_root(deposit_message, domain)
// if not bls.Verify(pubkey, signing_root, deposit.data.signature):
// return
//
// # Add validator and balance entries
// state.validators.append(get_validator_from_deposit(state, deposit))
// state.balances.append(amount)
// else:
// # Increase balance by deposit amount
// index = ValidatorIndex(validator_pubkeys.index(pubkey))
// increase_balance(state, index, amount)
func ProcessDeposit(beaconState state.BeaconState, deposit *ethpb.Deposit, verifySignature bool) (state.BeaconState, bool, error) {
var newValidator bool
// apply_deposit(
// state=state,
// pubkey=deposit.data.pubkey,
// withdrawal_credentials=deposit.data.withdrawal_credentials,
// amount=deposit.data.amount,
// signature=deposit.data.signature,
// )
func ProcessDeposit(beaconState state.BeaconState, deposit *ethpb.Deposit, verifySignature bool) (state.BeaconState, error) {
if err := verifyDeposit(beaconState, deposit); err != nil {
if deposit == nil || deposit.Data == nil {
return nil, newValidator, err
return nil, err
}
return nil, newValidator, errors.Wrapf(err, "could not verify deposit from %#x", bytesutil.Trunc(deposit.Data.PublicKey))
return nil, errors.Wrapf(err, "could not verify deposit from %#x", bytesutil.Trunc(deposit.Data.PublicKey))
}
if err := beaconState.SetEth1DepositIndex(beaconState.Eth1DepositIndex() + 1); err != nil {
return nil, newValidator, err
return nil, err
}
pubKey := deposit.Data.PublicKey
amount := deposit.Data.Amount
return ApplyDeposit(beaconState, deposit.Data, verifySignature)
}

// ApplyDeposit
// def apply_deposit(state: BeaconState, pubkey: BLSPubkey, withdrawal_credentials: Bytes32, amount: uint64, signature: BLSSignature) -> None:
// validator_pubkeys = [v.pubkey for v in state.validators]
// if pubkey not in validator_pubkeys:
//
// # Verify the deposit signature (proof of possession) which is not checked by the deposit contract
// if is_valid_deposit_signature(pubkey, withdrawal_credentials, amount, signature):
// add_validator_to_registry(state, pubkey, withdrawal_credentials, amount)
//
// else:
//
// # Increase balance by deposit amount
// index = ValidatorIndex(validator_pubkeys.index(pubkey))
// state.pending_balance_deposits.append(PendingBalanceDeposit(index=index, amount=amount)) # [Modified in Electra:EIP-7251]
// # Check if valid deposit switch to compounding credentials
//
// if ( is_compounding_withdrawal_credential(withdrawal_credentials) and has_eth1_withdrawal_credential(state.validators[index])
//
// and is_valid_deposit_signature(pubkey, withdrawal_credentials, amount, signature)
// ):
// switch_to_compounding_validator(state, index)
func ApplyDeposit(beaconState state.BeaconState, data *ethpb.Deposit_Data, verifySignature bool) (state.BeaconState, error) {
pubKey := data.PublicKey
amount := data.Amount
withdrawalCredentials := data.WithdrawalCredentials
index, ok := beaconState.ValidatorIndexByPubkey(bytesutil.ToBytes48(pubKey))
james-prysm marked this conversation as resolved.
Show resolved Hide resolved
if !ok {
if verifySignature {
domain, err := signing.ComputeDomain(params.BeaconConfig().DomainDeposit, nil, nil)
valid, err := IsValidDepositSignature(data)
if err != nil {
return nil, newValidator, err
return nil, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to return error here even if a non sig operation may fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this have been a concern before? I was just wrapping the function for spec readability

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functionally shouldn't work differently than before

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. The same question applies to previous implementations. Can take it offline

}
if err := verifyDepositDataSigningRoot(deposit.Data, domain); err != nil {
// Ignore this error as in the spec pseudo code.
log.WithError(err).Debug("Skipping deposit: could not verify deposit data signature")
return beaconState, newValidator, nil
if !valid {
return beaconState, nil
}
}

effectiveBalance := amount - (amount % params.BeaconConfig().EffectiveBalanceIncrement)
if params.BeaconConfig().MaxEffectiveBalance < effectiveBalance {
effectiveBalance = params.BeaconConfig().MaxEffectiveBalance
if err := AddValidatorToRegistry(beaconState, pubKey, withdrawalCredentials, amount); err != nil {
return nil, err
}
} else {
if beaconState.Version() >= version.Electra {
//if err := beaconState.AppendPendingBalanceDeposit(index, amount); err != nil {
// return nil, newValidator, err
// }
// if ( is_compounding_withdrawal_credential(withdrawal_credentials) and has_eth1_withdrawal_credential(state.validators[index])
//
// and is_valid_deposit_signature(pubkey, withdrawal_credentials, amount, signature)
// ):
// switch_to_compounding_validator(state, index)
} else {
if err := helpers.IncreaseBalance(beaconState, index, amount); err != nil {
return nil, err
}
}
if err := beaconState.AppendValidator(&ethpb.Validator{
PublicKey: pubKey,
WithdrawalCredentials: deposit.Data.WithdrawalCredentials,
ActivationEligibilityEpoch: params.BeaconConfig().FarFutureEpoch,
ActivationEpoch: params.BeaconConfig().FarFutureEpoch,
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
EffectiveBalance: effectiveBalance,
}); err != nil {
return nil, newValidator, err
}

return beaconState, nil
}

// AddValidatorToRegistry
// def add_validator_to_registry(state: BeaconState,
//
// pubkey: BLSPubkey,
// withdrawal_credentials: Bytes32,
// amount: uint64) -> None:
// index = get_index_for_new_validator(state)
// validator = get_validator_from_deposit(pubkey, withdrawal_credentials)
// set_or_append_list(state.validators, index, validator)
// set_or_append_list(state.balances, index, 0) # [Modified in Electra:EIP7251]
// set_or_append_list(state.previous_epoch_participation, index, ParticipationFlags(0b0000_0000))
// set_or_append_list(state.current_epoch_participation, index, ParticipationFlags(0b0000_0000))
// set_or_append_list(state.inactivity_scores, index, uint64(0))
// state.pending_balance_deposits.append(PendingBalanceDeposit(index=index, amount=amount)) # [New in Electra:EIP7251]
func AddValidatorToRegistry(beaconState state.BeaconState, pubKey []byte, withdrawalCredentials []byte, amount uint64) error {
val := GetValidatorFromDeposit(beaconState.Version(), pubKey, withdrawalCredentials, amount)
if err := beaconState.AppendValidator(val); err != nil {
return err
}
if beaconState.Version() >= version.Electra {
if err := beaconState.AppendBalance(0); err != nil {
return err
}
newValidator = true
// In specs this function is at the end function
james-prysm marked this conversation as resolved.
Show resolved Hide resolved
// if err := beaconState.AppendPendingBalanceDeposit(index, amount); err != nil {
// return nil, newValidator, err
// }
} else {
if err := beaconState.AppendBalance(amount); err != nil {
return nil, newValidator, err
return err
}
} else if err := helpers.IncreaseBalance(beaconState, index, amount); err != nil {
return nil, newValidator, err
}

return beaconState, newValidator, nil
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this newValidator variable because I don't think it's needed after moving some functions around

if err := beaconState.AppendPreviousParticipationBits(0); err != nil {
return err
}
if err := beaconState.AppendCurrentParticipationBits(0); err != nil {
return err
}
return beaconState.AppendInactivityScore(0)
}

// GetValidatorFromDeposit gets a new validator object with provided paramaters
//
// def get_validator_from_deposit(pubkey: BLSPubkey, withdrawal_credentials: Bytes32) -> Validator:
//
// return Validator(
// pubkey=pubkey,
// withdrawal_credentials=withdrawal_credentials,
// activation_eligibility_epoch=FAR_FUTURE_EPOCH,
// activation_epoch=FAR_FUTURE_EPOCH,
// exit_epoch=FAR_FUTURE_EPOCH,
// withdrawable_epoch=FAR_FUTURE_EPOCH,
// effective_balance=0, # [Modified in Electra:EIP7251]
//
// )
func GetValidatorFromDeposit(stateVersion int, pubKey []byte, withdrawalCredentials []byte, amount uint64) *ethpb.Validator {
var effectiveBalance uint64
if stateVersion >= version.Electra {
effectiveBalance = 0 // [Modified in Electra:EIP7251]
} else {
effectiveBalance = amount - (amount % params.BeaconConfig().EffectiveBalanceIncrement)
if params.BeaconConfig().MaxEffectiveBalance < effectiveBalance {
effectiveBalance = params.BeaconConfig().MaxEffectiveBalance
}
}

return &ethpb.Validator{
PublicKey: pubKey,
WithdrawalCredentials: withdrawalCredentials,
ActivationEligibilityEpoch: params.BeaconConfig().FarFutureEpoch,
ActivationEpoch: params.BeaconConfig().FarFutureEpoch,
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
EffectiveBalance: effectiveBalance,
}
}

// IsValidDepositSignature returns whether deposit_data is valid
// def is_valid_deposit_signature(pubkey: BLSPubkey, withdrawal_credentials: Bytes32, amount: uint64, signature: BLSSignature) -> bool:
//
// deposit_message = DepositMessage( pubkey=pubkey, withdrawal_credentials=withdrawal_credentials, amount=amount, )
// domain = compute_domain(DOMAIN_DEPOSIT) # Fork-agnostic domain since deposits are valid across forks
// signing_root = compute_signing_root(deposit_message, domain)
// return bls.Verify(pubkey, signing_root, signature)
func IsValidDepositSignature(data *ethpb.Deposit_Data) (bool, error) {
domain, err := signing.ComputeDomain(params.BeaconConfig().DomainDeposit, nil, nil)
if err != nil {
return false, err
}
if err := verifyDepositDataSigningRoot(data, domain); err != nil {
// Ignore this error as in the spec pseudo code.
log.WithError(err).Debug("Skipping deposit: could not verify deposit data signature")
return false, nil
}
return true, nil
}

func verifyDeposit(beaconState state.ReadOnlyBeaconState, deposit *ethpb.Deposit) error {
Expand Down
40 changes: 40 additions & 0 deletions beacon-chain/core/electra/deposit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package electra

import (
"context"

"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/altair"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
)

func ProcessDepositReceipts(ctx context.Context, beaconState state.BeaconState, receipts []*enginev1.DepositReceipt) (state.BeaconState, error) {
if beaconState.Version() < version.Electra {
return beaconState, nil
}
// # Set deposit receipt start index
// if state.deposit_receipts_start_index == UNSET_DEPOSIT_RECEIPTS_START_INDEX:
// state.deposit_receipts_start_index = deposit_receipt.index
//
// apply_deposit(
// state=state,
// pubkey=deposit_receipt.pubkey,
// withdrawal_credentials=deposit_receipt.withdrawal_credentials,
// amount=deposit_receipt.amount,
// signature=deposit_receipt.signature,
//)
deposits := make([]*eth.Deposit, len(receipts))
for i, receipt := range receipts {
deposits[i] = &eth.Deposit{
Data: &eth.Deposit_Data{
PublicKey: bytesutil.SafeCopyBytes(receipt.Pubkey),
WithdrawalCredentials: bytesutil.SafeCopyBytes(receipt.WithdrawalCredentials),
Signature: bytesutil.SafeCopyBytes(receipt.Signature),
},
}
}
return altair.ProcessDeposits(ctx, beaconState, deposits)
}
17 changes: 10 additions & 7 deletions beacon-chain/core/transition/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,16 @@ func VerifyOperationLengths(_ context.Context, state state.BeaconState, b interf
return nil, errors.New("nil eth1data in state")
}
if state.Eth1DepositIndex() > eth1Data.DepositCount {
return nil, fmt.Errorf("expected state.deposit_index %d <= eth1data.deposit_count %d", state.Eth1DepositIndex(), eth1Data.DepositCount)
}
maxDeposits := math.Min(params.BeaconConfig().MaxDeposits, eth1Data.DepositCount-state.Eth1DepositIndex())
// Verify outstanding deposits are processed up to max number of deposits
if uint64(len(body.Deposits())) != maxDeposits {
return nil, fmt.Errorf("incorrect outstanding deposits in block body, wanted: %d, got: %d",
maxDeposits, len(body.Deposits()))
if len(body.Deposits()) != 0 {
Copy link
Contributor Author

@james-prysm james-prysm May 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double check as this is changing existing logic or if I need to handle it in a fork specific way

return nil, fmt.Errorf("expected no deposits, but got %d", len(body.Deposits()))
}
} else {
maxDeposits := math.Min(params.BeaconConfig().MaxDeposits, eth1Data.DepositCount-state.Eth1DepositIndex())
// Verify outstanding deposits are processed up to max number of deposits
if uint64(len(body.Deposits())) != maxDeposits {
return nil, fmt.Errorf("incorrect outstanding deposits in block body, wanted: %d, got: %d",
maxDeposits, len(body.Deposits()))
}
}

return state, nil
Expand Down
Loading
Loading