Skip to content

Commit

Permalink
add calculate_root api for Note (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
XuyangSong authored Oct 16, 2023
1 parent fe2e920 commit 8626a44
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
7 changes: 2 additions & 5 deletions taiga_halo2/benches/action_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -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)
};
Expand Down
7 changes: 2 additions & 5 deletions taiga_halo2/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions taiga_halo2/src/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -496,10 +501,7 @@ impl InputNoteProvingInfo {
) -> Self {
let anchor = match custom_anchor {
Some(anchor) => anchor,
None => {
let cm_note = Node::from(&note);
merkle_path.root(cm_note)
}
None => note.calculate_root(&merkle_path),
};
Self {
note,
Expand Down
12 changes: 3 additions & 9 deletions taiga_halo2/src/taiga_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 8626a44

Please sign in to comment.