-
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.
Merge branch 'master' into debug-namespace-standardization
- Loading branch information
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