Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ update_all_mod:
@$(MAKE) update_mod MODULE=ops/tools
@$(MAKE) update_mod MODULE=oracle
@$(MAKE) update_mod MODULE=tx-submitter
@$(MAKE) update_mod MODULE=token-price-oracle


update:
Expand Down
793 changes: 793 additions & 0 deletions go.work.sum

Large diffs are not rendered by default.

65 changes: 5 additions & 60 deletions node/derivation/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"sync"

"github.com/morph-l2/go-ethereum/common"
"github.com/morph-l2/go-ethereum/common/hexutil"
"github.com/morph-l2/go-ethereum/core/types"
"github.com/morph-l2/go-ethereum/crypto/kzg4844"
"github.com/morph-l2/go-ethereum/params"
Expand Down Expand Up @@ -131,70 +130,16 @@ func (cl *L1BeaconClient) GetBlobSidecars(ctx context.Context, ref L1BlockRef, h
if err := cl.apiReq(ctx, &resp, builder.String()); err != nil {
return nil, fmt.Errorf("%w: failed to fetch blob sidecars for slot %v block %v", err, slot, ref)
}
if len(hashes) != len(resp.Data) {
return nil, fmt.Errorf("expected %v sidecars but got %v", len(hashes), len(resp.Data))
// Some Beacon nodes may ignore the indices parameter and return all sidecars for the slot.
// We only need to ensure we have at least the number of sidecars we requested.
// Callers are responsible for filtering the correct sidecars by index if needed.
if len(resp.Data) < len(hashes) {
return nil, fmt.Errorf("expected at least %v sidecars but got %v", len(hashes), len(resp.Data))
}

return resp.Data, nil
}

// GetBlobSidecar fetches blob sidecars that were confirmed in the specified L1 block with the
// given indexed hashes. Order of the returned sidecars is not guaranteed, and blob data is not
// checked for validity.
func (cl *L1BeaconClient) GetBlobSidecar(ctx context.Context, ref L1BlockRef, hashes []IndexedBlobHash) (types.BlobTxSidecar, error) {
blobSidecars, err := cl.GetBlobSidecars(ctx, ref, hashes)
if err != nil {
return types.BlobTxSidecar{}, fmt.Errorf("%w: failed to get blob sidecars for L1BlockRef %v", err, ref)
}
return sidecarFromSidecars(blobSidecars, hashes)
}

func indexFunc(s []*BlobSidecar, f func(blobSidecars *BlobSidecar) bool) int {
for i := range s {
if f(s[i]) {
return i
}
}
return -1
}

func sidecarFromSidecars(blobSidecars []*BlobSidecar, hashes []IndexedBlobHash) (types.BlobTxSidecar, error) {
var blobTxSidecar types.BlobTxSidecar
for i, ih := range hashes {
// The beacon node api makes no guarantees on order of the returned blob sidecars, so
// search for the sidecar that matches the current indexed hash to ensure blobs are
// returned in the same order.
scIndex := indexFunc(
blobSidecars,
func(sc *BlobSidecar) bool { return uint64(sc.Index) == ih.Index })
if scIndex == -1 {
return types.BlobTxSidecar{}, fmt.Errorf("no blob in response matches desired index: %v", ih.Index)
}
sidecar := blobSidecars[scIndex]

// make sure the blob's kzg commitment hashes to the expected value
hash := KZGToVersionedHash(kzg4844.Commitment(sidecar.KZGCommitment))
if hash != ih.Hash {
return types.BlobTxSidecar{}, fmt.Errorf("expected hash %s for blob at index %d but got %s", ih.Hash, ih.Index, hash)
}

// confirm blob data is valid by verifying its proof against the commitment
var blob Blob
b, err := hexutil.Decode(sidecar.Blob)
if err != nil {
return types.BlobTxSidecar{}, fmt.Errorf("hexutil.Decode(sidecar.Blob) error:%v", err)
}
copy(blob[:], b)
if err := VerifyBlobProof(&blob, kzg4844.Commitment(sidecar.KZGCommitment), kzg4844.Proof(sidecar.KZGProof)); err != nil {
return types.BlobTxSidecar{}, fmt.Errorf("%w: blob at index %d failed verification", err, i)
}
blobTxSidecar.Blobs = append(blobTxSidecar.Blobs, *blob.KZGBlob())
blobTxSidecar.Commitments = append(blobTxSidecar.Commitments, kzg4844.Commitment(sidecar.KZGCommitment))
blobTxSidecar.Proofs = append(blobTxSidecar.Proofs, kzg4844.Proof(sidecar.KZGProof))
}
return blobTxSidecar, nil
}

// IndexedBlobHash represents a blob hash that commits to a single blob confirmed in a block. The
// index helps us avoid unnecessary blob to blob hash conversions to find the right content in a
// sidecar.
Expand Down
6 changes: 3 additions & 3 deletions node/derivation/beacon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ func TestGetBlob(t *testing.T) {
fmt.Println(indexedBlobHashes)
header, err := l1Client.HeaderByNumber(context.Background(), big.NewInt(int64(lg.BlockNumber)))
require.NoError(t, err)
var bts eth.BlobTxSidecar
var bts []*BlobSidecar
if len(indexedBlobHashes) != 0 {
bts, err = l1BeaconClient.GetBlobSidecar(context.Background(), L1BlockRef{
bts, err = l1BeaconClient.GetBlobSidecarsEnhanced(context.Background(), L1BlockRef{
Time: header.Time,
}, indexedBlobHashes)
require.NoError(t, err)
}
t.Log(len(bts.Blobs))
t.Log(len(bts))
}

}
Expand Down
2 changes: 1 addition & 1 deletion token-price-oracle/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ replace (
)

require (
github.com/morph-l2/go-ethereum v1.10.14-0.20251125061742-69718a9dcab9
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53
github.com/prometheus/client_golang v1.17.0
github.com/sirupsen/logrus v1.9.3
github.com/urfave/cli v1.22.17
Expand Down
4 changes: 2 additions & 2 deletions token-price-oracle/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqky
github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/morph-l2/go-ethereum v1.10.14-0.20251125061742-69718a9dcab9 h1:IiOGoNPhICkQdLjwodT5lp4Vd9Zzfwl6cyk+HPwAeyA=
github.com/morph-l2/go-ethereum v1.10.14-0.20251125061742-69718a9dcab9/go.mod h1:tiFPeidxjoCmLj18ne9H3KQdIGTCvRC30qlef06Fd9M=
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53 h1:8+qaUTn1/eyS8er4RkibhHMFC/L4IgqIXLtORakBDkI=
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53/go.mod h1:tiFPeidxjoCmLj18ne9H3KQdIGTCvRC30qlef06Fd9M=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
Expand Down
Loading