Просмотр исходного кода

contract/money: removed unused coin from auth token mint call

skoupidi 2 лет назад
Родитель
Сommit
e3e8e3a8be

+ 2 - 35
src/contract/money/proof/auth_token_mint_v1.zk

@@ -1,33 +1,19 @@
-# Circuit used to mint arbitrary coins given a mint authority secret.
+# Circuit used to verify a token mint authority.
 k = 11;
 field = "pallas";
 
 constant "AuthTokenMint_V1" {
-    EcFixedPointShort VALUE_COMMIT_VALUE,
-    EcFixedPoint VALUE_COMMIT_RANDOM,
     EcFixedPointBase NULLIFIER_K,
 }
 
 witness "AuthTokenMint_V1" {
-    # CoinAttributes {
-    Base coin_public_x,
-    Base coin_public_y,
-    Base coin_value,
-    Base coin_spend_hook,
-    Base coin_user_data,
-    Base coin_blind,
-    # }
-
     # TokenAttributes {
     Base token_auth_parent,
     Base token_blind,
     # }
 
-    # Secret key used by mint
+    # Secret key used by the mint authority
     Base mint_secret,
-
-    # Random blinding factor for the value commitment
-    Scalar value_commit_blind,
 }
 
 circuit "AuthTokenMint_V1" {
@@ -42,23 +28,4 @@ circuit "AuthTokenMint_V1" {
     token_user_data = poseidon_hash(mint_x, mint_y);
     token_id = poseidon_hash(token_auth_parent, token_user_data, token_blind);
     constrain_instance(token_id);
-
-    # Poseidon hash of the minted coin
-    coin = poseidon_hash(
-        coin_public_x,
-        coin_public_y,
-        coin_value,
-        token_id,
-        coin_spend_hook,
-        coin_user_data,
-        coin_blind
-    );
-    constrain_instance(coin);
-
-    # Pedersen commitment for the coin's value
-    vcv = ec_mul_short(coin_value, VALUE_COMMIT_VALUE);
-    vcr = ec_mul(value_commit_blind, VALUE_COMMIT_RANDOM);
-    value_commit = ec_add(vcv, vcr);
-    constrain_instance(ec_get_x(value_commit));
-    constrain_instance(ec_get_y(value_commit));
 }

+ 1 - 1
src/contract/money/proof/token_mint_v1.zk

@@ -1,4 +1,4 @@
-# Circuit used to mint arbitrary coins given a mint authority secret.
+# Circuit used to mint arbitrary coins for given token attributes.
 k = 11;
 field = "pallas";
 

+ 7 - 34
src/contract/money/src/client/auth_token_mint_v1.rs

@@ -21,10 +21,7 @@ use darkfi::{
     zkas::ZkBinary,
     Result,
 };
-use darkfi_sdk::{
-    crypto::{note::AeadEncryptedNote, pasta_prelude::*, pedersen_commitment_u64, Blind, Keypair},
-    pasta::pallas,
-};
+use darkfi_sdk::crypto::{note::AeadEncryptedNote, Blind, Keypair};
 use log::debug;
 use rand::rngs::OsRng;
 
@@ -40,12 +37,12 @@ pub struct AuthTokenMintCallDebris {
 
 /// Struct holding necessary information to build a `Money::AuthTokenMintV1` contract call.
 pub struct AuthTokenMintCallBuilder {
+    /// Coin attributes
     pub coin_attrs: CoinAttributes,
+    /// Token attributes
     pub token_attrs: TokenAttributes,
-
     /// Mint authority keypair
     pub mint_keypair: Keypair,
-
     /// `AuthTokenMint_V1` zkas circuit ZkBinary
     pub auth_mint_zkbin: ZkBinary,
     /// Proving key for the `AuthTokenMint_V1` zk circuit,
@@ -56,55 +53,32 @@ impl AuthTokenMintCallBuilder {
     pub fn build(&self) -> Result<AuthTokenMintCallDebris> {
         debug!("Building Money::AuthTokenMintV1 contract call");
 
-        let value_blind = Blind::random(&mut OsRng);
-        let value_commit = pedersen_commitment_u64(self.coin_attrs.value, value_blind);
-
         // Create the proof
-
-        let (public_x, public_y) = self.coin_attrs.public_key.xy();
-
         let prover_witnesses = vec![
-            // Coin attributes
-            Witness::Base(Value::known(public_x)),
-            Witness::Base(Value::known(public_y)),
-            Witness::Base(Value::known(pallas::Base::from(self.coin_attrs.value))),
-            Witness::Base(Value::known(self.coin_attrs.spend_hook.inner())),
-            Witness::Base(Value::known(self.coin_attrs.user_data)),
-            Witness::Base(Value::known(self.coin_attrs.blind.inner())),
             // Token attributes
             Witness::Base(Value::known(self.token_attrs.auth_parent.inner())),
             Witness::Base(Value::known(self.token_attrs.blind.inner())),
-            // Secret key used by mint
+            // Secret key used by the mint authority
             Witness::Base(Value::known(self.mint_keypair.secret.inner())),
-            // Random blinding factor for the value commitment
-            Witness::Scalar(Value::known(value_blind.inner())),
         ];
 
         let mint_pubkey = self.mint_keypair.public;
-        let value_coords = value_commit.to_affine().coordinates().unwrap();
 
-        let public_inputs = vec![
-            mint_pubkey.x(),
-            mint_pubkey.y(),
-            self.token_attrs.to_token_id().inner(),
-            self.coin_attrs.to_coin().inner(),
-            *value_coords.x(),
-            *value_coords.y(),
-        ];
+        let public_inputs =
+            vec![mint_pubkey.x(), mint_pubkey.y(), self.token_attrs.to_token_id().inner()];
 
         //darkfi::zk::export_witness_json("proof/witness/auth_token_mint_v1.json", &prover_witnesses, &public_inputs);
         let circuit = ZkCircuit::new(prover_witnesses, &self.auth_mint_zkbin);
         let proof = Proof::create(&self.auth_mint_pk, &[circuit], &public_inputs, &mut OsRng)?;
 
         // Create the note
-
         let note = MoneyNote {
             value: self.coin_attrs.value,
             token_id: self.coin_attrs.token_id,
             spend_hook: self.coin_attrs.spend_hook,
             user_data: self.coin_attrs.user_data,
             coin_blind: self.coin_attrs.blind,
-            value_blind,
+            value_blind: Blind::random(&mut OsRng),
             token_blind: Blind::ZERO,
             memo: vec![],
         };
@@ -113,7 +87,6 @@ impl AuthTokenMintCallBuilder {
 
         let params = MoneyAuthTokenMintParamsV1 {
             token_id: self.token_attrs.to_token_id(),
-            value_commit,
             enc_note,
             mint_pubkey,
         };

+ 9 - 22
src/contract/money/src/entrypoint/auth_token_mint_v1.rs

@@ -17,7 +17,7 @@
  */
 
 use darkfi_sdk::{
-    crypto::{pasta_prelude::*, ContractId, PublicKey},
+    crypto::{ContractId, PublicKey},
     dark_tree::DarkLeaf,
     error::{ContractError, ContractResult},
     msg,
@@ -28,7 +28,7 @@ use darkfi_serial::{deserialize, serialize, Encodable, WriteExt};
 
 use crate::{
     error::MoneyError,
-    model::{MoneyAuthTokenMintParamsV1, MoneyAuthTokenMintUpdateV1, MoneyTokenMintParamsV1},
+    model::{MoneyAuthTokenMintParamsV1, MoneyAuthTokenMintUpdateV1},
     MoneyFunction, MONEY_CONTRACT_TOKEN_FREEZE_TREE, MONEY_CONTRACT_ZKAS_AUTH_TOKEN_MINT_NS_V1,
 };
 
@@ -38,38 +38,25 @@ pub(crate) fn money_auth_token_mint_get_metadata_v1(
     call_idx: usize,
     calls: Vec<DarkLeaf<ContractCall>>,
 ) -> Result<Vec<u8>, ContractError> {
-    let self_node = &calls[call_idx];
-    let self_data = &self_node.data;
-    let self_params: MoneyAuthTokenMintParamsV1 = deserialize(&self_data.data[1..])?;
-
-    if self_node.children_indexes.len() != 1 {
+    let self_ = &calls[call_idx];
+    if self_.children_indexes.len() != 1 {
         msg!(
             "[MintV1] Error: Children indexes length is not expected(1): {}",
-            self_node.children_indexes.len()
+            self_.children_indexes.len()
         );
         return Err(MoneyError::ChildrenIndexesLengthMismatch.into())
     }
-    let child_idx = self_node.children_indexes[0];
-    let child_node = &calls[child_idx];
-    let child_data = &child_node.data;
-    let child_params: MoneyTokenMintParamsV1 = deserialize(&child_data.data[1..])?;
+
+    let params: MoneyAuthTokenMintParamsV1 = deserialize(&self_.data.data[1..])?;
 
     // Public inputs for the ZK proofs we have to verify
     let mut zk_public_inputs: Vec<(String, Vec<pallas::Base>)> = vec![];
     // Public keys for the transaction signatures we have to verify.
-    let signature_pubkeys: Vec<PublicKey> = vec![self_params.mint_pubkey];
+    let signature_pubkeys: Vec<PublicKey> = vec![params.mint_pubkey];
 
-    let value_commit = self_params.value_commit.to_affine().coordinates().unwrap();
     zk_public_inputs.push((
         MONEY_CONTRACT_ZKAS_AUTH_TOKEN_MINT_NS_V1.to_string(),
-        vec![
-            self_params.mint_pubkey.x(),
-            self_params.mint_pubkey.y(),
-            self_params.token_id.inner(),
-            child_params.coin.inner(),
-            *value_commit.x(),
-            *value_commit.y(),
-        ],
+        vec![params.mint_pubkey.x(), params.mint_pubkey.y(), params.token_id.inner()],
     ));
 
     // Serialize everything gathered and return it

+ 0 - 1
src/contract/money/src/model/mod.rs

@@ -246,7 +246,6 @@ pub struct MoneyTokenMintUpdateV1 {
 #[derive(Clone, Debug, SerialEncodable, SerialDecodable)]
 pub struct MoneyAuthTokenMintParamsV1 {
     pub token_id: TokenId,
-    pub value_commit: pallas::Point,
     pub enc_note: AeadEncryptedNote,
     pub mint_pubkey: PublicKey,
 }

+ 2 - 2
src/contract/test-harness/src/vks.rs

@@ -48,8 +48,8 @@ use log::debug;
 
 /// Update these if any circuits are changed.
 /// Delete the existing cachefiles, and enable debug logging, you will see the new hashes.
-const PKS_HASH: &str = "8ab69a6b4cf92ccf5bf5ff7341d90dae72363e8a2c2f1bb05c1ed966fd5074be";
-const VKS_HASH: &str = "2cf53f1f216bf2c066d7a61ed582dbab7db028c782a51a24acdd0905e8bb8bb8";
+const PKS_HASH: &str = "74c32f44649aed0ef51193a64df15f2375fb81482479e49d6b3f53bab7ea102a";
+const VKS_HASH: &str = "ef943017346bc794b8dafa0b494e965d979352bc254e1549b52f5e1df38710bf";
 
 /// Build a `PathBuf` to a cachefile
 fn cache_path(typ: &str) -> Result<PathBuf> {