mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 13:21:37 +00:00
crypto/kzg4844: List semantic for CalcBlobHAshV1
This commit is contained in:
parent
0d043d071e
commit
f665f7dbab
5 changed files with 23 additions and 24 deletions
|
|
@ -18,7 +18,6 @@ package types
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
|
@ -87,11 +86,8 @@ func NewBlobTxSidecar(version byte, blobs []kzg4844.Blob, commitments []kzg4844.
|
|||
|
||||
// BlobHashes computes the blob hashes of the given blobs.
|
||||
func (sc *BlobTxSidecar) BlobHashes() []common.Hash {
|
||||
hasher := sha256.New()
|
||||
h := make([]common.Hash, len(sc.Commitments))
|
||||
for i := range sc.Blobs {
|
||||
h[i] = kzg4844.CalcBlobHashV1(hasher, &sc.Commitments[i])
|
||||
}
|
||||
kzg4844.CalcBlobHashV1List(sc.Commitments, h)
|
||||
return h
|
||||
}
|
||||
|
||||
|
|
@ -153,11 +149,11 @@ func (sc *BlobTxSidecar) ValidateBlobCommitmentHashes(hashes []common.Hash) erro
|
|||
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))
|
||||
}
|
||||
hasher := sha256.New()
|
||||
computed := make([]common.Hash, len(sc.Commitments))
|
||||
kzg4844.CalcBlobHashV1List(sc.Commitments, computed)
|
||||
for i, vhash := range hashes {
|
||||
computed := kzg4844.CalcBlobHashV1(hasher, &sc.Commitments[i])
|
||||
if vhash != computed {
|
||||
return fmt.Errorf("blob %d: computed hash %#x mismatches transaction one %#x", i, computed, vhash)
|
||||
if vhash != computed[i] {
|
||||
return fmt.Errorf("blob %d: computed hash %#x mismatches transaction one %#x", i, computed[i], vhash)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -18,12 +18,14 @@
|
|||
package kzg4844
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"embed"
|
||||
"errors"
|
||||
"hash"
|
||||
"reflect"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
)
|
||||
|
||||
|
|
@ -185,6 +187,14 @@ func CalcBlobHashV1(hasher hash.Hash, commit *Commitment) (vh [32]byte) {
|
|||
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.
|
||||
func IsValidVersionedHash(h []byte) bool {
|
||||
return len(h) == 32 && h[0] == 0x01
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package catalyst
|
|||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
|
|
@ -253,15 +252,17 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
|
|||
// Independently calculate the blob hashes from sidecars.
|
||||
blobHashes = make([]common.Hash, 0)
|
||||
if envelope.BlobsBundle != nil {
|
||||
hasher := sha256.New()
|
||||
for _, commit := range envelope.BlobsBundle.Commitments {
|
||||
blobHashes = make([]common.Hash, len(envelope.BlobsBundle.Commitments))
|
||||
commits := make([]kzg4844.Commitment, len(envelope.BlobsBundle.Commitments))
|
||||
for nr, commit := range envelope.BlobsBundle.Commitments {
|
||||
var c kzg4844.Commitment
|
||||
if len(commit) != len(c) {
|
||||
return errors.New("invalid commitment length")
|
||||
}
|
||||
copy(c[:], commit)
|
||||
blobHashes = append(blobHashes, kzg4844.CalcBlobHashV1(hasher, &c))
|
||||
copy(commits[nr][:], commit)
|
||||
}
|
||||
|
||||
kzg4844.CalcBlobHashV1List(commits, blobHashes)
|
||||
}
|
||||
beaconRoot = &common.Hash{}
|
||||
requests = envelope.Requests
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package ethapi
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"fmt"
|
||||
"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.
|
||||
hashes := make([]common.Hash, n)
|
||||
hasher := sha256.New()
|
||||
for i, c := range args.Commitments {
|
||||
hashes[i] = kzg4844.CalcBlobHashV1(hasher, &c)
|
||||
}
|
||||
kzg4844.CalcBlobHashV1List(args.Commitments, hashes)
|
||||
if args.BlobHashes != nil {
|
||||
for i, h := range hashes {
|
||||
if h != args.BlobHashes[i] {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package apitypes
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
|
@ -291,10 +290,7 @@ func (args *SendTxArgs) validateTxSidecar() error {
|
|||
}
|
||||
|
||||
hashes := make([]common.Hash, n)
|
||||
hasher := sha256.New()
|
||||
for i, c := range args.Commitments {
|
||||
hashes[i] = kzg4844.CalcBlobHashV1(hasher, &c)
|
||||
}
|
||||
kzg4844.CalcBlobHashV1List(args.Commitments, hashes)
|
||||
if args.BlobHashes != nil {
|
||||
for i, h := range hashes {
|
||||
if h != args.BlobHashes[i] {
|
||||
|
|
|
|||
Loading…
Reference in a new issue