Skip to content

Commit

Permalink
Wipg
Browse files Browse the repository at this point in the history
  • Loading branch information
calbera committed Oct 2, 2024
1 parent 62d6d23 commit a795152
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
1 change: 1 addition & 0 deletions mod/consensus-types/pkg/types/body.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 22 additions & 0 deletions mod/consensus-types/pkg/types/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions mod/consensus-types/pkg/types/deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
18 changes: 2 additions & 16 deletions mod/execution/pkg/deposit/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -79,19 +70,14 @@ func (dc *WrappedBeaconDepositContract[DepositT, _, _]) ReadDeposits(
ctx,
blkNum,
dc.address,
[][]common.ExecutionHash{{DepositEventSignature}},
[][]common.ExecutionHash{{types.DepositEventSignature}},
)
if err != nil {
return nil, err
}

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 {
Expand Down

0 comments on commit a795152

Please sign in to comment.