-
Notifications
You must be signed in to change notification settings - Fork 3k
/
blobs.go
53 lines (49 loc) · 1.46 KB
/
blobs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package transactions
import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/holiman/uint256"
)
var (
emptyBlob kzg4844.Blob
emptyBlobCommit kzg4844.Commitment
emptyBlobProof kzg4844.Proof
)
func init() {
var err error
emptyBlob = kzg4844.Blob{}
emptyBlobCommit, err = kzg4844.BlobToCommitment(emptyBlob)
if err != nil {
panic("failed to create empty blob commitment: " + err.Error())
}
emptyBlobProof, err = kzg4844.ComputeBlobProof(emptyBlob, emptyBlobCommit)
if err != nil {
panic("failed to create empty blob proof: " + err.Error())
}
}
// with thanks to fjl
// https://github.com/ethereum/go-ethereum/commit/2a6beb6a39d7cb3c5906dd4465d65da6efcc73cd
func CreateEmptyBlobTx(withSidecar bool, chainID uint64) *types.BlobTx {
sidecar := &types.BlobTxSidecar{
Blobs: []kzg4844.Blob{emptyBlob},
Commitments: []kzg4844.Commitment{emptyBlobCommit},
Proofs: []kzg4844.Proof{emptyBlobProof},
}
blobTx := &types.BlobTx{
ChainID: uint256.NewInt(chainID),
Nonce: 0,
GasTipCap: uint256.NewInt(2200000000000),
GasFeeCap: uint256.NewInt(5000000000000),
Gas: 25000,
To: common.Address{0x03, 0x04, 0x05},
Value: uint256.NewInt(99),
Data: make([]byte, 50),
BlobFeeCap: uint256.NewInt(150000000000),
BlobHashes: sidecar.BlobHashes(),
}
if withSidecar {
blobTx.Sidecar = sidecar
}
return blobTx
}