Skip to content

Commit e8e2b00

Browse files
authored
Add hashCommitment to public API (#51)
* export hashCommitment * add basic test * update tests
1 parent 24d77a6 commit e8e2b00

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src.ts/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ export const loadVerkleCrypto = async (): Promise<VerkleCrypto> => {
3232

3333
const zeroCommitment = zeroCommitmentBase()
3434

35+
const hashCommitment = (commitment: Uint8Array) => verkleFFI.hashCommitment(commitment)
3536
return {
3637
getTreeKey,
3738
getTreeKeyHash,
3839
updateCommitment,
3940
zeroCommitment,
40-
verifyExecutionWitnessPreState
41+
verifyExecutionWitnessPreState,
42+
hashCommitment
4143
}
4244
}
4345

@@ -52,6 +54,7 @@ export interface VerkleCrypto {
5254
) => Commitment
5355
zeroCommitment: Uint8Array
5456
verifyExecutionWitnessPreState: (prestateRoot: string, execution_witness_json: string) => boolean
57+
hashCommitment: (commitment: Uint8Array) => Uint8Array
5558
}
5659

5760
// This is a 32 byte serialized field element

src.ts/tests/ffi.spec.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { bytesToHex, randomBytes } from '@ethereumjs/util'
2-
import { beforeAll, describe, expect, test } from 'vitest'
2+
import { beforeAll, describe, expect, test, assert } from 'vitest'
33

44
import { VerkleCrypto, loadVerkleCrypto } from '../index.js'
55
import { verifyExecutionWitnessPreState, Context as VerkleFFI } from '../wasm/rust_verkle_wasm.js'
@@ -181,6 +181,16 @@ describe('bindings', () => {
181181
const updatedCommitmentHex = bytesToHex(updatedCommitment)
182182

183183
expect(updatedCommitmentHex).toBe(expectedHex)
184+
185+
// Create a brand new commitment (i.e. an empty array) and update it
186+
const zeros = new Uint8Array(32)
187+
const zc = verkleCrypto.zeroCommitment
188+
const index = 0
189+
const value = Uint8Array.from(zeros)
190+
value[0] = 1
191+
const newCommitment = verkleCrypto.updateCommitment(zc, index, zeros, value)
192+
const expectedCommitment = ffi.scalarMulIndex(value, 0)
193+
assert.deepEqual(newCommitment, expectedCommitment)
184194
})
185195

186196
test('verifyExecutionProof: block with a few txs', () => {

0 commit comments

Comments
 (0)