Skip to content

Commit

Permalink
fix: cannot unmarshal blob sidecar (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
welkin22 authored Apr 30, 2024
1 parent 1b1a90f commit d6e26db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
19 changes: 9 additions & 10 deletions op-service/eth/blobs_api.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package eth

import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
)

type BlobSidecar struct {
Expand Down Expand Up @@ -74,17 +73,17 @@ type VersionInformation struct {
}

type BSCBlobTxSidecar struct {
Blobs []Blob `json:"blobs"`
Commitments []Bytes48 `json:"commitments"`
Proofs []Bytes48 `json:"proofs"`
Blobs []Blob `json:"blobs"`
Commitments []Bytes48 `json:"commitments"`
Proofs []Bytes48 `json:"proofs"`
}

type BSCBlobSidecar struct {
BSCBlobTxSidecar
BlockNumber *big.Int `json:"blockNumber"`
BlockHash common.Hash `json:"blockHash"`
TxIndex uint64 `json:"transactionIndex"`
TxHash common.Hash `json:"transactionHash"`
BSCBlobTxSidecar `json:"blobSidecar"`
BlockNumber *hexutil.Big `json:"blockNumber"`
BlockHash common.Hash `json:"blockHash"`
TxIndex *hexutil.Uint64 `json:"txIndex"`
TxHash common.Hash `json:"txHash"`
}

type BSCBlobSidecars []*BSCBlobSidecar
10 changes: 5 additions & 5 deletions op-service/sources/l1_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,23 +295,23 @@ func (s *L1Client) getBlobSidecars(ctx context.Context, ref eth.L1BlockRef) (eth
return blobSidecars, nil
}

func validateBlobSidecars (blobSidecars eth.BSCBlobSidecars, ref eth.L1BlockRef) (map[common.Hash]*eth.Blob, error) {
func validateBlobSidecars(blobSidecars eth.BSCBlobSidecars, ref eth.L1BlockRef) (map[common.Hash]*eth.Blob, error) {
if len(blobSidecars) == 0 {
return nil, fmt.Errorf("invalidate api response, blob sidecars of block %s are empty", ref.Hash)
}
blobsMap := make(map[common.Hash]*eth.Blob)
for _, blobSidecar := range blobSidecars {
if blobSidecar.BlockNumber.Cmp(big.NewInt(0).SetUint64(ref.Number)) != 0 {
return nil, fmt.Errorf("invalidate api response of tx %s, expect block number %d, got %d", blobSidecar.TxHash, ref.Number, blobSidecar.BlockNumber.Uint64())
if blobSidecar.BlockNumber.ToInt().Cmp(big.NewInt(0).SetUint64(ref.Number)) != 0 {
return nil, fmt.Errorf("invalidate api response of tx %s, expect block number %d, got %d", blobSidecar.TxHash, ref.Number, blobSidecar.BlockNumber.ToInt().Uint64())
}
if blobSidecar.BlockHash.Cmp(ref.Hash) != 0 {
return nil, fmt.Errorf("invalidate api response of tx %s, expect block hash %s, got %s", blobSidecar.TxHash, ref.Hash, blobSidecar.BlockHash)
}
if len(blobSidecar.Blobs) == 0 || len(blobSidecar.Blobs) != len(blobSidecar.Commitments) || len(blobSidecar.Blobs) != len(blobSidecar.Proofs) {
return nil, fmt.Errorf("invalidate api response of tx %s, len of blobs/commitments/proofs is not equal or is 0", blobSidecar.TxHash)
return nil, fmt.Errorf("invalidate api response of tx %s,idx:%d, len of blobs(%d)/commitments(%d)/proofs(%d) is not equal or is 0", blobSidecar.TxHash, blobSidecar.TxIndex, len(blobSidecar.Blobs), len(blobSidecar.Commitments), len(blobSidecar.Proofs))
}

for i:=0; i<len(blobSidecar.Blobs); i++ {
for i := 0; i < len(blobSidecar.Blobs); i++ {
// confirm blob data is valid by verifying its proof against the commitment
if err := eth.VerifyBlobProof(&blobSidecar.Blobs[i], kzg4844.Commitment(blobSidecar.Commitments[i]), kzg4844.Proof(blobSidecar.Proofs[i])); err != nil {
return nil, fmt.Errorf("blob of tx %s at index %d failed verification: %w", blobSidecar.TxHash, i, err)
Expand Down

0 comments on commit d6e26db

Please sign in to comment.