Skip to content

Commit 3e4ed1c

Browse files
committed
internal/ethapi: fix test
1 parent b4bf2ae commit 3e4ed1c

File tree

3 files changed

+59
-24
lines changed

3 files changed

+59
-24
lines changed

internal/ethapi/api.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,17 +1519,18 @@ func (api *TransactionAPI) SendTransaction(ctx context.Context, args Transaction
15191519
// processing (signing + broadcast).
15201520
func (api *TransactionAPI) FillTransaction(ctx context.Context, args TransactionArgs) (*SignTransactionResult, error) {
15211521
// Set some sanity defaults and terminate on failure
1522-
config := sidecarConfig{
1523-
blobSidecarAllowed: true,
1524-
blobSidecarVersion: types.BlobSidecarVersion0,
1525-
}
1522+
sidecarVersion := types.BlobSidecarVersion0
15261523
if len(args.Blobs) > 0 {
15271524
chainHead := api.b.CurrentHeader()
15281525
isOsaka := api.b.ChainConfig().IsOsaka(chainHead.Number, chainHead.Time)
15291526
if isOsaka {
1530-
config.blobSidecarVersion = types.BlobSidecarVersion1
1527+
sidecarVersion = types.BlobSidecarVersion1
15311528
}
15321529
}
1530+
config := sidecarConfig{
1531+
blobSidecarAllowed: true,
1532+
blobSidecarVersion: sidecarVersion,
1533+
}
15331534
if err := args.setDefaults(ctx, api.b, config); err != nil {
15341535
return nil, err
15351536
}

internal/ethapi/api_test.go

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ import (
3434
"testing"
3535
"time"
3636

37-
"github.com/ethereum/go-ethereum/accounts/abi"
38-
"github.com/ethereum/go-ethereum/internal/ethapi/override"
39-
4037
"github.com/ethereum/go-ethereum"
4138
"github.com/ethereum/go-ethereum/accounts"
39+
"github.com/ethereum/go-ethereum/accounts/abi"
4240
"github.com/ethereum/go-ethereum/accounts/keystore"
4341
"github.com/ethereum/go-ethereum/common"
4442
"github.com/ethereum/go-ethereum/common/hexutil"
@@ -56,6 +54,7 @@ import (
5654
"github.com/ethereum/go-ethereum/ethdb"
5755
"github.com/ethereum/go-ethereum/event"
5856
"github.com/ethereum/go-ethereum/internal/blocktest"
57+
"github.com/ethereum/go-ethereum/internal/ethapi/override"
5958
"github.com/ethereum/go-ethereum/params"
6059
"github.com/ethereum/go-ethereum/rpc"
6160
"github.com/holiman/uint256"
@@ -2661,19 +2660,53 @@ func TestSendBlobTransaction(t *testing.T) {
26612660

26622661
func TestFillBlobTransaction(t *testing.T) {
26632662
t.Parallel()
2663+
2664+
testFillBlobTransaction(t, false)
2665+
testFillBlobTransaction(t, true)
2666+
}
2667+
2668+
func testFillBlobTransaction(t *testing.T, osaka bool) {
26642669
// Initialize test accounts
2670+
config := *params.MergedTestChainConfig
2671+
if !osaka {
2672+
config.OsakaTime = nil
2673+
}
26652674
var (
26662675
key, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
26672676
to = crypto.PubkeyToAddress(key.PublicKey)
26682677
genesis = &core.Genesis{
2669-
Config: params.MergedTestChainConfig,
2678+
Config: &config,
26702679
Alloc: types.GenesisAlloc{},
26712680
}
2672-
emptyBlob = new(kzg4844.Blob)
2673-
emptyBlobs = []kzg4844.Blob{*emptyBlob}
2674-
emptyBlobCommit, _ = kzg4844.BlobToCommitment(emptyBlob)
2675-
emptyBlobProof, _ = kzg4844.ComputeBlobProof(emptyBlob, emptyBlobCommit)
2676-
emptyBlobHash common.Hash = kzg4844.CalcBlobHashV1(sha256.New(), &emptyBlobCommit)
2681+
emptyBlob = new(kzg4844.Blob)
2682+
emptyBlobs = []kzg4844.Blob{*emptyBlob}
2683+
emptyBlobCommit, _ = kzg4844.BlobToCommitment(emptyBlob)
2684+
emptyBlobProof, _ = kzg4844.ComputeBlobProof(emptyBlob, emptyBlobCommit)
2685+
emptyBlobCellProofs, _ = kzg4844.ComputeCellProofs(emptyBlob)
2686+
emptyBlobHash common.Hash = kzg4844.CalcBlobHashV1(sha256.New(), &emptyBlobCommit)
2687+
2688+
fillEmptyKZGProofs = func(blobs int) []kzg4844.Proof {
2689+
if osaka {
2690+
return make([]kzg4844.Proof, blobs*kzg4844.CellProofsPerBlob)
2691+
}
2692+
return make([]kzg4844.Proof, blobs)
2693+
}
2694+
expectSidecar = func() *types.BlobTxSidecar {
2695+
if osaka {
2696+
return types.NewBlobTxSidecar(
2697+
types.BlobSidecarVersion1,
2698+
emptyBlobs,
2699+
[]kzg4844.Commitment{emptyBlobCommit},
2700+
emptyBlobCellProofs,
2701+
)
2702+
}
2703+
return types.NewBlobTxSidecar(
2704+
types.BlobSidecarVersion0,
2705+
emptyBlobs,
2706+
[]kzg4844.Commitment{emptyBlobCommit},
2707+
[]kzg4844.Proof{emptyBlobProof},
2708+
)
2709+
}
26772710
)
26782711
b := newTestBackend(t, 1, genesis, beacon.New(ethash.NewFaker()), func(i int, b *core.BlockGen) {
26792712
b.SetPoS()
@@ -2733,7 +2766,7 @@ func TestFillBlobTransaction(t *testing.T) {
27332766
Commitments: []kzg4844.Commitment{{}, {}},
27342767
Proofs: []kzg4844.Proof{{}},
27352768
},
2736-
err: `number of blobs and proofs mismatch (have=1, want=2)`,
2769+
err: fmt.Sprintf(`number of blobs and proofs mismatch (have=1, want=%d)`, len(fillEmptyKZGProofs(2))),
27372770
},
27382771
{
27392772
name: "TestInvalidProofVerification",
@@ -2743,7 +2776,7 @@ func TestFillBlobTransaction(t *testing.T) {
27432776
Value: (*hexutil.Big)(big.NewInt(1)),
27442777
Blobs: []kzg4844.Blob{{}, {}},
27452778
Commitments: []kzg4844.Commitment{{}, {}},
2746-
Proofs: []kzg4844.Proof{{}, {}},
2779+
Proofs: fillEmptyKZGProofs(2),
27472780
},
27482781
err: `failed to verify blob proof: short buffer`,
27492782
},
@@ -2759,7 +2792,7 @@ func TestFillBlobTransaction(t *testing.T) {
27592792
},
27602793
want: &result{
27612794
Hashes: []common.Hash{emptyBlobHash},
2762-
Sidecar: types.NewBlobTxSidecar(types.BlobSidecarVersion0, emptyBlobs, []kzg4844.Commitment{emptyBlobCommit}, []kzg4844.Proof{emptyBlobProof}),
2795+
Sidecar: expectSidecar(),
27632796
},
27642797
},
27652798
{
@@ -2775,7 +2808,7 @@ func TestFillBlobTransaction(t *testing.T) {
27752808
},
27762809
want: &result{
27772810
Hashes: []common.Hash{emptyBlobHash},
2778-
Sidecar: types.NewBlobTxSidecar(types.BlobSidecarVersion0, emptyBlobs, []kzg4844.Commitment{emptyBlobCommit}, []kzg4844.Proof{emptyBlobProof}),
2811+
Sidecar: expectSidecar(),
27792812
},
27802813
},
27812814
{
@@ -2801,7 +2834,7 @@ func TestFillBlobTransaction(t *testing.T) {
28012834
},
28022835
want: &result{
28032836
Hashes: []common.Hash{emptyBlobHash},
2804-
Sidecar: types.NewBlobTxSidecar(types.BlobSidecarVersion0, emptyBlobs, []kzg4844.Commitment{emptyBlobCommit}, []kzg4844.Proof{emptyBlobProof}),
2837+
Sidecar: expectSidecar(),
28052838
},
28062839
},
28072840
}

internal/ethapi/transaction_args.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,10 @@ func (args *TransactionArgs) setBlobTxSidecar(ctx context.Context, config sideca
306306
if args.Commitments != nil && len(args.Commitments) != n {
307307
return fmt.Errorf("number of blobs and commitments mismatch (have=%d, want=%d)", len(args.Commitments), n)
308308
}
309-
proofLen := n
309+
310310
// if V0: len(blobs) == len(proofs)
311311
// if V1: len(blobs) == len(proofs) * 128
312+
proofLen := n
312313
if config.blobSidecarVersion == types.BlobSidecarVersion1 {
313314
proofLen = n * kzg4844.CellProofsPerBlob
314315
}
@@ -326,7 +327,7 @@ func (args *TransactionArgs) setBlobTxSidecar(ctx context.Context, config sideca
326327
if args.Commitments == nil {
327328
var (
328329
commitments = make([]kzg4844.Commitment, n)
329-
proofs = make([]kzg4844.Proof, proofLen)
330+
proofs = make([]kzg4844.Proof, 0, proofLen)
330331
)
331332
for i, b := range args.Blobs {
332333
c, err := kzg4844.BlobToCommitment(&b)
@@ -341,11 +342,11 @@ func (args *TransactionArgs) setBlobTxSidecar(ctx context.Context, config sideca
341342
if err != nil {
342343
return fmt.Errorf("blobs[%d]: error computing proof: %v", i, err)
343344
}
344-
proofs[i] = p
345+
proofs = append(proofs, p)
345346
case types.BlobSidecarVersion1:
346347
ps, err := kzg4844.ComputeCellProofs(&b)
347348
if err != nil {
348-
return fmt.Errorf("blobs[%d]: error computing cell proof: %v", i, err)
349+
return fmt.Errorf("blobs[%d]: error computing proof: %v", i, err)
349350
}
350351
proofs = append(proofs, ps...)
351352
}
@@ -362,7 +363,7 @@ func (args *TransactionArgs) setBlobTxSidecar(ctx context.Context, config sideca
362363
}
363364
case types.BlobSidecarVersion1:
364365
if err := kzg4844.VerifyCellProofs(args.Blobs, args.Commitments, args.Proofs); err != nil {
365-
return fmt.Errorf("failed to verify blob cell proof: %v", err)
366+
return fmt.Errorf("failed to verify blob proof: %v", err)
366367
}
367368
}
368369
}

0 commit comments

Comments
 (0)