diff --git a/taiga_halo2/benches/action_proof.rs b/taiga_halo2/benches/action_proof.rs index b8ec0f05..9cf5ef64 100644 --- a/taiga_halo2/benches/action_proof.rs +++ b/taiga_halo2/benches/action_proof.rs @@ -13,7 +13,7 @@ use taiga_halo2::{ ACTION_CIRCUIT_PARAMS_SIZE, ACTION_PROVING_KEY, ACTION_VERIFYING_KEY, SETUP_PARAMS_MAP, TAIGA_COMMITMENT_TREE_DEPTH, }, - merkle_tree::{MerklePath, Node}, + merkle_tree::MerklePath, note::{Note, NoteType, RandomSeed}, nullifier::{Nullifier, NullifierKeyContainer}, }; @@ -66,10 +66,7 @@ fn bench_action_proof(name: &str, c: &mut Criterion) { } }; let input_merkle_path = MerklePath::random(&mut rng, TAIGA_COMMITMENT_TREE_DEPTH); - let anchor = { - let cm_note = Node::from(&input_note); - input_merkle_path.root(cm_note) - }; + let anchor = input_note.calculate_root(&input_merkle_path); let rseed = RandomSeed::random(&mut rng); ActionInfo::new(input_note, input_merkle_path, anchor, output_note, rseed) }; diff --git a/taiga_halo2/src/action.rs b/taiga_halo2/src/action.rs index b7f266b3..c27a9578 100644 --- a/taiga_halo2/src/action.rs +++ b/taiga_halo2/src/action.rs @@ -208,7 +208,7 @@ impl ActionInfo { pub mod tests { use super::ActionInfo; use crate::constant::TAIGA_COMMITMENT_TREE_DEPTH; - use crate::merkle_tree::{MerklePath, Node}; + use crate::merkle_tree::MerklePath; use crate::note::tests::{random_input_note, random_output_note}; use crate::note::RandomSeed; use rand::RngCore; @@ -217,10 +217,7 @@ pub mod tests { let input_note = random_input_note(&mut rng); let output_note = random_output_note(&mut rng, input_note.get_nf().unwrap()); let input_merkle_path = MerklePath::random(&mut rng, TAIGA_COMMITMENT_TREE_DEPTH); - let input_anchor = { - let cm_note = Node::from(&input_note); - input_merkle_path.root(cm_note) - }; + let input_anchor = input_note.calculate_root(&input_merkle_path); let rseed = RandomSeed::random(&mut rng); ActionInfo::new( input_note, diff --git a/taiga_halo2/src/note.rs b/taiga_halo2/src/note.rs index d7a2da51..8d1d68e9 100644 --- a/taiga_halo2/src/note.rs +++ b/taiga_halo2/src/note.rs @@ -279,6 +279,11 @@ impl Note { pub fn get_rcm(&self) -> pallas::Base { self.rcm } + + pub fn calculate_root(&self, path: &MerklePath) -> Anchor { + let cm_node = Node::from(self); + path.root(cm_node) + } } #[cfg(feature = "borsh")] @@ -496,10 +501,7 @@ impl InputNoteProvingInfo { ) -> Self { let anchor = match custom_anchor { Some(anchor) => anchor, - None => { - let cm_note = Node::from(¬e); - merkle_path.root(cm_note) - } + None => note.calculate_root(&merkle_path), }; Self { note, diff --git a/taiga_halo2/src/taiga_api.rs b/taiga_halo2/src/taiga_api.rs index 3597a75c..5e7013d3 100644 --- a/taiga_halo2/src/taiga_api.rs +++ b/taiga_halo2/src/taiga_api.rs @@ -270,7 +270,7 @@ pub mod tests { use crate::action::ActionInfo; use crate::circuit::vp_examples::TrivialValidityPredicateCircuit; use crate::constant::TAIGA_COMMITMENT_TREE_DEPTH; - use crate::merkle_tree::{MerklePath, Node}; + use crate::merkle_tree::MerklePath; use crate::note::{ tests::{random_input_note, random_output_note}, RandomSeed, @@ -283,10 +283,7 @@ pub mod tests { let input_note_1_nf = input_note_1.get_nf().unwrap(); let output_note_1 = random_output_note(&mut rng, input_note_1_nf); let merkle_path_1 = MerklePath::random(&mut rng, TAIGA_COMMITMENT_TREE_DEPTH); - let anchor_1 = { - let cm_note = Node::from(&input_note_1); - merkle_path_1.root(cm_note) - }; + let anchor_1 = input_note_1.calculate_root(&merkle_path_1); let rseed_1 = RandomSeed::random(&mut rng); let action_1 = ActionInfo::new( input_note_1, @@ -300,10 +297,7 @@ pub mod tests { let input_note_2_nf = input_note_2.get_nf().unwrap(); let output_note_2 = random_output_note(&mut rng, input_note_2_nf); let merkle_path_2 = MerklePath::random(&mut rng, TAIGA_COMMITMENT_TREE_DEPTH); - let anchor_2 = { - let cm_note = Node::from(&input_note_2); - merkle_path_2.root(cm_note) - }; + let anchor_2 = input_note_2.calculate_root(&merkle_path_2); let rseed_2 = RandomSeed::random(&mut rng); let action_2 = ActionInfo::new( input_note_2,