瀏覽代碼

state: pasta port.

parazyd 4 年之前
父節點
當前提交
6aa7a5e69c
共有 3 個文件被更改,包括 19 次插入25 次删除
  1. 1 1
      src/crypto/nullifier.rs
  2. 4 3
      src/crypto/spend_proof.rs
  3. 14 21
      src/state.rs

+ 1 - 1
src/crypto/nullifier.rs

@@ -8,7 +8,7 @@ use crate::{
 };
 
 #[derive(Clone, Copy, Debug)]
-pub struct Nullifier(pallas::Base);
+pub struct Nullifier(pub(crate) pallas::Base);
 
 impl Nullifier {
     pub fn from_bytes(bytes: &[u8; 32]) -> Self {

+ 4 - 3
src/crypto/spend_proof.rs

@@ -12,6 +12,7 @@ use pasta_curves::{
 };
 
 use super::{
+    nullifier::Nullifier,
     proof::{Proof, ProvingKey, VerifyingKey},
     util::{mod_r_p, pedersen_commitment_scalar, pedersen_commitment_u64},
 };
@@ -25,7 +26,7 @@ use crate::{
 pub struct SpendRevealedValues {
     pub value_commit: DrkValueCommit,
     pub token_commit: DrkValueCommit,
-    pub nullifier: DrkNullifier,
+    pub nullifier: Nullifier,
     //pub merkle_root: MerkleNode,
     pub signature_public: DrkPublicKey,
 }
@@ -70,7 +71,7 @@ impl SpendRevealedValues {
         SpendRevealedValues {
             value_commit,
             token_commit,
-            nullifier,
+            nullifier: Nullifier(nullifier),
             signature_public,
         }
     }
@@ -82,7 +83,7 @@ impl SpendRevealedValues {
 
         // TODO: merkle
         vec![
-            self.nullifier,
+            self.nullifier.inner(),
             *value_coords.x(),
             *value_coords.y(),
             *token_coords.x(),

+ 14 - 21
src/state.rs

@@ -1,22 +1,18 @@
 use std::fmt;
 
-/*
-use bellman::groth16;
-use bls12_381::Bls12;
 use log::debug;
 
-use crate::{
-    crypto::{coin::Coin, merkle_node::MerkleNode, note::EncryptedNote, nullifier::Nullifier},
-    tx,
-};
+use crate::crypto::{coin::Coin, note::EncryptedNote, nullifier::Nullifier, proof::VerifyingKey};
+use crate::tx::Transaction;
+use crate::types::*;
 
 pub trait ProgramState {
-    fn is_valid_cashier_public_key(&self, public: &jubjub::SubgroupPoint) -> bool;
-    fn is_valid_merkle(&self, merkle: &MerkleNode) -> bool;
+    fn is_valid_cashier_public_key(&self, public: &DrkPublicKey) -> bool;
+    // TODO: fn is_valid_merkle(&self, merkle: &MerkleNode) -> bool;
     fn nullifier_exists(&self, nullifier: &Nullifier) -> bool;
 
-    fn mint_pvk(&self) -> &groth16::PreparedVerifyingKey<Bls12>;
-    fn spend_pvk(&self) -> &groth16::PreparedVerifyingKey<Bls12>;
+    fn mint_pvk(&self) -> &VerifyingKey;
+    fn spend_pvk(&self) -> &VerifyingKey;
 }
 
 pub struct StateUpdate {
@@ -24,7 +20,6 @@ pub struct StateUpdate {
     pub coins: Vec<Coin>,
     pub enc_notes: Vec<EncryptedNote>,
 }
-*/
 
 pub type VerifyResult<T> = std::result::Result<T, VerifyFailed>;
 
@@ -71,10 +66,9 @@ impl fmt::Display for VerifyFailed {
     }
 }
 
-/*
 pub fn state_transition<S: ProgramState>(
     state: &async_std::sync::MutexGuard<S>,
-    tx: tx::Transaction,
+    tx: Transaction,
 ) -> VerifyResult<StateUpdate> {
     // Check deposits are legit
 
@@ -93,14 +87,14 @@ pub fn state_transition<S: ProgramState>(
     debug!(target: "STATE TRANSITION", "iterate inputs");
 
     for (i, input) in tx.inputs.iter().enumerate() {
-        // Check merkle roots
-        let merkle = &input.revealed.merkle_root;
+        // TODO: Check merkle roots
+        //let merkle = &input.revealed.merkle_root;
 
         // Merkle is used to know whether this is a coin that existed
         // in a previous state.
-        if !state.is_valid_merkle(merkle) {
-            return Err(VerifyFailed::InvalidMerkle(i));
-        }
+        // if !state.is_valid_merkle(merkle) {
+        // return Err(VerifyFailed::InvalidMerkle(i));
+        // }
 
         // The nullifiers should not already exist
         // It is double spend protection.
@@ -125,7 +119,7 @@ pub fn state_transition<S: ProgramState>(
     let mut enc_notes = vec![];
     for output in tx.outputs {
         // Gather all the coins
-        coins.push(Coin::new(output.revealed.coin));
+        coins.push(Coin::from_bytes(&output.revealed.coin));
         enc_notes.push(output.enc_note);
     }
 
@@ -135,4 +129,3 @@ pub fn state_transition<S: ProgramState>(
         enc_notes,
     })
 }
-*/