فهرست منبع

contract/money: renamed TokenFreeze to AuthTokenFreeze and removed redundant proof

skoupidi 2 سال پیش
والد
کامیت
8280857a00

+ 18 - 18
bin/drk/src/money.rs

@@ -35,8 +35,8 @@ use darkfi_money_contract::{
         MoneyNote, OwnCoin,
     },
     model::{
-        Coin, Input, MoneyAuthTokenMintParamsV1, MoneyFeeParamsV1, MoneyGenesisMintParamsV1,
-        MoneyPoWRewardParamsV1, MoneyTokenFreezeParamsV1, MoneyTokenMintParamsV1,
+        Coin, Input, MoneyAuthTokenFreezeParamsV1, MoneyAuthTokenMintParamsV1, MoneyFeeParamsV1,
+        MoneyGenesisMintParamsV1, MoneyPoWRewardParamsV1, MoneyTokenMintParamsV1,
         MoneyTransferParamsV1, Nullifier, Output, TokenId, DARK_TOKEN_ID,
     },
     MoneyFunction,
@@ -715,6 +715,12 @@ impl Drk {
                 coins.push(params.output.coin);
                 notes.push(params.output.note);
             }
+            MoneyFunction::PoWRewardV1 => {
+                println!("[parse_money_call] Found Money::PoWRewardV1 call");
+                let params: MoneyPoWRewardParamsV1 = deserialize_async(&data[1..]).await?;
+                coins.push(params.output.coin);
+                notes.push(params.output.note);
+            }
             MoneyFunction::TransferV1 => {
                 println!("[parse_money_call] Found Money::TransferV1 call");
                 let params: MoneyTransferParamsV1 = deserialize_async(&data[1..]).await?;
@@ -741,6 +747,16 @@ impl Drk {
                     notes.push(output.note);
                 }
             }
+            MoneyFunction::AuthTokenMintV1 => {
+                println!("[parse_money_call] Found Money::AuthTokenMintV1 call");
+                // Handled in TokenMint
+            }
+            MoneyFunction::AuthTokenFreezeV1 => {
+                println!("[parse_money_call] Found Money::AuthTokenFreezeV1 call");
+                let params: MoneyAuthTokenFreezeParamsV1 = deserialize_async(&data[1..]).await?;
+                let token_id = TokenId::derive_public(params.mint_public);
+                freezes.push(token_id);
+            }
             MoneyFunction::TokenMintV1 => {
                 println!("[parse_money_call] Found Money::TokenMintV1 call");
                 let params: MoneyTokenMintParamsV1 = deserialize_async(&data[1..]).await?;
@@ -752,22 +768,6 @@ impl Drk {
                     deserialize_async(&parent_call.data.data[1..]).await?;
                 notes.push(params.enc_note);
             }
-            MoneyFunction::TokenFreezeV1 => {
-                println!("[parse_money_call] Found Money::TokenFreezeV1 call");
-                let params: MoneyTokenFreezeParamsV1 = deserialize_async(&data[1..]).await?;
-                let token_id = TokenId::derive_public(params.mint_public);
-                freezes.push(token_id);
-            }
-            MoneyFunction::PoWRewardV1 => {
-                println!("[parse_money_call] Found Money::PoWRewardV1 call");
-                let params: MoneyPoWRewardParamsV1 = deserialize_async(&data[1..]).await?;
-                coins.push(params.output.coin);
-                notes.push(params.output.note);
-            }
-            MoneyFunction::AuthTokenMintV1 => {
-                println!("[parse_money_call] Found Money::AuthTokenMintV1 call");
-                // Handled in TokenMint
-            }
         }
 
         Ok((nullifiers, coins, notes, freezes))

+ 16 - 14
bin/drk/src/token.rs

@@ -28,12 +28,12 @@ use darkfi::{
 };
 use darkfi_money_contract::{
     client::{
-        auth_token_mint_v1::AuthTokenMintCallBuilder, token_freeze_v1::TokenFreezeCallBuilder,
-        token_mint_v1::TokenMintCallBuilder,
+        auth_token_freeze_v1::AuthTokenFreezeCallBuilder,
+        auth_token_mint_v1::AuthTokenMintCallBuilder, token_mint_v1::TokenMintCallBuilder,
     },
     model::{CoinAttributes, TokenAttributes, TokenId},
     MoneyFunction, MONEY_CONTRACT_ZKAS_AUTH_TOKEN_MINT_NS_V1, MONEY_CONTRACT_ZKAS_FEE_NS_V1,
-    MONEY_CONTRACT_ZKAS_TOKEN_FRZ_NS_V1, MONEY_CONTRACT_ZKAS_TOKEN_MINT_NS_V1,
+    MONEY_CONTRACT_ZKAS_TOKEN_MINT_NS_V1,
 };
 use darkfi_sdk::{
     crypto::{
@@ -353,29 +353,31 @@ impl Drk {
         let mint_authority = Keypair::new(token_mint_authority.1);
 
         let zkas_bins = self.lookup_zkas(&MONEY_CONTRACT_ID).await?;
-        let zkas_ns = MONEY_CONTRACT_ZKAS_TOKEN_FRZ_NS_V1;
 
-        let Some(token_freeze_zkbin) = zkas_bins.iter().find(|x| x.0 == zkas_ns) else {
-            return Err(Error::Custom("Token freeze circuit not found".to_string()))
+        let Some(auth_mint_zkbin) =
+            zkas_bins.iter().find(|x| x.0 == MONEY_CONTRACT_ZKAS_AUTH_TOKEN_MINT_NS_V1)
+        else {
+            return Err(Error::Custom("Auth token mint circuit not found".to_string()))
         };
 
-        let freeze_zkbin = ZkBinary::decode(&token_freeze_zkbin.1)?;
-        let token_freeze_circuit = ZkCircuit::new(empty_witnesses(&freeze_zkbin)?, &freeze_zkbin);
+        let auth_mint_zkbin = ZkBinary::decode(&auth_mint_zkbin.1)?;
+        let auth_mint_circuit =
+            ZkCircuit::new(empty_witnesses(&auth_mint_zkbin)?, &auth_mint_zkbin);
 
-        println!("Creating token freeze circuit proving keys");
-        let freeze_pk = ProvingKey::build(freeze_zkbin.k, &token_freeze_circuit);
-        let freeze_builder = TokenFreezeCallBuilder {
+        println!("Creating auth token mint circuit proving keys");
+        let auth_mint_pk = ProvingKey::build(auth_mint_zkbin.k, &auth_mint_circuit);
+        let freeze_builder = AuthTokenFreezeCallBuilder {
             mint_keypair: mint_authority,
             token_attrs,
-            freeze_zkbin,
-            freeze_pk,
+            auth_mint_zkbin,
+            auth_mint_pk,
         };
 
         println!("Building transaction parameters");
         let debris = freeze_builder.build()?;
 
         // Encode and sign the transaction
-        let mut data = vec![MoneyFunction::TokenFreezeV1 as u8];
+        let mut data = vec![MoneyFunction::AuthTokenFreezeV1 as u8];
         debris.params.encode_async(&mut data).await?;
         let call = ContractCall { contract_id: *MONEY_CONTRACT_ID, data };
         let mut tx_builder =

+ 0 - 31
src/contract/money/proof/token_freeze_v1.zk

@@ -1,31 +0,0 @@
-k = 11;
-field = "pallas";
-
-constant "TokenFreeze_V1" {
-    EcFixedPointBase NULLIFIER_K,
-}
-
-witness "TokenFreeze_V1" {
-    # TokenAttributes {
-    Base token_auth_parent,
-    Base token_blind,
-    # }
-
-    # Secret key used by mint
-    Base mint_secret,
-}
-
-circuit "TokenFreeze_V1" {
-    # Derive public key for the mint authority
-    mint_public = ec_mul_base(mint_secret, NULLIFIER_K);
-    mint_x = ec_get_x(mint_public);
-    mint_y = ec_get_y(mint_public);
-    constrain_instance(mint_x);
-    constrain_instance(mint_y);
-
-    # Derive the token ID
-    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);
-}
-

+ 0 - 18
src/contract/money/proof/witness/token_freeze_v1.json

@@ -1,18 +0,0 @@
-{
-  "instances": [
-    "0x3aa3904484b7b8ab6da61d8ae91dd71a55be07168a37e310ac6a8c6c2568fcdc",
-    "0x0ce67a960b8d0092c1c49da2d8b476e7dd7bd3e18c4040749eba7fdd49c7b5fe",
-    "0x164c3bca30a1c347c26256e16be1816c4cb222c0c77750a2a98ef0917e90c5e7"
-  ],
-  "witnesses": [
-    {
-      "Base": "0x2edd443860b042d6eadf74f6787bc99befe5a5c5f1b23c3cc8fbfa9f7f063a3e"
-    },
-    {
-      "Base": "0x016cfc54f899ba57ff3946adbecc6a9c06bb99ae4b51854312c19042b06b0725"
-    },
-    {
-      "Base": "0x36e43135c0f58c3bf4201f9829f71f93d9727ecd5c804f184987cd71de7190ab"
-    }
-  ]
-}

+ 19 - 18
src/contract/money/src/client/token_freeze_v1.rs → src/contract/money/src/client/auth_token_freeze_v1.rs

@@ -25,29 +25,29 @@ use darkfi_sdk::crypto::Keypair;
 use log::info;
 use rand::rngs::OsRng;
 
-use crate::model::{MoneyTokenFreezeParamsV1, TokenAttributes};
+use crate::model::{MoneyAuthTokenFreezeParamsV1, TokenAttributes};
 
-pub struct TokenFreezeCallDebris {
-    pub params: MoneyTokenFreezeParamsV1,
+pub struct AuthTokenFreezeCallDebris {
+    pub params: MoneyAuthTokenFreezeParamsV1,
     pub proofs: Vec<Proof>,
 }
 
-/// Struct holding necessary information to build a `Money::TokenFreezeV1` contract call.
-pub struct TokenFreezeCallBuilder {
+/// Struct holding necessary information to build a `Money::AuthTokenFreezeV1` contract call.
+pub struct AuthTokenFreezeCallBuilder {
     /// Mint authority keypair
     pub mint_keypair: Keypair,
     pub token_attrs: TokenAttributes,
-    /// `TokenFreeze_V1` zkas circuit ZkBinary
-    pub freeze_zkbin: ZkBinary,
-    /// Proving key for the `TokenFreeze_V1` zk circuit,
-    pub freeze_pk: ProvingKey,
+    /// `AuthTokenMint_V1` zkas circuit ZkBinary
+    pub auth_mint_zkbin: ZkBinary,
+    /// Proving key for the `AuthTokenMint_V1` zk circuit,
+    pub auth_mint_pk: ProvingKey,
 }
 
-impl TokenFreezeCallBuilder {
-    pub fn build(&self) -> Result<TokenFreezeCallDebris> {
-        info!("Building Money::TokenFreezeV1 contract call");
+impl AuthTokenFreezeCallBuilder {
+    pub fn build(&self) -> Result<AuthTokenFreezeCallDebris> {
+        info!("Building Money::AuthTokenFreezeV1 contract call");
 
-        // For the TokenFreeze call, we just need to produce a valid signature,
+        // For the AuthTokenFreeze call, we just need to produce a valid signature,
         // and enforce the correct derivation inside ZK.
         let prover_witnesses = vec![
             // Token attributes
@@ -61,12 +61,13 @@ impl TokenFreezeCallBuilder {
         let token_id = self.token_attrs.to_token_id();
 
         let public_inputs = vec![mint_pubkey.x(), mint_pubkey.y(), token_id.inner()];
-        //darkfi::zk::export_witness_json("proof/witness/token_freeze_v1.json", &prover_witnesses, &public_inputs);
-        let circuit = ZkCircuit::new(prover_witnesses, &self.freeze_zkbin);
-        let proof = Proof::create(&self.freeze_pk, &[circuit], &public_inputs, &mut OsRng)?;
+        //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)?;
 
-        let params = MoneyTokenFreezeParamsV1 { mint_public: self.mint_keypair.public, token_id };
-        let debris = TokenFreezeCallDebris { params, proofs: vec![proof] };
+        let params =
+            MoneyAuthTokenFreezeParamsV1 { mint_public: self.mint_keypair.public, token_id };
+        let debris = AuthTokenFreezeCallDebris { params, proofs: vec![proof] };
         Ok(debris)
     }
 }

+ 11 - 11
src/contract/money/src/client/mod.rs

@@ -43,27 +43,27 @@ use crate::model::{Coin, Nullifier, TokenId};
 /// `Money::FeeV1` API
 pub mod fee_v1;
 
+/// `Money::GenesisMintV1` API
+pub mod genesis_mint_v1;
+
+/// `Money::PoWRewardV1` API
+pub mod pow_reward_v1;
+
 /// `Money::TransferV1` API
 pub mod transfer_v1;
 
 /// `Money::OtcSwapV1` API
 pub mod swap_v1;
 
-/// `Money::GenesisMintV1` API
-pub mod genesis_mint_v1;
+/// `Money::AuthTokenMintV1` API
+pub mod auth_token_mint_v1;
+
+/// `Money::AuthTokenFreezeV1` API
+pub mod auth_token_freeze_v1;
 
 /// `Money::TokenMintV1` API
 pub mod token_mint_v1;
 
-/// `Money::TokenFreezeV1` API
-pub mod token_freeze_v1;
-
-/// `Money::PoWRewardV1` API
-pub mod pow_reward_v1;
-
-/// `Money::AuthTokenMintV1` API
-pub mod auth_token_mint_v1;
-
 /// `MoneyNote` holds the inner attributes of a `Coin`
 /// It does not store the public key since it's encrypted for that key,
 /// and so is not needed to infer the coin attributes.

+ 64 - 64
src/contract/money/src/entrypoint.rs

@@ -29,8 +29,8 @@ use darkfi_serial::{deserialize, serialize, Encodable, WriteExt};
 use crate::{
     error::MoneyError,
     model::{
-        MoneyAuthTokenMintUpdateV1, MoneyFeeUpdateV1, MoneyGenesisMintUpdateV1,
-        MoneyPoWRewardUpdateV1, MoneyTokenFreezeUpdateV1, MoneyTokenMintUpdateV1,
+        MoneyAuthTokenFreezeUpdateV1, MoneyAuthTokenMintUpdateV1, MoneyFeeUpdateV1,
+        MoneyGenesisMintUpdateV1, MoneyPoWRewardUpdateV1, MoneyTokenMintUpdateV1,
         MoneyTransferUpdateV1,
     },
     MoneyFunction, EMPTY_COINS_TREE_ROOT, MONEY_CONTRACT_COINS_TREE,
@@ -46,6 +46,20 @@ use fee_v1::{
     money_fee_get_metadata_v1, money_fee_process_instruction_v1, money_fee_process_update_v1,
 };
 
+/// `Money::GenesisMint` functions
+mod genesis_mint_v1;
+use genesis_mint_v1::{
+    money_genesis_mint_get_metadata_v1, money_genesis_mint_process_instruction_v1,
+    money_genesis_mint_process_update_v1,
+};
+
+/// `Money::PoWReward` functions
+mod pow_reward_v1;
+use pow_reward_v1::{
+    money_pow_reward_get_metadata_v1, money_pow_reward_process_instruction_v1,
+    money_pow_reward_process_update_v1,
+};
+
 /// `Money::Transfer` functions
 mod transfer_v1;
 use transfer_v1::{
@@ -60,11 +74,18 @@ use swap_v1::{
     money_otcswap_process_update_v1,
 };
 
-/// `Money::GenesisMint` functions
-mod genesis_mint_v1;
-use genesis_mint_v1::{
-    money_genesis_mint_get_metadata_v1, money_genesis_mint_process_instruction_v1,
-    money_genesis_mint_process_update_v1,
+/// `Money::AuthTokenMint` functions
+mod auth_token_mint_v1;
+use auth_token_mint_v1::{
+    money_auth_token_mint_get_metadata_v1, money_auth_token_mint_process_instruction_v1,
+    money_auth_token_mint_process_update_v1,
+};
+
+/// `Money::AuthTokenFreeze` functions
+mod auth_token_freeze_v1;
+use auth_token_freeze_v1::{
+    money_auth_token_freeze_get_metadata_v1, money_auth_token_freeze_process_instruction_v1,
+    money_auth_token_freeze_process_update_v1,
 };
 
 /// `Money::TokenMint` functions
@@ -74,27 +95,6 @@ use token_mint_v1::{
     money_token_mint_process_update_v1,
 };
 
-/// `Money::TokenFreeze` functions
-mod token_freeze_v1;
-use token_freeze_v1::{
-    money_token_freeze_get_metadata_v1, money_token_freeze_process_instruction_v1,
-    money_token_freeze_process_update_v1,
-};
-
-/// `Money::PoWReward` functions
-mod pow_reward_v1;
-use pow_reward_v1::{
-    money_pow_reward_get_metadata_v1, money_pow_reward_process_instruction_v1,
-    money_pow_reward_process_update_v1,
-};
-
-/// `Money::AuthTokenMint` functions
-mod auth_token_mint_v1;
-use auth_token_mint_v1::{
-    money_auth_token_mint_get_metadata_v1, money_auth_token_mint_process_instruction_v1,
-    money_auth_token_mint_process_update_v1,
-};
-
 darkfi_sdk::define_contract!(
     init: init_contract,
     exec: process_instruction,
@@ -115,7 +115,6 @@ fn init_contract(cid: ContractId, _ix: &[u8]) -> ContractResult {
     let mint_v1_bincode = include_bytes!("../proof/mint_v1.zk.bin");
     let burn_v1_bincode = include_bytes!("../proof/burn_v1.zk.bin");
     let token_mint_v1_bincode = include_bytes!("../proof/token_mint_v1.zk.bin");
-    let token_frz_v1_bincode = include_bytes!("../proof/token_freeze_v1.zk.bin");
     let auth_token_mint_v1_bincode = include_bytes!("../proof/auth_token_mint_v1.zk.bin");
 
     // For that, we use `wasm::db::zkas_wasm::db::db_set` and pass in the bincode.
@@ -123,7 +122,6 @@ fn init_contract(cid: ContractId, _ix: &[u8]) -> ContractResult {
     wasm::db::zkas_db_set(&mint_v1_bincode[..])?;
     wasm::db::zkas_db_set(&burn_v1_bincode[..])?;
     wasm::db::zkas_db_set(&token_mint_v1_bincode[..])?;
-    wasm::db::zkas_db_set(&token_frz_v1_bincode[..])?;
     wasm::db::zkas_db_set(&auth_token_mint_v1_bincode[..])?;
 
     let tx_hash = wasm::util::get_tx_hash()?;
@@ -230,22 +228,24 @@ fn get_metadata(cid: ContractId, ix: &[u8]) -> ContractResult {
     let func = MoneyFunction::try_from(self_.data[0])?;
 
     let metadata = match func {
-        MoneyFunction::FeeV1 => money_fee_get_metadata_v1(cid, call_idx, calls)?,
-        MoneyFunction::TransferV1 => {
+        MoneyFunction::FeeV1 => {
             // We pass everything into the correct function, and it will return
             // the metadata for us, which we can then copy into the host with
             // the `wasm::util::set_return_data` function. On the host, this metadata will
             // be used to do external verification (zk proofs, and signatures).
-            money_transfer_get_metadata_v1(cid, call_idx, calls)?
+            money_fee_get_metadata_v1(cid, call_idx, calls)?
         }
-        MoneyFunction::OtcSwapV1 => money_otcswap_get_metadata_v1(cid, call_idx, calls)?,
         MoneyFunction::GenesisMintV1 => money_genesis_mint_get_metadata_v1(cid, call_idx, calls)?,
-        MoneyFunction::TokenMintV1 => money_token_mint_get_metadata_v1(cid, call_idx, calls)?,
-        MoneyFunction::TokenFreezeV1 => money_token_freeze_get_metadata_v1(cid, call_idx, calls)?,
         MoneyFunction::PoWRewardV1 => money_pow_reward_get_metadata_v1(cid, call_idx, calls)?,
+        MoneyFunction::TransferV1 => money_transfer_get_metadata_v1(cid, call_idx, calls)?,
+        MoneyFunction::OtcSwapV1 => money_otcswap_get_metadata_v1(cid, call_idx, calls)?,
         MoneyFunction::AuthTokenMintV1 => {
             money_auth_token_mint_get_metadata_v1(cid, call_idx, calls)?
         }
+        MoneyFunction::AuthTokenFreezeV1 => {
+            money_auth_token_freeze_get_metadata_v1(cid, call_idx, calls)?
+        }
+        MoneyFunction::TokenMintV1 => money_token_mint_get_metadata_v1(cid, call_idx, calls)?,
     };
 
     wasm::util::set_return_data(&metadata)
@@ -261,31 +261,31 @@ fn process_instruction(cid: ContractId, ix: &[u8]) -> ContractResult {
     let func = MoneyFunction::try_from(self_.data[0])?;
 
     let update_data = match func {
-        MoneyFunction::FeeV1 => money_fee_process_instruction_v1(cid, call_idx, calls)?,
-        MoneyFunction::TransferV1 => {
+        MoneyFunction::FeeV1 => {
             // Again, we pass everything into the correct function.
             // If it executes successfully, we'll get a state update
             // which we can copy into the host using `wasm::util::set_return_data`.
             // This update can then be written with `process_update()`
             // if everything is in order.
-            money_transfer_process_instruction_v1(cid, call_idx, calls)?
+            money_fee_process_instruction_v1(cid, call_idx, calls)?
         }
-        MoneyFunction::OtcSwapV1 => money_otcswap_process_instruction_v1(cid, call_idx, calls)?,
         MoneyFunction::GenesisMintV1 => {
             money_genesis_mint_process_instruction_v1(cid, call_idx, calls)?
         }
-        MoneyFunction::TokenMintV1 => {
-            money_token_mint_process_instruction_v1(cid, call_idx, calls)?
-        }
-        MoneyFunction::TokenFreezeV1 => {
-            money_token_freeze_process_instruction_v1(cid, call_idx, calls)?
-        }
         MoneyFunction::PoWRewardV1 => {
             money_pow_reward_process_instruction_v1(cid, call_idx, calls)?
         }
+        MoneyFunction::TransferV1 => money_transfer_process_instruction_v1(cid, call_idx, calls)?,
+        MoneyFunction::OtcSwapV1 => money_otcswap_process_instruction_v1(cid, call_idx, calls)?,
         MoneyFunction::AuthTokenMintV1 => {
             money_auth_token_mint_process_instruction_v1(cid, call_idx, calls)?
         }
+        MoneyFunction::AuthTokenFreezeV1 => {
+            money_auth_token_freeze_process_instruction_v1(cid, call_idx, calls)?
+        }
+        MoneyFunction::TokenMintV1 => {
+            money_token_mint_process_instruction_v1(cid, call_idx, calls)?
+        }
     };
 
     wasm::util::set_return_data(&update_data)
@@ -302,6 +302,16 @@ fn process_update(cid: ContractId, update_data: &[u8]) -> ContractResult {
             Ok(money_fee_process_update_v1(cid, update)?)
         }
 
+        MoneyFunction::GenesisMintV1 => {
+            let update: MoneyGenesisMintUpdateV1 = deserialize(&update_data[1..])?;
+            Ok(money_genesis_mint_process_update_v1(cid, update)?)
+        }
+
+        MoneyFunction::PoWRewardV1 => {
+            let update: MoneyPoWRewardUpdateV1 = deserialize(&update_data[1..])?;
+            Ok(money_pow_reward_process_update_v1(cid, update)?)
+        }
+
         MoneyFunction::TransferV1 => {
             let update: MoneyTransferUpdateV1 = deserialize(&update_data[1..])?;
             Ok(money_transfer_process_update_v1(cid, update)?)
@@ -314,29 +324,19 @@ fn process_update(cid: ContractId, update_data: &[u8]) -> ContractResult {
             Ok(money_otcswap_process_update_v1(cid, update)?)
         }
 
-        MoneyFunction::GenesisMintV1 => {
-            let update: MoneyGenesisMintUpdateV1 = deserialize(&update_data[1..])?;
-            Ok(money_genesis_mint_process_update_v1(cid, update)?)
+        MoneyFunction::AuthTokenMintV1 => {
+            let update: MoneyAuthTokenMintUpdateV1 = deserialize(&update_data[1..])?;
+            Ok(money_auth_token_mint_process_update_v1(cid, update)?)
+        }
+
+        MoneyFunction::AuthTokenFreezeV1 => {
+            let update: MoneyAuthTokenFreezeUpdateV1 = deserialize(&update_data[1..])?;
+            Ok(money_auth_token_freeze_process_update_v1(cid, update)?)
         }
 
         MoneyFunction::TokenMintV1 => {
             let update: MoneyTokenMintUpdateV1 = deserialize(&update_data[1..])?;
             Ok(money_token_mint_process_update_v1(cid, update)?)
         }
-
-        MoneyFunction::TokenFreezeV1 => {
-            let update: MoneyTokenFreezeUpdateV1 = deserialize(&update_data[1..])?;
-            Ok(money_token_freeze_process_update_v1(cid, update)?)
-        }
-
-        MoneyFunction::PoWRewardV1 => {
-            let update: MoneyPoWRewardUpdateV1 = deserialize(&update_data[1..])?;
-            Ok(money_pow_reward_process_update_v1(cid, update)?)
-        }
-
-        MoneyFunction::AuthTokenMintV1 => {
-            let update: MoneyAuthTokenMintUpdateV1 = deserialize(&update_data[1..])?;
-            Ok(money_auth_token_mint_process_update_v1(cid, update)?)
-        }
     }
 }

+ 14 - 14
src/contract/money/src/entrypoint/token_freeze_v1.rs → src/contract/money/src/entrypoint/auth_token_freeze_v1.rs

@@ -28,18 +28,18 @@ use darkfi_serial::{deserialize, serialize, Encodable, WriteExt};
 
 use crate::{
     error::MoneyError,
-    model::{MoneyTokenFreezeParamsV1, MoneyTokenFreezeUpdateV1},
-    MoneyFunction, MONEY_CONTRACT_TOKEN_FREEZE_TREE, MONEY_CONTRACT_ZKAS_TOKEN_FRZ_NS_V1,
+    model::{MoneyAuthTokenFreezeParamsV1, MoneyAuthTokenFreezeUpdateV1},
+    MoneyFunction, MONEY_CONTRACT_TOKEN_FREEZE_TREE, MONEY_CONTRACT_ZKAS_AUTH_TOKEN_MINT_NS_V1,
 };
 
-/// `get_metadata` function for `Money::TokenFreezeV1`
-pub(crate) fn money_token_freeze_get_metadata_v1(
+/// `get_metadata` function for `Money::AuthTokenFreezeV1`
+pub(crate) fn money_auth_token_freeze_get_metadata_v1(
     _cid: ContractId,
     call_idx: usize,
     calls: Vec<DarkLeaf<ContractCall>>,
 ) -> Result<Vec<u8>, ContractError> {
     let self_ = &calls[call_idx].data;
-    let params: MoneyTokenFreezeParamsV1 = deserialize(&self_.data[1..])?;
+    let params: MoneyAuthTokenFreezeParamsV1 = deserialize(&self_.data[1..])?;
 
     // Public inputs for the ZK proofs we have to verify
     let mut zk_public_inputs: Vec<(String, Vec<pallas::Base>)> = vec![];
@@ -51,7 +51,7 @@ pub(crate) fn money_token_freeze_get_metadata_v1(
 
     // In ZK we just verify that the token ID is properly derived from the authority.
     zk_public_inputs.push((
-        MONEY_CONTRACT_ZKAS_TOKEN_FRZ_NS_V1.to_string(),
+        MONEY_CONTRACT_ZKAS_AUTH_TOKEN_MINT_NS_V1.to_string(),
         vec![mint_x, mint_y, params.token_id.inner()],
     ));
 
@@ -63,14 +63,14 @@ pub(crate) fn money_token_freeze_get_metadata_v1(
     Ok(metadata)
 }
 
-/// `process_instruction` function for `Money::TokenFreezeV1`
-pub(crate) fn money_token_freeze_process_instruction_v1(
+/// `process_instruction` function for `Money::AuthTokenFreezeV1`
+pub(crate) fn money_auth_token_freeze_process_instruction_v1(
     cid: ContractId,
     call_idx: usize,
     calls: Vec<DarkLeaf<ContractCall>>,
 ) -> Result<Vec<u8>, ContractError> {
     let self_ = &calls[call_idx].data;
-    let params: MoneyTokenFreezeParamsV1 = deserialize(&self_.data[1..])?;
+    let params: MoneyAuthTokenFreezeParamsV1 = deserialize(&self_.data[1..])?;
 
     // We just check if the mint was already frozen beforehand
     let token_freeze_db = wasm::db::db_lookup(cid, MONEY_CONTRACT_TOKEN_FREEZE_TREE)?;
@@ -82,18 +82,18 @@ pub(crate) fn money_token_freeze_process_instruction_v1(
     }
 
     // Create a state update. We only need the new coin.
-    let update = MoneyTokenFreezeUpdateV1 { token_id: params.token_id };
+    let update = MoneyAuthTokenFreezeUpdateV1 { token_id: params.token_id };
     let mut update_data = vec![];
-    update_data.write_u8(MoneyFunction::TokenFreezeV1 as u8)?;
+    update_data.write_u8(MoneyFunction::AuthTokenFreezeV1 as u8)?;
     update.encode(&mut update_data)?;
 
     Ok(update_data)
 }
 
-/// `process_update` function for `Money::TokenFreezeV1`
-pub(crate) fn money_token_freeze_process_update_v1(
+/// `process_update` function for `Money::AuthTokenFreezeV1`
+pub(crate) fn money_auth_token_freeze_process_update_v1(
     cid: ContractId,
-    update: MoneyTokenFreezeUpdateV1,
+    update: MoneyAuthTokenFreezeUpdateV1,
 ) -> ContractResult {
     let token_freeze_db = wasm::db::db_lookup(cid, MONEY_CONTRACT_TOKEN_FREEZE_TREE)?;
     msg!("[MintV1] Freezing mint for token {}", update.token_id);

+ 2 - 4
src/contract/money/src/lib.rs

@@ -31,7 +31,7 @@ pub enum MoneyFunction {
     TransferV1 = 0x03,
     OtcSwapV1 = 0x04,
     AuthTokenMintV1 = 0x05,
-    TokenFreezeV1 = 0x06,
+    AuthTokenFreezeV1 = 0x06,
     TokenMintV1 = 0x07,
 }
 // ANCHOR_END: money-function
@@ -47,7 +47,7 @@ impl TryFrom<u8> for MoneyFunction {
             0x03 => Ok(Self::TransferV1),
             0x04 => Ok(Self::OtcSwapV1),
             0x05 => Ok(Self::AuthTokenMintV1),
-            0x06 => Ok(Self::TokenFreezeV1),
+            0x06 => Ok(Self::AuthTokenFreezeV1),
             0x07 => Ok(Self::TokenMintV1),
             _ => Err(ContractError::InvalidFunction),
         }
@@ -98,7 +98,5 @@ pub const MONEY_CONTRACT_ZKAS_MINT_NS_V1: &str = "Mint_V1";
 pub const MONEY_CONTRACT_ZKAS_BURN_NS_V1: &str = "Burn_V1";
 /// zkas token auth mint circuit namespace
 pub const MONEY_CONTRACT_ZKAS_AUTH_TOKEN_MINT_NS_V1: &str = "AuthTokenMint_V1";
-/// zkas token freeze circuit namespace
-pub const MONEY_CONTRACT_ZKAS_TOKEN_FRZ_NS_V1: &str = "TokenFreeze_V1";
 /// zkas token mint circuit namespace
 pub const MONEY_CONTRACT_ZKAS_TOKEN_MINT_NS_V1: &str = "TokenMint_V1";

+ 6 - 6
src/contract/money/src/model/mod.rs

@@ -242,7 +242,7 @@ pub struct MoneyTokenMintUpdateV1 {
     pub coin: Coin,
 }
 
-/// Parameters for `Money::auth_token_mint()`
+/// Parameters for `Money::AuthTokenMint`
 #[derive(Clone, Debug, SerialEncodable, SerialDecodable)]
 pub struct MoneyAuthTokenMintParamsV1 {
     pub token_id: TokenId,
@@ -250,13 +250,13 @@ pub struct MoneyAuthTokenMintParamsV1 {
     pub mint_pubkey: PublicKey,
 }
 
-/// State update for `Money::auth_token_mint()`
+/// State update for `Money::AuthTokenMint`
 #[derive(Clone, Debug, SerialEncodable, SerialDecodable)]
 pub struct MoneyAuthTokenMintUpdateV1 {}
 
-/// Parameters for `Money::TokenFreeze`
+/// Parameters for `Money::AuthTokenFreeze`
 #[derive(Clone, Debug, SerialEncodable, SerialDecodable)]
-pub struct MoneyTokenFreezeParamsV1 {
+pub struct MoneyAuthTokenFreezeParamsV1 {
     /// Mint authority public key
     ///
     /// We use this to derive the token ID and verify the signature.
@@ -264,9 +264,9 @@ pub struct MoneyTokenFreezeParamsV1 {
     pub token_id: TokenId,
 }
 
-/// State update for `Money::TokenFreeze`
+/// State update for `Money::AuthTokenFreeze`
 #[derive(Clone, Debug, SerialEncodable, SerialDecodable)]
-pub struct MoneyTokenFreezeUpdateV1 {
+pub struct MoneyAuthTokenFreezeUpdateV1 {
     pub token_id: TokenId,
 }
 

+ 13 - 13
src/contract/test-harness/src/money_token.rs

@@ -23,15 +23,15 @@ use darkfi::{
 };
 use darkfi_money_contract::{
     client::{
-        auth_token_mint_v1::AuthTokenMintCallBuilder, token_freeze_v1::TokenFreezeCallBuilder,
-        token_mint_v1::TokenMintCallBuilder, MoneyNote, OwnCoin,
+        auth_token_freeze_v1::AuthTokenFreezeCallBuilder,
+        auth_token_mint_v1::AuthTokenMintCallBuilder, token_mint_v1::TokenMintCallBuilder,
+        MoneyNote, OwnCoin,
     },
     model::{
-        CoinAttributes, MoneyAuthTokenMintParamsV1, MoneyFeeParamsV1, MoneyTokenFreezeParamsV1,
+        CoinAttributes, MoneyAuthTokenFreezeParamsV1, MoneyAuthTokenMintParamsV1, MoneyFeeParamsV1,
         MoneyTokenMintParamsV1, TokenAttributes,
     },
-    MoneyFunction, MONEY_CONTRACT_ZKAS_AUTH_TOKEN_MINT_NS_V1, MONEY_CONTRACT_ZKAS_TOKEN_FRZ_NS_V1,
-    MONEY_CONTRACT_ZKAS_TOKEN_MINT_NS_V1,
+    MoneyFunction, MONEY_CONTRACT_ZKAS_AUTH_TOKEN_MINT_NS_V1, MONEY_CONTRACT_ZKAS_TOKEN_MINT_NS_V1,
 };
 use darkfi_sdk::{
     crypto::{poseidon_hash, BaseBlind, Blind, FuncId, FuncRef, MerkleNode, MONEY_CONTRACT_ID},
@@ -251,12 +251,12 @@ impl TestHarness {
         &mut self,
         holder: &Holder,
         block_height: u32,
-    ) -> Result<(Transaction, MoneyTokenFreezeParamsV1, Option<MoneyFeeParamsV1>)> {
+    ) -> Result<(Transaction, MoneyAuthTokenFreezeParamsV1, Option<MoneyFeeParamsV1>)> {
         let wallet = self.holders.get(holder).unwrap();
         let mint_authority = wallet.token_mint_authority;
 
-        let (frz_pk, frz_zkbin) =
-            self.proving_keys.get(MONEY_CONTRACT_ZKAS_TOKEN_FRZ_NS_V1).unwrap();
+        let (auth_mint_pk, auth_mint_zkbin) =
+            self.proving_keys.get(MONEY_CONTRACT_ZKAS_AUTH_TOKEN_MINT_NS_V1).unwrap();
 
         let auth_func_id = FuncRef {
             contract_id: *MONEY_CONTRACT_ID,
@@ -274,14 +274,14 @@ impl TestHarness {
         };
 
         // Create the freeze call
-        let builder = TokenFreezeCallBuilder {
+        let builder = AuthTokenFreezeCallBuilder {
             mint_keypair: mint_authority,
             token_attrs,
-            freeze_zkbin: frz_zkbin.clone(),
-            freeze_pk: frz_pk.clone(),
+            auth_mint_pk: auth_mint_pk.clone(),
+            auth_mint_zkbin: auth_mint_zkbin.clone(),
         };
         let freeze_debris = builder.build()?;
-        let mut data = vec![MoneyFunction::TokenFreezeV1 as u8];
+        let mut data = vec![MoneyFunction::AuthTokenFreezeV1 as u8];
         freeze_debris.params.encode_async(&mut data).await?;
         let freeze_call = ContractCall { contract_id: *MONEY_CONTRACT_ID, data };
 
@@ -327,7 +327,7 @@ impl TestHarness {
         &mut self,
         holder: &Holder,
         tx: Transaction,
-        _freeze_params: &MoneyTokenFreezeParamsV1,
+        _freeze_params: &MoneyAuthTokenFreezeParamsV1,
         fee_params: &Option<MoneyFeeParamsV1>,
         block_height: u32,
         append: bool,

+ 3 - 5
src/contract/test-harness/src/vks.rs

@@ -39,7 +39,7 @@ use darkfi_dao_contract::{
 use darkfi_money_contract::{
     MONEY_CONTRACT_ZKAS_AUTH_TOKEN_MINT_NS_V1, MONEY_CONTRACT_ZKAS_BURN_NS_V1,
     MONEY_CONTRACT_ZKAS_FEE_NS_V1, MONEY_CONTRACT_ZKAS_MINT_NS_V1,
-    MONEY_CONTRACT_ZKAS_TOKEN_FRZ_NS_V1, MONEY_CONTRACT_ZKAS_TOKEN_MINT_NS_V1,
+    MONEY_CONTRACT_ZKAS_TOKEN_MINT_NS_V1,
 };
 use darkfi_sdk::crypto::{DAO_CONTRACT_ID, MONEY_CONTRACT_ID};
 use darkfi_serial::{deserialize, serialize};
@@ -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 = "74c32f44649aed0ef51193a64df15f2375fb81482479e49d6b3f53bab7ea102a";
-const VKS_HASH: &str = "ef943017346bc794b8dafa0b494e965d979352bc254e1549b52f5e1df38710bf";
+const PKS_HASH: &str = "e8de97d286a4a31606f96dfd13bb5a6e9dfa49322573b8cd1fe936aee7e33e58";
+const VKS_HASH: &str = "aa59b5e53c10c994c127beb443d6b1b4c21ee7417ce1a4f717c82431b7b8c8d9";
 
 /// Build a `PathBuf` to a cachefile
 fn cache_path(typ: &str) -> Result<PathBuf> {
@@ -125,7 +125,6 @@ pub fn get_cached_pks_and_vks() -> Result<(Pks, Vks)> {
         &include_bytes!("../../money/proof/mint_v1.zk.bin")[..],
         &include_bytes!("../../money/proof/burn_v1.zk.bin")[..],
         &include_bytes!("../../money/proof/token_mint_v1.zk.bin")[..],
-        &include_bytes!("../../money/proof/token_freeze_v1.zk.bin")[..],
         &include_bytes!("../../money/proof/auth_token_mint_v1.zk.bin")[..],
         // DAO
         &include_bytes!("../../dao/proof/mint.zk.bin")[..],
@@ -193,7 +192,6 @@ pub fn inject(sled_db: &sled::Db, vks: &Vks) -> Result<()> {
             MONEY_CONTRACT_ZKAS_MINT_NS_V1 |
             MONEY_CONTRACT_ZKAS_BURN_NS_V1 |
             MONEY_CONTRACT_ZKAS_TOKEN_MINT_NS_V1 |
-            MONEY_CONTRACT_ZKAS_TOKEN_FRZ_NS_V1 |
             MONEY_CONTRACT_ZKAS_AUTH_TOKEN_MINT_NS_V1 => {
                 let key = serialize(&namespace.as_str());
                 let value = serialize(&(bincode.clone(), vk.clone()));