@@ -3,18 +3,21 @@ package txlistdecoder
3
3
import (
4
4
"context"
5
5
"crypto/sha256"
6
+ "errors"
6
7
"math/big"
7
8
8
9
"github.com/ethereum/go-ethereum/common"
9
10
"github.com/ethereum/go-ethereum/core/types"
10
11
"github.com/ethereum/go-ethereum/crypto/kzg4844"
11
12
"github.com/ethereum/go-ethereum/log"
13
+ "github.com/ethereum/go-ethereum/params"
12
14
"github.com/taikoxyz/taiko-client/bindings"
13
15
"github.com/taikoxyz/taiko-client/pkg/rpc"
14
16
)
15
17
16
- const (
18
+ var (
17
19
blobCommitmentVersionKZG uint8 = 0x01 // Version byte for the point evaluation precompile.
20
+ errBlobInvalid = errors .New ("invalid blob encoding" )
18
21
)
19
22
20
23
type BlobFetcher struct {
@@ -52,17 +55,39 @@ func (d *BlobFetcher) Fetch(
52
55
if KZGToVersionedHash (
53
56
kzg4844 .Commitment (common .FromHex (sidecar .KzgCommitment )),
54
57
) == common .BytesToHash (meta .BlobHash [:]) {
55
- return common .Hex2Bytes (sidecar .Blob ), nil
58
+ return DecodeBlob ( common .FromHex (sidecar .Blob ))
56
59
}
57
60
}
58
61
59
62
return nil , errSidecarNotFound
60
63
}
61
64
62
- // KZGToVersionedHash implements kzg_to_versioned_hash from EIP-4844
65
+ // KZGToVersionedHash implements kzg_to_versioned_hash from EIP-4844.
63
66
func KZGToVersionedHash (kzg kzg4844.Commitment ) common.Hash {
64
67
h := sha256 .Sum256 (kzg [:])
65
68
h [0 ] = blobCommitmentVersionKZG
66
69
67
70
return h
68
71
}
72
+
73
+ // DecodeBlob decode blob data.
74
+ func DecodeBlob (blob []byte ) ([]byte , error ) {
75
+ if len (blob ) != params .BlobTxFieldElementsPerBlob * 32 {
76
+ return nil , errBlobInvalid
77
+ }
78
+ log .Info ("OK" )
79
+ var data []byte
80
+ for i , j := 0 , 0 ; i < params .BlobTxFieldElementsPerBlob ; i ++ {
81
+ data = append (data , blob [j :j + 31 ]... )
82
+ j += 32
83
+ }
84
+
85
+ i := len (data ) - 1
86
+ for ; i >= 0 ; i -- {
87
+ if data [i ] != 0x00 {
88
+ break
89
+ }
90
+ }
91
+ data = data [:i + 1 ]
92
+ return data , nil
93
+ }
0 commit comments