From 1bfa72d427ac5777414c9c5199b38675d44385d9 Mon Sep 17 00:00:00 2001 From: syjn99 Date: Sun, 8 Dec 2024 15:24:47 +0900 Subject: [PATCH 1/5] fix: early return for gathering local deposits when EIP-6110 is applied --- .../v1alpha1/validator/proposer_deposits.go | 26 ++++++ .../validator/proposer_deposits_test.go | 84 +++++++++++++++++++ 2 files changed, 110 insertions(+) diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_deposits.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_deposits.go index fc6d238add4a..134eb956d48a 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_deposits.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_deposits.go @@ -94,6 +94,14 @@ func (vs *Server) deposits( return nil, err } + // In the post-electra phase, this function will usually return an empty list, + // as the legacy deposit process is deprecated. (EIP-6110) + // NOTE: During the transition period, the legacy deposit process + // may still be active and managed. This function handles that scenario. + if !isLegacyDepositProcessPeriod(beaconState, canonicalEth1Data) { + return []*ethpb.Deposit{}, nil + } + _, genesisEth1Block := vs.Eth1InfoFetcher.GenesisExecutionChainInfo() if genesisEth1Block.Cmp(canonicalEth1DataHeight) == 0 { return []*ethpb.Deposit{}, nil @@ -277,3 +285,21 @@ func shouldRebuildTrie(totalDepCount, unFinalizedDeps uint64) bool { unFinalizedCompute := unFinalizedDeps * params.BeaconConfig().DepositContractTreeDepth return unFinalizedCompute > totalDepCount } + +// isLegacyDepositProcessPeriod determines if the current state should use the legacy deposit process. +func isLegacyDepositProcessPeriod(beaconState state.BeaconState, canonicalEth1Data *ethpb.Eth1Data) bool { + // Before the Electra upgrade, always use the legacy deposit process. + if beaconState.Version() < version.Electra { + return true + } + + // Handle the transition period between the legacy and the new deposit process. + requestsStartIndex, err := beaconState.DepositRequestsStartIndex() + if err != nil { + // If we can't get the deposit requests start index, + // we should default to the legacy deposit process. + return true + } + eth1DepositIndexLimit := math.Min(canonicalEth1Data.DepositCount, requestsStartIndex) + return beaconState.Eth1DepositIndex() < eth1DepositIndexLimit +} diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_deposits_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_deposits_test.go index 3b58a88f4fe1..851f2374e90d 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_deposits_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_deposits_test.go @@ -2,12 +2,14 @@ package validator import ( "context" + "math" "math/big" "testing" mock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing" "github.com/prysmaticlabs/prysm/v5/beacon-chain/cache/depositsnapshot" mockExecution "github.com/prysmaticlabs/prysm/v5/beacon-chain/execution/testing" + "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" state_native "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/container/trie" @@ -212,3 +214,85 @@ func TestProposer_PendingDeposits_Electra(t *testing.T) { assert.Equal(t, 0, len(deposits), "Received unexpected number of pending deposits") } + +func TestIsLegacyDepositProcessPeriod(t *testing.T) { + tests := []struct { + name string + state state.BeaconState + canonicalEth1Data *ethpb.Eth1Data + want bool + }{ + { + name: "pre-electra", + state: func() state.BeaconState { + st, err := state_native.InitializeFromProtoDeneb(ðpb.BeaconStateDeneb{ + Eth1Data: ðpb.Eth1Data{ + BlockHash: []byte("0x0"), + DepositRoot: make([]byte, 32), + DepositCount: 5, + }, + Eth1DepositIndex: 1, + }) + require.NoError(t, err) + return st + }(), + canonicalEth1Data: ðpb.Eth1Data{ + BlockHash: []byte("0x0"), + DepositRoot: make([]byte, 32), + DepositCount: 5, + }, + want: true, + }, + { + name: "post-electra, pending deposits from pre-electra", + state: func() state.BeaconState { + st, err := state_native.InitializeFromProtoElectra(ðpb.BeaconStateElectra{ + Eth1Data: ðpb.Eth1Data{ + BlockHash: []byte("0x0"), + DepositRoot: make([]byte, 32), + DepositCount: 5, + }, + DepositRequestsStartIndex: math.MaxUint64, + Eth1DepositIndex: 1, + }) + require.NoError(t, err) + return st + }(), + canonicalEth1Data: ðpb.Eth1Data{ + BlockHash: []byte("0x0"), + DepositRoot: make([]byte, 32), + DepositCount: 5, + }, + want: true, + }, + { + name: "post-electra, no pending deposits from pre-alpaca", + state: func() state.BeaconState { + st, err := state_native.InitializeFromProtoElectra(ðpb.BeaconStateElectra{ + Eth1Data: ðpb.Eth1Data{ + BlockHash: []byte("0x0"), + DepositRoot: make([]byte, 32), + DepositCount: 5, + }, + DepositRequestsStartIndex: 1, + Eth1DepositIndex: 5, + }) + require.NoError(t, err) + return st + }(), + canonicalEth1Data: ðpb.Eth1Data{ + BlockHash: []byte("0x0"), + DepositRoot: make([]byte, 32), + DepositCount: 5, + }, + want: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := isLegacyDepositProcessPeriod(tt.state, tt.canonicalEth1Data); got != tt.want { + t.Errorf("isLegacyDepositProcessPeriod() = %v, want %v", got, tt.want) + } + }) + } +} From 0d1fcd6360c7441da5a0ff51afc85505bb776f38 Mon Sep 17 00:00:00 2001 From: syjn99 Date: Sun, 8 Dec 2024 16:05:35 +0900 Subject: [PATCH 2/5] Add an entry on CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33055932d05d..08ab37a42a91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -110,6 +110,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve - P2P: Avoid infinite loop when looking for peers in small networks. - Fixed another rollback bug due to a context deadline. - Fix checkpoint sync bug on holesky. [pr](https://github.com/prysmaticlabs/prysm/pull/14689) +- Fixed deposit packing for post-Electra: early return if EIP-6110 is applied. ### Security @@ -1701,7 +1702,7 @@ Aside from the critical fixes for mainnet, this release contains a number of new - Use next slot cache for payload attribute - Cleanup keymanager mock - Update to go 1.20 -- Modify InsertFinalizedDeposits signature to return an error + - Modify InsertFinalizedDeposits signature to return an error - Improved statefeed initialization - Use v1alpha1 server in block production - Updated go generated files From 0e35d25cc2ae3c2201ed23ccb1004ea96b1548af Mon Sep 17 00:00:00 2001 From: syjn99 Date: Thu, 9 Jan 2025 17:06:03 +0900 Subject: [PATCH 3/5] Fix weird indent at CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43d162b82a27..23d6b58720ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1784,7 +1784,7 @@ Aside from the critical fixes for mainnet, this release contains a number of new - Use next slot cache for payload attribute - Cleanup keymanager mock - Update to go 1.20 - - Modify InsertFinalizedDeposits signature to return an error +- Modify InsertFinalizedDeposits signature to return an error - Improved statefeed initialization - Use v1alpha1 server in block production - Updated go generated files From a2dc7afd64837c0936c4a7db5d6daefe09e8fbf1 Mon Sep 17 00:00:00 2001 From: syjn99 Date: Thu, 23 Jan 2025 14:34:25 +0900 Subject: [PATCH 4/5] Add changelog --- CHANGELOG.md | 1 - changelog/syjn99_early-return-local-deposits.md | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelog/syjn99_early-return-local-deposits.md diff --git a/CHANGELOG.md b/CHANGELOG.md index a47b75a9a403..3c06aaf16733 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -136,7 +136,6 @@ Notable features: - Fix segmentation fault in E2E when light-client feature flag is enabled. [PR](https://github.com/prysmaticlabs/prysm/pull/14699) - Fix `searchForPeers` infinite loop in small networks. - Fix slashing pool behavior to enforce MaxAttesterSlashings limit in Electra version. -- Fixed deposit packing for post-Electra: early return if EIP-6110 is applied. ### Security diff --git a/changelog/syjn99_early-return-local-deposits.md b/changelog/syjn99_early-return-local-deposits.md new file mode 100644 index 000000000000..447b64cf186a --- /dev/null +++ b/changelog/syjn99_early-return-local-deposits.md @@ -0,0 +1,3 @@ +### Fixed + +- Fixed deposit packing for post-Electra: early return if EIP-6110 is applied. \ No newline at end of file From 05bea97fbe0b28c30b80c111fe1fd5fabf46165a Mon Sep 17 00:00:00 2001 From: syjn99 Date: Thu, 23 Jan 2025 14:35:05 +0900 Subject: [PATCH 5/5] Fix CHANGELOG.md --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c06aaf16733..18d61c61fd47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -137,7 +137,6 @@ Notable features: - Fix `searchForPeers` infinite loop in small networks. - Fix slashing pool behavior to enforce MaxAttesterSlashings limit in Electra version. - ### Security ## [v5.1.2](https://github.com/prysmaticlabs/prysm/compare/v5.1.1...v5.1.2) - 2024-10-16