narodnik 4 лет назад
Родитель
Сommit
c521c3d25c
4 измененных файлов с 40 добавлено и 17 удалено
  1. 31 15
      src/bin/tx2.rs
  2. 3 0
      src/circuit/mint_contract.rs
  3. 3 1
      src/crypto/mint_proof.rs
  4. 3 1
      src/crypto/spend_proof.rs

+ 31 - 15
src/bin/tx2.rs

@@ -43,6 +43,7 @@ use drk::{
             sinsemilla::{OrchardCommitDomains, OrchardHashDomains, MERKLE_CRH_PERSONALIZATION},
             OrchardFixedBases,
         },
+        note::{Note, EncryptedNote},
         nullifier::Nullifier,
         util::{
             pedersen_commitment_u64,
@@ -77,7 +78,11 @@ mod tx2 {
     };
 
     use drk::{
-        crypto::note::{Note, EncryptedNote},
+        crypto::{
+            mint_proof::{create_mint_proof, MintRevealedValues},
+            proof::Proof,
+            note::{Note, EncryptedNote}
+        },
         error::Result,
         types::{
         DrkValueBlind,
@@ -165,15 +170,15 @@ mod tx2 {
                 let serial = DrkSerial::random(&mut OsRng);
                 let coin_blind = DrkCoinBlind::random(&mut OsRng);
 
-                //let (mint_proof, revealed) = create_mint_proof(
-                //    output.value,
-                //    output.token_id,
-                //    value_blind,
-                //    token_blind,
-                //    serial,
-                //    coin_blind,
-                //    output.public,
-                //)?;
+                let (mint_proof, revealed) = create_mint_proof(
+                    output.value,
+                    pallas::Base::from(output.token_id),
+                    value_blind,
+                    token_blind,
+                    serial,
+                    coin_blind,
+                    output.public,
+                )?;
 
                 // Encrypted note
 
@@ -188,8 +193,8 @@ mod tx2 {
                 let encrypted_note = note.encrypt(&output.public).unwrap();
 
                 let output = TransactionOutput {
-                    //mint_proof,
-                    //revealed,
+                    mint_proof,
+                    revealed,
                     enc_note: encrypted_note,
                 };
                 outputs.push(output);
@@ -260,8 +265,8 @@ mod tx2 {
     }
 
     pub struct TransactionOutput {
-        //pub mint_proof: Proof,
-        //pub revealed: MintRevealedValues,
+        pub mint_proof: Proof,
+        pub revealed: MintRevealedValues,
         pub enc_note: EncryptedNote,
     }
 }
@@ -278,7 +283,7 @@ pub trait ProgramState {
 pub struct StateUpdate {
     pub nullifiers: Vec<Nullifier>,
     pub coins: Vec<Coin>,
-    //pub enc_notes: Vec<EncryptedNote>,
+    pub enc_notes: Vec<EncryptedNote>,
 }
 
 pub type VerifyResult<T> = std::result::Result<T, VerifyFailed>;
@@ -344,14 +349,25 @@ pub fn state_transition<S: ProgramState>(
         }
     }
 
+    debug!(target: "STATE TRANSITION", "Check the tx Verifies correctly");
+    // Check the tx verifies correctly
+    //tx.verify(state.mint_pvk(), state.spend_pvk())?;
+
     let mut nullifiers = vec![];
 
     // Newly created coins for this tx
     let mut coins = vec![];
+    let mut enc_notes = vec![];
+    for output in tx.outputs {
+        // Gather all the coins
+        coins.push(Coin::from_bytes(&output.revealed.coin));
+        enc_notes.push(output.enc_note);
+    }
 
     Ok(StateUpdate {
         nullifiers,
         coins,
+        enc_notes
     })
 }
 

+ 3 - 0
src/circuit/mint_contract.rs

@@ -237,6 +237,9 @@ impl Circuit<pasta::Fp> for MintContract {
         config: Self::Config,
         mut layouter: impl Layouter<pasta::Fp>,
     ) -> Result<(), plonk::Error> {
+        // Load the Sinsemilla generator lookup table used by the whole circuit.
+        SinsemillaChip::load(config.sinsemilla_config_1.clone(), &mut layouter)?;
+
         let ecc_chip = config.ecc_chip();
 
         let pub_x = self.load_private(

+ 3 - 1
src/crypto/mint_proof.rs

@@ -106,6 +106,8 @@ pub fn create_mint_proof(
     coin_blind: DrkCoinBlind,
     public_key: DrkPublicKey,
 ) -> Result<(Proof, MintRevealedValues)> {
+    const K: u32 = 11;
+
     let revealed = MintRevealedValues::compute(
         value,
         token_id,
@@ -131,7 +133,7 @@ pub fn create_mint_proof(
 
     let start = Instant::now();
     // TODO: Don't always build this
-    let pk = ProvingKey::build(11, MintContract::default());
+    let pk = ProvingKey::build(K, MintContract::default());
     debug!("Setup: [{:?}]", start.elapsed());
 
     let start = Instant::now();

+ 3 - 1
src/crypto/spend_proof.rs

@@ -133,6 +133,8 @@ pub fn create_spend_proof(
     merkle_path: Vec<DrkCoin>,
     signature_secret: DrkSecretKey,
 ) -> Result<(Proof, SpendRevealedValues)> {
+    const K: u32 = 11;
+
     let revealed = SpendRevealedValues::compute(
         value,
         token_id,
@@ -161,7 +163,7 @@ pub fn create_spend_proof(
 
     let start = Instant::now();
     // TODO: Don't always build this
-    let pk = ProvingKey::build(11, SpendContract::default());
+    let pk = ProvingKey::build(K, SpendContract::default());
     debug!("Setup: [{:?}]", start.elapsed());
 
     let start = Instant::now();