Skip to content

Commit 452b422

Browse files
committed
Moved to better API for EIP-7594 PeerDAS (#5062).
1 parent 6d64889 commit 452b422

File tree

2 files changed

+56
-20
lines changed

2 files changed

+56
-20
lines changed

src.ts/providers/provider.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,14 @@ export interface TransactionRequest {
242242
*/
243243
kzg?: null | KzgLibraryLike;
244244

245+
/**
246+
* The [[link-eip-7594]] BLOb Wrapper Version used for PeerDAS.
247+
*
248+
* For networks that use EIP-7594, this property is required to
249+
* serialize the sidecar correctly.
250+
*/
251+
blobWrapperVersion?: null | number;
252+
245253
/**
246254
* The [[link-eip-7702]] authorizations (if any).
247255
*/
@@ -406,6 +414,8 @@ export function copyRequest(req: TransactionRequest): PreparedTransactionRequest
406414

407415
if ("kzg" in req) { result.kzg = req.kzg; }
408416

417+
if ("blobWrapperVersion" in req) { result.blobWrapperVersion = req.blobWrapperVersion; }
418+
409419
if ("blobs" in req && req.blobs) {
410420
result.blobs = req.blobs.map((b) => {
411421
if (isBytesLike(b)) { return hexlify(b); }

src.ts/transaction/transaction.ts

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ export interface TransactionLike<A = string> {
134134
*/
135135
kzg?: null | KzgLibraryLike;
136136

137+
/**
138+
* The [[link-eip-7594]] BLOb Wrapper Version used for PeerDAS.
139+
*
140+
* For networks that use EIP-7594, this property is required to
141+
* serialize the sidecar correctly.
142+
*/
143+
blobWrapperVersion?: null | number;
144+
137145
/**
138146
* The [[link-eip-7702]] authorizations (if any).
139147
*/
@@ -156,7 +164,7 @@ export interface Blob {
156164
* A EIP-4844 BLOb uses a string proof, while EIP-7594 use an
157165
* array of strings representing the cells of the proof.
158166
*/
159-
proof: string | Array<string>;
167+
proof: string;
160168

161169
/**
162170
* The BLOb commitment.
@@ -173,7 +181,7 @@ export interface Blob {
173181
*/
174182
export type BlobLike = BytesLike | {
175183
data: BytesLike;
176-
proof: BytesLike | Array<BytesLike>;
184+
proof: BytesLike;
177185
commitment: BytesLike;
178186
};
179187

@@ -574,13 +582,16 @@ function _parseEip4844(data: Uint8Array): TransactionLike {
574582

575583
let typeName = "3";
576584

585+
let blobWrapperVersion: null | number = null;
586+
577587
let blobs: null | Array<Blob> = null;
578588

579589
// Parse the network format
580590
if (fields.length === 4 && Array.isArray(fields[0])) {
581591
// EIP-4844 format with sidecar
582592

583593
typeName = "3 (network format)";
594+
584595
const fBlobs = fields[1], fCommits = fields[2], fProofs = fields[3];
585596
assertArgument(Array.isArray(fBlobs), "invalid network format: blobs not an array", "fields[1]", fBlobs);
586597
assertArgument(Array.isArray(fCommits), "invalid network format: commitments not an array", "fields[2]", fCommits);
@@ -606,9 +617,11 @@ function _parseEip4844(data: Uint8Array): TransactionLike {
606617
const cellCount = 128;
607618

608619
typeName = "3 (EIP-7594 network format)";
609-
const fVersion = getNumber(fields[1]), fBlobs = fields[2], fCommits = fields[3], fProofs = fields[4];
610620

611-
assertArgument(fVersion === 1, `unsupported EIP-7594 network format version: ${ fVersion }`, "fields[1]", fVersion);
621+
blobWrapperVersion = getNumber(fields[1]);
622+
const fBlobs = fields[2], fCommits = fields[3], fProofs = fields[4];
623+
624+
assertArgument(blobWrapperVersion === 1, `unsupported EIP-7594 network format version: ${ blobWrapperVersion }`, "fields[1]", blobWrapperVersion);
612625
assertArgument(Array.isArray(fBlobs), "invalid EIP-7594 network format: blobs not an array", "fields[2]", fBlobs);
613626
assertArgument(Array.isArray(fCommits), "invalid EIP-7594 network format: commitments not an array", "fields[3]", fCommits);
614627
assertArgument(Array.isArray(fProofs), "invalid EIP-7594 network format: proofs not an array", "fields[4]", fProofs);
@@ -617,10 +630,15 @@ function _parseEip4844(data: Uint8Array): TransactionLike {
617630

618631
blobs = [ ];
619632
for (let i = 0; i < fBlobs.length; i++) {
633+
const proof = [ ];
634+
for (let j = 0; j < cellCount; j++) {
635+
proof.push(fProofs[(i * cellCount) + j]);
636+
}
637+
620638
blobs.push({
621639
data: fBlobs[i],
622640
commitment: fCommits[i],
623-
proof: fProofs.slice(cellCount * i, cellCount * (i + 1))
641+
proof: concat(proof)
624642
});
625643
}
626644

@@ -643,7 +661,8 @@ function _parseEip4844(data: Uint8Array): TransactionLike {
643661
data: hexlify(fields[7]),
644662
accessList: handleAccessList(fields[8], "accessList"),
645663
maxFeePerBlobGas: handleUint(fields[9], "maxFeePerBlobGas"),
646-
blobVersionedHashes: fields[10]
664+
blobVersionedHashes: fields[10],
665+
blobWrapperVersion
647666
};
648667

649668
if (blobs) { tx.blobs = blobs; }
@@ -691,14 +710,18 @@ function _serializeEip4844(tx: Transaction, sig: null | Signature, blobs: null |
691710
if (blobs) {
692711

693712
// Use EIP-7594
694-
const useCells = (blobs.filter((b) => Array.isArray(b.proof)).length > 0);
695-
if (useCells) {
696-
const wrapperVersion = toBeArray(1);
713+
if (tx.blobWrapperVersion != null) {
714+
const wrapperVersion = toBeArray(tx.blobWrapperVersion);
715+
716+
// The number of cells per blob
717+
const cellCount = 128;
697718

698-
const cellProofs: any = [ ];
719+
const cellProofs: Array<Uint8Array> = [ ];
699720
for (const { proof } of blobs) {
700-
for (const cp of (proof || [])) {
701-
cellProofs.push(cp);
721+
const p = getBytes(proof);
722+
const cellSize = p.length / cellCount;
723+
for (let i = 0; i < p.length; i += cellSize) {
724+
cellProofs.push(p.subarray(i, i + cellSize));
702725
}
703726
}
704727

@@ -815,6 +838,7 @@ export class Transaction implements TransactionLike<string> {
815838
#kzg: null | KzgLibrary;
816839
#blobs: null | Array<Blob>;
817840
#auths: null | Array<Authorization>;
841+
#blobWrapperVersion: null | number;
818842

819843
/**
820844
* The transaction type.
@@ -1120,14 +1144,7 @@ export class Transaction implements TransactionLike<string> {
11201144
} else {
11211145
const data = hexlify(blob.data);
11221146
const commitment = hexlify(blob.commitment);
1123-
1124-
let proof: string | Array<string>;
1125-
if (Array.isArray(blob.proof)) {
1126-
proof = blob.proof.map(hexlify);
1127-
} else {
1128-
proof = hexlify(blob.proof);
1129-
}
1130-
1147+
const proof = hexlify(blob.proof);
11311148
blobs.push({ data, commitment, proof });
11321149

11331150
versionedHashes.push(getVersionedHash(1, commitment));
@@ -1147,6 +1164,13 @@ export class Transaction implements TransactionLike<string> {
11471164
}
11481165
}
11491166

1167+
get blobWrapperVersion(): null | number {
1168+
return this.#blobWrapperVersion;
1169+
}
1170+
set blobWrapperVersion(value: null | number) {
1171+
this.#blobWrapperVersion = value;
1172+
}
1173+
11501174
/**
11511175
* Creates a new Transaction with default values.
11521176
*/
@@ -1168,6 +1192,7 @@ export class Transaction implements TransactionLike<string> {
11681192
this.#kzg = null;
11691193
this.#blobs = null;
11701194
this.#auths = null;
1195+
this.#blobWrapperVersion = null;
11711196
}
11721197

11731198
/**
@@ -1498,6 +1523,7 @@ export class Transaction implements TransactionLike<string> {
14981523
// Make sure we assign the kzg before assigning blobs, which
14991524
// require the library in the event raw blob data is provided.
15001525
if (tx.kzg != null) { result.kzg = tx.kzg; }
1526+
if (tx.blobWrapperVersion != null) { result.blobWrapperVersion = tx.blobWrapperVersion; }
15011527
if (tx.blobs != null) { result.blobs = tx.blobs; }
15021528

15031529
if (tx.hash != null) {

0 commit comments

Comments
 (0)