Skip to content

Commit 6236bfe

Browse files
committed
crypto: add support for blobs in eth_fillTransaction (ethereum#28839)
1 parent 01674a2 commit 6236bfe

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

crypto/kzg4844/kzg4844.go

+39
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,60 @@ import (
2121
"embed"
2222
"errors"
2323
"hash"
24+
"reflect"
2425
"sync/atomic"
26+
27+
"github.com/XinFinOrg/XDPoSChain/common/hexutil"
2528
)
2629

2730
//go:embed trusted_setup.json
2831
var content embed.FS
2932

33+
var (
34+
blobT = reflect.TypeOf(Blob{})
35+
commitmentT = reflect.TypeOf(Commitment{})
36+
proofT = reflect.TypeOf(Proof{})
37+
)
38+
3039
// Blob represents a 4844 data blob.
3140
type Blob [131072]byte
3241

42+
// UnmarshalJSON parses a blob in hex syntax.
43+
func (b *Blob) UnmarshalJSON(input []byte) error {
44+
return hexutil.UnmarshalFixedJSON(blobT, input, b[:])
45+
}
46+
47+
// MarshalText returns the hex representation of b.
48+
func (b Blob) MarshalText() ([]byte, error) {
49+
return hexutil.Bytes(b[:]).MarshalText()
50+
}
51+
3352
// Commitment is a serialized commitment to a polynomial.
3453
type Commitment [48]byte
3554

55+
// UnmarshalJSON parses a commitment in hex syntax.
56+
func (c *Commitment) UnmarshalJSON(input []byte) error {
57+
return hexutil.UnmarshalFixedJSON(commitmentT, input, c[:])
58+
}
59+
60+
// MarshalText returns the hex representation of c.
61+
func (c Commitment) MarshalText() ([]byte, error) {
62+
return hexutil.Bytes(c[:]).MarshalText()
63+
}
64+
3665
// Proof is a serialized commitment to the quotient polynomial.
3766
type Proof [48]byte
3867

68+
// UnmarshalJSON parses a proof in hex syntax.
69+
func (p *Proof) UnmarshalJSON(input []byte) error {
70+
return hexutil.UnmarshalFixedJSON(proofT, input, p[:])
71+
}
72+
73+
// MarshalText returns the hex representation of p.
74+
func (p Proof) MarshalText() ([]byte, error) {
75+
return hexutil.Bytes(p[:]).MarshalText()
76+
}
77+
3978
// Point is a BLS field element.
4079
type Point [32]byte
4180

0 commit comments

Comments
 (0)