-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat(RLN): add new_with_params
#36
Conversation
Allows passing the wasm, zkey and verification key data as buffers, instead of using a path to a folder
53092c2
to
9471c90
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thank you! Left some comments about adding a test and renaming old procs.
rln/src/circuit.rs
Outdated
#[allow(non_snake_case)] | ||
pub fn ZKEY(zkey_data: &Vec<u8>) -> Result<(ProvingKey<Curve>, ConstraintMatrices<Fr>)> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can call this something like zkey_from_raw
to differentiate it from zkey_from_folder
and same for VK, CIRCOM
? At that point we might remove all capitalizations in proc names and the #[allow(non_snake_case)]
too.
@@ -47,6 +47,23 @@ pub extern "C" fn new(tree_height: usize, input_buffer: *const Buffer, ctx: *mut | |||
true | |||
} | |||
|
|||
#[allow(clippy::not_unsafe_ptr_arg_deref)] | |||
#[no_mangle] | |||
pub extern "C" fn new_with_params( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will be great if we can add a test, e.g. load params with File
and create a new RLN object and maybe compare with an RLN object created with new
(doing it directly would probably require implementation of Eq/PartialEq for RLN, but you can compare e.g. tree roots and you can try to create/verify a proof for a random witness
Lines 557 to 585 in 9471c90
let rln_witness = random_rln_witness(tree_height); | |
let proof_values = proof_values_from_witness(&rln_witness); | |
// We prepare id_commitment and we set the leaf at provided index | |
let rln_witness_ser = serialize_witness(&rln_witness); | |
let input_buffer = &Buffer::from(rln_witness_ser.as_ref()); | |
let mut output_buffer = MaybeUninit::<Buffer>::uninit(); | |
let now = Instant::now(); | |
let success = prove(rln_pointer, input_buffer, output_buffer.as_mut_ptr()); | |
prove_time += now.elapsed().as_nanos(); | |
assert!(success, "prove call failed"); | |
let output_buffer = unsafe { output_buffer.assume_init() }; | |
// We read the returned proof and we append proof values for verify | |
let serialized_proof = <&[u8]>::from(&output_buffer).to_vec(); | |
let serialized_proof_values = serialize_proof_values(&proof_values); | |
let mut verify_data = Vec::<u8>::new(); | |
verify_data.extend(&serialized_proof); | |
verify_data.extend(&serialized_proof_values); | |
// We prepare input proof values and we call verify | |
let input_buffer = &Buffer::from(verify_data.as_ref()); | |
let mut proof_is_valid: bool = false; | |
let proof_is_valid_ptr = &mut proof_is_valid as *mut bool; | |
let now = Instant::now(); | |
let success = verify(rln_pointer, input_buffer, proof_is_valid_ptr); | |
verify_time += now.elapsed().as_nanos(); | |
assert!(success, "verify call failed"); | |
assert_eq!(proof_is_valid, true); |
FYI (not for this PR) you can actually check if they generate the same proofs by passing the same inputs and same r,s randomness here
Lines 443 to 444 in 9471c90
r, | |
s, |
Allows passing the wasm, zkey and verification key data as buffers, instead of using a path to a folder
* refactor(rln): removing unused crates/dependencies * cargo fmt * refactor(rln): removed more dependencies; curve/fields as parameters * refactor(rln): use poseidon-rs hash instead of semaphore-rs poseidon * chore(rln): remove deps * refactor(rln): use exclusively arkworks Fr * refactor(rln): integrate poseidon-rs implementation to work with arkworks arithmetic * fix(rln): remove previous poseidon-rs wrapper * feat(rln): add features to select MT; remove prints if not in debug mode * fix(rln): collect test parameters in a vector * feat(RLN): add `new_with_params` (#36) Allows passing the wasm, zkey and verification key data as buffers, instead of using a path to a folder * chore(rln): simplify read wasm * fix(rln): remove unused dependencies * cargo fmt * fix(rln): update dependencies, fix commit * refactor(rln): restore ark-circom original dep Co-authored-by: Richard Ramos <info@richardramos.me>
Allows passing the wasm, zkey and verification key data as buffers, instead of using a path to a folder.
This is useful when you want to have this data embedded in a program / library, to not deal with paths to the resource folders
Required by: