Przeglądaj źródła

rename ambigous 'Node' to MerkleNode

narodnik 5 lat temu
rodzic
commit
c97feb8f0b

+ 9 - 9
src/bin/tx.rs

@@ -8,7 +8,7 @@ use drk::crypto::{
     coin::Coin,
     load_params,
     merkle::{CommitmentTree, IncrementalWitness},
-    node::{hash_coin, Node},
+    merkle_node::{hash_coin, MerkleNode},
     note::{EncryptedNote, Note},
     nullifier::Nullifier,
     save_params, setup_mint_prover, setup_spend_prover,
@@ -19,10 +19,10 @@ use drk::tx;
 
 struct MemoryState {
     // The entire merkle tree state
-    tree: CommitmentTree<Node>,
+    tree: CommitmentTree<MerkleNode>,
     // List of all previous and the current merkle roots
     // This is the hashed value of all the children.
-    merkle_roots: Vec<Node>,
+    merkle_roots: Vec<MerkleNode>,
     // Nullifiers prevent double spending
     nullifiers: Vec<Nullifier>,
     // All received coins
@@ -30,7 +30,7 @@ struct MemoryState {
     // Maybe the spend field links to a tx hash:input index
     // We should also keep track of the tx hash:output index where this
     // coin was received
-    own_coins: Vec<(Coin, Note, jubjub::Fr, IncrementalWitness<Node>)>,
+    own_coins: Vec<(Coin, Note, jubjub::Fr, IncrementalWitness<MerkleNode>)>,
 
     // Mint verifying key used by ZK
     mint_pvk: groth16::PreparedVerifyingKey<Bls12>,
@@ -47,7 +47,7 @@ impl ProgramState for MemoryState {
     fn is_valid_cashier_public_key(&self, public: &jubjub::SubgroupPoint) -> bool {
         public == &self.cashier_public
     }
-    fn is_valid_merkle(&self, merkle_root: &Node) -> bool {
+    fn is_valid_merkle(&self, merkle_root: &MerkleNode) -> bool {
         self.merkle_roots.iter().any(|m| *m == *merkle_root)
     }
     fn nullifier_exists(&self, nullifier: &Nullifier) -> bool {
@@ -70,7 +70,7 @@ impl MemoryState {
         // Update merkle tree and witnesses
         for (coin, enc_note) in update.coins.into_iter().zip(update.enc_notes.into_iter()) {
             // Add the new coins to the merkle tree
-            let node = Node::from_coin(&coin);
+            let node = MerkleNode::from_coin(&coin);
             self.tree.append(node).expect("Append to merkle tree");
 
             // Keep track of all merkle roots that have existed
@@ -186,7 +186,7 @@ fn main() {
         for i in 0..5 {
             // Don't worry about any of the code in this block
             // We're just filling the tree with fake coins
-            let cmu = Node::new(bls12_381::Scalar::random(&mut OsRng).to_repr());
+            let cmu = MerkleNode::new(bls12_381::Scalar::random(&mut OsRng).to_repr());
             tree.append(cmu);
 
             let root = tree.root();
@@ -221,7 +221,7 @@ fn main() {
         for i in 0..10 {
             // Don't worry about any of the code in this block
             // We're just filling the tree with fake coins
-            let cmu = Node::new(bls12_381::Scalar::random(&mut OsRng).to_repr());
+            let cmu = MerkleNode::new(bls12_381::Scalar::random(&mut OsRng).to_repr());
             tree.append(cmu);
             witness.append(cmu);
             assert_eq!(tree.root(), witness.root());
@@ -241,7 +241,7 @@ fn main() {
         let merkle_path = witness.path().unwrap();
 
         // Just test the path is good because we just added a bunch of fake coins
-        let node = Node::from_coin(&coin);
+        let node = MerkleNode::from_coin(&coin);
         let root = tree.root();
         drop(tree);
         drop(witness);

+ 1 - 1
src/circuit/spend_contract.rs

@@ -13,7 +13,7 @@ use ff::{Field, PrimeField};
 use group::Curve;
 use zcash_proofs::circuit::{ecc, pedersen_hash};
 
-use crate::crypto::node::SAPLING_COMMITMENT_TREE_DEPTH;
+use crate::crypto::merkle_node::SAPLING_COMMITMENT_TREE_DEPTH;
 
 pub struct SpendContract {
     pub value: Option<u64>,

+ 1 - 1
src/crypto/merkle.rs

@@ -6,7 +6,7 @@ use std::collections::VecDeque;
 use std::io::{self, Read, Write};
 
 //use crate::serialize::{Optional, Vector};
-use super::node::SAPLING_COMMITMENT_TREE_DEPTH;
+use super::merkle_node::SAPLING_COMMITMENT_TREE_DEPTH;
 
 /// A hashable node within a Merkle tree.
 pub trait Hashable: Clone + Copy {

+ 10 - 10
src/crypto/node.rs → src/crypto/merkle_node.rs

@@ -65,11 +65,11 @@ pub fn hash_coin(coin: &[u8; 32]) -> bls12_381::Scalar {
 
 /// A node within the Sapling commitment tree.
 #[derive(Clone, Copy, Debug, PartialEq)]
-pub struct Node {
+pub struct MerkleNode {
     pub repr: [u8; 32],
 }
 
-impl Node {
+impl MerkleNode {
     pub fn new(repr: [u8; 32]) -> Self {
         Self { repr }
     }
@@ -81,7 +81,7 @@ impl Node {
     }
 }
 
-impl Hashable for Node {
+impl Hashable for MerkleNode {
     fn read<R: io::Read>(mut reader: R) -> io::Result<Self> {
         let mut repr = [0u8; 32];
         reader.read_exact(&mut repr)?;
@@ -112,19 +112,19 @@ impl Hashable for Node {
     }
 }
 
-impl From<Node> for bls12_381::Scalar {
-    fn from(node: Node) -> Self {
+impl From<MerkleNode> for bls12_381::Scalar {
+    fn from(node: MerkleNode) -> Self {
         bls12_381::Scalar::from_repr(node.repr).expect("Tree nodes should be in the prime field")
     }
 }
 
-impl Encodable for Node {
+impl Encodable for MerkleNode {
     fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
         Ok(self.repr.encode(s)?)
     }
 }
 
-impl Decodable for Node {
+impl Decodable for MerkleNode {
     fn decode<D: io::Read>(mut d: D) -> Result<Self> {
         Ok(Self {
             repr: Decodable::decode(d)?,
@@ -133,10 +133,10 @@ impl Decodable for Node {
 }
 
 lazy_static! {
-    static ref EMPTY_ROOTS: Vec<Node> = {
-        let mut v = vec![Node::blank()];
+    static ref EMPTY_ROOTS: Vec<MerkleNode> = {
+        let mut v = vec![MerkleNode::blank()];
         for d in 0..SAPLING_COMMITMENT_TREE_DEPTH {
-            let next = Node::combine(d, &v[d], &v[d]);
+            let next = MerkleNode::combine(d, &v[d], &v[d]);
             v.push(next);
         }
         v

+ 1 - 1
src/crypto/mod.rs

@@ -3,7 +3,7 @@ pub mod diffie_hellman;
 pub mod fr_serial;
 pub mod merkle;
 pub mod mint_proof;
-pub mod node;
+pub mod merkle_node;
 pub mod note;
 pub mod nullifier;
 pub mod schnorr;

+ 3 - 3
src/crypto/spend_proof.rs

@@ -8,7 +8,7 @@ use rand::rngs::OsRng;
 use std::io;
 use std::time::Instant;
 
-use super::node::{merkle_hash, Node, SAPLING_COMMITMENT_TREE_DEPTH};
+use super::merkle_node::{merkle_hash, MerkleNode, SAPLING_COMMITMENT_TREE_DEPTH};
 use super::nullifier::Nullifier;
 use crate::circuit::spend_contract::SpendContract;
 use crate::error::Result;
@@ -19,7 +19,7 @@ pub struct SpendRevealedValues {
     pub nullifier: Nullifier,
     // This should not be here, we just have it for debugging
     //coin: [u8; 32],
-    pub merkle_root: Node,
+    pub merkle_root: MerkleNode,
     pub signature_public: jubjub::SubgroupPoint,
 }
 
@@ -85,7 +85,7 @@ impl SpendRevealedValues {
             }
         }
 
-        let merkle_root = Node::new(merkle_root.to_repr());
+        let merkle_root = MerkleNode::new(merkle_root.to_repr());
 
         SpendRevealedValues {
             value_commit,

+ 2 - 2
src/state.rs

@@ -3,13 +3,13 @@ use bls12_381::Bls12;
 use std::fmt;
 
 use crate::{
-    crypto::{coin::Coin, node::Node, note::EncryptedNote, nullifier::Nullifier},
+    crypto::{coin::Coin, merkle_node::MerkleNode, note::EncryptedNote, nullifier::Nullifier},
     tx,
 };
 
 pub trait ProgramState {
     fn is_valid_cashier_public_key(&self, public: &jubjub::SubgroupPoint) -> bool;
-    fn is_valid_merkle(&self, merkle: &Node) -> bool;
+    fn is_valid_merkle(&self, merkle: &MerkleNode) -> bool;
     fn nullifier_exists(&self, nullifier: &Nullifier) -> bool;
 
     fn mint_pvk(&self) -> &groth16::PreparedVerifyingKey<Bls12>;

+ 2 - 2
src/tx/builder.rs

@@ -8,7 +8,7 @@ use super::{
     Transaction, TransactionClearInput, TransactionInput, TransactionOutput,
 };
 use crate::crypto::{
-    create_mint_proof, create_spend_proof, merkle::MerklePath, node::Node, note::Note, schnorr,
+    create_mint_proof, create_spend_proof, merkle::MerklePath, merkle_node::MerkleNode, note::Note, schnorr,
 };
 use crate::serial::Encodable;
 
@@ -24,7 +24,7 @@ pub struct TransactionBuilderClearInputInfo {
 }
 
 pub struct TransactionBuilderInputInfo {
-    pub merkle_path: MerklePath<Node>,
+    pub merkle_path: MerklePath<MerkleNode>,
     pub secret: jubjub::Fr,
     pub note: Note,
 }