Skip to content

Commit

Permalink
Pin vitest deps (#3688)
Browse files Browse the repository at this point in the history
* update interface

* update verkle crypto dep

* fix types
  • Loading branch information
acolytec3 authored Sep 19, 2024
1 parent 4aa4cef commit 75ce1ca
Show file tree
Hide file tree
Showing 7 changed files with 852 additions and 431 deletions.
1,223 changes: 818 additions & 405 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"@types/tape": "4.13.2",
"@typescript-eslint/eslint-plugin": "5.33.1",
"@typescript-eslint/parser": "5.33.1",
"@vitest/coverage-v8": "^2.1.0",
"@vitest/ui": "^2.1.0",
"@vitest/coverage-v8": "2.1.0",
"@vitest/ui": "2.1.0",
"c8": "7.12.0",
"cspell": "^8.13.3",
"embedme": "1.22.1",
Expand All @@ -62,7 +62,7 @@
"vite-plugin-node-polyfills": "^0.21.0",
"vite-plugin-top-level-await": "^1.4.1",
"vite-plugin-wasm": "^3.3.0",
"vitest": "^2.1.0"
"vitest": "2.1.0"
},
"optionalDependencies": {
"@rollup/rollup-linux-x64-gnu": "*"
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"memory-level": "^1.0.0",
"prom-client": "^15.1.0",
"rustbn-wasm": "^0.4.0",
"verkle-cryptography-wasm": "^0.4.6",
"verkle-cryptography-wasm": "^0.4.8",
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.5",
"yargs": "^17.7.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/statemanager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@
"@ethereumjs/genesis": "^0.2.3",
"@types/debug": "^4.1.9",
"rustbn-wasm": "^0.4.0",
"verkle-cryptography-wasm": "^0.4.6"
"verkle-cryptography-wasm": "^0.4.8"
}
}
14 changes: 12 additions & 2 deletions packages/util/src/verkle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,20 @@ export interface VerkleCrypto {
verifyExecutionWitnessPreState: (prestateRoot: string, execution_witness_json: string) => boolean
hashCommitment: (commitment: Uint8Array) => Uint8Array
serializeCommitment: (commitment: Uint8Array) => Uint8Array
createProof: (bytes: Uint8Array) => Uint8Array
verifyProof: (proof: Uint8Array) => boolean
createProof: (bytes: ProverInput[]) => Uint8Array
verifyProof: (proof: Uint8Array, verifierInput: VerifierInput[]) => boolean
}

export interface ProverInput {
serializedCommitment: Uint8Array // serialized node commitment we want a proof from i.e. verkleCrypto.serializeCommitment(commitment)
vector: Uint8Array[] // Array of 256 children/values
indices: number[] // Indices from the valuesArray we are proving existence of
}

export interface VerifierInput {
serializedCommitment: Uint8Array // serialized node commitment we want a proof from i.e. verkleCrypto.serializeCommitment(commitment)
indexValuePairs: Array<{ index: number; value: Uint8Array }> // array of tuples of indices and values from node's children array being verified by proof
}
/**
* @dev Returns the 31-bytes verkle tree stem for a given address and tree index.
* @dev Assumes that the verkle node width = 256
Expand Down
2 changes: 1 addition & 1 deletion packages/verkle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"dependencies": {
"debug": "^4.3.4",
"lru-cache": "10.1.0",
"verkle-cryptography-wasm": "^0.4.6",
"verkle-cryptography-wasm": "^0.4.8",
"@ethereumjs/block": "^5.3.0",
"@ethereumjs/rlp": "^5.0.2",
"@ethereumjs/util": "^9.1.0"
Expand Down
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 75ce1ca

Please sign in to comment.