Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: add proofs to blobsbundle #2642

Merged
merged 1 commit into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]))
Copy link
Contributor Author

@g11tech g11tech Apr 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@holgerd77 this checks if the bundle has the proof and valdiates it as well,

Also getBlobsBundle api is being removed (discussed in yesterdays 4844 call) and the bundle and payload is going to be included in a new getPayloadV3, so will make sure spec test for that will cover proof check in the bundle

st.end()
})
t.test('should reset td', (st) => {
Expand Down