narodnik 5 лет назад
Родитель
Сommit
86b3bd496e
5 измененных файлов с 11 добавлено и 13 удалено
  1. 4 4
      src/bin/tx.rs
  2. 1 1
      src/crypto/coin.rs
  3. 1 0
      src/crypto/mod.rs
  4. 5 7
      src/state.rs
  5. 0 1
      src/tx.rs

+ 4 - 4
src/bin/tx.rs

@@ -10,6 +10,7 @@ use sapvi::crypto::{
     coin::Coin,
     create_mint_proof, create_spend_proof, load_params,
     merkle::{CommitmentTree, IncrementalWitness},
+    nullifier::Nullifier,
     note::{EncryptedNote, Note},
     save_params, setup_mint_prover, setup_spend_prover, verify_mint_proof, verify_spend_proof,
     MintRevealedValues, SpendRevealedValues,
@@ -21,8 +22,8 @@ use sapvi::tx;
 
 struct MemoryState {
     tree: CommitmentTree<Coin>,
-    nullifiers: Vec<[u8; 32]>,
-    own_coins: Vec<([u8; 32], Note, jubjub::Fr, IncrementalWitness<Coin>)>,
+    nullifiers: Vec<Nullifier>,
+    own_coins: Vec<(Coin, Note, jubjub::Fr, IncrementalWitness<Coin>)>,
     mint_pvk: groth16::PreparedVerifyingKey<Bls12>,
     spend_pvk: groth16::PreparedVerifyingKey<Bls12>,
     cashier_public: jubjub::SubgroupPoint,
@@ -56,7 +57,7 @@ impl MemoryState {
         for (coin, enc_note) in updates.coins.into_iter().zip(updates.enc_notes.into_iter()) {
             // Add the new coins to the merkle tree
             self.tree
-                .append(Coin::new(coin.clone()))
+                .append(coin.clone())
                 .expect("Append to merkle tree");
 
             if let Some((note, secret)) = self.try_decrypt_note(enc_note) {
@@ -224,7 +225,6 @@ fn main() {
     let builder = tx::TransactionBuilder {
         clear_inputs: vec![],
         inputs: vec![tx::TransactionBuilderInputInfo {
-            coin,
             merkle_path: auth_path,
             secret: secret.clone(),
             note: state.own_coins[0].1.clone(),

+ 1 - 1
src/crypto/coin.rs

@@ -45,7 +45,7 @@ pub fn merkle_hash(depth: usize, lhs: &[u8; 32], rhs: &[u8; 32]) -> bls12_381::S
 /// A node within the Sapling commitment tree.
 #[derive(Clone, Copy, Debug, PartialEq)]
 pub struct Coin {
-    repr: [u8; 32],
+    pub repr: [u8; 32],
 }
 
 impl Coin {

+ 1 - 0
src/crypto/mod.rs

@@ -4,6 +4,7 @@ pub mod fr_serial;
 pub mod merkle;
 pub mod mint_proof;
 pub mod note;
+pub mod nullifier;
 pub mod schnorr;
 pub mod spend_proof;
 pub mod util;

+ 5 - 7
src/state.rs

@@ -2,9 +2,7 @@ use bellman::groth16;
 use bls12_381::Bls12;
 use std::fmt;
 
-use crate::crypto::note::{EncryptedNote, Note};
-use crate::error::{Error, Result};
-use crate::tx;
+use crate::{crypto::{coin::Coin, note::{EncryptedNote, Note}, nullifier::Nullifier}, error::{Error, Result}, tx};
 
 pub trait ProgramState {
     fn is_valid_cashier_public_key(&self, public: &jubjub::SubgroupPoint) -> bool;
@@ -16,8 +14,8 @@ pub trait ProgramState {
 }
 
 pub struct StateUpdates {
-    pub nullifiers: Vec<[u8; 32]>,
-    pub coins: Vec<[u8; 32]>,
+    pub nullifiers: Vec<Nullifier>,
+    pub coins: Vec<Coin>,
     pub enc_notes: Vec<EncryptedNote>
 }
 
@@ -99,7 +97,7 @@ pub fn state_transition<S: ProgramState>(
 
     let mut nullifiers = vec![];
     for input in tx.inputs {
-        nullifiers.push(input.revealed.nullifier);
+        nullifiers.push(Nullifier::new(input.revealed.nullifier));
     }
 
     // Newly created coins for this tx
@@ -107,7 +105,7 @@ pub fn state_transition<S: ProgramState>(
     let mut enc_notes = vec![];
     for output in tx.outputs {
         // Gather all the coins
-        coins.push(output.revealed.coin);
+        coins.push(Coin::new(output.revealed.coin));
         enc_notes.push(output.enc_note);
     }
 

+ 0 - 1
src/tx.rs

@@ -189,7 +189,6 @@ pub struct TransactionBuilderClearInputInfo {
 }
 
 pub struct TransactionBuilderInputInfo {
-    pub coin: [u8; 32],
     pub merkle_path: Vec<(bls12_381::Scalar, bool)>,
     pub secret: jubjub::Fr,
     pub note: Note,