Skip to content

Commit 67b201e

Browse files
Merge branch 'master' into gligneul/resource-constrait-precompiles
2 parents 06eb2dc + 908d07e commit 67b201e

File tree

2 files changed

+85
-5
lines changed

2 files changed

+85
-5
lines changed

signer/core/apitypes/types.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,13 @@ func (args *SendTxArgs) validateTxSidecar() error {
231231
}
232232

233233
// len(blobs) == len(commitments) == len(proofs) == len(hashes)
234+
// Note: proofs can be either 1:1 (Version 0) or 128:1 cell proofs (Version 1)
234235
n := len(args.Blobs)
235236
if args.Commitments != nil && len(args.Commitments) != n {
236237
return fmt.Errorf("number of blobs and commitments mismatch (have=%d, want=%d)", len(args.Commitments), n)
237238
}
238-
if args.Proofs != nil && len(args.Proofs) != n {
239-
return fmt.Errorf("number of blobs and proofs mismatch (have=%d, want=%d)", len(args.Proofs), n)
239+
if args.Proofs != nil && len(args.Proofs) != n && len(args.Proofs) != n*kzg4844.CellProofsPerBlob {
240+
return fmt.Errorf("number of blobs and proofs mismatch (have=%d, want=%d or %d)", len(args.Proofs), n, n*kzg4844.CellProofsPerBlob)
240241
}
241242
if args.BlobHashes != nil && len(args.BlobHashes) != n {
242243
return fmt.Errorf("number of blobs and hashes mismatch (have=%d, want=%d)", len(args.BlobHashes), n)
@@ -261,9 +262,18 @@ func (args *SendTxArgs) validateTxSidecar() error {
261262
args.Commitments = commitments
262263
args.Proofs = proofs
263264
} else {
264-
for i, b := range args.Blobs {
265-
if err := kzg4844.VerifyBlobProof(&b, args.Commitments[i], args.Proofs[i]); err != nil {
266-
return fmt.Errorf("failed to verify blob proof: %v", err)
265+
// Verify proofs: either 1:1 blob proofs (Version 0) or 128:1 cell proofs (Version 1)
266+
if len(args.Proofs) == n*kzg4844.CellProofsPerBlob {
267+
// Version 1: Cell proofs - verify all at once
268+
if err := kzg4844.VerifyCellProofs(args.Blobs, args.Commitments, args.Proofs); err != nil {
269+
return fmt.Errorf("failed to verify cell proofs: %v", err)
270+
}
271+
} else {
272+
// Version 0: Blob proofs - verify individually
273+
for i, b := range args.Blobs {
274+
if err := kzg4844.VerifyBlobProof(&b, args.Commitments[i], args.Proofs[i]); err != nil {
275+
return fmt.Errorf("failed to verify blob proof: %v", err)
276+
}
267277
}
268278
}
269279
}

signer/core/apitypes/types_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ package apitypes
1919
import (
2020
"crypto/sha256"
2121
"encoding/json"
22+
"math/big"
2223
"testing"
2324

2425
"github.com/ethereum/go-ethereum/common"
26+
"github.com/ethereum/go-ethereum/common/hexutil"
2527
"github.com/ethereum/go-ethereum/core/types"
2628
"github.com/ethereum/go-ethereum/crypto/kzg4844"
2729
"github.com/holiman/uint256"
@@ -139,6 +141,74 @@ func TestBlobTxs(t *testing.T) {
139141
t.Logf("tx %v", string(data))
140142
}
141143

144+
func TestBlobTxsWithCellProofs(t *testing.T) {
145+
blob := kzg4844.Blob{0x1}
146+
commitment, err := kzg4844.BlobToCommitment(&blob)
147+
if err != nil {
148+
t.Fatal(err)
149+
}
150+
151+
// Generate cell proofs (128 proofs per blob) instead of a single blob proof
152+
cellProofs, err := kzg4844.ComputeCellProofs(&blob)
153+
if err != nil {
154+
t.Fatal(err)
155+
}
156+
157+
// Verify we got the expected number of cell proofs
158+
if len(cellProofs) != kzg4844.CellProofsPerBlob {
159+
t.Fatalf("expected %d cell proofs, got %d", kzg4844.CellProofsPerBlob, len(cellProofs))
160+
}
161+
162+
// Test that SendTxArgs accepts cell proofs and converts to Version 1 sidecar
163+
hash := kzg4844.CalcBlobHashV1(sha256.New(), &commitment)
164+
args := &SendTxArgs{
165+
From: common.MixedcaseAddress{},
166+
To: &common.MixedcaseAddress{},
167+
Gas: 21000,
168+
MaxFeePerGas: (*hexutil.Big)(big.NewInt(600)),
169+
MaxPriorityFeePerGas: (*hexutil.Big)(big.NewInt(500)),
170+
BlobFeeCap: (*hexutil.Big)(big.NewInt(700)),
171+
Value: hexutil.Big(*big.NewInt(100)),
172+
Nonce: 8,
173+
ChainID: (*hexutil.Big)(big.NewInt(6)),
174+
BlobHashes: []common.Hash{hash},
175+
Blobs: []kzg4844.Blob{blob},
176+
Commitments: []kzg4844.Commitment{commitment},
177+
Proofs: cellProofs,
178+
}
179+
180+
// This should succeed with the validation fix
181+
tx, err := args.ToTransaction()
182+
if err != nil {
183+
t.Fatalf("failed to convert args with cell proofs to transaction: %v", err)
184+
}
185+
186+
// Verify the transaction type is BlobTx
187+
if tx.Type() != types.BlobTxType {
188+
t.Fatalf("expected BlobTxType, got %d", tx.Type())
189+
}
190+
191+
// Verify the transaction has a Version 1 sidecar
192+
sidecar := tx.BlobTxSidecar()
193+
if sidecar == nil {
194+
t.Fatal("expected sidecar to be present")
195+
}
196+
if sidecar.Version != types.BlobSidecarVersion1 {
197+
t.Fatalf("expected sidecar version %d, got %d", types.BlobSidecarVersion1, sidecar.Version)
198+
}
199+
200+
// Verify the sidecar has the correct number of proofs
201+
if len(sidecar.Proofs) != len(cellProofs) {
202+
t.Fatalf("expected %d proofs in sidecar, got %d", len(cellProofs), len(sidecar.Proofs))
203+
}
204+
205+
data, err := json.Marshal(tx)
206+
if err != nil {
207+
t.Fatal(err)
208+
}
209+
t.Logf("cell proof tx %v", string(data))
210+
}
211+
142212
func TestType_IsArray(t *testing.T) {
143213
t.Parallel()
144214
// Expected positives

0 commit comments

Comments
 (0)