Skip to content

Commit 844aa06

Browse files
committed
ckzg for testing revert later
1 parent 07517ad commit 844aa06

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

packages/util/test/kzg.spec.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,68 @@ import { getBlobs } from '../src/blobs.ts'
88

99
import type { KZG } from '../src/kzg.ts'
1010

11+
import * as ckzg from 'c-kzg'
12+
import { bytesToHex, hexToBytes } from '../src/bytes.ts'
13+
1114
export const jsKZG = new microEthKZG(trustedSetup)
15+
const cKzg = {
16+
blobToKzgCommitment: (blob: string) => {
17+
const blobBytes = hexToBytes(blob)
18+
const commitmentBytes = ckzg.blobToKzgCommitment(blobBytes)
19+
return bytesToHex(commitmentBytes)
20+
},
21+
computeBlobProof: (blob: string, commitment: string) => {
22+
const blobBytes = hexToBytes(blob)
23+
const commitmentBytes = hexToBytes(commitment)
24+
const proofBytes = ckzg.computeBlobKzgProof(blobBytes, commitmentBytes)
25+
return bytesToHex(proofBytes)
26+
},
27+
verifyProof: (commitment: string, z: string, y: string, proof: string) => {
28+
const commitmentBytes = hexToBytes(commitment)
29+
const zBytes = hexToBytes(z)
30+
const yBytes = hexToBytes(y)
31+
const proofBytes = hexToBytes(proof)
32+
return ckzg.verifyKzgProof(commitmentBytes, zBytes, yBytes, proofBytes)
33+
},
34+
verifyBlobProofBatch: (blobs: string[], commitments: string[], proofs: string[]) => {
35+
const blobsBytes = blobs.map((blb) => hexToBytes(blb))
36+
const commitmentsBytes = commitments.map((cmt) => hexToBytes(cmt))
37+
const proofsBytes = proofs.map((prf) => hexToBytes(prf))
38+
return ckzg.verifyBlobKzgProofBatch(blobsBytes, commitmentsBytes, proofsBytes)
39+
},
40+
computeCells: (blob: string) => {
41+
const blobBytes = hexToBytes(blob)
42+
const cellsBytes = ckzg.computeCells(blobBytes)
43+
return cellsBytes.map((cellBytes) => bytesToHex(cellBytes))
44+
},
45+
computeCellsAndProofs: (blob: string) => {
46+
const blobBytes = hexToBytes(blob)
47+
const [cellsBytes, proofsBytes] = ckzg.computeCellsAndKzgProofs(blobBytes)
48+
return [
49+
cellsBytes.map((cellBytes) => bytesToHex(cellBytes)),
50+
proofsBytes.map((prfBytes) => bytesToHex(prfBytes)),
51+
] as [string[], string[]]
52+
},
53+
recoverCellsAndProofs: (indices: number[], cells: string[]) => {
54+
const cellsBytes = cells.map((cell) => hexToBytes(cell))
55+
const [allCellsBytes, allProofsBytes] = ckzg.recoverCellsAndKzgProofs(indices, cellsBytes)
56+
return [
57+
allCellsBytes.map((cellBytes) => bytesToHex(cellBytes)),
58+
allProofsBytes.map((prfBytes) => bytesToHex(prfBytes)),
59+
] as [string[], string[]]
60+
},
61+
verifyCellKzgProofBatch: (
62+
commitments: string[],
63+
indices: number[],
64+
cells: string[],
65+
proofs: string[],
66+
) => {
67+
const commitmentsBytes = commitments.map((commit) => hexToBytes(commit))
68+
const cellsBytes = cells.map((cell) => hexToBytes(cell))
69+
const proofsBytes = proofs.map((prf) => hexToBytes(prf))
70+
return ckzg.verifyCellKzgProofBatch(commitmentsBytes, indices, cellsBytes, proofsBytes)
71+
},
72+
}
1273

1374
describe('KZG API tests', () => {
1475
let wasm: Awaited<ReturnType<typeof loadKZG>>
@@ -43,6 +104,9 @@ describe('KZG API tests', () => {
43104
const commit = wasmKZG.blobToKzgCommitment(blob)
44105
const proof = wasmKZG.computeBlobProof(blob, commit)
45106

107+
console.log(jsKZG.blobToKzgCommitment(blob).toLowerCase())
108+
console.log(cKzg.blobToKzgCommitment(blob).toLowerCase())
109+
46110
assert.equal(
47111
wasmKZG.blobToKzgCommitment(blob).toLowerCase(),
48112
jsKZG.blobToKzgCommitment(blob).toLowerCase(),

0 commit comments

Comments
 (0)