Skip to content

Add *Proof functions to verkleFFI #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src.rs/src/verkle_ffi_api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ffi_interface::Context as InnerContext;
pub use ffi_interface::{CommitmentBytes, ScalarBytes, ZERO_POINT};
use ipa_multipoint::committer::Committer;
use js_sys::Uint8Array;
use js_sys::{Boolean, Uint8Array};
use wasm_bindgen::{prelude::wasm_bindgen, JsError, JsValue};

#[wasm_bindgen]
Expand Down Expand Up @@ -197,6 +197,31 @@ impl Context {

Ok(bytes_to_js_value(commitment).into())
}

/// Create a proof from a serialized array of tuples
#[wasm_bindgen(js_name = "createProof")]
pub fn create_proof(
&self,
input: Uint8Array,
) -> Result<Uint8Array, JsError>
{
let input_bytes = serde_wasm_bindgen::from_value(input.into()).unwrap();
let proof = ffi_interface::create_proof(&self.inner, input_bytes).map_err(|err| JsError::new(&format!("could not create proof: {:?}", err)))?;
return Ok(Uint8Array::from(&proof[..]));
}

/// Verify a proof created by `createProof`
#[wasm_bindgen(js_name = "verifyProof")]
pub fn verify_proof(
&self,
input: Uint8Array,
) -> Result<Boolean, JsError>
{
let input_bytes = serde_wasm_bindgen::from_value(input.into()).unwrap();
let result = ffi_interface::verify_proof(&self.inner, input_bytes).map(|_op |Boolean::from(true))
.map_err(|err| JsError::new(&format!("proof verification failed]: {:?}", err)));
return result
}
}

/// This is the default commitment to use when nothing has been committed to
Expand Down
8 changes: 7 additions & 1 deletion src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
updateCommitment as updateCommitmentBase,
zeroCommitment as zeroCommitmentBase,
verifyExecutionWitnessPreState as verifyExecutionWitnessPreStateBase,
createProof as createProofBase,
verifyProof as verifyProofBase,
} from './verkleFFIBindings/index.js'
import { Context as VerkleFFI } from './wasm/rust_verkle_wasm.js'

Expand Down Expand Up @@ -34,14 +36,18 @@ export const loadVerkleCrypto = async () => {

const hashCommitment = (commitment: Uint8Array) => verkleFFI.hashCommitment(commitment)
const serializeCommitment = (commitment: Uint8Array) => verkleFFI.serializeCommitment(commitment)
const createProof = (input: Uint8Array) => verkleFFI.createProof(input)
const verifyProof = (proofInput: Uint8Array) => verkleFFI.verifyProof(proofInput)
return {
getTreeKey,
getTreeKeyHash,
updateCommitment,
zeroCommitment,
verifyExecutionWitnessPreState,
hashCommitment,
serializeCommitment
serializeCommitment,
createProof,
verifyProof
}
}

Expand Down
6 changes: 4 additions & 2 deletions src.ts/verkleFFIBindings/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { initVerkleWasm, zeroCommitment, verifyExecutionWitnessPreState } from '../wasm/rust_verkle_wasm.js'

import { getTreeKey, getTreeKeyHash, updateCommitment } from './verkleFFI.js'
import { getTreeKey, getTreeKeyHash, updateCommitment, createProof, verifyProof } from './verkleFFI.js'

export {
initVerkleWasm,
getTreeKey,
getTreeKeyHash,
updateCommitment,
zeroCommitment,
verifyExecutionWitnessPreState
verifyExecutionWitnessPreState,
createProof,
verifyProof
}
8 changes: 8 additions & 0 deletions src.ts/verkleFFIBindings/verkleFFI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,11 @@ export function updateCommitment(
): Uint8Array {
return verkleFFI.updateCommitment(commitment, commitmentIndex, oldScalarValue, newScalarValue)
}

export function createProof(verkleFFI: VerkleFFI, bytes: Uint8Array): Uint8Array {
return verkleFFI.createProof(bytes)
}

export function verifyProof(verkleFFI: VerkleFFI, proof: Uint8Array): boolean {
return verkleFFI.verifyProof(proof)
}