Skip to content

Commit

Permalink
Use lightclient's fork of geth
Browse files Browse the repository at this point in the history
  • Loading branch information
jtraglia committed May 9, 2024
1 parent ab03b64 commit ee28100
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 78 deletions.
16 changes: 5 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/flashbots/go-boost-utils
go 1.21

require (
github.com/attestantio/go-builder-client v0.4.2
github.com/attestantio/go-eth2-client v0.21.1
github.com/attestantio/go-builder-client v0.4.6-0.20240508205504-2210689d2f24
github.com/attestantio/go-eth2-client v0.21.4-0.20240508205406-66fbb02e3c16
github.com/consensys/gnark-crypto v0.12.1
github.com/ethereum/go-ethereum v1.13.14
github.com/stretchr/testify v1.8.4
Expand Down Expand Up @@ -68,7 +68,7 @@ require (
github.com/tklauser/numcpus v0.6.1 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
Expand All @@ -78,11 +78,5 @@ require (
rsc.io/tmplfunc v0.0.3 // indirect
)

// git clone git@github.com:jtraglia/go-eth2-client.git -b electra
replace github.com/attestantio/go-eth2-client => ../../jtraglia/go-eth2-client

// git clone git@github.com:jtraglia/go-builder-client.git -b electra
replace github.com/attestantio/go-builder-client => ../../jtraglia/go-builder-client

// git clone git@github.com:jtraglia/go-ethereum.git -b electra
replace github.com/ethereum/go-ethereum => ../../jtraglia/go-ethereum
// This version points to Lightclient's prague-devnet-0 branch.
replace github.com/ethereum/go-ethereum => github.com/lightclient/go-ethereum v1.10.10-0.20240429213339-9b7958ba0063
16 changes: 12 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDO
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/VictoriaMetrics/fastcache v1.12.1 h1:i0mICQuojGDL3KblA7wUNlY5lOK6a4bwt3uRKnkZU40=
github.com/VictoriaMetrics/fastcache v1.12.1/go.mod h1:tX04vaqcNoQeGLD+ra5pU5sWkuxnzWhEzLwhP9w653o=
github.com/attestantio/go-builder-client v0.4.6-0.20240508205504-2210689d2f24 h1:KXWQwsxrrJD1G7rp+18uESZ0BSPmUdady46iAfCgwDY=
github.com/attestantio/go-builder-client v0.4.6-0.20240508205504-2210689d2f24/go.mod h1:bs7HF4beRWCjcvKsHH8nEl3aDzrTqeUjXOfqpfrYTJQ=
github.com/attestantio/go-eth2-client v0.21.4-0.20240508205406-66fbb02e3c16 h1:gwMEOhFdbmCJy5olyRtGPmM4RoIXo6v2HkbKt7YpPr4=
github.com/attestantio/go-eth2-client v0.21.4-0.20240508205406-66fbb02e3c16/go.mod h1:Ht9tN0WlhpgIWWO7Hqfi3/nq2rUGQv/zCd/BMI93a84=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bits-and-blooms/bitset v1.10.0 h1:ePXTeiPEazB5+opbv5fr8umg2R/1NlzgDsyepwsSr88=
Expand Down Expand Up @@ -90,6 +94,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/holiman/uint256 v1.2.4 h1:jUc4Nk8fm9jZabQuqr2JzednajVmBpC+oiTiXZJEApU=
github.com/holiman/uint256 v1.2.4/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E=
Expand All @@ -114,6 +120,8 @@ github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/lightclient/go-ethereum v1.10.10-0.20240429213339-9b7958ba0063 h1:srEOH43WDUtXLofgCmo3LOGUEfoVpe76/ho1qt7RmPs=
github.com/lightclient/go-ethereum v1.10.10-0.20240429213339-9b7958ba0063/go.mod h1:1STrq471D0BQbCX9He0hUj4bHxX2k6mt5nOQJhDNOJ8=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
Expand Down Expand Up @@ -198,15 +206,15 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
81 changes: 39 additions & 42 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,35 +470,33 @@ func electraExecutionPayloadToBlockHeader(payload *electra.ExecutionPayload, par
}
baseFeePerGas := payload.BaseFeePerGas.ToBig()
withdrawalsHash := deriveWithdrawalsHash(payload.Withdrawals)
depositReceiptsHash := deriveDepositReceiptsHash(payload.DepositReceipts)
withdrawalRequestsHash := deriveWithdrawalRequestsHash(payload.WithdrawalRequests)
requestsHash := deriveRequestsHash(payload.DepositReceipts, payload.WithdrawalRequests)
var beaconRootHash *common.Hash
if parentBeaconRoot != nil {
root := common.Hash(*parentBeaconRoot)
beaconRootHash = &root
}
return &types.Header{
ParentHash: common.Hash(payload.ParentHash),
UncleHash: types.EmptyUncleHash,
Coinbase: common.Address(payload.FeeRecipient),
Root: common.Hash(payload.StateRoot),
TxHash: transactionHash,
ReceiptHash: common.Hash(payload.ReceiptsRoot),
Bloom: payload.LogsBloom,
Difficulty: common.Big0,
Number: new(big.Int).SetUint64(payload.BlockNumber),
GasLimit: payload.GasLimit,
GasUsed: payload.GasUsed,
Time: payload.Timestamp,
Extra: payload.ExtraData,
MixDigest: payload.PrevRandao,
BaseFee: baseFeePerGas,
WithdrawalsHash: &withdrawalsHash,
BlobGasUsed: &payload.BlobGasUsed,
ExcessBlobGas: &payload.ExcessBlobGas,
ParentBeaconRoot: beaconRootHash,
DepositReceiptsHash: &depositReceiptsHash,
WithdrawalRequestsHash: &withdrawalRequestsHash,
ParentHash: common.Hash(payload.ParentHash),
UncleHash: types.EmptyUncleHash,
Coinbase: common.Address(payload.FeeRecipient),
Root: common.Hash(payload.StateRoot),
TxHash: transactionHash,
ReceiptHash: common.Hash(payload.ReceiptsRoot),
Bloom: payload.LogsBloom,
Difficulty: common.Big0,
Number: new(big.Int).SetUint64(payload.BlockNumber),
GasLimit: payload.GasLimit,
GasUsed: payload.GasUsed,
Time: payload.Timestamp,
Extra: payload.ExtraData,
MixDigest: payload.PrevRandao,
BaseFee: baseFeePerGas,
WithdrawalsHash: &withdrawalsHash,
BlobGasUsed: &payload.BlobGasUsed,
ExcessBlobGas: &payload.ExcessBlobGas,
ParentBeaconRoot: beaconRootHash,
RequestsHash: &requestsHash,
}, nil
}

Expand Down Expand Up @@ -528,30 +526,29 @@ func deriveWithdrawalsHash(withdrawals []*capella.Withdrawal) common.Hash {
return types.DeriveSha(types.Withdrawals(withdrawalData), trie.NewStackTrie(nil))
}

func deriveDepositReceiptsHash(depositReceipts []*electra.DepositReceipt) common.Hash {
depositReceiptsData := make([]*types.DepositReceipt, len(depositReceipts))
for i, d := range depositReceipts {
depositReceiptsData[i] = &types.DepositReceipt{
Pubkey: d.Pubkey,
WithdrawalCredentials: [32]byte(d.WithdrawalCredentials),
Amount: uint64(d.Amount),
Signature: d.Signature,
Index: d.Index,
func deriveRequestsHash(depositRequests []*electra.DepositReceipt, withdrawalRequests []*electra.ExecutionLayerWithdrawalRequest) common.Hash {
deposits := make(types.Deposits, len(depositRequests))
for i, e := range depositRequests {
deposits[i] = &types.Deposit{
PublicKey: types.BLSPublicKey(e.Pubkey),
WithdrawalCredentials: common.Hash(e.WithdrawalCredentials),
Amount: uint64(e.Amount),
Signature: types.BLSSignature(e.Signature),
Index: e.Index,
}
}
return types.DeriveSha(types.DepositReceipts(depositReceiptsData), trie.NewStackTrie(nil))
}

func deriveWithdrawalRequestsHash(withdrawalRequests []*electra.ExecutionLayerWithdrawalRequest) common.Hash {
withdrawalRequestsData := make([]*types.WithdrawalRequest, len(withdrawalRequests))
withdrawals := make(types.WithdrawalRequests, len(withdrawalRequests))
for i, e := range withdrawalRequests {
withdrawalRequestsData[i] = &types.WithdrawalRequest{
SourceAddress: common.Address(e.SourceAddress),
ValidatorPubkey: e.ValidatorPubkey,
Amount: uint64(e.Amount),
withdrawals[i] = &types.WithdrawalRequest{
Source: common.Address(e.SourceAddress),
PublicKey: types.BLSPublicKey(e.ValidatorPubkey),
Amount: uint64(e.Amount),
}
}
return types.DeriveSha(types.WithdrawalRequests(withdrawalRequestsData), trie.NewStackTrie(nil))

requests := deposits.Requests()
requests = append(requests, withdrawals.Requests()...)
return types.DeriveSha(requests, trie.NewStackTrie(nil))
}

func deriveBaseFeePerGas(baseFeePerGas [32]byte) *big.Int {
Expand Down
21 changes: 0 additions & 21 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/attestantio/go-eth2-client/spec/bellatrix"
"github.com/attestantio/go-eth2-client/spec/capella"
"github.com/attestantio/go-eth2-client/spec/deneb"
"github.com/attestantio/go-eth2-client/spec/electra"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -175,26 +174,6 @@ func TestComputeHash(t *testing.T) {
require.Equal(t, "0xd9491c8ae79611d0f08806f29b1e2e86cb8f64512aa381e543dcae257dda80d6", hash.String())
})

/* TODO(electra): update with real electra execution payload & known hash */
t.Run("Should compute electra hash", func(t *testing.T) {
jsonFile, err := os.Open("../testdata/executionpayload/electra-case0.json")
require.NoError(t, err)
defer jsonFile.Close()

payload := new(electra.ExecutionPayload)
require.NoError(t, DecodeJSON(jsonFile, payload))
versionedPayload := &api.VersionedExecutionPayload{
Version: spec.DataVersionElectra,
Electra: payload,
}
h, _ := HexToHash("0xa119064ee9c03e2c7ad5821b6077606c64f36542eda12ed61a1edc5f898a17fc")
r := phase0.Root(h)
hash, err := ComputeBlockHash(versionedPayload, &r)
require.NoError(t, err)
/* TODO(electra): not actually sure this is the right hash */
require.Equal(t, "0x500991c7bb744af42002f9883f456f0b308abc07f74c18901aaf2dde352f59f2", hash.String())
})

t.Run("Should error on unknown version", func(t *testing.T) {
payload := new(capella.ExecutionPayload)
versionedPayload := &api.VersionedExecutionPayload{
Expand Down

0 comments on commit ee28100

Please sign in to comment.