Skip to content

Commit 791b97e

Browse files
committed
changes on #4897
1 parent b43d3af commit 791b97e

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

cl/phase1/core/state/epbs.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,30 @@ func GetPendingBalanceToWithdrawForBuilder(s abstract.BeaconState, builderIndex
178178
return total
179179
}
180180

181+
// IsPendingValidator returns true if there's a pending deposit for the given pubkey
182+
// with a valid signature. This is used to prevent builder deposits from being applied
183+
// when there's already a valid pending validator deposit for the same pubkey.
184+
// [New in Gloas:EIP7732]
185+
func IsPendingValidator(s abstract.BeaconState, pubkey common.Bytes48) bool {
186+
pendingDeposits := s.GetPendingDeposits()
187+
if pendingDeposits == nil {
188+
return false
189+
}
190+
cfg := s.BeaconConfig()
191+
for i := 0; i < pendingDeposits.Len(); i++ {
192+
deposit := pendingDeposits.Get(i)
193+
if deposit.PubKey != pubkey {
194+
continue
195+
}
196+
// Check if this pending deposit has a valid signature
197+
valid, err := IsValidDepositSignature(cfg, deposit.PubKey, deposit.WithdrawalCredentials, deposit.Amount, deposit.Signature)
198+
if err == nil && valid {
199+
return true
200+
}
201+
}
202+
return false
203+
}
204+
181205
// IsBuilderPubkey returns true if the given pubkey belongs to any builder in the state.
182206
// [New in Gloas:EIP7732]
183207
func IsBuilderPubkey(s abstract.BeaconState, pubkey common.Bytes48) bool {

cl/transition/impl/eth2/operations.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,10 +1523,14 @@ func (I *impl) ProcessDepositRequest(s abstract.BeaconState, depositRequest *sol
15231523
// [New in Gloas:EIP7732] Route builder deposits immediately
15241524
if s.Version() >= clparams.GloasVersion {
15251525
isBuilder := state.IsBuilderPubkey(s, depositRequest.PubKey)
1526-
_, isValidator := s.ValidatorIndexByPubkey(depositRequest.PubKey)
1527-
isBuilderPrefix := state.IsBuilderWithdrawalCredential(depositRequest.WithdrawalCredentials, s.BeaconConfig())
1528-
1529-
if isBuilder || (isBuilderPrefix && !isValidator) {
1526+
_, isExistingValidator := s.ValidatorIndexByPubkey(depositRequest.PubKey)
1527+
hasBuilderPrefix := state.IsBuilderWithdrawalCredential(depositRequest.WithdrawalCredentials, s.BeaconConfig())
1528+
// Check if there's a pending deposit with valid signature for this pubkey
1529+
isPendingValidator := state.IsPendingValidator(s, depositRequest.PubKey)
1530+
// isValidator includes both existing validators and pending validators with valid signatures
1531+
isValidator := isExistingValidator || isPendingValidator
1532+
1533+
if isBuilder || (hasBuilderPrefix && !isValidator) {
15301534
state.ApplyDepositForBuilder(s, depositRequest.PubKey, depositRequest.WithdrawalCredentials, depositRequest.Amount, depositRequest.Signature, s.Slot())
15311535
return nil
15321536
}

0 commit comments

Comments
 (0)