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

fix(state-transitions): verify deposits against contract #2115

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f4a7d79
wip: adding UTs to state transition package
abi87 Oct 29, 2024
0f46172
wip: completed simple UT for state transition package
abi87 Oct 29, 2024
22c7717
wip: minimal execution engine stub
abi87 Oct 29, 2024
05cba80
extended asserts
abi87 Oct 29, 2024
443ac1b
added test case
abi87 Oct 29, 2024
10efd5e
nits
abi87 Oct 29, 2024
099716d
tests for helpers in state transition using mock
nidhi-singh02 Oct 30, 2024
151a533
Revert "tests for helpers in state transition using mock"
nidhi-singh02 Oct 30, 2024
9818c7e
tests with only mock for execution engine
nidhi-singh02 Oct 30, 2024
160cc88
removed test for VerifyAndNotifyNewPayload
nidhi-singh02 Oct 30, 2024
6a191d1
validate deposits against deposit store ones
abi87 Oct 30, 2024
64d19e5
cleaned up UTs
abi87 Oct 30, 2024
d94bf97
nits
abi87 Oct 30, 2024
4a9fe1c
nit
abi87 Oct 31, 2024
67f2597
Merge branch 'state-transition-add-UTs' into verify-deposits-against-…
abi87 Oct 31, 2024
e048be4
improved unit tests asserts
abi87 Oct 31, 2024
8bf34db
appease linter
abi87 Oct 31, 2024
d90a95a
fix(state-transition): fix deposit index upon genesis processing (#2116)
abi87 Oct 31, 2024
e17d29c
fixed bad merge
abi87 Oct 31, 2024
7b2bf91
Merge branch 'state-transition-add-UTs' into verify-deposits-against-…
abi87 Oct 31, 2024
6286b20
Merge branch 'main' into state-transition-add-UTs
abi87 Nov 1, 2024
df81bae
Merge branch 'state-transition-add-UTs' into verify-deposits-against-…
abi87 Nov 1, 2024
af8c5e0
fix(build): erigon repo
gummybera Nov 1, 2024
023ebfd
fix(build): bump erigon to recent version
gummybera Nov 1, 2024
d66b298
nits from code review
abi87 Nov 1, 2024
18ba094
Merge branch 'state-transition-add-UTs' into verify-deposits-against-…
abi87 Nov 4, 2024
e47219a
fixed deposit index use + UTs
abi87 Nov 4, 2024
a3cd2d9
replace DeelEqual with Equal method
abi87 Nov 5, 2024
3a0923e
nits
abi87 Nov 5, 2024
712d3fe
Merge branch 'fix-erigon' into verify-deposits-against-contract
abi87 Nov 5, 2024
6b90b87
added logger to state processor
abi87 Nov 5, 2024
83ad2fd
duly incremented build block deposit index
abi87 Nov 5, 2024
69d568b
tmp debugging
abi87 Nov 5, 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
5 changes: 5 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,8 @@ packages:
recursive: False
with-expecter: true
all: True
github.com/berachain/beacon-kit/mod/state-transition/pkg/core:
config:
recursive: False
with-expecter: true
include-regex: ExecutionEngine
6 changes: 3 additions & 3 deletions beacond/cmd/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ func DefaultComponents() []any {
*BeaconBlock, *BeaconBlockBody, *BeaconBlockHeader,
],
components.ProvideStateProcessor[
*BeaconBlock, *BeaconBlockBody, *BeaconBlockHeader,
*BeaconState, *BeaconStateMarshallable, *Deposit, *ExecutionPayload,
*ExecutionPayloadHeader, *KVStore,
*Logger, *BeaconBlock, *BeaconBlockBody, *BeaconBlockHeader,
*BeaconState, *BeaconStateMarshallable, *Deposit, *DepositStore,
*ExecutionPayload, *ExecutionPayloadHeader, *KVStore,
],
components.ProvideKVStore[*BeaconBlockHeader, *ExecutionPayloadHeader],
components.ProvideStorageBackend[
Expand Down
4 changes: 2 additions & 2 deletions build/scripts/testing.mk
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ start-erigon: ## start an ephemeral `erigon` node
docker run \
--rm -v $(PWD)/${TESTAPP_FILES_DIR}:/${TESTAPP_FILES_DIR} \
-v $(PWD)/.tmp:/.tmp \
thorax/erigon:latest init \
erigontech/erigon:latest init \
--datadir .tmp/erigon \
${ETH_GENESIS_PATH}

Expand All @@ -212,7 +212,7 @@ start-erigon: ## start an ephemeral `erigon` node
-p 8551:8551 \
--rm -v $(PWD)/${TESTAPP_FILES_DIR}:/${TESTAPP_FILES_DIR} \
-v $(PWD)/.tmp:/.tmp \
thorax/erigon:latest \
erigontech/erigon:latest \
--http \
--http.addr 0.0.0.0 \
--http.api eth,net \
Expand Down
2 changes: 1 addition & 1 deletion kurtosis/beaconkit-all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ node_settings:
max_memory: 2048
images:
besu: hyperledger/besu:24.5.4
erigon: thorax/erigon:v2.60.1
erigon: erigontech/erigon:v2.60.9
ethereumjs: ethpandaops/ethereumjs:stable
geth: ethereum/client-go:latest
nethermind: nethermind/nethermind:latest
Expand Down
2 changes: 1 addition & 1 deletion kurtosis/beaconkit-base-gcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ node_settings:
max_memory: 32768
images:
besu: hyperledger/besu:latest
erigon: thorax/erigon:v2.60.1
erigon: erigontech/erigon:v2.60.9
ethereumjs: ethpandaops/ethereumjs:stable
geth: ethereum/client-go:latest
nethermind: nethermind/nethermind:latest
Expand Down
2 changes: 1 addition & 1 deletion kurtosis/src/nodes/nodes.star
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ EXECUTION_DEFAULT_SETTINGS = {
},
"images": {
"besu": "hyperledger/besu:latest",
"erigon": "thorax/erigon:v2.60.1",
"erigon": "erigontech/erigon:v2.60.9",
"ethereumjs": "ethpandaops/ethereumjs:stable",
"geth": "ethereum/client-go:latest",
"nethermind": "nethermind/nethermind:latest",
Expand Down
4 changes: 3 additions & 1 deletion mod/beacon/validator/block_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ func (s *Service[
envelope, err := s.retrieveExecutionPayload(ctx, st, blk)
if err != nil {
return blk, sidecars, err
} else if envelope == nil {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not strictly necessary but OCD kicking in here 😅

}
if envelope == nil {
return blk, sidecars, ErrNilPayload
}

Expand Down Expand Up @@ -278,6 +279,7 @@ func (s *Service[
if err != nil {
return ErrNilDepositIndexStart
}
// depositIndex++ // TMP DEBUGGING

// Dequeue deposits from the state.
deposits, err := s.sb.DepositStore().GetDepositsByIndex(
Expand Down
8 changes: 8 additions & 0 deletions mod/consensus-types/pkg/types/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ func (d *Deposit) GetTree() (*fastssz.Node, error) {
/* -------------------------------------------------------------------------- */
/* Getters and Setters */
/* -------------------------------------------------------------------------- */
// Equals returns true if the Deposit is equal to the other.
func (d *Deposit) Equals(rhs *Deposit) bool {
return d.Pubkey == rhs.Pubkey &&
d.Credentials == rhs.Credentials &&
d.Amount == rhs.Amount &&
d.Signature == rhs.Signature &&
d.Index == rhs.Index
}

// GetAmount returns the deposit amount in gwei.
func (d *Deposit) GetAmount() math.Gwei {
Expand Down
2 changes: 2 additions & 0 deletions mod/node-core/pkg/components/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ type (
crypto.BLSSignature,
uint64,
) T
// Equals returns true if the Deposit is equal to the other.
Equals(T) bool
// GetIndex returns the index of the deposit.
GetIndex() math.U64
// GetAmount returns the amount of the deposit.
Expand Down
14 changes: 12 additions & 2 deletions mod/node-core/pkg/components/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"cosmossdk.io/depinject"
engineprimitives "github.com/berachain/beacon-kit/mod/engine-primitives/pkg/engine-primitives"
"github.com/berachain/beacon-kit/mod/execution/pkg/engine"
"github.com/berachain/beacon-kit/mod/log"
"github.com/berachain/beacon-kit/mod/primitives/pkg/common"
"github.com/berachain/beacon-kit/mod/primitives/pkg/crypto"
"github.com/berachain/beacon-kit/mod/state-transition/pkg/core"
Expand All @@ -32,27 +33,32 @@ import (
// StateProcessorInput is the input for the state processor for the depinject
// framework.
type StateProcessorInput[
LoggerT any,
ExecutionPayloadT ExecutionPayload[
ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalsT,
],
ExecutionPayloadHeaderT ExecutionPayloadHeader[ExecutionPayloadHeaderT],
DepositT Deposit[DepositT, *ForkData, WithdrawalCredentials],
WithdrawalT Withdrawal[WithdrawalT],
WithdrawalsT Withdrawals[WithdrawalT],
] struct {
depinject.In
Logger LoggerT
ChainSpec common.ChainSpec
ExecutionEngine *engine.Engine[
ExecutionPayloadT,
*engineprimitives.PayloadAttributes[WithdrawalT],
PayloadID,
WithdrawalsT,
]
Signer crypto.BLSSigner
DepositStore DepositStore[DepositT]
Signer crypto.BLSSigner
}

// ProvideStateProcessor provides the state processor to the depinject
// framework.
func ProvideStateProcessor[
LoggerT log.AdvancedLogger[LoggerT],
BeaconBlockT BeaconBlock[BeaconBlockT, BeaconBlockBodyT, BeaconBlockHeaderT],
BeaconBlockBodyT BeaconBlockBody[
BeaconBlockBodyT, *AttestationData, DepositT,
Expand All @@ -66,6 +72,7 @@ func ProvideStateProcessor[
],
BeaconStateMarshallableT any,
DepositT Deposit[DepositT, *ForkData, WithdrawalCredentials],
DepositStoreT DepositStore[DepositT],
ExecutionPayloadT ExecutionPayload[
ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalsT,
],
Expand All @@ -78,7 +85,8 @@ func ProvideStateProcessor[
WithdrawalT Withdrawal[WithdrawalT],
](
in StateProcessorInput[
ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalT, WithdrawalsT,
LoggerT, ExecutionPayloadT, ExecutionPayloadHeaderT,
DepositT, WithdrawalT, WithdrawalsT,
],
) *core.StateProcessor[
BeaconBlockT, BeaconBlockBodyT, BeaconBlockHeaderT,
Expand All @@ -105,8 +113,10 @@ func ProvideStateProcessor[
WithdrawalsT,
WithdrawalCredentials,
](
in.Logger.With("service", "state-processor"),
in.ChainSpec,
in.ExecutionEngine,
in.DepositStore,
in.Signer,
)
}
143 changes: 143 additions & 0 deletions mod/state-transition/pkg/core/helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// SPDX-License-Identifier: BUSL-1.1
//
// Copyright (C) 2024, Berachain Foundation. All rights reserved.
// Use of this software is governed by the Business Source License included
// in the LICENSE file of this repository and at www.mariadb.com/bsl11.
//
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
// VERSIONS OF THE LICENSED WORK.
//
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
//
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.

package core_test

import (
"context"
"fmt"

corestore "cosmossdk.io/core/store"
"cosmossdk.io/log"
"cosmossdk.io/store"
"cosmossdk.io/store/metrics"
storetypes "cosmossdk.io/store/types"
"github.com/berachain/beacon-kit/mod/consensus-types/pkg/types"
engineprimitives "github.com/berachain/beacon-kit/mod/engine-primitives/pkg/engine-primitives"
"github.com/berachain/beacon-kit/mod/node-core/pkg/components"
statedb "github.com/berachain/beacon-kit/mod/state-transition/pkg/core/state"
"github.com/berachain/beacon-kit/mod/storage/pkg/beacondb"
"github.com/berachain/beacon-kit/mod/storage/pkg/db"
depositstore "github.com/berachain/beacon-kit/mod/storage/pkg/deposit"
"github.com/berachain/beacon-kit/mod/storage/pkg/encoding"
dbm "github.com/cosmos/cosmos-db"
sdk "github.com/cosmos/cosmos-sdk/types"
)

type (
TestBeaconStateMarshallableT = types.BeaconState[
*types.BeaconBlockHeader,
*types.Eth1Data,
*types.ExecutionPayloadHeader,
*types.Fork,
*types.Validator,
types.BeaconBlockHeader,
types.Eth1Data,
types.ExecutionPayloadHeader,
types.Fork,
types.Validator,
]

TestKVStoreT = beacondb.KVStore[
*types.BeaconBlockHeader,
*types.Eth1Data,
*types.ExecutionPayloadHeader,
*types.Fork,
*types.Validator,
types.Validators,
]

TestBeaconStateT = statedb.StateDB[
*types.BeaconBlockHeader,
*TestBeaconStateMarshallableT,
*types.Eth1Data,
*types.ExecutionPayloadHeader,
*types.Fork,
*TestKVStoreT,
*types.Validator,
types.Validators,
*engineprimitives.Withdrawal,
types.WithdrawalCredentials,
]
)

type testKVStoreService struct {
ctx sdk.Context
}

func (kvs *testKVStoreService) OpenKVStore(context.Context) corestore.KVStore {
//nolint:contextcheck // fine with tests
return components.NewKVStore(
sdk.UnwrapSDKContext(kvs.ctx).KVStore(testStoreKey),
)
}

var (
testStoreKey = storetypes.NewKVStoreKey("state-transition-tests")
testCodec = &encoding.SSZInterfaceCodec[*types.ExecutionPayloadHeader]{}
)

func initTestStores() (
*beacondb.KVStore[
*types.BeaconBlockHeader,
*types.Eth1Data,
*types.ExecutionPayloadHeader,
*types.Fork,
*types.Validator,
types.Validators,
],
*depositstore.KVStore[*types.Deposit],
error) {
db, err := db.OpenDB("", dbm.MemDBBackend)
if err != nil {
return nil, nil, fmt.Errorf("failed opening mem db: %w", err)
}
var (
nopLog = log.NewNopLogger()
nopMetrics = metrics.NewNoOpMetrics()
)

cms := store.NewCommitMultiStore(
db,
nopLog,
nopMetrics,
)

ctx := sdk.NewContext(cms, true, nopLog)
cms.MountStoreWithDB(testStoreKey, storetypes.StoreTypeIAVL, nil)
if err = cms.LoadLatestVersion(); err != nil {
return nil, nil, fmt.Errorf("failed to load latest version: %w", err)
}
testStoreService := &testKVStoreService{ctx: ctx}

return beacondb.New[
*types.BeaconBlockHeader,
*types.Eth1Data,
*types.ExecutionPayloadHeader,
*types.Fork,
*types.Validator,
types.Validators,
](
testStoreService,
testCodec,
),
depositstore.NewStore[*types.Deposit](testStoreService),
nil
}
Loading
Loading