diff --git a/beacon-chain/state/BUILD.bazel b/beacon-chain/state/BUILD.bazel index 298a1adbb7f9..274a8adc3e89 100644 --- a/beacon-chain/state/BUILD.bazel +++ b/beacon-chain/state/BUILD.bazel @@ -13,7 +13,6 @@ go_library( "//config/fieldparams:go_default_library", "//consensus-types/interfaces:go_default_library", "//consensus-types/primitives:go_default_library", - "//proto/engine/v1:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "@com_github_prometheus_client_golang//prometheus:go_default_library", "@com_github_prometheus_client_golang//prometheus/promauto:go_default_library", diff --git a/beacon-chain/state/interfaces.go b/beacon-chain/state/interfaces.go index 6397684ecbdf..6d17353e43f6 100644 --- a/beacon-chain/state/interfaces.go +++ b/beacon-chain/state/interfaces.go @@ -10,7 +10,6 @@ import ( fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" ) @@ -63,6 +62,7 @@ type ReadOnlyBeaconState interface { IsNil() bool Version() int LatestExecutionPayloadHeader() (interfaces.ExecutionData, error) + LastWithdrawalValidatorIndex() (types.ValidatorIndex, error) } // WriteOnlyBeaconState defines a struct which only has write access to beacon state methods. @@ -85,10 +85,8 @@ type WriteOnlyBeaconState interface { UpdateSlashingsAtIndex(idx, val uint64) error AppendHistoricalRoots(root [32]byte) error SetLatestExecutionPayloadHeader(payload interfaces.ExecutionData) error - SetWithdrawalQueue(val []*enginev1.Withdrawal) error - AppendWithdrawal(val *enginev1.Withdrawal) error SetNextWithdrawalIndex(i uint64) error - SetNextPartialWithdrawalValidatorIndex(i types.ValidatorIndex) error + SetLastWithdrawalValidatorIndex(i types.ValidatorIndex) error } // ReadOnlyValidator defines a struct which only has read access to validator methods. diff --git a/beacon-chain/state/state-native/beacon_state_mainnet.go b/beacon-chain/state/state-native/beacon_state_mainnet.go index 722bcae8c292..cd16775decb0 100644 --- a/beacon-chain/state/state-native/beacon_state_mainnet.go +++ b/beacon-chain/state/state-native/beacon_state_mainnet.go @@ -47,9 +47,8 @@ type BeaconState struct { nextSyncCommittee *ethpb.SyncCommittee `ssz-gen:"true"` latestExecutionPayloadHeader *enginev1.ExecutionPayloadHeader `ssz-gen:"true"` latestExecutionPayloadHeaderCapella *enginev1.ExecutionPayloadHeaderCapella `ssz-gen:"true"` - withdrawalQueue []*enginev1.Withdrawal `ssz-gen:"true" ssz-max:"1099511627776"` nextWithdrawalIndex uint64 `ssz-gen:"true"` - nextPartialWithdrawalValidatorIndex eth2types.ValidatorIndex `ssz-gen:"true"` + lastWithdrawalValidatorIndex eth2types.ValidatorIndex `ssz-gen:"true"` lock sync.RWMutex dirtyFields map[nativetypes.FieldIndex]bool diff --git a/beacon-chain/state/state-native/beacon_state_minimal.go b/beacon-chain/state/state-native/beacon_state_minimal.go index 0fd83f705561..b2e829a7326a 100644 --- a/beacon-chain/state/state-native/beacon_state_minimal.go +++ b/beacon-chain/state/state-native/beacon_state_minimal.go @@ -47,9 +47,8 @@ type BeaconState struct { nextSyncCommittee *ethpb.SyncCommittee `ssz-gen:"true"` latestExecutionPayloadHeader *enginev1.ExecutionPayloadHeader `ssz-gen:"true"` latestExecutionPayloadHeaderCapella *enginev1.ExecutionPayloadHeaderCapella `ssz-gen:"true"` - withdrawalQueue []*enginev1.Withdrawal `ssz-gen:"true" ssz-max:"1099511627776"` nextWithdrawalIndex uint64 `ssz-gen:"true"` - nextPartialWithdrawalValidatorIndex eth2types.ValidatorIndex `ssz-gen:"true"` + lastWithdrawalValidatorIndex eth2types.ValidatorIndex `ssz-gen:"true"` lock sync.RWMutex dirtyFields map[nativetypes.FieldIndex]bool diff --git a/beacon-chain/state/state-native/getters_state.go b/beacon-chain/state/state-native/getters_state.go index 177e727e936a..dd96816daa0e 100644 --- a/beacon-chain/state/state-native/getters_state.go +++ b/beacon-chain/state/state-native/getters_state.go @@ -99,34 +99,33 @@ func (b *BeaconState) ToProtoUnsafe() interface{} { } case version.Capella: return ðpb.BeaconStateCapella{ - GenesisTime: b.genesisTime, - GenesisValidatorsRoot: gvrCopy[:], - Slot: b.slot, - Fork: b.fork, - LatestBlockHeader: b.latestBlockHeader, - BlockRoots: b.blockRoots.Slice(), - StateRoots: b.stateRoots.Slice(), - HistoricalRoots: b.historicalRoots.Slice(), - Eth1Data: b.eth1Data, - Eth1DataVotes: b.eth1DataVotes, - Eth1DepositIndex: b.eth1DepositIndex, - Validators: b.validators, - Balances: b.balances, - RandaoMixes: b.randaoMixes.Slice(), - Slashings: b.slashings, - PreviousEpochParticipation: b.previousEpochParticipation, - CurrentEpochParticipation: b.currentEpochParticipation, - JustificationBits: b.justificationBits, - PreviousJustifiedCheckpoint: b.previousJustifiedCheckpoint, - CurrentJustifiedCheckpoint: b.currentJustifiedCheckpoint, - FinalizedCheckpoint: b.finalizedCheckpoint, - InactivityScores: b.inactivityScores, - CurrentSyncCommittee: b.currentSyncCommittee, - NextSyncCommittee: b.nextSyncCommittee, - LatestExecutionPayloadHeader: b.latestExecutionPayloadHeaderCapella, - WithdrawalQueue: b.withdrawalQueue, - NextWithdrawalIndex: b.nextWithdrawalIndex, - NextPartialWithdrawalValidatorIndex: b.nextPartialWithdrawalValidatorIndex, + GenesisTime: b.genesisTime, + GenesisValidatorsRoot: gvrCopy[:], + Slot: b.slot, + Fork: b.fork, + LatestBlockHeader: b.latestBlockHeader, + BlockRoots: b.blockRoots.Slice(), + StateRoots: b.stateRoots.Slice(), + HistoricalRoots: b.historicalRoots.Slice(), + Eth1Data: b.eth1Data, + Eth1DataVotes: b.eth1DataVotes, + Eth1DepositIndex: b.eth1DepositIndex, + Validators: b.validators, + Balances: b.balances, + RandaoMixes: b.randaoMixes.Slice(), + Slashings: b.slashings, + PreviousEpochParticipation: b.previousEpochParticipation, + CurrentEpochParticipation: b.currentEpochParticipation, + JustificationBits: b.justificationBits, + PreviousJustifiedCheckpoint: b.previousJustifiedCheckpoint, + CurrentJustifiedCheckpoint: b.currentJustifiedCheckpoint, + FinalizedCheckpoint: b.finalizedCheckpoint, + InactivityScores: b.inactivityScores, + CurrentSyncCommittee: b.currentSyncCommittee, + NextSyncCommittee: b.nextSyncCommittee, + LatestExecutionPayloadHeader: b.latestExecutionPayloadHeaderCapella, + NextWithdrawalIndex: b.nextWithdrawalIndex, + LastWithdrawalValidatorIndex: b.lastWithdrawalValidatorIndex, } default: return nil @@ -226,34 +225,33 @@ func (b *BeaconState) ToProto() interface{} { } case version.Capella: return ðpb.BeaconStateCapella{ - GenesisTime: b.genesisTime, - GenesisValidatorsRoot: gvrCopy[:], - Slot: b.slot, - Fork: b.forkVal(), - LatestBlockHeader: b.latestBlockHeaderVal(), - BlockRoots: b.blockRoots.Slice(), - StateRoots: b.stateRoots.Slice(), - HistoricalRoots: b.historicalRoots.Slice(), - Eth1Data: b.eth1DataVal(), - Eth1DataVotes: b.eth1DataVotesVal(), - Eth1DepositIndex: b.eth1DepositIndex, - Validators: b.validatorsVal(), - Balances: b.balancesVal(), - RandaoMixes: b.randaoMixes.Slice(), - Slashings: b.slashingsVal(), - PreviousEpochParticipation: b.previousEpochParticipationVal(), - CurrentEpochParticipation: b.currentEpochParticipationVal(), - JustificationBits: b.justificationBitsVal(), - PreviousJustifiedCheckpoint: b.previousJustifiedCheckpointVal(), - CurrentJustifiedCheckpoint: b.currentJustifiedCheckpointVal(), - FinalizedCheckpoint: b.finalizedCheckpointVal(), - InactivityScores: b.inactivityScoresVal(), - CurrentSyncCommittee: b.currentSyncCommitteeVal(), - NextSyncCommittee: b.nextSyncCommitteeVal(), - LatestExecutionPayloadHeader: b.latestExecutionPayloadHeaderCapellaVal(), - WithdrawalQueue: b.withdrawalQueueVal(), - NextWithdrawalIndex: b.nextWithdrawalIndex, - NextPartialWithdrawalValidatorIndex: b.nextPartialWithdrawalValidatorIndex, + GenesisTime: b.genesisTime, + GenesisValidatorsRoot: gvrCopy[:], + Slot: b.slot, + Fork: b.forkVal(), + LatestBlockHeader: b.latestBlockHeaderVal(), + BlockRoots: b.blockRoots.Slice(), + StateRoots: b.stateRoots.Slice(), + HistoricalRoots: b.historicalRoots.Slice(), + Eth1Data: b.eth1DataVal(), + Eth1DataVotes: b.eth1DataVotesVal(), + Eth1DepositIndex: b.eth1DepositIndex, + Validators: b.validatorsVal(), + Balances: b.balancesVal(), + RandaoMixes: b.randaoMixes.Slice(), + Slashings: b.slashingsVal(), + PreviousEpochParticipation: b.previousEpochParticipationVal(), + CurrentEpochParticipation: b.currentEpochParticipationVal(), + JustificationBits: b.justificationBitsVal(), + PreviousJustifiedCheckpoint: b.previousJustifiedCheckpointVal(), + CurrentJustifiedCheckpoint: b.currentJustifiedCheckpointVal(), + FinalizedCheckpoint: b.finalizedCheckpointVal(), + InactivityScores: b.inactivityScoresVal(), + CurrentSyncCommittee: b.currentSyncCommitteeVal(), + NextSyncCommittee: b.nextSyncCommitteeVal(), + LatestExecutionPayloadHeader: b.latestExecutionPayloadHeaderCapellaVal(), + NextWithdrawalIndex: b.nextWithdrawalIndex, + LastWithdrawalValidatorIndex: b.lastWithdrawalValidatorIndex, } default: return nil diff --git a/beacon-chain/state/state-native/getters_withdrawal.go b/beacon-chain/state/state-native/getters_withdrawal.go index fc0c9675268d..580f2bed43da 100644 --- a/beacon-chain/state/state-native/getters_withdrawal.go +++ b/beacon-chain/state/state-native/getters_withdrawal.go @@ -2,27 +2,9 @@ package state_native import ( types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v3/runtime/version" ) -// WithdrawalQueue returns the list of pending withdrawals. -func (b *BeaconState) WithdrawalQueue() ([]*enginev1.Withdrawal, error) { - if b.version < version.Capella { - return nil, errNotSupported("WithdrawalQueue", b.version) - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.withdrawalQueueVal(), nil -} - -func (b *BeaconState) withdrawalQueueVal() []*enginev1.Withdrawal { - return ethpb.CopyWithdrawalSlice(b.withdrawalQueue) -} - // NextWithdrawalIndex returns the index that will be assigned to the next withdrawal. func (b *BeaconState) NextWithdrawalIndex() (uint64, error) { if b.version < version.Capella { @@ -37,13 +19,13 @@ func (b *BeaconState) NextWithdrawalIndex() (uint64, error) { // NextPartialWithdrawalValidatorIndex returns the index of the validator which is // next in line for a partial withdrawal. -func (b *BeaconState) NextPartialWithdrawalValidatorIndex() (types.ValidatorIndex, error) { +func (b *BeaconState) LastWithdrawalValidatorIndex() (types.ValidatorIndex, error) { if b.version < version.Capella { - return 0, errNotSupported("NextPartialWithdrawalValidatorIndex", b.version) + return 0, errNotSupported("LastWithdrawalValidatorIndex", b.version) } b.lock.RLock() defer b.lock.RUnlock() - return b.nextPartialWithdrawalValidatorIndex, nil + return b.lastWithdrawalValidatorIndex, nil } diff --git a/beacon-chain/state/state-native/getters_withdrawal_test.go b/beacon-chain/state/state-native/getters_withdrawal_test.go index 2147acf28786..547becb9cf27 100644 --- a/beacon-chain/state/state-native/getters_withdrawal_test.go +++ b/beacon-chain/state/state-native/getters_withdrawal_test.go @@ -4,38 +4,11 @@ import ( "testing" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1" "github.com/prysmaticlabs/prysm/v3/runtime/version" "github.com/prysmaticlabs/prysm/v3/testing/assert" "github.com/prysmaticlabs/prysm/v3/testing/require" ) -func TestWithdrawalQueue(t *testing.T) { - t.Run("ok", func(t *testing.T) { - ws := []*enginev1.Withdrawal{ - { - WithdrawalIndex: 0, - ExecutionAddress: []byte("address1"), - Amount: 1, - }, - { - WithdrawalIndex: 1, - ExecutionAddress: []byte("address2"), - Amount: 2, - }, - } - s := BeaconState{version: version.Capella, withdrawalQueue: ws} - q, err := s.WithdrawalQueue() - require.NoError(t, err) - assert.DeepEqual(t, ws, q) - }) - t.Run("version before Capella not supported", func(t *testing.T) { - s := BeaconState{version: version.Bellatrix} - _, err := s.WithdrawalQueue() - assert.ErrorContains(t, "WithdrawalQueue is not supported", err) - }) -} - func TestNextWithdrawalIndex(t *testing.T) { t.Run("ok", func(t *testing.T) { s := BeaconState{version: version.Capella, nextWithdrawalIndex: 123} @@ -50,16 +23,16 @@ func TestNextWithdrawalIndex(t *testing.T) { }) } -func TestNextPartialWithdrawalValidatorIndex(t *testing.T) { +func TestLastWithdrawalValidatorIndex(t *testing.T) { t.Run("ok", func(t *testing.T) { - s := BeaconState{version: version.Capella, nextPartialWithdrawalValidatorIndex: 123} - i, err := s.NextPartialWithdrawalValidatorIndex() + s := BeaconState{version: version.Capella, lastWithdrawalValidatorIndex: 123} + i, err := s.LastWithdrawalValidatorIndex() require.NoError(t, err) assert.Equal(t, types.ValidatorIndex(123), i) }) t.Run("version before Capella not supported", func(t *testing.T) { s := BeaconState{version: version.Bellatrix} - _, err := s.NextPartialWithdrawalValidatorIndex() - assert.ErrorContains(t, "NextPartialWithdrawalValidatorIndex is not supported", err) + _, err := s.LastWithdrawalValidatorIndex() + assert.ErrorContains(t, "LastWithdrawalValidatorIndex is not supported", err) }) } diff --git a/beacon-chain/state/state-native/hasher.go b/beacon-chain/state/state-native/hasher.go index 3e49cc31c018..28fc588cdf17 100644 --- a/beacon-chain/state/state-native/hasher.go +++ b/beacon-chain/state/state-native/hasher.go @@ -246,13 +246,6 @@ func ComputeFieldRootsWithHasher(ctx context.Context, state *BeaconState) ([][]b } fieldRoots[nativetypes.LatestExecutionPayloadHeaderCapella.RealPosition()] = executionPayloadRoot[:] - // Withdrawal queue root. - withdrawalQueueRoot, err := ssz.WithdrawalSliceRoot(hasher, state.withdrawalQueue, fieldparams.WithdrawalQueueLimit) - if err != nil { - return nil, err - } - fieldRoots[nativetypes.WithdrawalQueue.RealPosition()] = withdrawalQueueRoot[:] - // Next withdrawal index root. nextWithdrawalIndexRoot := make([]byte, 32) binary.LittleEndian.PutUint64(nextWithdrawalIndexRoot, state.nextWithdrawalIndex) @@ -260,8 +253,8 @@ func ComputeFieldRootsWithHasher(ctx context.Context, state *BeaconState) ([][]b // Next partial withdrawal validator index root. nextPartialWithdrawalValidatorIndexRoot := make([]byte, 32) - binary.LittleEndian.PutUint64(nextPartialWithdrawalValidatorIndexRoot, uint64(state.nextPartialWithdrawalValidatorIndex)) - fieldRoots[nativetypes.NextPartialWithdrawalValidatorIndex.RealPosition()] = nextPartialWithdrawalValidatorIndexRoot + binary.LittleEndian.PutUint64(nextPartialWithdrawalValidatorIndexRoot, uint64(state.lastWithdrawalValidatorIndex)) + fieldRoots[nativetypes.LastWithdrawalValidatorIndex.RealPosition()] = nextPartialWithdrawalValidatorIndexRoot } return fieldRoots, nil diff --git a/beacon-chain/state/state-native/hasher_test.go b/beacon-chain/state/state-native/hasher_test.go index 8d724aa5c802..7b081f72aacc 100644 --- a/beacon-chain/state/state-native/hasher_test.go +++ b/beacon-chain/state/state-native/hasher_test.go @@ -256,9 +256,8 @@ func TestComputeFieldRootsWithHasher_Capella(t *testing.T) { wrappedHeader, err := blocks.WrappedExecutionPayloadHeaderCapella(executionPayloadHeaderCapella()) require.NoError(t, err) require.NoError(t, beaconState.SetLatestExecutionPayloadHeader(wrappedHeader)) - require.NoError(t, beaconState.SetWithdrawalQueue([]*enginev1.Withdrawal{withdrawal()})) require.NoError(t, beaconState.SetNextWithdrawalIndex(123)) - require.NoError(t, beaconState.SetNextPartialWithdrawalValidatorIndex(123)) + require.NoError(t, beaconState.SetLastWithdrawalValidatorIndex(123)) nativeState, ok := beaconState.(*statenative.BeaconState) require.Equal(t, true, ok) @@ -297,7 +296,6 @@ func TestComputeFieldRootsWithHasher_Capella(t *testing.T) { {0x3d, 0xf3, 0x66, 0xd4, 0x12, 0x40, 0x3f, 0x28, 0xeb, 0xe4, 0x19, 0x59, 0xae, 0xab, 0x4d, 0xf3, 0x98, 0x88, 0x7f, 0x1e, 0x58, 0xa, 0x5d, 0xd4, 0xeb, 0xe5, 0x5d, 0x3d, 0x11, 0x70, 0x24, 0x76}, {0xd6, 0x4c, 0xb1, 0xac, 0x61, 0x7, 0x26, 0xbb, 0xd3, 0x27, 0x2a, 0xcd, 0xdd, 0x55, 0xf, 0x2b, 0x6a, 0xe8, 0x1, 0x31, 0x48, 0x66, 0x2f, 0x98, 0x7b, 0x6d, 0x27, 0x69, 0xd9, 0x40, 0xcc, 0x37}, {0x39, 0x29, 0x16, 0xe8, 0x5a, 0xd2, 0xb, 0xbb, 0x1f, 0xef, 0x6a, 0xe0, 0x2d, 0xa6, 0x6a, 0x46, 0x81, 0xba, 0xcf, 0x86, 0xfc, 0x16, 0x22, 0x2a, 0x9b, 0x72, 0x96, 0x71, 0x2b, 0xc7, 0x5b, 0x9d}, - {0xf4, 0x45, 0x82, 0x69, 0xdb, 0xbf, 0x2e, 0x9, 0x52, 0xc0, 0xf9, 0xe8, 0x59, 0x17, 0xe0, 0xaf, 0x31, 0x80, 0x79, 0xf3, 0x1d, 0x9d, 0xce, 0xaa, 0xd8, 0x22, 0xc7, 0xeb, 0xf5, 0xd3, 0x85, 0x7e}, {0x7b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, {0x7b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, } diff --git a/beacon-chain/state/state-native/setters_withdrawal.go b/beacon-chain/state/state-native/setters_withdrawal.go index 7ec1dc0fdedc..a19156a0b5e6 100644 --- a/beacon-chain/state/state-native/setters_withdrawal.go +++ b/beacon-chain/state/state-native/setters_withdrawal.go @@ -1,63 +1,10 @@ package state_native import ( - "fmt" - - nativetypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native/types" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1" "github.com/prysmaticlabs/prysm/v3/runtime/version" ) -// SetWithdrawalQueue for the beacon state. Updates the entire list -// to a new value by overwriting the previous one. -func (b *BeaconState) SetWithdrawalQueue(val []*enginev1.Withdrawal) error { - if b.version < version.Capella { - return errNotSupported("SetWithdrawalQueue", b.version) - } - - b.lock.Lock() - defer b.lock.Unlock() - - b.withdrawalQueue = val - b.sharedFieldReferences[nativetypes.WithdrawalQueue].MinusRef() - b.sharedFieldReferences[nativetypes.WithdrawalQueue] = stateutil.NewRef(1) - b.markFieldAsDirty(nativetypes.WithdrawalQueue) - b.rebuildTrie[nativetypes.WithdrawalQueue] = true - return nil -} - -// AppendWithdrawal adds a new withdrawal to the end of withdrawal queue. -func (b *BeaconState) AppendWithdrawal(val *enginev1.Withdrawal) error { - if b.version < version.Capella { - return errNotSupported("AppendWithdrawal", b.version) - } - - b.lock.Lock() - defer b.lock.Unlock() - - q := b.withdrawalQueue - max := uint64(fieldparams.ValidatorRegistryLimit) - if uint64(len(q)) == max { - return fmt.Errorf("withdrawal queue has max length %d", max) - } - - if b.sharedFieldReferences[nativetypes.WithdrawalQueue].Refs() > 1 { - // Copy elements in underlying array by reference. - q = make([]*enginev1.Withdrawal, len(b.withdrawalQueue)) - copy(q, b.withdrawalQueue) - b.sharedFieldReferences[nativetypes.WithdrawalQueue].MinusRef() - b.sharedFieldReferences[nativetypes.WithdrawalQueue] = stateutil.NewRef(1) - } - - b.withdrawalQueue = append(q, val) - b.markFieldAsDirty(nativetypes.WithdrawalQueue) - b.addDirtyIndices(nativetypes.WithdrawalQueue, []uint64{uint64(len(b.withdrawalQueue) - 1)}) - return nil -} - // SetNextWithdrawalIndex sets the index that will be assigned to the next withdrawal. func (b *BeaconState) SetNextWithdrawalIndex(i uint64) error { if b.version < version.Capella { @@ -71,9 +18,9 @@ func (b *BeaconState) SetNextWithdrawalIndex(i uint64) error { return nil } -// SetNextPartialWithdrawalValidatorIndex sets the index of the validator which is +// SetLastWithdrawalValidatorIndex sets the index of the validator which is // next in line for a partial withdrawal. -func (b *BeaconState) SetNextPartialWithdrawalValidatorIndex(i types.ValidatorIndex) error { +func (b *BeaconState) SetLastWithdrawalValidatorIndex(i types.ValidatorIndex) error { if b.version < version.Capella { return errNotSupported("SetNextPartialWithdrawalValidatorIndex", b.version) } @@ -81,6 +28,6 @@ func (b *BeaconState) SetNextPartialWithdrawalValidatorIndex(i types.ValidatorIn b.lock.Lock() defer b.lock.Unlock() - b.nextPartialWithdrawalValidatorIndex = i + b.lastWithdrawalValidatorIndex = i return nil } diff --git a/beacon-chain/state/state-native/setters_withdrawal_test.go b/beacon-chain/state/state-native/setters_withdrawal_test.go index 55849ea36eda..09ede1c4d5a3 100644 --- a/beacon-chain/state/state-native/setters_withdrawal_test.go +++ b/beacon-chain/state/state-native/setters_withdrawal_test.go @@ -3,99 +3,24 @@ package state_native import ( "testing" - nativetypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native/types" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1" + types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v3/runtime/version" - "github.com/prysmaticlabs/prysm/v3/testing/assert" "github.com/prysmaticlabs/prysm/v3/testing/require" ) -func TestSetWithdrawalQueue(t *testing.T) { - t.Run("ok", func(t *testing.T) { - oldQ := []*enginev1.Withdrawal{ - { - WithdrawalIndex: 0, - ExecutionAddress: []byte("address1"), - Amount: 1, - ValidatorIndex: 2, - }, - { - WithdrawalIndex: 1, - ExecutionAddress: []byte("address2"), - Amount: 2, - ValidatorIndex: 3, - }, - } - newQ := []*enginev1.Withdrawal{ - { - WithdrawalIndex: 2, - ExecutionAddress: []byte("address3"), - Amount: 3, - ValidatorIndex: 4, - }, - { - WithdrawalIndex: 3, - ExecutionAddress: []byte("address4"), - Amount: 4, - ValidatorIndex: 5, - }, - } - s := BeaconState{ - version: version.Capella, - withdrawalQueue: oldQ, - sharedFieldReferences: map[nativetypes.FieldIndex]*stateutil.Reference{nativetypes.WithdrawalQueue: stateutil.NewRef(1)}, - dirtyFields: map[nativetypes.FieldIndex]bool{}, - rebuildTrie: map[nativetypes.FieldIndex]bool{}, - } - err := s.SetWithdrawalQueue(newQ) - require.NoError(t, err) - assert.DeepEqual(t, newQ, s.withdrawalQueue) - }) - t.Run("version before Capella not supported", func(t *testing.T) { - s := BeaconState{version: version.Bellatrix} - err := s.SetWithdrawalQueue([]*enginev1.Withdrawal{}) - assert.ErrorContains(t, "SetWithdrawalQueue is not supported", err) - }) +func TestSetNextWithdrawalIndex(t *testing.T) { + s := BeaconState{ + version: version.Capella, + nextWithdrawalIndex: 3, + } + require.NoError(t, s.SetNextWithdrawalIndex(5)) + require.Equal(t, uint64(5), s.nextWithdrawalIndex) } - -func TestAppendWithdrawal(t *testing.T) { - t.Run("ok", func(t *testing.T) { - oldWithdrawal1 := &enginev1.Withdrawal{ - WithdrawalIndex: 0, - ExecutionAddress: []byte("address1"), - Amount: 1, - ValidatorIndex: 2, - } - oldWithdrawal2 := &enginev1.Withdrawal{ - WithdrawalIndex: 1, - ExecutionAddress: []byte("address2"), - Amount: 2, - ValidatorIndex: 3, - } - q := []*enginev1.Withdrawal{oldWithdrawal1, oldWithdrawal2} - s := BeaconState{ - version: version.Capella, - withdrawalQueue: q, - sharedFieldReferences: map[nativetypes.FieldIndex]*stateutil.Reference{nativetypes.WithdrawalQueue: stateutil.NewRef(1)}, - dirtyFields: map[nativetypes.FieldIndex]bool{}, - dirtyIndices: map[nativetypes.FieldIndex][]uint64{}, - rebuildTrie: map[nativetypes.FieldIndex]bool{}, - } - newWithdrawal := &enginev1.Withdrawal{ - WithdrawalIndex: 2, - ExecutionAddress: []byte("address3"), - Amount: 3, - ValidatorIndex: 4, - } - err := s.AppendWithdrawal(newWithdrawal) - require.NoError(t, err) - expectedQ := []*enginev1.Withdrawal{oldWithdrawal1, oldWithdrawal2, newWithdrawal} - assert.DeepEqual(t, expectedQ, s.withdrawalQueue) - }) - t.Run("version before Capella not supported", func(t *testing.T) { - s := BeaconState{version: version.Bellatrix} - err := s.AppendWithdrawal(&enginev1.Withdrawal{}) - assert.ErrorContains(t, "AppendWithdrawal is not supported", err) - }) +func TestSetLastWithdrawalValidatorIndex(t *testing.T) { + s := BeaconState{ + version: version.Capella, + lastWithdrawalValidatorIndex: 3, + } + require.NoError(t, s.SetLastWithdrawalValidatorIndex(5)) + require.Equal(t, types.ValidatorIndex(5), s.lastWithdrawalValidatorIndex) } diff --git a/beacon-chain/state/state-native/state_trie.go b/beacon-chain/state/state-native/state_trie.go index 0f0f53ae1034..d6285eb54e7d 100644 --- a/beacon-chain/state/state-native/state_trie.go +++ b/beacon-chain/state/state-native/state_trie.go @@ -80,9 +80,8 @@ var bellatrixFields = append(altairFields, nativetypes.LatestExecutionPayloadHea var capellaFields = append( altairFields, nativetypes.LatestExecutionPayloadHeaderCapella, - nativetypes.WithdrawalQueue, nativetypes.NextWithdrawalIndex, - nativetypes.NextPartialWithdrawalValidatorIndex, + nativetypes.LastWithdrawalValidatorIndex, ) const ( @@ -432,9 +431,8 @@ func InitializeFromProtoUnsafeCapella(st *ethpb.BeaconStateCapella) (state.Beaco currentSyncCommittee: st.CurrentSyncCommittee, nextSyncCommittee: st.NextSyncCommittee, latestExecutionPayloadHeaderCapella: st.LatestExecutionPayloadHeader, - withdrawalQueue: st.WithdrawalQueue, nextWithdrawalIndex: st.NextWithdrawalIndex, - nextPartialWithdrawalValidatorIndex: st.NextPartialWithdrawalValidatorIndex, + lastWithdrawalValidatorIndex: st.LastWithdrawalValidatorIndex, dirtyFields: make(map[nativetypes.FieldIndex]bool, fieldCount), dirtyIndices: make(map[nativetypes.FieldIndex][]uint64, fieldCount), @@ -468,7 +466,6 @@ func InitializeFromProtoUnsafeCapella(st *ethpb.BeaconStateCapella) (state.Beaco b.sharedFieldReferences[nativetypes.CurrentEpochParticipationBits] = stateutil.NewRef(1) b.sharedFieldReferences[nativetypes.InactivityScores] = stateutil.NewRef(1) b.sharedFieldReferences[nativetypes.LatestExecutionPayloadHeaderCapella] = stateutil.NewRef(1) // New in Capella. - b.sharedFieldReferences[nativetypes.WithdrawalQueue] = stateutil.NewRef(1) // New in Capella. state.StateCount.Inc() // Finalizer runs when dst is being destroyed in garbage collection. @@ -497,11 +494,11 @@ func (b *BeaconState) Copy() state.BeaconState { version: b.version, // Primitive nativetypes, safe to copy. - genesisTime: b.genesisTime, - slot: b.slot, - eth1DepositIndex: b.eth1DepositIndex, - nextWithdrawalIndex: b.nextWithdrawalIndex, - nextPartialWithdrawalValidatorIndex: b.nextPartialWithdrawalValidatorIndex, + genesisTime: b.genesisTime, + slot: b.slot, + eth1DepositIndex: b.eth1DepositIndex, + nextWithdrawalIndex: b.nextWithdrawalIndex, + lastWithdrawalValidatorIndex: b.lastWithdrawalValidatorIndex, // Large arrays, infrequently changed, constant size. blockRoots: b.blockRoots, @@ -519,7 +516,6 @@ func (b *BeaconState) Copy() state.BeaconState { previousEpochParticipation: b.previousEpochParticipation, currentEpochParticipation: b.currentEpochParticipation, inactivityScores: b.inactivityScores, - withdrawalQueue: b.withdrawalQueue, // Everything else, too small to be concerned about, constant size. genesisValidatorsRoot: b.genesisValidatorsRoot, @@ -833,12 +829,10 @@ func (b *BeaconState) rootSelector(ctx context.Context, field nativetypes.FieldI return b.latestExecutionPayloadHeader.HashTreeRoot() case nativetypes.LatestExecutionPayloadHeaderCapella: return b.latestExecutionPayloadHeaderCapella.HashTreeRoot() - case nativetypes.WithdrawalQueue: - return ssz.WithdrawalSliceRoot(hasher, b.withdrawalQueue, fieldparams.WithdrawalQueueLimit) case nativetypes.NextWithdrawalIndex: return ssz.Uint64Root(b.nextWithdrawalIndex), nil - case nativetypes.NextPartialWithdrawalValidatorIndex: - return ssz.Uint64Root(uint64(b.nextPartialWithdrawalValidatorIndex)), nil + case nativetypes.LastWithdrawalValidatorIndex: + return ssz.Uint64Root(uint64(b.lastWithdrawalValidatorIndex)), nil } return [32]byte{}, errors.New("invalid field index provided") } diff --git a/beacon-chain/state/state-native/types/types.go b/beacon-chain/state/state-native/types/types.go index 0491f443cb62..caab5400f3e2 100644 --- a/beacon-chain/state/state-native/types/types.go +++ b/beacon-chain/state/state-native/types/types.go @@ -67,12 +67,10 @@ func (f FieldIndex) String(_ int) string { return "latestExecutionPayloadHeader" case LatestExecutionPayloadHeaderCapella: return "LatestExecutionPayloadHeaderCapella" - case WithdrawalQueue: - return "WithdrawalQueue" case NextWithdrawalIndex: return "NextWithdrawalIndex" - case NextPartialWithdrawalValidatorIndex: - return "NextPartialWithdrawalValidatorIndex" + case LastWithdrawalValidatorIndex: + return "LastWithdrawalValidatorIndex" default: return "" } @@ -132,12 +130,10 @@ func (f FieldIndex) RealPosition() int { return 23 case LatestExecutionPayloadHeader, LatestExecutionPayloadHeaderCapella: return 24 - case WithdrawalQueue: - return 25 case NextWithdrawalIndex: + return 25 + case LastWithdrawalValidatorIndex: return 26 - case NextPartialWithdrawalValidatorIndex: - return 27 default: return -1 } @@ -193,7 +189,6 @@ const ( NextSyncCommittee LatestExecutionPayloadHeader LatestExecutionPayloadHeaderCapella - WithdrawalQueue NextWithdrawalIndex - NextPartialWithdrawalValidatorIndex + LastWithdrawalValidatorIndex ) diff --git a/config/params/mainnet_config.go b/config/params/mainnet_config.go index 11746c273c67..a6e3d63f3636 100644 --- a/config/params/mainnet_config.go +++ b/config/params/mainnet_config.go @@ -188,7 +188,7 @@ var mainnetBeaconConfig = &BeaconChainConfig{ BeaconStateFieldCount: 21, BeaconStateAltairFieldCount: 24, BeaconStateBellatrixFieldCount: 25, - BeaconStateCapellaFieldCount: 28, + BeaconStateCapellaFieldCount: 27, // Slasher related values. WeakSubjectivityPeriod: 54000, diff --git a/proto/engine/v1/generated.ssz.go b/proto/engine/v1/generated.ssz.go index 513f068b0b0d..eea7213491a5 100644 --- a/proto/engine/v1/generated.ssz.go +++ b/proto/engine/v1/generated.ssz.go @@ -1,5 +1,5 @@ // Code generated by fastssz. DO NOT EDIT. -// Hash: 31e013ad8172683b80becdea6758152590fde462f910057764c6505bc7ea8a00 +// Hash: 4e8004aa4b0d6e4e28f371cdc26af4fa63db0b593f92b190ebe7ad8897e76d91 package enginev1 import ( diff --git a/proto/eth/ext/options.pb.go b/proto/eth/ext/options.pb.go index f87a62f72444..827f9f8e2d50 100755 --- a/proto/eth/ext/options.pb.go +++ b/proto/eth/ext/options.pb.go @@ -9,9 +9,9 @@ package ext import ( reflect "reflect" + descriptor "github.com/golang/protobuf/protoc-gen-go/descriptor" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" - descriptorpb "google.golang.org/protobuf/types/descriptorpb" ) const ( @@ -23,7 +23,7 @@ const ( var file_proto_eth_ext_options_proto_extTypes = []protoimpl.ExtensionInfo{ { - ExtendedType: (*descriptorpb.FieldOptions)(nil), + ExtendedType: (*descriptor.FieldOptions)(nil), ExtensionType: (*string)(nil), Field: 50000, Name: "ethereum.eth.ext.cast_type", @@ -31,7 +31,7 @@ var file_proto_eth_ext_options_proto_extTypes = []protoimpl.ExtensionInfo{ Filename: "proto/eth/ext/options.proto", }, { - ExtendedType: (*descriptorpb.FieldOptions)(nil), + ExtendedType: (*descriptor.FieldOptions)(nil), ExtensionType: (*string)(nil), Field: 50001, Name: "ethereum.eth.ext.ssz_size", @@ -39,7 +39,7 @@ var file_proto_eth_ext_options_proto_extTypes = []protoimpl.ExtensionInfo{ Filename: "proto/eth/ext/options.proto", }, { - ExtendedType: (*descriptorpb.FieldOptions)(nil), + ExtendedType: (*descriptor.FieldOptions)(nil), ExtensionType: (*string)(nil), Field: 50002, Name: "ethereum.eth.ext.ssz_max", @@ -47,7 +47,7 @@ var file_proto_eth_ext_options_proto_extTypes = []protoimpl.ExtensionInfo{ Filename: "proto/eth/ext/options.proto", }, { - ExtendedType: (*descriptorpb.FieldOptions)(nil), + ExtendedType: (*descriptor.FieldOptions)(nil), ExtensionType: (*string)(nil), Field: 50003, Name: "ethereum.eth.ext.spec_name", @@ -56,7 +56,7 @@ var file_proto_eth_ext_options_proto_extTypes = []protoimpl.ExtensionInfo{ }, } -// Extension fields to descriptorpb.FieldOptions. +// Extension fields to descriptor.FieldOptions. var ( // optional string cast_type = 50000; E_CastType = &file_proto_eth_ext_options_proto_extTypes[0] @@ -103,7 +103,7 @@ var file_proto_eth_ext_options_proto_rawDesc = []byte{ } var file_proto_eth_ext_options_proto_goTypes = []interface{}{ - (*descriptorpb.FieldOptions)(nil), // 0: google.protobuf.FieldOptions + (*descriptor.FieldOptions)(nil), // 0: google.protobuf.FieldOptions } var file_proto_eth_ext_options_proto_depIdxs = []int32{ 0, // 0: ethereum.eth.ext.cast_type:extendee -> google.protobuf.FieldOptions diff --git a/proto/eth/v1/generated.ssz.go b/proto/eth/v1/generated.ssz.go index 8acf3d345abd..bc491259a55f 100644 --- a/proto/eth/v1/generated.ssz.go +++ b/proto/eth/v1/generated.ssz.go @@ -1,5 +1,5 @@ // Code generated by fastssz. DO NOT EDIT. -// Hash: 41b1687c0049ab35fd19ee80d7cf1f4e7cbef38df496d12f5712307cf18c7c22 +// Hash: 3678f7a589562bfa6f57a029a8af1b650a425ceaac9640563f0c6acbe4605afb package v1 import ( diff --git a/proto/eth/v2/generated.ssz.go b/proto/eth/v2/generated.ssz.go index a4460926d756..5a4f531abac3 100644 --- a/proto/eth/v2/generated.ssz.go +++ b/proto/eth/v2/generated.ssz.go @@ -1,5 +1,5 @@ // Code generated by fastssz. DO NOT EDIT. -// Hash: e539e7c3cea2056d796d5846d655be313a15d46696724acd627234a2f25d8b2b +// Hash: 5c8f9b4b976753e80d600bd0a18f70be6d3021b18e7d4b82a5ab22e5c521f061 package eth import ( diff --git a/proto/prysm/v1alpha1/attestation/aggregation/attestations/attestations.go b/proto/prysm/v1alpha1/attestation/aggregation/attestations/attestations.go index ebfae92a5cf1..79c6c6f089b0 100644 --- a/proto/prysm/v1alpha1/attestation/aggregation/attestations/attestations.go +++ b/proto/prysm/v1alpha1/attestation/aggregation/attestations/attestations.go @@ -27,11 +27,11 @@ var ErrInvalidAttestationCount = errors.New("invalid number of attestations") // Aggregation occurs in-place i.e. contents of input array will be modified. Should you need to // preserve input attestations, clone them before aggregating: // -// clonedAtts := make([]*ethpb.Attestation, len(atts)) -// for i, a := range atts { -// clonedAtts[i] = stateTrie.CopyAttestation(a) -// } -// aggregatedAtts, err := attaggregation.Aggregate(clonedAtts) +// clonedAtts := make([]*ethpb.Attestation, len(atts)) +// for i, a := range atts { +// clonedAtts[i] = stateTrie.CopyAttestation(a) +// } +// aggregatedAtts, err := attaggregation.Aggregate(clonedAtts) func Aggregate(atts []*ethpb.Attestation) ([]*ethpb.Attestation, error) { return MaxCoverAttestationAggregation(atts) } diff --git a/proto/prysm/v1alpha1/attestation/attestation_utils.go b/proto/prysm/v1alpha1/attestation/attestation_utils.go index 21e8de7bccd7..d57fb59ef885 100644 --- a/proto/prysm/v1alpha1/attestation/attestation_utils.go +++ b/proto/prysm/v1alpha1/attestation/attestation_utils.go @@ -25,17 +25,18 @@ import ( // a state. // // Spec pseudocode definition: -// def get_indexed_attestation(state: BeaconState, attestation: Attestation) -> IndexedAttestation: -// """ -// Return the indexed attestation corresponding to ``attestation``. -// """ -// attesting_indices = get_attesting_indices(state, attestation.data, attestation.aggregation_bits) // -// return IndexedAttestation( -// attesting_indices=sorted(attesting_indices), -// data=attestation.data, -// signature=attestation.signature, -// ) +// def get_indexed_attestation(state: BeaconState, attestation: Attestation) -> IndexedAttestation: +// """ +// Return the indexed attestation corresponding to ``attestation``. +// """ +// attesting_indices = get_attesting_indices(state, attestation.data, attestation.aggregation_bits) +// +// return IndexedAttestation( +// attesting_indices=sorted(attesting_indices), +// data=attestation.data, +// signature=attestation.signature, +// ) func ConvertToIndexed(ctx context.Context, attestation *ethpb.Attestation, committee []types.ValidatorIndex) (*ethpb.IndexedAttestation, error) { ctx, span := trace.StartSpan(ctx, "attestationutil.ConvertToIndexed") defer span.End() @@ -61,14 +62,15 @@ func ConvertToIndexed(ctx context.Context, attestation *ethpb.Attestation, commi // Having the committee as an argument allows for re-use of beacon committees when possible. // // Spec pseudocode definition: -// def get_attesting_indices(state: BeaconState, -// data: AttestationData, -// bits: Bitlist[MAX_VALIDATORS_PER_COMMITTEE]) -> Set[ValidatorIndex]: -// """ -// Return the set of attesting indices corresponding to ``data`` and ``bits``. -// """ -// committee = get_beacon_committee(state, data.slot, data.index) -// return set(index for i, index in enumerate(committee) if bits[i]) +// +// def get_attesting_indices(state: BeaconState, +// data: AttestationData, +// bits: Bitlist[MAX_VALIDATORS_PER_COMMITTEE]) -> Set[ValidatorIndex]: +// """ +// Return the set of attesting indices corresponding to ``data`` and ``bits``. +// """ +// committee = get_beacon_committee(state, data.slot, data.index) +// return set(index for i, index in enumerate(committee) if bits[i]) func AttestingIndices(bf bitfield.Bitfield, committee []types.ValidatorIndex) ([]uint64, error) { if bf.Len() != uint64(len(committee)) { return nil, fmt.Errorf("bitfield length %d is not equal to committee length %d", bf.Len(), len(committee)) @@ -87,19 +89,20 @@ func AttestingIndices(bf bitfield.Bitfield, committee []types.ValidatorIndex) ([ // comment. // // Spec pseudocode definition: -// def is_valid_indexed_attestation(state: BeaconState, indexed_attestation: IndexedAttestation) -> bool: -// """ -// Check if ``indexed_attestation`` is not empty, has sorted and unique indices and has a valid aggregate signature. -// """ -// # Verify indices are sorted and unique -// indices = indexed_attestation.attesting_indices -// if len(indices) == 0 or not indices == sorted(set(indices)): -// return False -// # Verify aggregate signature -// pubkeys = [state.validators[i].pubkey for i in indices] -// domain = get_domain(state, DOMAIN_BEACON_ATTESTER, indexed_attestation.data.target.epoch) -// signing_root = compute_signing_root(indexed_attestation.data, domain) -// return bls.FastAggregateVerify(pubkeys, signing_root, indexed_attestation.signature) +// +// def is_valid_indexed_attestation(state: BeaconState, indexed_attestation: IndexedAttestation) -> bool: +// """ +// Check if ``indexed_attestation`` is not empty, has sorted and unique indices and has a valid aggregate signature. +// """ +// # Verify indices are sorted and unique +// indices = indexed_attestation.attesting_indices +// if len(indices) == 0 or not indices == sorted(set(indices)): +// return False +// # Verify aggregate signature +// pubkeys = [state.validators[i].pubkey for i in indices] +// domain = get_domain(state, DOMAIN_BEACON_ATTESTER, indexed_attestation.data.target.epoch) +// signing_root = compute_signing_root(indexed_attestation.data, domain) +// return bls.FastAggregateVerify(pubkeys, signing_root, indexed_attestation.signature) func VerifyIndexedAttestationSig(ctx context.Context, indexedAtt *ethpb.IndexedAttestation, pubKeys []bls.PublicKey, domain []byte) error { ctx, span := trace.StartSpan(ctx, "attestationutil.VerifyIndexedAttestationSig") defer span.End() @@ -122,23 +125,24 @@ func VerifyIndexedAttestationSig(ctx context.Context, indexedAtt *ethpb.IndexedA } // IsValidAttestationIndices this helper function performs the first part of the -// spec indexed attestation validation starting at Check if ``indexed_attestation`` +// spec indexed attestation validation starting at Check if “indexed_attestation“ // comment and ends at Verify aggregate signature comment. // // Spec pseudocode definition: -// def is_valid_indexed_attestation(state: BeaconState, indexed_attestation: IndexedAttestation) -> bool: -// """ -// Check if ``indexed_attestation`` is not empty, has sorted and unique indices and has a valid aggregate signature. -// """ -// # Verify indices are sorted and unique -// indices = indexed_attestation.attesting_indices -// if len(indices) == 0 or not indices == sorted(set(indices)): -// return False -// # Verify aggregate signature -// pubkeys = [state.validators[i].pubkey for i in indices] -// domain = get_domain(state, DOMAIN_BEACON_ATTESTER, indexed_attestation.data.target.epoch) -// signing_root = compute_signing_root(indexed_attestation.data, domain) -// return bls.FastAggregateVerify(pubkeys, signing_root, indexed_attestation.signature) +// +// def is_valid_indexed_attestation(state: BeaconState, indexed_attestation: IndexedAttestation) -> bool: +// """ +// Check if ``indexed_attestation`` is not empty, has sorted and unique indices and has a valid aggregate signature. +// """ +// # Verify indices are sorted and unique +// indices = indexed_attestation.attesting_indices +// if len(indices) == 0 or not indices == sorted(set(indices)): +// return False +// # Verify aggregate signature +// pubkeys = [state.validators[i].pubkey for i in indices] +// domain = get_domain(state, DOMAIN_BEACON_ATTESTER, indexed_attestation.data.target.epoch) +// signing_root = compute_signing_root(indexed_attestation.data, domain) +// return bls.FastAggregateVerify(pubkeys, signing_root, indexed_attestation.signature) func IsValidAttestationIndices(ctx context.Context, indexedAttestation *ethpb.IndexedAttestation) error { ctx, span := trace.StartSpan(ctx, "attestationutil.IsValidAttestationIndices") defer span.End() diff --git a/proto/prysm/v1alpha1/beacon_state.pb.go b/proto/prysm/v1alpha1/beacon_state.pb.go index 37725e05134b..2405a8777a28 100755 --- a/proto/prysm/v1alpha1/beacon_state.pb.go +++ b/proto/prysm/v1alpha1/beacon_state.pb.go @@ -1313,34 +1313,33 @@ type BeaconStateCapella struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - GenesisTime uint64 `protobuf:"varint,1001,opt,name=genesis_time,json=genesisTime,proto3" json:"genesis_time,omitempty"` - GenesisValidatorsRoot []byte `protobuf:"bytes,1002,opt,name=genesis_validators_root,json=genesisValidatorsRoot,proto3" json:"genesis_validators_root,omitempty" ssz-size:"32"` - Slot github_com_prysmaticlabs_prysm_v3_consensus_types_primitives.Slot `protobuf:"varint,1003,opt,name=slot,proto3" json:"slot,omitempty" cast-type:"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives.Slot"` - Fork *Fork `protobuf:"bytes,1004,opt,name=fork,proto3" json:"fork,omitempty"` - LatestBlockHeader *BeaconBlockHeader `protobuf:"bytes,2001,opt,name=latest_block_header,json=latestBlockHeader,proto3" json:"latest_block_header,omitempty"` - BlockRoots [][]byte `protobuf:"bytes,2002,rep,name=block_roots,json=blockRoots,proto3" json:"block_roots,omitempty" ssz-size:"8192,32"` - StateRoots [][]byte `protobuf:"bytes,2003,rep,name=state_roots,json=stateRoots,proto3" json:"state_roots,omitempty" ssz-size:"8192,32"` - HistoricalRoots [][]byte `protobuf:"bytes,2004,rep,name=historical_roots,json=historicalRoots,proto3" json:"historical_roots,omitempty" ssz-max:"16777216" ssz-size:"?,32"` - Eth1Data *Eth1Data `protobuf:"bytes,3001,opt,name=eth1_data,json=eth1Data,proto3" json:"eth1_data,omitempty"` - Eth1DataVotes []*Eth1Data `protobuf:"bytes,3002,rep,name=eth1_data_votes,json=eth1DataVotes,proto3" json:"eth1_data_votes,omitempty" ssz-max:"2048"` - Eth1DepositIndex uint64 `protobuf:"varint,3003,opt,name=eth1_deposit_index,json=eth1DepositIndex,proto3" json:"eth1_deposit_index,omitempty"` - Validators []*Validator `protobuf:"bytes,4001,rep,name=validators,proto3" json:"validators,omitempty" ssz-max:"1099511627776"` - Balances []uint64 `protobuf:"varint,4002,rep,packed,name=balances,proto3" json:"balances,omitempty" ssz-max:"1099511627776"` - RandaoMixes [][]byte `protobuf:"bytes,5001,rep,name=randao_mixes,json=randaoMixes,proto3" json:"randao_mixes,omitempty" ssz-size:"65536,32"` - Slashings []uint64 `protobuf:"varint,6001,rep,packed,name=slashings,proto3" json:"slashings,omitempty" ssz-size:"8192"` - PreviousEpochParticipation []byte `protobuf:"bytes,7001,opt,name=previous_epoch_participation,json=previousEpochParticipation,proto3" json:"previous_epoch_participation,omitempty" ssz-max:"1099511627776"` - CurrentEpochParticipation []byte `protobuf:"bytes,7002,opt,name=current_epoch_participation,json=currentEpochParticipation,proto3" json:"current_epoch_participation,omitempty" ssz-max:"1099511627776"` - JustificationBits github_com_prysmaticlabs_go_bitfield.Bitvector4 `protobuf:"bytes,8001,opt,name=justification_bits,json=justificationBits,proto3" json:"justification_bits,omitempty" cast-type:"github.com/prysmaticlabs/go-bitfield.Bitvector4" ssz-size:"1"` - PreviousJustifiedCheckpoint *Checkpoint `protobuf:"bytes,8002,opt,name=previous_justified_checkpoint,json=previousJustifiedCheckpoint,proto3" json:"previous_justified_checkpoint,omitempty"` - CurrentJustifiedCheckpoint *Checkpoint `protobuf:"bytes,8003,opt,name=current_justified_checkpoint,json=currentJustifiedCheckpoint,proto3" json:"current_justified_checkpoint,omitempty"` - FinalizedCheckpoint *Checkpoint `protobuf:"bytes,8004,opt,name=finalized_checkpoint,json=finalizedCheckpoint,proto3" json:"finalized_checkpoint,omitempty"` - InactivityScores []uint64 `protobuf:"varint,9001,rep,packed,name=inactivity_scores,json=inactivityScores,proto3" json:"inactivity_scores,omitempty" ssz-max:"1099511627776"` - CurrentSyncCommittee *SyncCommittee `protobuf:"bytes,9002,opt,name=current_sync_committee,json=currentSyncCommittee,proto3" json:"current_sync_committee,omitempty"` - NextSyncCommittee *SyncCommittee `protobuf:"bytes,9003,opt,name=next_sync_committee,json=nextSyncCommittee,proto3" json:"next_sync_committee,omitempty"` - LatestExecutionPayloadHeader *v1.ExecutionPayloadHeaderCapella `protobuf:"bytes,10001,opt,name=latest_execution_payload_header,json=latestExecutionPayloadHeader,proto3" json:"latest_execution_payload_header,omitempty"` - WithdrawalQueue []*v1.Withdrawal `protobuf:"bytes,11001,rep,name=withdrawal_queue,json=withdrawalQueue,proto3" json:"withdrawal_queue,omitempty" ssz-max:"1099511627776"` - NextWithdrawalIndex uint64 `protobuf:"varint,11002,opt,name=next_withdrawal_index,json=nextWithdrawalIndex,proto3" json:"next_withdrawal_index,omitempty"` - NextPartialWithdrawalValidatorIndex github_com_prysmaticlabs_prysm_v3_consensus_types_primitives.ValidatorIndex `protobuf:"varint,11003,opt,name=next_partial_withdrawal_validator_index,json=nextPartialWithdrawalValidatorIndex,proto3" json:"next_partial_withdrawal_validator_index,omitempty" cast-type:"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives.ValidatorIndex"` + GenesisTime uint64 `protobuf:"varint,1001,opt,name=genesis_time,json=genesisTime,proto3" json:"genesis_time,omitempty"` + GenesisValidatorsRoot []byte `protobuf:"bytes,1002,opt,name=genesis_validators_root,json=genesisValidatorsRoot,proto3" json:"genesis_validators_root,omitempty" ssz-size:"32"` + Slot github_com_prysmaticlabs_prysm_v3_consensus_types_primitives.Slot `protobuf:"varint,1003,opt,name=slot,proto3" json:"slot,omitempty" cast-type:"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives.Slot"` + Fork *Fork `protobuf:"bytes,1004,opt,name=fork,proto3" json:"fork,omitempty"` + LatestBlockHeader *BeaconBlockHeader `protobuf:"bytes,2001,opt,name=latest_block_header,json=latestBlockHeader,proto3" json:"latest_block_header,omitempty"` + BlockRoots [][]byte `protobuf:"bytes,2002,rep,name=block_roots,json=blockRoots,proto3" json:"block_roots,omitempty" ssz-size:"8192,32"` + StateRoots [][]byte `protobuf:"bytes,2003,rep,name=state_roots,json=stateRoots,proto3" json:"state_roots,omitempty" ssz-size:"8192,32"` + HistoricalRoots [][]byte `protobuf:"bytes,2004,rep,name=historical_roots,json=historicalRoots,proto3" json:"historical_roots,omitempty" ssz-max:"16777216" ssz-size:"?,32"` + Eth1Data *Eth1Data `protobuf:"bytes,3001,opt,name=eth1_data,json=eth1Data,proto3" json:"eth1_data,omitempty"` + Eth1DataVotes []*Eth1Data `protobuf:"bytes,3002,rep,name=eth1_data_votes,json=eth1DataVotes,proto3" json:"eth1_data_votes,omitempty" ssz-max:"2048"` + Eth1DepositIndex uint64 `protobuf:"varint,3003,opt,name=eth1_deposit_index,json=eth1DepositIndex,proto3" json:"eth1_deposit_index,omitempty"` + Validators []*Validator `protobuf:"bytes,4001,rep,name=validators,proto3" json:"validators,omitempty" ssz-max:"1099511627776"` + Balances []uint64 `protobuf:"varint,4002,rep,packed,name=balances,proto3" json:"balances,omitempty" ssz-max:"1099511627776"` + RandaoMixes [][]byte `protobuf:"bytes,5001,rep,name=randao_mixes,json=randaoMixes,proto3" json:"randao_mixes,omitempty" ssz-size:"65536,32"` + Slashings []uint64 `protobuf:"varint,6001,rep,packed,name=slashings,proto3" json:"slashings,omitempty" ssz-size:"8192"` + PreviousEpochParticipation []byte `protobuf:"bytes,7001,opt,name=previous_epoch_participation,json=previousEpochParticipation,proto3" json:"previous_epoch_participation,omitempty" ssz-max:"1099511627776"` + CurrentEpochParticipation []byte `protobuf:"bytes,7002,opt,name=current_epoch_participation,json=currentEpochParticipation,proto3" json:"current_epoch_participation,omitempty" ssz-max:"1099511627776"` + JustificationBits github_com_prysmaticlabs_go_bitfield.Bitvector4 `protobuf:"bytes,8001,opt,name=justification_bits,json=justificationBits,proto3" json:"justification_bits,omitempty" cast-type:"github.com/prysmaticlabs/go-bitfield.Bitvector4" ssz-size:"1"` + PreviousJustifiedCheckpoint *Checkpoint `protobuf:"bytes,8002,opt,name=previous_justified_checkpoint,json=previousJustifiedCheckpoint,proto3" json:"previous_justified_checkpoint,omitempty"` + CurrentJustifiedCheckpoint *Checkpoint `protobuf:"bytes,8003,opt,name=current_justified_checkpoint,json=currentJustifiedCheckpoint,proto3" json:"current_justified_checkpoint,omitempty"` + FinalizedCheckpoint *Checkpoint `protobuf:"bytes,8004,opt,name=finalized_checkpoint,json=finalizedCheckpoint,proto3" json:"finalized_checkpoint,omitempty"` + InactivityScores []uint64 `protobuf:"varint,9001,rep,packed,name=inactivity_scores,json=inactivityScores,proto3" json:"inactivity_scores,omitempty" ssz-max:"1099511627776"` + CurrentSyncCommittee *SyncCommittee `protobuf:"bytes,9002,opt,name=current_sync_committee,json=currentSyncCommittee,proto3" json:"current_sync_committee,omitempty"` + NextSyncCommittee *SyncCommittee `protobuf:"bytes,9003,opt,name=next_sync_committee,json=nextSyncCommittee,proto3" json:"next_sync_committee,omitempty"` + LatestExecutionPayloadHeader *v1.ExecutionPayloadHeaderCapella `protobuf:"bytes,10001,opt,name=latest_execution_payload_header,json=latestExecutionPayloadHeader,proto3" json:"latest_execution_payload_header,omitempty"` + NextWithdrawalIndex uint64 `protobuf:"varint,11001,opt,name=next_withdrawal_index,json=nextWithdrawalIndex,proto3" json:"next_withdrawal_index,omitempty"` + LastWithdrawalValidatorIndex github_com_prysmaticlabs_prysm_v3_consensus_types_primitives.ValidatorIndex `protobuf:"varint,11002,opt,name=last_withdrawal_validator_index,json=lastWithdrawalValidatorIndex,proto3" json:"last_withdrawal_validator_index,omitempty" cast-type:"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives.ValidatorIndex"` } func (x *BeaconStateCapella) Reset() { @@ -1550,13 +1549,6 @@ func (x *BeaconStateCapella) GetLatestExecutionPayloadHeader() *v1.ExecutionPayl return nil } -func (x *BeaconStateCapella) GetWithdrawalQueue() []*v1.Withdrawal { - if x != nil { - return x.WithdrawalQueue - } - return nil -} - func (x *BeaconStateCapella) GetNextWithdrawalIndex() uint64 { if x != nil { return x.NextWithdrawalIndex @@ -1564,9 +1556,9 @@ func (x *BeaconStateCapella) GetNextWithdrawalIndex() uint64 { return 0 } -func (x *BeaconStateCapella) GetNextPartialWithdrawalValidatorIndex() github_com_prysmaticlabs_prysm_v3_consensus_types_primitives.ValidatorIndex { +func (x *BeaconStateCapella) GetLastWithdrawalValidatorIndex() github_com_prysmaticlabs_prysm_v3_consensus_types_primitives.ValidatorIndex { if x != nil { - return x.NextPartialWithdrawalValidatorIndex + return x.LastWithdrawalValidatorIndex } return github_com_prysmaticlabs_prysm_v3_consensus_types_primitives.ValidatorIndex(0) } @@ -2081,7 +2073,7 @@ var file_proto_prysm_v1alpha1_beacon_state_proto_rawDesc = []byte{ 0x69, 0x6e, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x52, 0x1c, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x50, 0x61, - 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x22, 0x8b, 0x11, 0x0a, 0x12, + 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x22, 0x9d, 0x10, 0x0a, 0x12, 0x42, 0x65, 0x61, 0x63, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x43, 0x61, 0x70, 0x65, 0x6c, 0x6c, 0x61, 0x12, 0x22, 0x0a, 0x0c, 0x67, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0xe9, 0x07, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x67, 0x65, 0x6e, 0x65, 0x73, @@ -2198,46 +2190,40 @@ var file_proto_prysm_v1alpha1_beacon_state_proto_rawDesc = []byte{ 0x2e, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x43, 0x61, 0x70, 0x65, 0x6c, 0x6c, 0x61, 0x52, 0x1c, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x50, - 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x5d, 0x0a, 0x10, - 0x77, 0x69, 0x74, 0x68, 0x64, 0x72, 0x61, 0x77, 0x61, 0x6c, 0x5f, 0x71, 0x75, 0x65, 0x75, 0x65, - 0x18, 0xf9, 0x55, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x65, 0x74, 0x68, 0x65, 0x72, 0x65, - 0x75, 0x6d, 0x2e, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x57, 0x69, 0x74, - 0x68, 0x64, 0x72, 0x61, 0x77, 0x61, 0x6c, 0x42, 0x11, 0x92, 0xb5, 0x18, 0x0d, 0x31, 0x30, 0x39, - 0x39, 0x35, 0x31, 0x31, 0x36, 0x32, 0x37, 0x37, 0x37, 0x36, 0x52, 0x0f, 0x77, 0x69, 0x74, 0x68, - 0x64, 0x72, 0x61, 0x77, 0x61, 0x6c, 0x51, 0x75, 0x65, 0x75, 0x65, 0x12, 0x33, 0x0a, 0x15, 0x6e, - 0x65, 0x78, 0x74, 0x5f, 0x77, 0x69, 0x74, 0x68, 0x64, 0x72, 0x61, 0x77, 0x61, 0x6c, 0x5f, 0x69, - 0x6e, 0x64, 0x65, 0x78, 0x18, 0xfa, 0x55, 0x20, 0x01, 0x28, 0x04, 0x52, 0x13, 0x6e, 0x65, 0x78, - 0x74, 0x57, 0x69, 0x74, 0x68, 0x64, 0x72, 0x61, 0x77, 0x61, 0x6c, 0x49, 0x6e, 0x64, 0x65, 0x78, - 0x12, 0xa6, 0x01, 0x0a, 0x27, 0x6e, 0x65, 0x78, 0x74, 0x5f, 0x70, 0x61, 0x72, 0x74, 0x69, 0x61, - 0x6c, 0x5f, 0x77, 0x69, 0x74, 0x68, 0x64, 0x72, 0x61, 0x77, 0x61, 0x6c, 0x5f, 0x76, 0x61, 0x6c, - 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x5f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0xfb, 0x55, 0x20, - 0x01, 0x28, 0x04, 0x42, 0x4f, 0x82, 0xb5, 0x18, 0x4b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, - 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x61, 0x74, 0x69, 0x63, 0x6c, 0x61, 0x62, - 0x73, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x2f, 0x76, 0x33, 0x2f, 0x63, 0x6f, 0x6e, 0x73, 0x65, - 0x6e, 0x73, 0x75, 0x73, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x70, 0x72, 0x69, 0x6d, 0x69, - 0x74, 0x69, 0x76, 0x65, 0x73, 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x49, - 0x6e, 0x64, 0x65, 0x78, 0x52, 0x23, 0x6e, 0x65, 0x78, 0x74, 0x50, 0x61, 0x72, 0x74, 0x69, 0x61, - 0x6c, 0x57, 0x69, 0x74, 0x68, 0x64, 0x72, 0x61, 0x77, 0x61, 0x6c, 0x56, 0x61, 0x6c, 0x69, 0x64, - 0x61, 0x74, 0x6f, 0x72, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x22, 0x8d, 0x01, 0x0a, 0x08, 0x50, 0x6f, - 0x77, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x25, 0x0a, 0x0a, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, - 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x06, 0x8a, 0xb5, 0x18, 0x02, - 0x33, 0x32, 0x52, 0x09, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x61, 0x73, 0x68, 0x12, 0x27, 0x0a, - 0x0b, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x0c, 0x42, 0x06, 0x8a, 0xb5, 0x18, 0x02, 0x33, 0x32, 0x52, 0x0a, 0x70, 0x61, 0x72, 0x65, - 0x6e, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x31, 0x0a, 0x10, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x5f, - 0x64, 0x69, 0x66, 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, - 0x42, 0x06, 0x8a, 0xb5, 0x18, 0x02, 0x33, 0x32, 0x52, 0x0f, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x44, - 0x69, 0x66, 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, 0x79, 0x42, 0x9b, 0x01, 0x0a, 0x19, 0x6f, 0x72, - 0x67, 0x2e, 0x65, 0x74, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6d, 0x2e, 0x65, 0x74, 0x68, 0x2e, 0x76, - 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x42, 0x10, 0x42, 0x65, 0x61, 0x63, 0x6f, 0x6e, 0x53, - 0x74, 0x61, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3a, 0x67, 0x69, 0x74, - 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x61, 0x74, 0x69, - 0x63, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x2f, 0x76, 0x33, 0x2f, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, - 0x68, 0x61, 0x31, 0x3b, 0x65, 0x74, 0x68, 0xaa, 0x02, 0x15, 0x45, 0x74, 0x68, 0x65, 0x72, 0x65, - 0x75, 0x6d, 0x2e, 0x45, 0x74, 0x68, 0x2e, 0x56, 0x31, 0x41, 0x6c, 0x70, 0x68, 0x61, 0x31, 0xca, - 0x02, 0x15, 0x45, 0x74, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6d, 0x5c, 0x45, 0x74, 0x68, 0x5c, 0x76, - 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x33, 0x0a, 0x15, + 0x6e, 0x65, 0x78, 0x74, 0x5f, 0x77, 0x69, 0x74, 0x68, 0x64, 0x72, 0x61, 0x77, 0x61, 0x6c, 0x5f, + 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0xf9, 0x55, 0x20, 0x01, 0x28, 0x04, 0x52, 0x13, 0x6e, 0x65, + 0x78, 0x74, 0x57, 0x69, 0x74, 0x68, 0x64, 0x72, 0x61, 0x77, 0x61, 0x6c, 0x49, 0x6e, 0x64, 0x65, + 0x78, 0x12, 0x97, 0x01, 0x0a, 0x1f, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x77, 0x69, 0x74, 0x68, 0x64, + 0x72, 0x61, 0x77, 0x61, 0x6c, 0x5f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x5f, + 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0xfa, 0x55, 0x20, 0x01, 0x28, 0x04, 0x42, 0x4f, 0x82, 0xb5, + 0x18, 0x4b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x72, 0x79, + 0x73, 0x6d, 0x61, 0x74, 0x69, 0x63, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, + 0x2f, 0x76, 0x33, 0x2f, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x2d, 0x74, 0x79, + 0x70, 0x65, 0x73, 0x2f, 0x70, 0x72, 0x69, 0x6d, 0x69, 0x74, 0x69, 0x76, 0x65, 0x73, 0x2e, 0x56, + 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x52, 0x1c, 0x6c, + 0x61, 0x73, 0x74, 0x57, 0x69, 0x74, 0x68, 0x64, 0x72, 0x61, 0x77, 0x61, 0x6c, 0x56, 0x61, 0x6c, + 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x22, 0x8d, 0x01, 0x0a, 0x08, + 0x50, 0x6f, 0x77, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x25, 0x0a, 0x0a, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x06, 0x8a, 0xb5, + 0x18, 0x02, 0x33, 0x32, 0x52, 0x09, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x61, 0x73, 0x68, 0x12, + 0x27, 0x0a, 0x0b, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0c, 0x42, 0x06, 0x8a, 0xb5, 0x18, 0x02, 0x33, 0x32, 0x52, 0x0a, 0x70, 0x61, + 0x72, 0x65, 0x6e, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x31, 0x0a, 0x10, 0x74, 0x6f, 0x74, 0x61, + 0x6c, 0x5f, 0x64, 0x69, 0x66, 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, 0x79, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x0c, 0x42, 0x06, 0x8a, 0xb5, 0x18, 0x02, 0x33, 0x32, 0x52, 0x0f, 0x74, 0x6f, 0x74, 0x61, + 0x6c, 0x44, 0x69, 0x66, 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, 0x79, 0x42, 0x9b, 0x01, 0x0a, 0x19, + 0x6f, 0x72, 0x67, 0x2e, 0x65, 0x74, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6d, 0x2e, 0x65, 0x74, 0x68, + 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x42, 0x10, 0x42, 0x65, 0x61, 0x63, 0x6f, + 0x6e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3a, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x61, + 0x74, 0x69, 0x63, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x2f, 0x76, 0x33, + 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x2f, 0x76, 0x31, 0x61, + 0x6c, 0x70, 0x68, 0x61, 0x31, 0x3b, 0x65, 0x74, 0x68, 0xaa, 0x02, 0x15, 0x45, 0x74, 0x68, 0x65, + 0x72, 0x65, 0x75, 0x6d, 0x2e, 0x45, 0x74, 0x68, 0x2e, 0x56, 0x31, 0x41, 0x6c, 0x70, 0x68, 0x61, + 0x31, 0xca, 0x02, 0x15, 0x45, 0x74, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6d, 0x5c, 0x45, 0x74, 0x68, + 0x5c, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( @@ -2276,7 +2262,6 @@ var file_proto_prysm_v1alpha1_beacon_state_proto_goTypes = []interface{}{ (*AttestationData)(nil), // 19: ethereum.eth.v1alpha1.AttestationData (*v1.ExecutionPayloadHeader)(nil), // 20: ethereum.engine.v1.ExecutionPayloadHeader (*v1.ExecutionPayloadHeaderCapella)(nil), // 21: ethereum.engine.v1.ExecutionPayloadHeaderCapella - (*v1.Withdrawal)(nil), // 22: ethereum.engine.v1.Withdrawal } var file_proto_prysm_v1alpha1_beacon_state_proto_depIdxs = []int32{ 2, // 0: ethereum.eth.v1alpha1.BeaconState.fork:type_name -> ethereum.eth.v1alpha1.Fork @@ -2323,12 +2308,11 @@ var file_proto_prysm_v1alpha1_beacon_state_proto_depIdxs = []int32{ 10, // 41: ethereum.eth.v1alpha1.BeaconStateCapella.current_sync_committee:type_name -> ethereum.eth.v1alpha1.SyncCommittee 10, // 42: ethereum.eth.v1alpha1.BeaconStateCapella.next_sync_committee:type_name -> ethereum.eth.v1alpha1.SyncCommittee 21, // 43: ethereum.eth.v1alpha1.BeaconStateCapella.latest_execution_payload_header:type_name -> ethereum.engine.v1.ExecutionPayloadHeaderCapella - 22, // 44: ethereum.eth.v1alpha1.BeaconStateCapella.withdrawal_queue:type_name -> ethereum.engine.v1.Withdrawal - 45, // [45:45] is the sub-list for method output_type - 45, // [45:45] is the sub-list for method input_type - 45, // [45:45] is the sub-list for extension type_name - 45, // [45:45] is the sub-list for extension extendee - 0, // [0:45] is the sub-list for field type_name + 44, // [44:44] is the sub-list for method output_type + 44, // [44:44] is the sub-list for method input_type + 44, // [44:44] is the sub-list for extension type_name + 44, // [44:44] is the sub-list for extension extendee + 0, // [0:44] is the sub-list for field type_name } func init() { file_proto_prysm_v1alpha1_beacon_state_proto_init() } diff --git a/proto/prysm/v1alpha1/beacon_state.proto b/proto/prysm/v1alpha1/beacon_state.proto index 0b6332df6c4e..08fdd664dbc1 100644 --- a/proto/prysm/v1alpha1/beacon_state.proto +++ b/proto/prysm/v1alpha1/beacon_state.proto @@ -284,9 +284,8 @@ message BeaconStateCapella { ethereum.engine.v1.ExecutionPayloadHeaderCapella latest_execution_payload_header = 10001; // [New in Bellatrix] // Capella fields [11001-12000] - repeated ethereum.engine.v1.Withdrawal withdrawal_queue = 11001 [(ethereum.eth.ext.ssz_max) = "1099511627776"]; // [New in Capella] - uint64 next_withdrawal_index = 11002; // [New in Capella] - uint64 next_partial_withdrawal_validator_index = 11003 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives.ValidatorIndex"]; // [New in Capella] + uint64 next_withdrawal_index = 11001; // [New in Capella] + uint64 last_withdrawal_validator_index = 11002 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives.ValidatorIndex"]; // [New in Capella] } // PowBlock is a definition from Bellatrix fork choice spec to represent a block with total difficulty in the PoW chain. diff --git a/proto/prysm/v1alpha1/generated.ssz.go b/proto/prysm/v1alpha1/generated.ssz.go index d2059202f40d..963ee5bc7944 100644 --- a/proto/prysm/v1alpha1/generated.ssz.go +++ b/proto/prysm/v1alpha1/generated.ssz.go @@ -1,5 +1,5 @@ // Code generated by fastssz. DO NOT EDIT. -// Hash: 78cb87810a0a9059f8ff1ca454ad851165b447f064b52d2824bb03063938e4c2 +// Hash: e37978aba7c76852f838285a3da40b5f5269ec01320882c5a6c557e84ab7ddd1 package eth import ( @@ -10070,7 +10070,7 @@ func (b *BeaconStateCapella) MarshalSSZ() ([]byte, error) { // MarshalSSZTo ssz marshals the BeaconStateCapella object to a target array func (b *BeaconStateCapella) MarshalSSZTo(buf []byte) (dst []byte, err error) { dst = buf - offset := int(2736653) + offset := int(2736649) // Field (0) 'GenesisTime' dst = ssz.MarshalUint64(dst, b.GenesisTime) @@ -10242,15 +10242,11 @@ func (b *BeaconStateCapella) MarshalSSZTo(buf []byte) (dst []byte, err error) { } offset += b.LatestExecutionPayloadHeader.SizeSSZ() - // Offset (25) 'WithdrawalQueue' - dst = ssz.WriteOffset(dst, offset) - offset += len(b.WithdrawalQueue) * 44 - - // Field (26) 'NextWithdrawalIndex' + // Field (25) 'NextWithdrawalIndex' dst = ssz.MarshalUint64(dst, b.NextWithdrawalIndex) - // Field (27) 'NextPartialWithdrawalValidatorIndex' - dst = ssz.MarshalUint64(dst, uint64(b.NextPartialWithdrawalValidatorIndex)) + // Field (26) 'LastWithdrawalValidatorIndex' + dst = ssz.MarshalUint64(dst, uint64(b.LastWithdrawalValidatorIndex)) // Field (7) 'HistoricalRoots' if size := len(b.HistoricalRoots); size > 16777216 { @@ -10324,17 +10320,6 @@ func (b *BeaconStateCapella) MarshalSSZTo(buf []byte) (dst []byte, err error) { return } - // Field (25) 'WithdrawalQueue' - if size := len(b.WithdrawalQueue); size > 1099511627776 { - err = ssz.ErrListTooBigFn("--.WithdrawalQueue", size, 1099511627776) - return - } - for ii := 0; ii < len(b.WithdrawalQueue); ii++ { - if dst, err = b.WithdrawalQueue[ii].MarshalSSZTo(dst); err != nil { - return - } - } - return } @@ -10342,12 +10327,12 @@ func (b *BeaconStateCapella) MarshalSSZTo(buf []byte) (dst []byte, err error) { func (b *BeaconStateCapella) UnmarshalSSZ(buf []byte) error { var err error size := uint64(len(buf)) - if size < 2736653 { + if size < 2736649 { return ssz.ErrSize } tail := buf - var o7, o9, o11, o12, o15, o16, o21, o24, o25 uint64 + var o7, o9, o11, o12, o15, o16, o21, o24 uint64 // Field (0) 'GenesisTime' b.GenesisTime = ssz.UnmarshallUint64(buf[0:8]) @@ -10400,7 +10385,7 @@ func (b *BeaconStateCapella) UnmarshalSSZ(buf []byte) error { return ssz.ErrOffset } - if o7 < 2736653 { + if o7 < 2736649 { return ssz.ErrInvalidVariableOffset } @@ -10511,16 +10496,11 @@ func (b *BeaconStateCapella) UnmarshalSSZ(buf []byte) error { return ssz.ErrOffset } - // Offset (25) 'WithdrawalQueue' - if o25 = ssz.ReadOffset(buf[2736633:2736637]); o25 > size || o24 > o25 { - return ssz.ErrOffset - } + // Field (25) 'NextWithdrawalIndex' + b.NextWithdrawalIndex = ssz.UnmarshallUint64(buf[2736633:2736641]) - // Field (26) 'NextWithdrawalIndex' - b.NextWithdrawalIndex = ssz.UnmarshallUint64(buf[2736637:2736645]) - - // Field (27) 'NextPartialWithdrawalValidatorIndex' - b.NextPartialWithdrawalValidatorIndex = github_com_prysmaticlabs_prysm_v3_consensus_types_primitives.ValidatorIndex(ssz.UnmarshallUint64(buf[2736645:2736653])) + // Field (26) 'LastWithdrawalValidatorIndex' + b.LastWithdrawalValidatorIndex = github_com_prysmaticlabs_prysm_v3_consensus_types_primitives.ValidatorIndex(ssz.UnmarshallUint64(buf[2736641:2736649])) // Field (7) 'HistoricalRoots' { @@ -10626,7 +10606,7 @@ func (b *BeaconStateCapella) UnmarshalSSZ(buf []byte) error { // Field (24) 'LatestExecutionPayloadHeader' { - buf = tail[o24:o25] + buf = tail[o24:] if b.LatestExecutionPayloadHeader == nil { b.LatestExecutionPayloadHeader = new(v1.ExecutionPayloadHeaderCapella) } @@ -10634,30 +10614,12 @@ func (b *BeaconStateCapella) UnmarshalSSZ(buf []byte) error { return err } } - - // Field (25) 'WithdrawalQueue' - { - buf = tail[o25:] - num, err := ssz.DivideInt2(len(buf), 44, 1099511627776) - if err != nil { - return err - } - b.WithdrawalQueue = make([]*v1.Withdrawal, num) - for ii := 0; ii < num; ii++ { - if b.WithdrawalQueue[ii] == nil { - b.WithdrawalQueue[ii] = new(v1.Withdrawal) - } - if err = b.WithdrawalQueue[ii].UnmarshalSSZ(buf[ii*44 : (ii+1)*44]); err != nil { - return err - } - } - } return err } // SizeSSZ returns the ssz encoded size in bytes for the BeaconStateCapella object func (b *BeaconStateCapella) SizeSSZ() (size int) { - size = 2736653 + size = 2736649 // Field (7) 'HistoricalRoots' size += len(b.HistoricalRoots) * 32 @@ -10686,9 +10648,6 @@ func (b *BeaconStateCapella) SizeSSZ() (size int) { } size += b.LatestExecutionPayloadHeader.SizeSSZ() - // Field (25) 'WithdrawalQueue' - size += len(b.WithdrawalQueue) * 44 - return } @@ -10988,31 +10947,11 @@ func (b *BeaconStateCapella) HashTreeRootWith(hh *ssz.Hasher) (err error) { return } - // Field (25) 'WithdrawalQueue' - { - subIndx := hh.Index() - num := uint64(len(b.WithdrawalQueue)) - if num > 1099511627776 { - err = ssz.ErrIncorrectListSize - return - } - for _, elem := range b.WithdrawalQueue { - if err = elem.HashTreeRootWith(hh); err != nil { - return - } - } - if ssz.EnableVectorizedHTR { - hh.MerkleizeWithMixinVectorizedHTR(subIndx, num, 1099511627776) - } else { - hh.MerkleizeWithMixin(subIndx, num, 1099511627776) - } - } - - // Field (26) 'NextWithdrawalIndex' + // Field (25) 'NextWithdrawalIndex' hh.PutUint64(b.NextWithdrawalIndex) - // Field (27) 'NextPartialWithdrawalValidatorIndex' - hh.PutUint64(uint64(b.NextPartialWithdrawalValidatorIndex)) + // Field (26) 'LastWithdrawalValidatorIndex' + hh.PutUint64(uint64(b.LastWithdrawalValidatorIndex)) if ssz.EnableVectorizedHTR { hh.MerkleizeVectorizedHTR(indx) diff --git a/proto/prysm/v1alpha1/slashings/surround_votes.go b/proto/prysm/v1alpha1/slashings/surround_votes.go index 5a029e6cce58..7a6e6a0ec713 100644 --- a/proto/prysm/v1alpha1/slashings/surround_votes.go +++ b/proto/prysm/v1alpha1/slashings/surround_votes.go @@ -6,11 +6,10 @@ import ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" // another one, b, based on the Ethereum slashing conditions specified // by @protolambda https://github.com/protolambda/eth2-surround#definition. // -// s: source -// t: target -// -// a surrounds b if: s_a < s_b and t_b < t_a +// s: source +// t: target // +// a surrounds b if: s_a < s_b and t_b < t_a func IsSurround(a, b *ethpb.IndexedAttestation) bool { return a.Data.Source.Epoch < b.Data.Source.Epoch && b.Data.Target.Epoch < a.Data.Target.Epoch } diff --git a/testing/util/state.go b/testing/util/state.go index 354e5382f1ec..1c6ba7b0684f 100644 --- a/testing/util/state.go +++ b/testing/util/state.go @@ -288,7 +288,6 @@ func NewBeaconStateCapella(options ...func(state *ethpb.BeaconStateCapella) erro TransactionsRoot: make([]byte, 32), WithdrawalsRoot: make([]byte, 32), }, - WithdrawalQueue: make([]*enginev1.Withdrawal, 0), } for _, opt := range options {