Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed Sep 19, 2024
1 parent 1656d15 commit 841e4bb
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions packages/verkle/test/proof.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { MapDB, concatBytes, hexToBytes } from '@ethereumjs/util'
import { MapDB, hexToBytes } from '@ethereumjs/util'
import { loadVerkleCrypto } from 'verkle-cryptography-wasm'
import { assert, beforeAll, describe, it } from 'vitest'

import { createVerkleTree } from '../src/constructors.js'

import type { LeafNode } from '../src/index.js'
import type { PrefixedHexString, VerkleCrypto } from '@ethereumjs/util'
import type { PrefixedHexString, ProverInput, VerifierInput, VerkleCrypto } from '@ethereumjs/util'

describe('lets make proofs', () => {
let verkleCrypto: VerkleCrypto
Expand Down Expand Up @@ -43,29 +43,27 @@ describe('lets make proofs', () => {
const path = await trie.findPath(keys[0].slice(0, 31))

const leafNode = path.node! as LeafNode
let valuesArray = new Uint8Array()
const valuesArray = []
for (let x = 0; x < 256; x++) {
let value = leafNode.getValue(x)
if (value === undefined) value = new Uint8Array(32)
valuesArray = concatBytes(valuesArray, value)
valuesArray.push(value)
}
const proofInput = concatBytes(
verkleCrypto.serializeCommitment(leafNode.commitment), // serialized (not hashed!) node commitment
valuesArray, // All values from node concatenated
new Uint8Array(1).fill(1), // Position in values array (aka "z value")
leafNode.getValue(1)!, // Value at position (aka "y value")
)
const proof = verkleCrypto.createProof(proofInput)
const proofInput: ProverInput = {
serializedCommitment: verkleCrypto.serializeCommitment(leafNode.commitment), // serialized (not hashed!) node commitment
vector: valuesArray, // All values from node
indices: [1], // Position in values array (aka "z value")
}

const proof = verkleCrypto.createProof([proofInput])

const verificationInput = concatBytes(
proof, // 576 byte proof
verkleCrypto.serializeCommitment(leafNode.commitment), // serialized leafNode commitment
new Uint8Array(1).fill(1), // Position in values array (aka "z value")
leafNode.getValue(1)!, // Value at position (aka "y value")
)
const verificationInput: VerifierInput = {
serializedCommitment: verkleCrypto.serializeCommitment(leafNode.commitment), // serialized leafNode commitment
indexValuePairs: [{ index: 1, value: leafNode.getValue(1)! }], // Position in values array (aka "z value")
}

try {
const res = verkleCrypto.verifyProof(verificationInput)
const res = verkleCrypto.verifyProof(proof, [verificationInput])
assert.ok(res)
} catch (err) {
assert.fail(`Failed to verify proof: ${err}`)
Expand Down

0 comments on commit 841e4bb

Please sign in to comment.