Skip to content
This repository was archived by the owner on May 11, 2024. It is now read-only.

Commit cca1518

Browse files
committed
feat: add kZGToVersionedHash
1 parent 6e19a32 commit cca1518

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

driver/txlist_fetcher/blob.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@ package txlistdecoder
22

33
import (
44
"context"
5+
"crypto/sha256"
56
"math/big"
67

78
"github.com/ethereum/go-ethereum/common"
89
"github.com/ethereum/go-ethereum/core/types"
10+
"github.com/ethereum/go-ethereum/crypto/kzg4844"
911
"github.com/ethereum/go-ethereum/log"
1012
"github.com/taikoxyz/taiko-client/bindings"
1113
"github.com/taikoxyz/taiko-client/pkg/rpc"
1214
)
1315

16+
const (
17+
blobCommitmentVersionKZG uint8 = 0x01 // Version byte for the point evaluation precompile.
18+
)
19+
1420
type BlobFetcher struct {
1521
rpc *rpc.Client
1622
}
@@ -38,10 +44,20 @@ func (d *BlobFetcher) Fetch(
3844
for _, sidecar := range sidecars {
3945
log.Info("Found sidecar", "KzgCommitment", sidecar.KzgCommitment, "blobHash", common.Bytes2Hex(meta.BlobHash[:]))
4046

41-
if sidecar.KzgCommitment == common.Bytes2Hex(meta.BlobHash[:]) {
47+
if kZGToVersionedHash(
48+
kzg4844.Commitment(common.Hex2Bytes(sidecar.KzgCommitment)[:]),
49+
) == common.BytesToHash(meta.BlobHash[:]) {
4250
return common.Hex2Bytes(sidecar.Blob), nil
4351
}
4452
}
4553

4654
return nil, errSidecarNotFound
4755
}
56+
57+
// kZGToVersionedHash implements kzg_to_versioned_hash from EIP-4844
58+
func kZGToVersionedHash(kzg kzg4844.Commitment) common.Hash {
59+
h := sha256.Sum256(kzg[:])
60+
h[0] = blobCommitmentVersionKZG
61+
62+
return h
63+
}

go.sum

+3
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,9 @@ github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d h1:vfofYNRScrDd
997997
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48=
998998
github.com/taikoxyz/taiko-geth v0.0.0-20240207045737-1f775750a248 h1:biOi7poktBhAsrkxrvO3Sczs8L6OyvBFtt7lUxdwe7A=
999999
github.com/taikoxyz/taiko-geth v0.0.0-20240207045737-1f775750a248/go.mod h1:gFtlVORuUcT+UUIcJ/veCNjkuOSujCi338uSHJrYAew=
1000+
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
1001+
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161/go.mod h1:wM7WEvslTq+iOEAMDLSzhVuOt5BRZ05WirO+b09GHQU=
1002+
github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b/go.mod h1:5XA7W9S6mni3h5uvOC75dA3m9CCCaS83lltmc0ukdi4=
10001003
github.com/thomaso-mirodin/intmath v0.0.0-20160323211736-5dc6d854e46e h1:cR8/SYRgyQCt5cNCMniB/ZScMkhI9nk8U5C7SbISXjo=
10011004
github.com/thomaso-mirodin/intmath v0.0.0-20160323211736-5dc6d854e46e/go.mod h1:Tu4lItkATkonrYuvtVjG0/rhy15qrNGNTjPdaphtZ/8=
10021005
github.com/tjfoc/gmsm v1.3.0/go.mod h1:HaUcFuY0auTiaHB9MHFGCPx5IaLhTUd2atbCFBQXn9w=

0 commit comments

Comments
 (0)