diff --git a/mod/consensus-types/pkg/types/body.go b/mod/consensus-types/pkg/types/body.go index 56a5fc5b80..429154efe0 100644 --- a/mod/consensus-types/pkg/types/body.go +++ b/mod/consensus-types/pkg/types/body.go @@ -69,6 +69,7 @@ func BlockBodyKZGOffset( // BeaconBlockBody represents the body of a beacon block in the Deneb // chain. type BeaconBlockBody[LogT interface { + GetTopics() []common.ExecutionHash GetData() []byte }] struct { // RandaoReveal is the reveal of the RANDAO. diff --git a/mod/consensus-types/pkg/types/deposit.go b/mod/consensus-types/pkg/types/deposit.go index e9b06dbd4c..779526a3e0 100644 --- a/mod/consensus-types/pkg/types/deposit.go +++ b/mod/consensus-types/pkg/types/deposit.go @@ -30,6 +30,7 @@ import ( "github.com/berachain/beacon-kit/mod/primitives/pkg/constraints" "github.com/berachain/beacon-kit/mod/primitives/pkg/crypto" "github.com/berachain/beacon-kit/mod/primitives/pkg/math" + gethcrypto "github.com/ethereum/go-ethereum/crypto" fastssz "github.com/ferranbt/fastssz" "github.com/karalabe/ssz" ) @@ -46,6 +47,7 @@ var ( // Deposit into the consensus layer from the deposit contract in the execution // layer. type Deposit[LogT interface { + GetTopics() []common.ExecutionHash GetData() []byte }] struct { // Public key of the validator specified in the deposit. @@ -63,6 +65,7 @@ type Deposit[LogT interface { // NewDeposit creates a new Deposit instance. func NewDeposit[LogT interface { + GetTopics() []common.ExecutionHash GetData() []byte }]( pubkey crypto.BLSPubkey, @@ -196,10 +199,29 @@ func (d *Deposit[_]) GetTree() (*fastssz.Node, error) { /* EthLog */ /* -------------------------------------------------------------------------- */ +// DepositEventSignatureString is the Deposit event signature human readable +// string that should be keccak256 hashed for the event's topic. +const DepositEventSignatureString = "Deposit(bytes,bytes,uint64,bytes,uint64)" + +//nolint:gochecknoglobals // TODO: remove usage of geth's crypto.Keccak256. +var DepositEventSignature = common.ExecutionHash( + gethcrypto.Keccak256([]byte(DepositEventSignatureString)), +) + // UnmarshalLog unmarshals the Deposit object from an Ethereum log. // // TODO: use abi decoding or constants for reading the bytes. func (d *Deposit[LogT]) UnmarshalLog(log LogT) error { + topics := log.GetTopics() + if len(topics) != 1 { + return fmt.Errorf("expected 1 topic, got %d", len(topics)) + } + if topics[0] != DepositEventSignature { + return fmt.Errorf( + "expected topic %s, got %s", DepositEventSignature, topics[0], + ) + } + data := log.GetData() if len(data) < 448 { return fmt.Errorf( diff --git a/mod/consensus-types/pkg/types/deposits.go b/mod/consensus-types/pkg/types/deposits.go index b60a7863f9..155e7c2f54 100644 --- a/mod/consensus-types/pkg/types/deposits.go +++ b/mod/consensus-types/pkg/types/deposits.go @@ -28,6 +28,7 @@ import ( // Deposits is a typealias for a list of Deposits. type Deposits[LogT interface { + GetTopics() []common.ExecutionHash GetData() []byte }] []*Deposit[LogT] diff --git a/mod/execution/pkg/deposit/contract.go b/mod/execution/pkg/deposit/contract.go index 48658e5d8d..ed1c798e93 100644 --- a/mod/execution/pkg/deposit/contract.go +++ b/mod/execution/pkg/deposit/contract.go @@ -23,18 +23,9 @@ package deposit import ( "context" + "github.com/berachain/beacon-kit/mod/consensus-types/pkg/types" "github.com/berachain/beacon-kit/mod/primitives/pkg/common" "github.com/berachain/beacon-kit/mod/primitives/pkg/math" - "github.com/ethereum/go-ethereum/crypto" -) - -// DepositEventSignatureString is the Deposit event signature human readable -// string that should be keccak256 hashed for the event's topic. -const DepositEventSignatureString = "Deposit(bytes,bytes,uint64,bytes,uint64)" - -//nolint:gochecknoglobals // TODO: remove usage of geth's crypto.Keccak256. -var DepositEventSignature = common.ExecutionHash( - crypto.Keccak256([]byte(DepositEventSignatureString)), ) // WrappedBeaconDepositContract is a struct that holds a pointer to an ABI. @@ -79,7 +70,7 @@ func (dc *WrappedBeaconDepositContract[DepositT, _, _]) ReadDeposits( ctx, blkNum, dc.address, - [][]common.ExecutionHash{{DepositEventSignature}}, + [][]common.ExecutionHash{{types.DepositEventSignature}}, ) if err != nil { return nil, err @@ -87,11 +78,6 @@ func (dc *WrappedBeaconDepositContract[DepositT, _, _]) ReadDeposits( deposits := make([]DepositT, 0) for _, log := range logs { - if log.GetAddress() != dc.address || - log.GetTopics()[0] != DepositEventSignature { - continue - } - var d DepositT d = d.Empty() if err = d.UnmarshalLog(log); err != nil {