-
Notifications
You must be signed in to change notification settings - Fork 759
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* scaffolding * broken WIP * partial implementations * fix getAccount * add todo * make trie.get accept suffixes * clean up reference * Add reserved bytes to encodeBasicData function * FIx encoding again * spelling [no ci] * change param to account [no ci] * Add support for basic account delete * implement chunkify code * Add putCode * Move code to helpers * getCode and getCodeSize * Start work on tests * Update magic numbers to constants * Make get/putCode work * Fix various get/putCode bugs * add get/putstorage * export SFVKSM [no ci] * add commit/flush/revert * Tests for caching * make cspell happy * lint * add back missing method from interface * Update packages/util/test/verkle.spec.ts * Apply suggestions from code review * address some feedback * Update types and add test * FIx commitment format * Update verkle crypto and add proof test * add max chunks constant * delete account in put if no account * spelling * fix basic data encoding offsets * remove console log * Fix suffix logic * wasm update * update interface * update package lock * update verkle crypto wasm again * console logs * maybe another fix * various fixes * update tests * Remove obsolete proof helpers * add second test * add explanatory comment for leaf marker * Add safeguards to leafnode.create * use correct randomBytes --------- Co-authored-by: Gabriel Rocheleau <[email protected]>
- Loading branch information
1 parent
3a7e07f
commit 15f8ff2
Showing
6 changed files
with
158 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { MapDB, bytesToHex } from '@ethereumjs/util' | ||
import { loadVerkleCrypto } from 'verkle-cryptography-wasm' | ||
import { assert, beforeAll, describe, it } from 'vitest' | ||
|
||
import { createVerkleTree } from '../src/constructors.js' | ||
|
||
describe('rust-verkle test vectors', () => { | ||
let verkleCrypto: Awaited<ReturnType<typeof loadVerkleCrypto>> | ||
beforeAll(async () => { | ||
verkleCrypto = await loadVerkleCrypto() | ||
}) | ||
it('should produce the correct commitment', async () => { | ||
// Test from python implementation | ||
//https://github.com/crate-crypto/verkle-trie-ref/blob/483f40c737f27bc8f059870f862cf6c244159cd4/verkle/verkle_test.py#L63 | ||
// It inserts a single value and then verifies that the hash of the root node matches (not the `trie.root` which is a serialized commitment and not the hash) | ||
const key = Uint8Array.from([ | ||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, | ||
27, 28, 29, 30, 31, 32, | ||
]) | ||
const trie = await createVerkleTree({ verkleCrypto, db: new MapDB() }) | ||
await trie.put(key.slice(0, 31), [key[31]], [key]) | ||
|
||
const path = await trie.findPath(key.slice(0, 31)) | ||
|
||
assert.equal( | ||
bytesToHex(path.stack[0][0].hash()), | ||
'0x029b6c4c8af9001f0ac76472766c6579f41eec84a73898da06eb97ebdab80a09', | ||
) | ||
assert.equal( | ||
bytesToHex(trie.root()), | ||
'0x6f5e7cfc3a158a64e5718b0d2f18f564171342380f5808f3d2a82f7e7f3c2778', | ||
) | ||
}) | ||
it('should produce correct commitments after value updates', async () => { | ||
// Variant of previous test that puts 0s at a specific key and then updates that value | ||
// https://github.com/crate-crypto/verkle-trie-ref/blob/483f40c737f27bc8f059870f862cf6c244159cd4/verkle/verkle_test.py#L96 | ||
const key = Uint8Array.from([ | ||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, | ||
27, 28, 29, 30, 31, 32, | ||
]) | ||
const stem = key.slice(0, 31) | ||
const trie = await createVerkleTree({ verkleCrypto, db: new MapDB() }) | ||
await trie.put(stem, [key[31]], [new Uint8Array(32)]) | ||
let path = await trie.findPath(stem) | ||
assert.equal( | ||
bytesToHex(path.stack[0][0].hash()), | ||
'0x77a0747bd526d9d9af60bd5665d24d6cb421f5c8e726b1de62f914f3ff9a361c', | ||
) | ||
await trie.put(stem, [key[31]], [key]) | ||
path = await trie.findPath(key.slice(0, 31)) | ||
|
||
assert.equal( | ||
bytesToHex(path.stack[0][0].hash()), | ||
'0x029b6c4c8af9001f0ac76472766c6579f41eec84a73898da06eb97ebdab80a09', | ||
) | ||
assert.equal( | ||
bytesToHex(trie.root()), | ||
'0x6f5e7cfc3a158a64e5718b0d2f18f564171342380f5808f3d2a82f7e7f3c2778', | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters