From 358535afc6e6671c9887cc9cf812aab31333464d Mon Sep 17 00:00:00 2001 From: lovesh Date: Mon, 24 Jun 2024 17:25:26 +0530 Subject: [PATCH] Fix test and fmt Signed-off-by: lovesh --- src/accumulator/common.rs | 9 ++- src/keyed_proof.rs | 84 ++++++++++++++++++++----- src/threshold_sig/signing.rs | 7 ++- tests/js/thresholdBbsPlusAndBbs.spec.ts | 9 ++- 4 files changed, 85 insertions(+), 24 deletions(-) diff --git a/src/accumulator/common.rs b/src/accumulator/common.rs index 6e26074..ee43c09 100644 --- a/src/accumulator/common.rs +++ b/src/accumulator/common.rs @@ -1,4 +1,7 @@ -use crate::{utils::{fr_to_jsvalue, random_bytes, set_panic_hook}, Fr, G1Affine}; +use crate::{ + utils::{fr_to_jsvalue, random_bytes, set_panic_hook}, + Fr, G1Affine, +}; use ark_bls12_381::Bls12_381; use ark_serialize::CanonicalDeserialize; use blake2::Blake2b512; @@ -27,7 +30,9 @@ pub fn generate_accumulator_params(label: Option>) -> Result>) -> Result { +pub fn generate_accumulator_params_for_keyed_verification( + label: Option>, +) -> Result { set_panic_hook(); let label = label.unwrap_or_else(random_bytes); let params = AccumSetupParamsKV::new::(&label); diff --git a/src/keyed_proof.rs b/src/keyed_proof.rs index 48a10ef..58f161c 100644 --- a/src/keyed_proof.rs +++ b/src/keyed_proof.rs @@ -1,5 +1,5 @@ use crate::{ - accumulator::common::AccumSk, + accumulator::common::{AccumPkKV, AccumSetupParamsKV, AccumSk}, bddt16_kvac::{BDDT16MACParams, BDDT16MACPublicKeyG1, BDDT16MACSecretKey}, common::VerifyResponse, composite_proof_system::Proof, @@ -16,18 +16,20 @@ use kvac::bddt_2016::keyed_proof::{ use proof_system::prelude::StatementProof; use vb_accumulator::{ kb_universal_accumulator::proofs_keyed_verification::{ - KBUniversalAccumulatorKeyedMembershipProof as KBUniMemKp, KBUniversalAccumulatorProofOfValidityOfKeyedMembershipProof as KBUniMemPvkp, + KBUniversalAccumulatorKeyedMembershipProof as KBUniMemKp, + KBUniversalAccumulatorKeyedNonMembershipProof as KBUniNonMemKp, KBUniversalAccumulatorProofOfInvalidityOfKeyedMembershipProof as KBUniMemPivkp, - KBUniversalAccumulatorKeyedNonMembershipProof as KBUniNonMemKp, KBUniversalAccumulatorProofOfValidityOfKeyedNonMembershipProof as KBUniNonMemPvkp, - KBUniversalAccumulatorProofOfInvalidityOfKeyedNonMembershipProof as KBUniNonMemPivkp + KBUniversalAccumulatorProofOfInvalidityOfKeyedNonMembershipProof as KBUniNonMemPivkp, + KBUniversalAccumulatorProofOfValidityOfKeyedMembershipProof as KBUniMemPvkp, + KBUniversalAccumulatorProofOfValidityOfKeyedNonMembershipProof as KBUniNonMemPvkp, }, proofs_keyed_verification::{ - KeyedMembershipProof as VBMemKp, ProofOfValidityOfKeyedMembershipProof as VbMemPvkp, ProofOfInvalidityOfKeyedMembershipProof as VbMemPivkp + KeyedMembershipProof as VBMemKp, ProofOfInvalidityOfKeyedMembershipProof as VbMemPivkp, + ProofOfValidityOfKeyedMembershipProof as VbMemPvkp, }, }; use wasm_bindgen::{prelude::wasm_bindgen, JsValue}; use zeroize::Zeroize; -use crate::accumulator::common::{AccumPkKV, AccumSetupParamsKV}; #[wasm_bindgen(js_name = getAllKeyedSubproofsFromProof)] pub fn get_all_keyed_subproofs_from_proof(proof: Uint8Array) -> Result { @@ -233,7 +235,12 @@ pub fn verify_proof_of_validity_of_vb_accum_membership_keyed_proof( false, "ProofOfValidityOfVBAccumMembershipKeyedProof" ); - let keyed_proof = obj_from_uint8array!(VBMemKp, keyed_proof, false, "VBMembershipKeyedProof"); + let keyed_proof = obj_from_uint8array!( + VBMemKp, + keyed_proof, + false, + "VBMembershipKeyedProof" + ); let pk = obj_from_uint8array!(AccumPkKV, public_key, false, "VBAccumulatorPkG1"); let params = obj_from_uint8array!(AccumSetupParamsKV, params, false); to_verify_response!(proof_of_validity.verify::(&keyed_proof, &pk, ¶ms)) @@ -276,7 +283,12 @@ pub fn verify_proof_of_invalidity_of_vb_accum_membership_keyed_proof( false, "ProofOfInvalidityOfVBAccumMembershipKeyedProof" ); - let keyed_proof = obj_from_uint8array!(VBMemKp, keyed_proof, false, "VBMembershipKeyedProof"); + let keyed_proof = obj_from_uint8array!( + VBMemKp, + keyed_proof, + false, + "VBMembershipKeyedProof" + ); let pk = obj_from_uint8array!(AccumPkKV, public_key, false, "VBAccumulatorPkG1"); let params = obj_from_uint8array!(AccumSetupParamsKV, params, false); to_verify_response!(proof_of_invalidity.verify::(&keyed_proof, &pk, ¶ms)) @@ -306,7 +318,12 @@ pub fn proof_of_validity_of_kb_uni_accum_membership_keyed_proof( params: Uint8Array, ) -> Result { set_panic_hook(); - let proof = obj_from_uint8array!(KBUniMemKp, proof, false, "KBUniMembershipKeyedProof"); + let proof = obj_from_uint8array!( + KBUniMemKp, + proof, + false, + "KBUniMembershipKeyedProof" + ); let sk = obj_from_uint8array!(AccumSk, secret_key, true, "VBAccumulatorSk"); let pk = obj_from_uint8array!(AccumPkKV, public_key, false, "VBAccumulatorPkG1"); let params = obj_from_uint8array!(AccumSetupParamsKV, params, false); @@ -333,7 +350,12 @@ pub fn verify_proof_of_validity_of_kb_uni_accum_membership_keyed_proof( false, "ProofOfValidityOfKBUniAccumMembershipKeyedProof" ); - let keyed_proof = obj_from_uint8array!(KBUniMemKp, keyed_proof, false, "KBUniMembershipKeyedProof"); + let keyed_proof = obj_from_uint8array!( + KBUniMemKp, + keyed_proof, + false, + "KBUniMembershipKeyedProof" + ); let pk = obj_from_uint8array!(AccumPkKV, public_key, false, "VBAccumulatorPkG1"); let params = obj_from_uint8array!(AccumSetupParamsKV, params, false); to_verify_response!(proof_of_validity.verify::(&keyed_proof, &pk, ¶ms)) @@ -347,7 +369,12 @@ pub fn proof_of_invalidity_of_kb_uni_accum_membership_keyed_proof( params: Uint8Array, ) -> Result { set_panic_hook(); - let proof = obj_from_uint8array!(KBUniMemKp, proof, false, "KBUniMembershipKeyedProof"); + let proof = obj_from_uint8array!( + KBUniMemKp, + proof, + false, + "KBUniMembershipKeyedProof" + ); let sk = obj_from_uint8array!(AccumSk, secret_key, true, "VBAccumulatorSk"); let pk = obj_from_uint8array!(AccumPkKV, public_key, false, "VBAccumulatorPkG1"); let params = obj_from_uint8array!(AccumSetupParamsKV, params, false); @@ -376,7 +403,12 @@ pub fn verify_proof_of_invalidity_of_kb_uni_accum_membership_keyed_proof( false, "ProofOfInvalidityOfKBUniAccumMembershipKeyedProof" ); - let keyed_proof = obj_from_uint8array!(KBUniMemKp, keyed_proof, false, "KBUniMembershipKeyedProof"); + let keyed_proof = obj_from_uint8array!( + KBUniMemKp, + keyed_proof, + false, + "KBUniMembershipKeyedProof" + ); let pk = obj_from_uint8array!(AccumPkKV, public_key, false, "VBAccumulatorPkG1"); let params = obj_from_uint8array!(AccumSetupParamsKV, params, false); to_verify_response!(proof_of_invalidity.verify::(&keyed_proof, &pk, ¶ms)) @@ -406,7 +438,12 @@ pub fn proof_of_validity_of_kb_uni_accum_non_membership_keyed_proof( params: Uint8Array, ) -> Result { set_panic_hook(); - let proof = obj_from_uint8array!(KBUniNonMemKp, proof, false, "KBUniNonMembershipKeyedProof"); + let proof = obj_from_uint8array!( + KBUniNonMemKp, + proof, + false, + "KBUniNonMembershipKeyedProof" + ); let sk = obj_from_uint8array!(AccumSk, secret_key, true, "VBAccumulatorSk"); let pk = obj_from_uint8array!(AccumPkKV, public_key, false, "VBAccumulatorPkG1"); let params = obj_from_uint8array!(AccumSetupParamsKV, params, false); @@ -433,7 +470,12 @@ pub fn verify_proof_of_validity_of_kb_uni_accum_non_membership_keyed_proof( false, "ProofOfValidityOfKBUniAccumNonMembershipKeyedProof" ); - let keyed_proof = obj_from_uint8array!(KBUniNonMemKp, keyed_proof, false, "KBUniNonMembershipKeyedProof"); + let keyed_proof = obj_from_uint8array!( + KBUniNonMemKp, + keyed_proof, + false, + "KBUniNonMembershipKeyedProof" + ); let pk = obj_from_uint8array!(AccumPkKV, public_key, false, "VBAccumulatorPkG1"); let params = obj_from_uint8array!(AccumSetupParamsKV, params, false); to_verify_response!(proof_of_validity.verify::(&keyed_proof, &pk, ¶ms)) @@ -447,7 +489,12 @@ pub fn proof_of_invalidity_of_kb_uni_accum_non_membership_keyed_proof( params: Uint8Array, ) -> Result { set_panic_hook(); - let proof = obj_from_uint8array!(KBUniNonMemKp, proof, false, "KBUniNonMembershipKeyedProof"); + let proof = obj_from_uint8array!( + KBUniNonMemKp, + proof, + false, + "KBUniNonMembershipKeyedProof" + ); let sk = obj_from_uint8array!(AccumSk, secret_key, true, "VBAccumulatorSk"); let pk = obj_from_uint8array!(AccumPkKV, public_key, false, "VBAccumulatorPkG1"); let params = obj_from_uint8array!(AccumSetupParamsKV, params, false); @@ -476,7 +523,12 @@ pub fn verify_proof_of_invalidity_of_kb_uni_accum_non_membership_keyed_proof( false, "ProofOfInvalidityOfKBUniAccumNonMembershipKeyedProof" ); - let keyed_proof = obj_from_uint8array!(KBUniNonMemKp, keyed_proof, false, "KBUniNonMembershipKeyedProof"); + let keyed_proof = obj_from_uint8array!( + KBUniNonMemKp, + keyed_proof, + false, + "KBUniNonMembershipKeyedProof" + ); let pk = obj_from_uint8array!(AccumPkKV, public_key, false, "VBAccumulatorPkG1"); let params = obj_from_uint8array!(AccumSetupParamsKV, params, false); to_verify_response!(proof_of_invalidity.verify::(&keyed_proof, &pk, ¶ms)) diff --git a/src/threshold_sig/signing.rs b/src/threshold_sig/signing.rs index f1cd48f..d75d7ab 100644 --- a/src/threshold_sig/signing.rs +++ b/src/threshold_sig/signing.rs @@ -3,8 +3,8 @@ use crate::{ bbs_plus::BBSPlusSigParamsG1, threshold_sig::{KAPPA, SALT_SIZE, STATISTICAL_SECURITY_PARAMETER}, utils::{ - encode_messages_as_js_array_to_fr_vec_in_constant_time, fr_from_uint8_array, get_seeded_rng, - js_array_to_iter, js_set_to_btree_set, set_panic_hook, + encode_messages_as_js_array_to_fr_vec_in_constant_time, fr_from_uint8_array, + get_seeded_rng, js_array_to_iter, js_set_to_btree_set, set_panic_hook, }, Fr, }; @@ -109,7 +109,8 @@ macro_rules! create_signature_share { ($messages: ident, $index_in_output: ident, $phase1_output: ident, $phase2_output: ident, $params: ident, $encode_messages: ident, $params_type: ident, $phase1_output_type: ident, $share_type: ident, $sig_name: expr) => {{ set_panic_hook(); let params: $params_type = serde_wasm_bindgen::from_value($params)?; - let messages = encode_messages_as_js_array_to_fr_vec_in_constant_time(&$messages, $encode_messages)?; + let messages = + encode_messages_as_js_array_to_fr_vec_in_constant_time(&$messages, $encode_messages)?; let phase1_output = obj_from_uint8array!($phase1_output_type, $phase1_output, true); let phase2_output = obj_from_uint8array!(Phase2Output, $phase2_output, true); let share = $share_type::new( diff --git a/tests/js/thresholdBbsPlusAndBbs.spec.ts b/tests/js/thresholdBbsPlusAndBbs.spec.ts index e292189..d4d6004 100644 --- a/tests/js/thresholdBbsPlusAndBbs.spec.ts +++ b/tests/js/thresholdBbsPlusAndBbs.spec.ts @@ -48,7 +48,10 @@ import { thresholdBbsPhase2ReceiveMessage1, thresholdBbsPhase2ReceiveMessage2, thresholdBbsPhase2Finish, - thresholdBbsCreateSignatureShare, thresholdBbsAggregateSignatureShares + thresholdBbsCreateSignatureShare, + thresholdBbsAggregateSignatureShares, + bbsPlusVerifyG1ConstantTime, + bbsVerifyConstantTime } from "../../lib"; import {doFrostDKG, stringToBytes} from "./util"; @@ -257,11 +260,11 @@ describe("For threshold BBS+ and BBS", () => { it("create a threshold BBS+ signature", () => { const protocolId = stringToBytes("test BBS+"); - checkThresholdSig(protocolId, paramsBbsPlus, thresholdPubkeyBbsPlus, secretKeysBbsPlus, thresholdBbsPlusStartPhase1, thresholdBbsPlusPhase1ProcessCommitments, thresholdBbsPlusPhase1GetSharesForOther, thresholdBbsPlusPhase1ProcessShares, thresholdBbsPlusPhase1Finish, thresholdBbsPlusPhase2Start, thresholdBbsPlusPhase2ReceiveMessage1, thresholdBbsPlusPhase2ReceiveMessage2, thresholdBbsPlusPhase2Finish, thresholdBbsPlusCreateSignatureShare, thresholdBbsPlusAggregateSignatureShares, bbsPlusVerifyG1) + checkThresholdSig(protocolId, paramsBbsPlus, thresholdPubkeyBbsPlus, secretKeysBbsPlus, thresholdBbsPlusStartPhase1, thresholdBbsPlusPhase1ProcessCommitments, thresholdBbsPlusPhase1GetSharesForOther, thresholdBbsPlusPhase1ProcessShares, thresholdBbsPlusPhase1Finish, thresholdBbsPlusPhase2Start, thresholdBbsPlusPhase2ReceiveMessage1, thresholdBbsPlusPhase2ReceiveMessage2, thresholdBbsPlusPhase2Finish, thresholdBbsPlusCreateSignatureShare, thresholdBbsPlusAggregateSignatureShares, bbsPlusVerifyG1ConstantTime) }) it("create a threshold BBS signature", () => { const protocolId = stringToBytes("test BBS"); - checkThresholdSig(protocolId, paramsBbs, thresholdPubkeyBbs, secretKeysBbs, thresholdBbsStartPhase1, thresholdBbsPhase1ProcessCommitments, thresholdBbsPhase1GetSharesForOther, thresholdBbsPhase1ProcessShares, thresholdBbsPhase1Finish, thresholdBbsPhase2Start, thresholdBbsPhase2ReceiveMessage1, thresholdBbsPhase2ReceiveMessage2, thresholdBbsPhase2Finish, thresholdBbsCreateSignatureShare, thresholdBbsAggregateSignatureShares, bbsVerify) + checkThresholdSig(protocolId, paramsBbs, thresholdPubkeyBbs, secretKeysBbs, thresholdBbsStartPhase1, thresholdBbsPhase1ProcessCommitments, thresholdBbsPhase1GetSharesForOther, thresholdBbsPhase1ProcessShares, thresholdBbsPhase1Finish, thresholdBbsPhase2Start, thresholdBbsPhase2ReceiveMessage1, thresholdBbsPhase2ReceiveMessage2, thresholdBbsPhase2Finish, thresholdBbsCreateSignatureShare, thresholdBbsAggregateSignatureShares, bbsVerifyConstantTime) }) }) \ No newline at end of file