Skip to content

Commit

Permalink
client: add proofs to blobsbundle
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed Apr 14, 2023
1 parent 158b750 commit 09f1111
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/client/lib/miner/pendingBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface BlobBundle {
blockHash: string
blobs: Uint8Array[]
kzgCommitments: Uint8Array[]
proofs: Uint8Array[]
}
/**
* In the future this class should build a pending block by keeping the
Expand Down Expand Up @@ -323,23 +324,27 @@ export class PendingBlock {
) => {
let blobs: Uint8Array[] = []
let kzgCommitments: Uint8Array[] = []
let proofs: Uint8Array[] = []
const bundle = this.blobBundles.get(payloadId)
if (bundle !== undefined) {
blobs = bundle.blobs
kzgCommitments = bundle.kzgCommitments
proofs = bundle.proofs
}

for (let tx of txs) {
tx = tx as BlobEIP4844Transaction
if (tx.blobs !== undefined && tx.blobs.length > 0) {
blobs = blobs.concat(tx.blobs)
kzgCommitments = kzgCommitments.concat(tx.kzgCommitments!)
proofs = proofs.concat(tx.kzgProofs!)
}
}
this.blobBundles.set(payloadId, {
blockHash: bytesToPrefixedHexString(blockHash),
blobs,
kzgCommitments,
proofs,
})
}
}
2 changes: 2 additions & 0 deletions packages/client/lib/rpc/modules/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ type BlobsBundleV1 = {
blockHash: string
kzgs: Bytes48[]
blobs: Blob[]
proofs: Bytes48[]
}

type ExecutionPayloadBodyV1 = {
Expand Down Expand Up @@ -1074,6 +1075,7 @@ export class Engine {
blockHash: bundle.blockHash,
kzgs: bundle.kzgCommitments.map(bytesToPrefixedHexString),
blobs: bundle.blobs.map(bytesToPrefixedHexString),
proofs: bundle.proofs.map(bytesToPrefixedHexString),
}
}

Expand Down
10 changes: 9 additions & 1 deletion packages/client/test/miner/pendingBlock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Account,
Address,
blobsToCommitments,
blobsToProofs,
bytesToHex,
bytesToPrefixedHexString,
commitmentsToVersionedHashes,
Expand Down Expand Up @@ -277,12 +278,14 @@ tape('[PendingBlock]', async (t) => {
const blobs = getBlobs('hello world')
const commitments = blobsToCommitments(blobs)
const versionedHashes = commitmentsToVersionedHashes(commitments)
const proofs = blobsToProofs(blobs, commitments)

const txA01 = BlobEIP4844Transaction.fromTxData(
{
versionedHashes,
blobs,
kzgCommitments: commitments,
kzgProofs: proofs,
maxFeePerDataGas: 100000000n,
gasLimit: 0xffffffn,
maxFeePerGas: 1000000000n,
Expand All @@ -298,8 +301,13 @@ tape('[PendingBlock]', async (t) => {
const parentBlock = await vm.blockchain.getCanonicalHeadBlock!()
const payloadId = await pendingBlock.start(vm, parentBlock)
await pendingBlock.build(payloadId)
const pendingBlob = pendingBlock.blobBundles.get(bytesToPrefixedHexString(payloadId))?.blobs[0]

const blobBundle = pendingBlock.blobBundles.get(bytesToPrefixedHexString(payloadId))!
st.ok(blobBundle !== undefined)
const pendingBlob = blobBundle.blobs[0]
st.ok(pendingBlob !== undefined && equalsBytes(pendingBlob, blobs[0]))
const blobProof = blobBundle.proofs[0]
st.ok(blobProof !== undefined && equalsBytes(blobProof, proofs[0]))
st.end()
})
t.test('should reset td', (st) => {
Expand Down

0 comments on commit 09f1111

Please sign in to comment.