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

Eip6110 queue deposit requests #14430

Merged
merged 64 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
2cc1ff3
wip
james-prysm Aug 8, 2024
b008a3b
updating types and wip on functions
james-prysm Aug 9, 2024
8d0d444
fixing conficts and merging develop
james-prysm Sep 6, 2024
4a87609
Merge branch 'develop' into eip6110-queue
james-prysm Sep 6, 2024
a0bef32
renaming to MAX_PENDING_DEPOSITS_PER_EPOCH
james-prysm Sep 6, 2024
46e88f0
fixing linting and conversions
james-prysm Sep 6, 2024
6cf54bc
adding queue deposit changes
james-prysm Sep 6, 2024
5334144
Merge branch 'develop' into eip6110-queue
james-prysm Sep 6, 2024
3c25797
fixing test and cloning
james-prysm Sep 6, 2024
330cfa3
removing unneeded test based on update
james-prysm Sep 6, 2024
3566543
gaz
james-prysm Sep 6, 2024
41ba44b
Merge branch 'develop' into eip6110-queue
james-prysm Sep 9, 2024
0690e44
Merge branch 'develop' into eip6110-queue
james-prysm Sep 10, 2024
f697f65
wip apply pending deposit
james-prysm Sep 10, 2024
792a4f7
fixing replay test and adding apply pending deposit
james-prysm Sep 10, 2024
af3f8d0
Merge branch 'develop' into eip6110-queue
james-prysm Sep 12, 2024
8bb1fcc
fixing setters test
james-prysm Sep 11, 2024
5dda6df
updating transition test
james-prysm Sep 11, 2024
1e4e826
changelog
james-prysm Sep 12, 2024
29cf448
Merge branch 'develop' into eip6110-queue
james-prysm Sep 16, 2024
f1a2dca
updating pending deposits
james-prysm Sep 12, 2024
944afd1
fixing ProcessPendingDeposit unit tests
james-prysm Sep 16, 2024
5fb1e10
gaz
james-prysm Sep 16, 2024
1a55937
fixing cyclic dependencies
james-prysm Sep 16, 2024
fe2598d
fix visiblity
james-prysm Sep 17, 2024
26216ef
missed adding the right signature verification
james-prysm Sep 17, 2024
582444c
adding point to infinity topup test
james-prysm Sep 18, 2024
8776421
adding apply pending deposit test
james-prysm Sep 18, 2024
f6e06d7
making changes based on eip6110 changes
james-prysm Sep 19, 2024
9110135
fixing ineffassign
james-prysm Sep 19, 2024
9abebd7
gaz
james-prysm Sep 19, 2024
41f1406
Merge branch 'develop' into eip6110-queue
james-prysm Sep 20, 2024
f95f87c
adding batched verifications sigs
james-prysm Sep 23, 2024
377f5a6
Merge branch 'develop' into eip6110-queue
james-prysm Sep 23, 2024
134fe8c
Merge branch 'develop' into eip6110-queue
james-prysm Sep 24, 2024
fe5c942
Merge branch 'develop' into eip6110-queue
james-prysm Sep 26, 2024
b5d2d90
fixing broken type
james-prysm Sep 26, 2024
446cba2
fixing proto
james-prysm Sep 27, 2024
c3fb312
Merge branch 'develop' into eip6110-queue
james-prysm Sep 27, 2024
7a5ff1a
Merge branch 'develop' into eip6110-queue
james-prysm Oct 7, 2024
f976c26
updated consensus spec tests and fixed consensus bug tests
james-prysm Oct 8, 2024
c2e6686
Merge branch 'develop' into eip6110-queue
james-prysm Oct 8, 2024
abd0e1e
testing readability improvement by avoiding ApplyPendingDeposit
james-prysm Oct 8, 2024
5b40a23
removing the boolean from apply pending deposit
james-prysm Oct 8, 2024
64545de
improve naming
james-prysm Oct 8, 2024
c37cd17
review comments and fixing a small bug using wrong variable
james-prysm Oct 8, 2024
de43591
fixing tests and skipping a test
james-prysm Oct 8, 2024
dc38cf9
Merge branch 'develop' into eip6110-queue
james-prysm Oct 8, 2024
7abdd5d
adding some test skips
james-prysm Oct 8, 2024
6677634
fixing bugs terence found
james-prysm Oct 8, 2024
4e310e7
Merge branch 'develop' into eip6110-queue
james-prysm Oct 8, 2024
d52d819
adding test for batchProcessNewPendingDeposits
james-prysm Oct 8, 2024
c66c2e9
gaz
james-prysm Oct 8, 2024
44a41c4
adding churn test
james-prysm Oct 9, 2024
197163b
updating spec tests to alpha.8
james-prysm Oct 9, 2024
1c0d70e
Merge branch 'develop' into eip6110-queue
james-prysm Oct 9, 2024
0eb8e79
adding pr to changelog
james-prysm Oct 9, 2024
c48a58b
addressing terence's comments
james-prysm Oct 10, 2024
cc3e941
Update beacon-chain/core/electra/validator.go
james-prysm Oct 10, 2024
a637027
adding tests for batch verify and rename some variables
james-prysm Oct 10, 2024
fa23924
Merge branch 'develop' into eip6110-queue
james-prysm Oct 10, 2024
cd39461
skipping tests , add them back in later
james-prysm Oct 10, 2024
9b96fa6
skipping one more test
james-prysm Oct 10, 2024
d786dc5
Merge branch 'develop' into eip6110-queue
james-prysm Oct 11, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
- Light client support: Implement `ComputeFieldRootsForBlockBody`.
- Light client support: Add light client database changes.
- Light client support: Implement capella and deneb changes.
- Electra EIP6110: Queue deposit [pr](https://github.com/prysmaticlabs/prysm/pull/14430)
- Light client support: Implement `BlockToLightClientHeader` function.
- Light client support: Consensus types.
- GetBeaconStateV2: add Electra case.
Expand Down Expand Up @@ -44,6 +45,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
- `grpc-gateway-corsdomain` is renamed to http-cors-domain. The old name can still be used as an alias.
- `api-timeout` is changed from int flag to duration flag, default value updated.
- Light client support: abstracted out the light client headers with different versions.
- Electra EIP6110: Queue deposit requests changes from consensus spec pr #3818
- `ApplyToEveryValidator` has been changed to prevent misuse bugs, it takes a closure that takes a `ReadOnlyValidator` and returns a raw pointer to a `Validator`.
- Removed gorilla mux library and replaced it with net/http updates in go 1.22.
- Clean up `ProposeBlock` for validator client to reduce cognitive scoring and enable further changes.
Expand Down
10 changes: 5 additions & 5 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ filegroup(
url = "https://github.com/ethereum/EIPs/archive/5480440fe51742ed23342b68cf106cefd427e39d.tar.gz",
)

consensus_spec_version = "v1.5.0-alpha.6"
consensus_spec_version = "v1.5.0-alpha.8"

bls_test_version = "v0.1.1"

Expand All @@ -243,7 +243,7 @@ filegroup(
visibility = ["//visibility:public"],
)
""",
integrity = "sha256-M7u/Ot/Vzorww+dFbHp0cxLyM2mezJjijCzq+LY3uvs=",
integrity = "sha256-BsGIbEyJuYrzhShGl0tHhR4lP5Qwno8R3k8a6YBR/DA=",
url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/general.tar.gz" % consensus_spec_version,
)

Expand All @@ -259,7 +259,7 @@ filegroup(
visibility = ["//visibility:public"],
)
""",
integrity = "sha256-deOSeLRsmHXvkRp8n2bs3HXdkGUJWWqu8KFM/QABbZg=",
integrity = "sha256-DkdvhPP2KiqUOpwFXQIFDCWCwsUDIC/xhTBD+TZevm0=",
url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/minimal.tar.gz" % consensus_spec_version,
)

Expand All @@ -275,7 +275,7 @@ filegroup(
visibility = ["//visibility:public"],
)
""",
integrity = "sha256-Zz7YCf6XVf57nzSEGq9ToflJFHM0lAGwhd18l9Rf3hA=",
integrity = "sha256-vkZqV0HB8A2Uc56C1Us/p5G57iaHL+zw2No93Xt6M/4=",
url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/mainnet.tar.gz" % consensus_spec_version,
)

Expand All @@ -290,7 +290,7 @@ filegroup(
visibility = ["//visibility:public"],
)
""",
integrity = "sha256-BoXckDxXnDcEmAjg/dQgf/tLiJsb6CT0aZvmWHFijrY=",
integrity = "sha256-D/HPAW61lKqjoWwl7N0XvhdX+67dCEFAy8JxVzqBGtU=",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

can someone double check this one for me

strip_prefix = "consensus-specs-" + consensus_spec_version[1:],
url = "https://github.com/ethereum/consensus-specs/archive/refs/tags/%s.tar.gz" % consensus_spec_version,
)
Expand Down
13 changes: 8 additions & 5 deletions api/server/structs/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1476,12 +1476,15 @@ func DepositSnapshotFromConsensus(ds *eth.DepositSnapshot) *DepositSnapshot {
}
}

func PendingBalanceDepositsFromConsensus(ds []*eth.PendingBalanceDeposit) []*PendingBalanceDeposit {
deposits := make([]*PendingBalanceDeposit, len(ds))
func PendingDepositsFromConsensus(ds []*eth.PendingDeposit) []*PendingDeposit {
deposits := make([]*PendingDeposit, len(ds))
for i, d := range ds {
deposits[i] = &PendingBalanceDeposit{
Index: fmt.Sprintf("%d", d.Index),
Amount: fmt.Sprintf("%d", d.Amount),
deposits[i] = &PendingDeposit{
Pubkey: hexutil.Encode(d.PublicKey),
WithdrawalCredentials: hexutil.Encode(d.WithdrawalCredentials),
Amount: fmt.Sprintf("%d", d.Amount),
Signature: hexutil.Encode(d.Signature),
Slot: fmt.Sprintf("%d", d.Slot),
}
}
return deposits
Expand Down
4 changes: 2 additions & 2 deletions api/server/structs/conversions_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ func BeaconStateElectraFromConsensus(st beaconState.BeaconState) (*BeaconStateEl
if err != nil {
return nil, err
}
pbd, err := st.PendingBalanceDeposits()
pbd, err := st.PendingDeposits()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -770,7 +770,7 @@ func BeaconStateElectraFromConsensus(st beaconState.BeaconState) (*BeaconStateEl
EarliestExitEpoch: fmt.Sprintf("%d", eee),
ConsolidationBalanceToConsume: fmt.Sprintf("%d", cbtc),
EarliestConsolidationEpoch: fmt.Sprintf("%d", ece),
PendingBalanceDeposits: PendingBalanceDepositsFromConsensus(pbd),
PendingDeposits: PendingDepositsFromConsensus(pbd),
PendingPartialWithdrawals: PendingPartialWithdrawalsFromConsensus(ppw),
PendingConsolidations: PendingConsolidationsFromConsensus(pc),
}, nil
Expand Down
9 changes: 6 additions & 3 deletions api/server/structs/other.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,12 @@ type ConsolidationRequest struct {
TargetPubkey string `json:"target_pubkey"`
}

type PendingBalanceDeposit struct {
Index string `json:"index"`
Amount string `json:"amount"`
type PendingDeposit struct {
Pubkey string `json:"pubkey"`
WithdrawalCredentials string `json:"withdrawal_credentials"`
Amount string `json:"amount"`
Signature string `json:"signature"`
Slot string `json:"slot"`
}

type PendingPartialWithdrawal struct {
Expand Down
2 changes: 1 addition & 1 deletion api/server/structs/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ type BeaconStateElectra struct {
EarliestExitEpoch string `json:"earliest_exit_epoch"`
ConsolidationBalanceToConsume string `json:"consolidation_balance_to_consume"`
EarliestConsolidationEpoch string `json:"earliest_consolidation_epoch"`
PendingBalanceDeposits []*PendingBalanceDeposit `json:"pending_balance_deposits"`
PendingDeposits []*PendingDeposit `json:"pending_deposits"`
PendingPartialWithdrawals []*PendingPartialWithdrawal `json:"pending_partial_withdrawals"`
PendingConsolidations []*PendingConsolidation `json:"pending_consolidations"`
}
56 changes: 56 additions & 0 deletions beacon-chain/core/blocks/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ func BatchVerifyDepositsSignatures(ctx context.Context, deposits []*ethpb.Deposi
return true, nil
}

// BatchVerifyPendingDepositsSignatures batch verifies pending deposit signatures.
func BatchVerifyPendingDepositsSignatures(ctx context.Context, deposits []*ethpb.PendingDeposit) (bool, error) {
var err error
domain, err := signing.ComputeDomain(params.BeaconConfig().DomainDeposit, nil, nil)
if err != nil {
return false, err
}

if err := verifyPendingDepositDataWithDomain(ctx, deposits, domain); err != nil {
log.WithError(err).Debug("Failed to batch verify deposits signatures, will try individual verify")
return false, nil
}
return true, nil
}

// IsValidDepositSignature returns whether deposit_data is valid
// def is_valid_deposit_signature(pubkey: BLSPubkey, withdrawal_credentials: Bytes32, amount: uint64, signature: BLSSignature) -> bool:
//
Expand Down Expand Up @@ -158,3 +173,44 @@ func verifyDepositDataWithDomain(ctx context.Context, deps []*ethpb.Deposit, dom
}
return nil
}

func verifyPendingDepositDataWithDomain(ctx context.Context, deps []*ethpb.PendingDeposit, domain []byte) error {
Copy link
Member

Choose a reason for hiding this comment

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

In general, all of these may benefit from unit tests, but I’ll leave that decision to you:

  • verifyPendingDepositDataWithDomain
  • BatchVerifyPendingDepositsSignatures
  • batchProcessNewPendingDeposits

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added one for batch ProcessNewPendingDeposits, can add more

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added more tests

if len(deps) == 0 {
return nil
}
pks := make([]bls.PublicKey, len(deps))
sigs := make([][]byte, len(deps))
msgs := make([][32]byte, len(deps))
for i, dep := range deps {
if ctx.Err() != nil {
return ctx.Err()
}
if dep == nil {
return errors.New("nil deposit")
}
dpk, err := bls.PublicKeyFromBytes(dep.PublicKey)
if err != nil {
return err
}
pks[i] = dpk
sigs[i] = dep.Signature
depositMessage := &ethpb.DepositMessage{
PublicKey: dep.PublicKey,
WithdrawalCredentials: dep.WithdrawalCredentials,
Amount: dep.Amount,
}
sr, err := signing.ComputeSigningRoot(depositMessage, domain)
if err != nil {
return err
}
msgs[i] = sr
}
verify, err := bls.VerifyMultipleSignatures(sigs, msgs, pks)
if err != nil {
return errors.Errorf("could not verify multiple signatures: %v", err)
}
if !verify {
return errors.New("one or more deposit signatures did not verify")
}
return nil
}
51 changes: 51 additions & 0 deletions beacon-chain/core/blocks/deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,54 @@ func TestIsValidDepositSignature_Ok(t *testing.T) {
require.NoError(t, err)
require.Equal(t, true, valid)
}

func TestBatchVerifyPendingDepositsSignatures_Ok(t *testing.T) {
sk, err := bls.RandKey()
require.NoError(t, err)
domain, err := signing.ComputeDomain(params.BeaconConfig().DomainDeposit, nil, nil)
require.NoError(t, err)
pendingDeposit := &ethpb.PendingDeposit{
PublicKey: sk.PublicKey().Marshal(),
WithdrawalCredentials: make([]byte, 32),
Amount: 3000,
}
sr, err := signing.ComputeSigningRoot(&ethpb.DepositMessage{
PublicKey: pendingDeposit.PublicKey,
WithdrawalCredentials: pendingDeposit.WithdrawalCredentials,
Amount: 3000,
}, domain)
require.NoError(t, err)
sig := sk.Sign(sr[:])
pendingDeposit.Signature = sig.Marshal()

sk2, err := bls.RandKey()
require.NoError(t, err)
pendingDeposit2 := &ethpb.PendingDeposit{
PublicKey: sk2.PublicKey().Marshal(),
WithdrawalCredentials: make([]byte, 32),
Amount: 4000,
}
sr2, err := signing.ComputeSigningRoot(&ethpb.DepositMessage{
PublicKey: pendingDeposit2.PublicKey,
WithdrawalCredentials: pendingDeposit2.WithdrawalCredentials,
Amount: 4000,
}, domain)
require.NoError(t, err)
sig2 := sk2.Sign(sr2[:])
pendingDeposit2.Signature = sig2.Marshal()

verified, err := blocks.BatchVerifyPendingDepositsSignatures(context.Background(), []*ethpb.PendingDeposit{pendingDeposit, pendingDeposit2})
require.NoError(t, err)
require.Equal(t, true, verified)
}

func TestBatchVerifyPendingDepositsSignatures_InvalidSignature(t *testing.T) {
pendingDeposit := &ethpb.PendingDeposit{
PublicKey: bytesutil.PadTo([]byte{1, 2, 3}, 48),
WithdrawalCredentials: make([]byte, 32),
Signature: make([]byte, 96),
}
verified, err := blocks.BatchVerifyPendingDepositsSignatures(context.Background(), []*ethpb.PendingDeposit{pendingDeposit})
require.NoError(t, err)
require.Equal(t, false, verified)
}
7 changes: 6 additions & 1 deletion beacon-chain/core/electra/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ go_library(
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//contracts/deposit:go_default_library",
"//crypto/bls/common:go_default_library",
"//encoding/bytesutil:go_default_library",
"//math:go_default_library",
"//monitoring/tracing/trace:go_default_library",
"//proto/engine/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//runtime/version:go_default_library",
"//time/slots:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_pkg_errors//:go_default_library",
Expand All @@ -52,24 +54,27 @@ go_test(
"deposit_fuzz_test.go",
"deposits_test.go",
"effective_balance_updates_test.go",
"export_test.go",
"registry_updates_test.go",
"transition_test.go",
"upgrade_test.go",
"validator_test.go",
"withdrawals_test.go",
],
embed = [":go_default_library"],
deps = [
":go_default_library",
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/core/signing:go_default_library",
"//beacon-chain/core/time:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/state-native:go_default_library",
"//beacon-chain/state/testing:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//consensus-types/blocks:go_default_library",
"//consensus-types/primitives:go_default_library",
"//crypto/bls:go_default_library",
"//crypto/bls/common:go_default_library",
"//encoding/bytesutil:go_default_library",
"//proto/engine/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
Expand Down
32 changes: 0 additions & 32 deletions beacon-chain/core/electra/consolidations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,38 +201,6 @@ func TestProcessPendingConsolidations(t *testing.T) {
}
}

func stateWithActiveBalanceETH(t *testing.T, balETH uint64) state.BeaconState {
gwei := balETH * 1_000_000_000
balPerVal := params.BeaconConfig().MinActivationBalance
numVals := gwei / balPerVal

vals := make([]*eth.Validator, numVals)
bals := make([]uint64, numVals)
for i := uint64(0); i < numVals; i++ {
wc := make([]byte, 32)
wc[0] = params.BeaconConfig().ETH1AddressWithdrawalPrefixByte
wc[31] = byte(i)
vals[i] = &eth.Validator{
ActivationEpoch: 0,
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
EffectiveBalance: balPerVal,
WithdrawalCredentials: wc,
}
bals[i] = balPerVal
}
st, err := state_native.InitializeFromProtoUnsafeElectra(&eth.BeaconStateElectra{
Slot: 10 * params.BeaconConfig().SlotsPerEpoch,
Validators: vals,
Balances: bals,
Fork: &eth.Fork{
CurrentVersion: params.BeaconConfig().ElectraForkVersion,
},
})
require.NoError(t, err)

return st
}

func TestProcessConsolidationRequests(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading
Loading