mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
new commit
This commit is contained in:
parent
5181cb5cfc
commit
2f9ab7d28f
4 changed files with 49 additions and 6 deletions
|
|
@ -236,6 +236,25 @@ func makeMultiBlobTx(nonce uint64, gasTipCap uint64, gasFeeCap uint64, blobFeeCa
|
|||
return types.MustSignNewTx(key, types.LatestSigner(params.MainnetChainConfig), blobtx)
|
||||
}
|
||||
|
||||
func makeMultiBlobTxWithCellProofs(nonce uint64, gasTipCap uint64, gasFeeCap uint64, blobFeeCap uint64, blobCount int, key *ecdsa.PrivateKey) *types.Transaction {
|
||||
tx := makeMultiBlobTx(nonce, gasTipCap, gasFeeCap, blobFeeCap, blobCount, key)
|
||||
|
||||
proofs := make([]kzg4844.Proof, 0)
|
||||
for i, blob := range tx.BlobTxSidecar().Blobs {
|
||||
cps, err := kzg4844.ComputeCells(&blob)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
tx.BlobTxSidecar().Proofs = append(proofs, cps...)
|
||||
}
|
||||
tx.Sidecar.Proofs = make([]kzg4844.Proof, blobCount)
|
||||
for i := 0; i < blobCount; i++ {
|
||||
tx.Sidecar.Proofs[i] = testBlobProofs[i]
|
||||
}
|
||||
|
||||
return tx
|
||||
}
|
||||
|
||||
// makeUnsignedTx is a utility method to construct a random blob transaction
|
||||
// without signing it.
|
||||
func makeUnsignedTx(nonce uint64, gasTipCap uint64, gasFeeCap uint64, blobFeeCap uint64) *types.BlobTx {
|
||||
|
|
@ -1482,6 +1501,19 @@ func TestAdd(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
// Testing blob transaction verification around Osaka fork boundary
|
||||
{
|
||||
seeds: map[string]seed{
|
||||
"alice": {balance: 10000000},
|
||||
},
|
||||
adds: []addtx{
|
||||
{ // New account, no previous txs, nonce 0, but blob fee cap too low
|
||||
from: "alice",
|
||||
tx: makeUnsignedTxWithTestBlob(0, 1, 1, 1, 0),
|
||||
err: nil,
|
||||
},
|
||||
},
|
||||
},
|
||||
// Tests issue #30518 where a refactor broke internal state invariants,
|
||||
// causing included transactions not to be properly accounted and thus
|
||||
// account states going our of sync with the chain.
|
||||
|
|
|
|||
|
|
@ -56,4 +56,7 @@ var (
|
|||
// input transaction of non-blob type when a blob transaction from this sender
|
||||
// remains pending (and vice-versa).
|
||||
ErrAlreadyReserved = errors.New("address already reserved")
|
||||
|
||||
// ErrInvalidBlobSidecar is returned if the blob sidecar is invalid.
|
||||
ErrInvalidBlobSidecar = errors.New("invalid blob sidecar, incorrect proofs")
|
||||
)
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types
|
|||
|
||||
func validateBlobSidecar(cfg *params.ChainConfig, time uint64, hashes []common.Hash, sidecar *types.BlobTxSidecar) error {
|
||||
if len(sidecar.Blobs) != len(hashes) {
|
||||
return fmt.Errorf("invalid number of %d blobs compared to %d blob hashes", len(sidecar.Blobs), len(hashes))
|
||||
return fmt.Errorf("invalid number of %d blobs compared to %d blob hashes", ErrInvalidBlobSidecar, len(sidecar.Blobs), len(hashes))
|
||||
}
|
||||
if err := sidecar.ValidateBlobCommitmentHashes(hashes); err != nil {
|
||||
return err
|
||||
|
|
@ -178,7 +178,7 @@ func validateBlobSidecar(cfg *params.ChainConfig, time uint64, hashes []common.H
|
|||
fork := cfg.LatestFork(time)
|
||||
if fork >= forks.Osaka {
|
||||
if len(sidecar.Blobs)*goethkzg.CellsPerExtBlob != len(sidecar.Proofs) {
|
||||
return fmt.Errorf("invalid number of %d cell proofs compared to %d blobs", len(sidecar.Proofs), len(sidecar.Blobs))
|
||||
return fmt.Errorf("invalid number of %d cell proofs compared to %d blobs", ErrInvalidBlobSidecar, len(sidecar.Proofs), len(sidecar.Blobs))
|
||||
}
|
||||
|
||||
// Prepare cells and cell indices for each blob
|
||||
|
|
@ -189,7 +189,7 @@ func validateBlobSidecar(cfg *params.ChainConfig, time uint64, hashes []common.H
|
|||
// Compute cells for the currentblob
|
||||
blobCells, err := kzg4844.ComputeCells(&sidecar.Blobs[i])
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to compute cells for blob %d: %v", i, err)
|
||||
return fmt.Errorf("failed to compute cells for blob %d: %v", ErrInvalidBlobSidecar, i, err)
|
||||
}
|
||||
|
||||
cells = append(cells, blobCells...)
|
||||
|
|
@ -199,18 +199,18 @@ func validateBlobSidecar(cfg *params.ChainConfig, time uint64, hashes []common.H
|
|||
}
|
||||
|
||||
if err := kzg4844.VerifyCellKZGProofBatch(sidecar.Commitments, cellIndices, cells, sidecar.Proofs); err != nil {
|
||||
return fmt.Errorf("failed to verify cell proofs: %v", err)
|
||||
return fmt.Errorf("failed to verify cell proofs: %v", ErrInvalidBlobSidecar, err)
|
||||
}
|
||||
} else { // older folks
|
||||
if len(sidecar.Proofs) != len(hashes) {
|
||||
return fmt.Errorf("invalid number of %d blob proofs compared to %d blob hashes", len(sidecar.Proofs), len(hashes))
|
||||
return fmt.Errorf("invalid number of %d blob proofs compared to %d blob hashes", ErrInvalidBlobSidecar, len(sidecar.Proofs), len(hashes))
|
||||
}
|
||||
|
||||
// Blob commitments match with the hashes in the transaction, verify the
|
||||
// blobs themselves via KZG
|
||||
for i := range sidecar.Blobs {
|
||||
if err := kzg4844.VerifyBlobProof(&sidecar.Blobs[i], sidecar.Commitments[i], sidecar.Proofs[i]); err != nil {
|
||||
return fmt.Errorf("invalid blob %d: %v", i, err)
|
||||
return fmt.Errorf("invalid blob %d: %v", ErrInvalidBlobSidecar, i, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,6 +168,14 @@ func ComputeCells(blob *Blob) ([]Cell, error) {
|
|||
return gokzgComputeCells(blob)
|
||||
}
|
||||
|
||||
// ComputeCellsAndKZGProofs computes the cells and KZG proofs for a given blob.
|
||||
func ComputeCellsAndKZGProofs(blob *Blob) ([]Cell, []Proof, error) {
|
||||
if useCKZG.Load() {
|
||||
return ckzgComputeCellsAndKZGProofs(blob)
|
||||
}
|
||||
return gokzgComputeCellsAndKZGProofs(blob)
|
||||
}
|
||||
|
||||
// CalcBlobHashV1 calculates the 'versioned blob hash' of a commitment.
|
||||
// The given hasher must be a sha256 hash instance, otherwise the result will be invalid!
|
||||
func CalcBlobHashV1(hasher hash.Hash, commit *Commitment) (vh [32]byte) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue