From 6a10f456fce09d3e256000923881dbdb0615ea7e Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 23 May 2022 14:20:04 +0300 Subject: [PATCH] added test for `native` note type --- src/note/note_type.rs | 2 +- src/value.rs | 51 ++++++++++++++++++++++++++----------------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/note/note_type.rs b/src/note/note_type.rs index c26150fd..3d5ae2a3 100644 --- a/src/note/note_type.rs +++ b/src/note/note_type.rs @@ -13,7 +13,7 @@ pub struct NoteType(pub(crate) pallas::Point); // the hasher used to derive the assetID #[allow(non_snake_case)] fn assetID_hasher(msg: Vec) -> pallas::Point { - // TODO(zsa) replace personalization, will require circuit change. + // TODO(zsa) replace personalization, will require circuit change? pallas::Point::hash_to_curve(VALUE_COMMITMENT_PERSONALIZATION)(&msg) } diff --git a/src/value.rs b/src/value.rs index 26ac695f..24deb4a9 100644 --- a/src/value.rs +++ b/src/value.rs @@ -408,6 +408,7 @@ pub mod testing { #[cfg(test)] mod tests { use crate::note::note_type::testing::arb_note_type; + use crate::note::NoteType; use proptest::prelude::*; use super::{ @@ -416,6 +417,32 @@ mod tests { }; use crate::primitives::redpallas; + fn _bsk_consistent_with_bvk( + values: &Vec<(ValueSum, ValueCommitTrapdoor)>, + note_type: NoteType, + ) { + let value_balance = values + .iter() + .map(|(value, _)| value) + .sum::>() + .expect("we generate values that won't overflow"); + + let bsk = values + .iter() + .map(|(_, rcv)| rcv) + .sum::() + .into_bsk(); + + let bvk = (values + .into_iter() + .map(|(value, rcv)| ValueCommitment::derive(value.clone(), rcv.clone(), note_type)) + .sum::() + - ValueCommitment::derive(value_balance, ValueCommitTrapdoor::zero(), note_type)) + .into_bvk(); + + assert_eq!(redpallas::VerificationKey::from(&bsk), bvk); + } + proptest! { #[test] fn bsk_consistent_with_bvk( @@ -426,26 +453,10 @@ mod tests { ), arb_note_type in arb_note_type(), ) { - let value_balance = values - .iter() - .map(|(value, _)| value) - .sum::>() - .expect("we generate values that won't overflow"); - - let bsk = values - .iter() - .map(|(_, rcv)| rcv) - .sum::() - .into_bsk(); - - let bvk = (values - .into_iter() - .map(|(value, rcv)| ValueCommitment::derive(value, rcv, arb_note_type)) - .sum::() - - ValueCommitment::derive(value_balance, ValueCommitTrapdoor::zero(), arb_note_type)) - .into_bvk(); - - assert_eq!(redpallas::VerificationKey::from(&bsk), bvk); + // Test with native note type (zec) + _bsk_consistent_with_bvk(&values, NoteType::native()); + // Test with arbitrary note type + _bsk_consistent_with_bvk(&values, arb_note_type); } } }