|
1 |
| -import { MapDB, concatBytes, hexToBytes } from '@ethereumjs/util' |
| 1 | +import { MapDB, hexToBytes } from '@ethereumjs/util' |
2 | 2 | import { loadVerkleCrypto } from 'verkle-cryptography-wasm'
|
3 | 3 | import { assert, beforeAll, describe, it } from 'vitest'
|
4 | 4 |
|
5 | 5 | import { createVerkleTree } from '../src/constructors.js'
|
6 | 6 |
|
7 | 7 | import type { LeafNode } from '../src/index.js'
|
8 |
| -import type { PrefixedHexString, VerkleCrypto } from '@ethereumjs/util' |
| 8 | +import type { PrefixedHexString, ProverInput, VerifierInput, VerkleCrypto } from '@ethereumjs/util' |
9 | 9 |
|
10 | 10 | describe('lets make proofs', () => {
|
11 | 11 | let verkleCrypto: VerkleCrypto
|
@@ -43,29 +43,27 @@ describe('lets make proofs', () => {
|
43 | 43 | const path = await trie.findPath(keys[0].slice(0, 31))
|
44 | 44 |
|
45 | 45 | const leafNode = path.node! as LeafNode
|
46 |
| - let valuesArray = new Uint8Array() |
| 46 | + const valuesArray = [] |
47 | 47 | for (let x = 0; x < 256; x++) {
|
48 | 48 | let value = leafNode.getValue(x)
|
49 | 49 | if (value === undefined) value = new Uint8Array(32)
|
50 |
| - valuesArray = concatBytes(valuesArray, value) |
| 50 | + valuesArray.push(value) |
51 | 51 | }
|
52 |
| - const proofInput = concatBytes( |
53 |
| - verkleCrypto.serializeCommitment(leafNode.commitment), // serialized (not hashed!) node commitment |
54 |
| - valuesArray, // All values from node concatenated |
55 |
| - new Uint8Array(1).fill(1), // Position in values array (aka "z value") |
56 |
| - leafNode.getValue(1)!, // Value at position (aka "y value") |
57 |
| - ) |
58 |
| - const proof = verkleCrypto.createProof(proofInput) |
| 52 | + const proofInput: ProverInput = { |
| 53 | + serializedCommitment: verkleCrypto.serializeCommitment(leafNode.commitment), // serialized (not hashed!) node commitment |
| 54 | + vector: valuesArray, // All values from node |
| 55 | + indices: [1], // Position in values array (aka "z value") |
| 56 | + } |
| 57 | + |
| 58 | + const proof = verkleCrypto.createProof([proofInput]) |
59 | 59 |
|
60 |
| - const verificationInput = concatBytes( |
61 |
| - proof, // 576 byte proof |
62 |
| - verkleCrypto.serializeCommitment(leafNode.commitment), // serialized leafNode commitment |
63 |
| - new Uint8Array(1).fill(1), // Position in values array (aka "z value") |
64 |
| - leafNode.getValue(1)!, // Value at position (aka "y value") |
65 |
| - ) |
| 60 | + const verificationInput: VerifierInput = { |
| 61 | + serializedCommitment: verkleCrypto.serializeCommitment(leafNode.commitment), // serialized leafNode commitment |
| 62 | + indexValuePairs: [{ index: 1, value: leafNode.getValue(1)! }], // Position in values array (aka "z value") |
| 63 | + } |
66 | 64 |
|
67 | 65 | try {
|
68 |
| - const res = verkleCrypto.verifyProof(verificationInput) |
| 66 | + const res = verkleCrypto.verifyProof(proof, [verificationInput]) |
69 | 67 | assert.ok(res)
|
70 | 68 | } catch (err) {
|
71 | 69 | assert.fail(`Failed to verify proof: ${err}`)
|
|
0 commit comments