mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
erge branch 'juga1980/calcBlob'
This commit is contained in:
commit
204f8d6c96
5 changed files with 23 additions and 24 deletions
|
|
@ -18,7 +18,6 @@ package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/sha256"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
@ -87,11 +86,8 @@ func NewBlobTxSidecar(version byte, blobs []kzg4844.Blob, commitments []kzg4844.
|
||||||
|
|
||||||
// BlobHashes computes the blob hashes of the given blobs.
|
// BlobHashes computes the blob hashes of the given blobs.
|
||||||
func (sc *BlobTxSidecar) BlobHashes() []common.Hash {
|
func (sc *BlobTxSidecar) BlobHashes() []common.Hash {
|
||||||
hasher := sha256.New()
|
|
||||||
h := make([]common.Hash, len(sc.Commitments))
|
h := make([]common.Hash, len(sc.Commitments))
|
||||||
for i := range sc.Blobs {
|
kzg4844.CalcBlobHashV1List(sc.Commitments, h)
|
||||||
h[i] = kzg4844.CalcBlobHashV1(hasher, &sc.Commitments[i])
|
|
||||||
}
|
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -153,11 +149,11 @@ func (sc *BlobTxSidecar) ValidateBlobCommitmentHashes(hashes []common.Hash) erro
|
||||||
if len(sc.Commitments) != len(hashes) {
|
if len(sc.Commitments) != len(hashes) {
|
||||||
return fmt.Errorf("invalid number of %d blob commitments compared to %d blob hashes", len(sc.Commitments), len(hashes))
|
return fmt.Errorf("invalid number of %d blob commitments compared to %d blob hashes", len(sc.Commitments), len(hashes))
|
||||||
}
|
}
|
||||||
hasher := sha256.New()
|
computed := make([]common.Hash, len(sc.Commitments))
|
||||||
|
kzg4844.CalcBlobHashV1List(sc.Commitments, computed)
|
||||||
for i, vhash := range hashes {
|
for i, vhash := range hashes {
|
||||||
computed := kzg4844.CalcBlobHashV1(hasher, &sc.Commitments[i])
|
if vhash != computed[i] {
|
||||||
if vhash != computed {
|
return fmt.Errorf("blob %d: computed hash %#x mismatches transaction one %#x", i, computed[i], vhash)
|
||||||
return fmt.Errorf("blob %d: computed hash %#x mismatches transaction one %#x", i, computed, vhash)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,14 @@
|
||||||
package kzg4844
|
package kzg4844
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
"embed"
|
"embed"
|
||||||
"errors"
|
"errors"
|
||||||
"hash"
|
"hash"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -185,6 +187,14 @@ func CalcBlobHashV1(hasher hash.Hash, commit *Commitment) (vh [32]byte) {
|
||||||
return vh
|
return vh
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hashes List of commitments
|
||||||
|
func CalcBlobHashV1List(list []Commitment, hashes []common.Hash) {
|
||||||
|
hasher := sha256.New()
|
||||||
|
for nr, commit := range list {
|
||||||
|
hashes[nr] = CalcBlobHashV1(hasher, &commit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// IsValidVersionedHash checks that h is a structurally-valid versioned blob hash.
|
// IsValidVersionedHash checks that h is a structurally-valid versioned blob hash.
|
||||||
func IsValidVersionedHash(h []byte) bool {
|
func IsValidVersionedHash(h []byte) bool {
|
||||||
return len(h) == 32 && h[0] == 0x01
|
return len(h) == 32 && h[0] == 0x01
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ package catalyst
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/sha256"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
|
@ -270,15 +269,17 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
|
||||||
// Independently calculate the blob hashes from sidecars.
|
// Independently calculate the blob hashes from sidecars.
|
||||||
blobHashes = make([]common.Hash, 0)
|
blobHashes = make([]common.Hash, 0)
|
||||||
if envelope.BlobsBundle != nil {
|
if envelope.BlobsBundle != nil {
|
||||||
hasher := sha256.New()
|
blobHashes = make([]common.Hash, len(envelope.BlobsBundle.Commitments))
|
||||||
for _, commit := range envelope.BlobsBundle.Commitments {
|
commits := make([]kzg4844.Commitment, len(envelope.BlobsBundle.Commitments))
|
||||||
|
for nr, commit := range envelope.BlobsBundle.Commitments {
|
||||||
var c kzg4844.Commitment
|
var c kzg4844.Commitment
|
||||||
if len(commit) != len(c) {
|
if len(commit) != len(c) {
|
||||||
return errors.New("invalid commitment length")
|
return errors.New("invalid commitment length")
|
||||||
}
|
}
|
||||||
copy(c[:], commit)
|
copy(commits[nr][:], commit)
|
||||||
blobHashes = append(blobHashes, kzg4844.CalcBlobHashV1(hasher, &c))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kzg4844.CalcBlobHashV1List(commits, blobHashes)
|
||||||
}
|
}
|
||||||
beaconRoot = &common.Hash{}
|
beaconRoot = &common.Hash{}
|
||||||
requests = envelope.Requests
|
requests = envelope.Requests
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ package ethapi
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
|
@ -371,10 +370,7 @@ func (args *TransactionArgs) setBlobTxSidecar(ctx context.Context, config sideca
|
||||||
|
|
||||||
// Generate blob hashes if they are missing, or validate them if they are provided.
|
// Generate blob hashes if they are missing, or validate them if they are provided.
|
||||||
hashes := make([]common.Hash, n)
|
hashes := make([]common.Hash, n)
|
||||||
hasher := sha256.New()
|
kzg4844.CalcBlobHashV1List(args.Commitments, hashes)
|
||||||
for i, c := range args.Commitments {
|
|
||||||
hashes[i] = kzg4844.CalcBlobHashV1(hasher, &c)
|
|
||||||
}
|
|
||||||
if args.BlobHashes != nil {
|
if args.BlobHashes != nil {
|
||||||
for i, h := range hashes {
|
for i, h := range hashes {
|
||||||
if h != args.BlobHashes[i] {
|
if h != args.BlobHashes[i] {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package apitypes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/sha256"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -291,10 +290,7 @@ func (args *SendTxArgs) validateTxSidecar() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
hashes := make([]common.Hash, n)
|
hashes := make([]common.Hash, n)
|
||||||
hasher := sha256.New()
|
kzg4844.CalcBlobHashV1List(args.Commitments, hashes)
|
||||||
for i, c := range args.Commitments {
|
|
||||||
hashes[i] = kzg4844.CalcBlobHashV1(hasher, &c)
|
|
||||||
}
|
|
||||||
if args.BlobHashes != nil {
|
if args.BlobHashes != nil {
|
||||||
for i, h := range hashes {
|
for i, h := range hashes {
|
||||||
if h != args.BlobHashes[i] {
|
if h != args.BlobHashes[i] {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue