[SPEC] Anchor integration into wasm-utils
Closed this issue · 0 comments
lazovicff commented
Anchor will have its own ProofInput
, Leaf
, and Proof
. It will also have its own generate_proof
function. This should be placed in src/wasm/anchor.rs
ProofInput:
struct ProofInput {
leaves: Vec<Vec<u8>>,
index: u64,
roots: Vec<Vec<u8>>,
recipient: Vec<u8>,
relayer: Vec<u8>,
commitment: Vec<u8>,
fee: u128,
refund: u128,
}
pub struct ProofInputBuilder {
leaves: Option<Vec<Vec<u8>>>,
index: Option<u64>,
roots: Option<Vec<Vec<u8>>>,
recipient: Option<Vec<u8>>,
relayer: Vec<u8>,
commitment: Vec<u8>,
fee: Option<u128>,
refund: Option<u128>,
}
For Proof:
#[wasm_bindgen]
pub struct Proof {
#[wasm_bindgen(skip)]
pub proof: String,
#[wasm_bindgen(skip)]
pub nullifier_hash: String,
#[wasm_bindgen(skip)]
pub roots: Vec<String>,
}
#[wasm_bindgen]
impl Proof {
#[wasm_bindgen(getter)]
pub fn proof(&self) -> JsString {
self.proof.clone().into()
}
#[wasm_bindgen(getter)]
pub fn nullifier_hash(&self) -> JsString {
self.nullifier_hash.clone().into()
}
#[wasm_bindgen(getter)]
pub fn roots(&self) -> Vec<JsString> {
self.roots.clone().into()
}
}
#[wasm_bindgen]
fn generate_proof_js(note: Note, proof_input: ProofInput) -> Proof {
// Get the values from note and proof_input and convert them to rust types
// Call generate_proof from arkworks gadgets repo which returns proof (Vec<u8u>), nullified (Vec<u8>), roots (Vec<Vec<u8>>)
}
For generating secrets:
pub fn generate_secrets(
prefix: Prefix,
exponentiation: i8,
width: usize,
curve: Curve,
rng: &mut OsRng,
) -> Result<Vec<u8>, OpStatusCode> {
let secrets: Vec<u8> = match (curve, exponentiation, width) {
...
(Prefix::Anchor, Curve::Bls381, 5, 4) => {
let (secret_bytes, nullifier_bytes, ..) = setup_anchor_leaf_x5_4::<BlsFr, _>(ArkworksCurve::Bls381, rng);
[secret_bytes, nullifier_bytes].concat()
}
(Prefix::Anchor, Curve::Bn254, 5, 4) => {
let (secret_bytes, nullifier_bytes, ..) = setup_anchor_leaf_x5_4::<Bn254Fr, _>(ArkworksCurve::Bn254, rng);
[secret_bytes, nullifier_bytes].concat()
}
...
};
Ok(secrets)
}