diff --git a/.gitignore b/.gitignore index 6a1402a47..ad2331397 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ /cashierd /dao /daod +/dhtd /darkfid /darkotc /dnetview diff --git a/bin/drk/src/rpc_token.rs b/bin/drk/src/rpc_token.rs index 53719bf6d..6eb6be4f0 100644 --- a/bin/drk/src/rpc_token.rs +++ b/bin/drk/src/rpc_token.rs @@ -24,7 +24,7 @@ use darkfi::{ zkas::ZkBinary, }; use darkfi_money_contract::{ - client::{freeze_v1::FreezeCallBuilder, mint_v1::MintCallBuilder}, + client::{token_freeze_v1::TokenFreezeCallBuilder, token_mint_v1::TokenMintCallBuilder}, MoneyFunction, MONEY_CONTRACT_ZKAS_TOKEN_FRZ_NS_V1, MONEY_CONTRACT_ZKAS_TOKEN_MINT_NS_V1, }; use darkfi_sdk::{ @@ -80,7 +80,7 @@ impl Drk { ZkCircuit::new(empty_witnesses(&token_mint_zkbin), token_mint_zkbin.clone()); eprintln!("Creating token mint circuit proving keys"); - let mint_builder = MintCallBuilder { + let mint_builder = TokenMintCallBuilder { mint_authority, recipient, amount, @@ -94,7 +94,7 @@ impl Drk { let debris = mint_builder.build()?; // Encode and sign the transaction - let mut data = vec![MoneyFunction::MintV1 as u8]; + let mut data = vec![MoneyFunction::TokenMintV1 as u8]; debris.params.encode(&mut data)?; let calls = vec![ContractCall { contract_id: *MONEY_CONTRACT_ID, data }]; let proofs = vec![debris.proofs]; @@ -133,7 +133,7 @@ impl Drk { ZkCircuit::new(empty_witnesses(&token_freeze_zkbin), token_freeze_zkbin.clone()); eprintln!("Creating token freeze circuit proving keys"); - let freeze_builder = FreezeCallBuilder { + let freeze_builder = TokenFreezeCallBuilder { mint_authority, token_freeze_zkbin, token_freeze_pk: ProvingKey::build(k, &token_freeze_circuit), @@ -143,7 +143,7 @@ impl Drk { let debris = freeze_builder.build()?; // Encode and sign the transaction - let mut data = vec![MoneyFunction::FreezeV1 as u8]; + let mut data = vec![MoneyFunction::TokenFreezeV1 as u8]; debris.params.encode(&mut data)?; let calls = vec![ContractCall { contract_id: *MONEY_CONTRACT_ID, data }]; let proofs = vec![debris.proofs]; diff --git a/bin/drk/src/wallet_money.rs b/bin/drk/src/wallet_money.rs index 55ecac3aa..4b3b6eff1 100644 --- a/bin/drk/src/wallet_money.rs +++ b/bin/drk/src/wallet_money.rs @@ -32,7 +32,7 @@ use darkfi_money_contract::{ MONEY_KEYS_COL_SECRET, MONEY_KEYS_TABLE, MONEY_TOKENS_COL_IS_FROZEN, MONEY_TOKENS_COL_TOKEN_ID, MONEY_TOKENS_TABLE, MONEY_TREE_COL_TREE, MONEY_TREE_TABLE, }, - model::{MoneyFreezeParamsV1, MoneyMintParamsV1, MoneyTransferParamsV1, Output}, + model::{MoneyTokenFreezeParamsV1, MoneyTokenMintParamsV1, MoneyTransferParamsV1, Output}, MoneyFunction, }; use darkfi_sdk::{ @@ -520,18 +520,18 @@ impl Drk { continue } - if call.contract_id == cid && call.data[0] == MoneyFunction::MintV1 as u8 { + if call.contract_id == cid && call.data[0] == MoneyFunction::TokenMintV1 as u8 { eprintln!("Found Money::MintV1 in call {}", i); - let params: MoneyMintParamsV1 = deserialize(&call.data[1..])?; + let params: MoneyTokenMintParamsV1 = deserialize(&call.data[1..])?; outputs.push(params.output); continue } - if call.contract_id == cid && call.data[0] == MoneyFunction::FreezeV1 as u8 { + if call.contract_id == cid && call.data[0] == MoneyFunction::TokenFreezeV1 as u8 { eprintln!("Found Money::FreezeV1 in call {}", i); - let params: MoneyFreezeParamsV1 = deserialize(&call.data[1..])?; + let params: MoneyTokenFreezeParamsV1 = deserialize(&call.data[1..])?; let (mint_x, mint_y) = params.signature_public.xy(); let token_id = TokenId::from(poseidon_hash([mint_x, mint_y])); diff --git a/src/contract/dao/tests/integration.rs b/src/contract/dao/tests/integration.rs index 14d921f1f..1e00af3e3 100644 --- a/src/contract/dao/tests/integration.rs +++ b/src/contract/dao/tests/integration.rs @@ -36,8 +36,8 @@ use darkfi_dao_contract::{ }; use darkfi_money_contract::{ - client::mint_v1::MintCallBuilder, - model::{MoneyMintParamsV1, MoneyTransferParamsV1}, + client::token_mint_v1::TokenMintCallBuilder, + model::{MoneyTokenMintParamsV1, MoneyTransferParamsV1}, MoneyFunction, }; @@ -266,7 +266,7 @@ async fn integration_test() -> Result<()> { let spend_hook = pallas::Base::from(0); let user_data = pallas::Base::from(0); - let mut builder = MintCallBuilder { + let mut builder = TokenMintCallBuilder { mint_authority: gdrk_mint_auth, recipient: dao_th.alice_kp.public, amount: 400000, @@ -287,7 +287,7 @@ async fn integration_test() -> Result<()> { assert!(2 * 400000 + 200000 == gdrk_supply); // This should actually be 3 calls in a single tx, but w/e. - let mut data = vec![MoneyFunction::MintV1 as u8]; + let mut data = vec![MoneyFunction::TokenMintV1 as u8]; debris1.params.encode(&mut data)?; let calls = vec![ContractCall { contract_id: *MONEY_CONTRACT_ID, data }]; let proofs = vec![debris1.proofs]; @@ -295,7 +295,7 @@ async fn integration_test() -> Result<()> { let sigs = tx1.create_sigs(&mut OsRng, &[gdrk_mint_auth.secret])?; tx1.signatures = vec![sigs]; - let mut data = vec![MoneyFunction::MintV1 as u8]; + let mut data = vec![MoneyFunction::TokenMintV1 as u8]; debris2.params.encode(&mut data)?; let calls = vec![ContractCall { contract_id: *MONEY_CONTRACT_ID, data }]; let proofs = vec![debris2.proofs]; @@ -303,7 +303,7 @@ async fn integration_test() -> Result<()> { let sigs = tx2.create_sigs(&mut OsRng, &[gdrk_mint_auth.secret])?; tx2.signatures = vec![sigs]; - let mut data = vec![MoneyFunction::MintV1 as u8]; + let mut data = vec![MoneyFunction::TokenMintV1 as u8]; debris3.params.encode(&mut data)?; let calls = vec![ContractCall { contract_id: *MONEY_CONTRACT_ID, data }]; let proofs = vec![debris3.proofs]; @@ -325,7 +325,7 @@ async fn integration_test() -> Result<()> { assert_eq!(tx.calls.len(), 1); let calldata = &tx.calls[0].data; let params_data = &calldata[1..]; - let params: MoneyMintParamsV1 = Decodable::decode(params_data)?; + let params: MoneyTokenMintParamsV1 = Decodable::decode(params_data)?; cache.try_decrypt_note(params.output.coin, ¶ms.output.note); } } diff --git a/src/contract/money/src/client/genesis_mint_v1.rs b/src/contract/money/src/client/genesis_mint_v1.rs index 357cbe9dd..5b4d6b2c1 100644 --- a/src/contract/money/src/client/genesis_mint_v1.rs +++ b/src/contract/money/src/client/genesis_mint_v1.rs @@ -36,11 +36,11 @@ use crate::{ }, MoneyNote, }, - model::{ClearInput, MoneyMintParamsV1, Output}, + model::{ClearInput, MoneyTokenMintParamsV1, Output}, }; pub struct GenesisMintCallDebris { - pub params: MoneyMintParamsV1, + pub params: MoneyTokenMintParamsV1, pub proofs: Vec, } @@ -156,7 +156,7 @@ impl GenesisMintCallBuilder { note: encrypted_note, }; - let params = MoneyMintParamsV1 { input: c_input, output: c_output }; + let params = MoneyTokenMintParamsV1 { input: c_input, output: c_output }; let debris = GenesisMintCallDebris { params, proofs: vec![proof] }; Ok(debris) } diff --git a/src/contract/money/src/client/mod.rs b/src/contract/money/src/client/mod.rs index 158cc99dd..a03528178 100644 --- a/src/contract/money/src/client/mod.rs +++ b/src/contract/money/src/client/mod.rs @@ -41,11 +41,11 @@ pub mod swap_v1; /// `Money::GenesisMintV1` API pub mod genesis_mint_v1; -/// `Money::MintV1` API -pub mod mint_v1; +/// `Money::TokenMintV1` API +pub mod token_mint_v1; -/// `Money::FreezeV1` API -pub mod freeze_v1; +/// `Money::TokenFreezeV1` API +pub mod token_freeze_v1; /// `Money::StakeV1` API pub mod stake_v1; diff --git a/src/contract/money/src/client/freeze_v1.rs b/src/contract/money/src/client/token_freeze_v1.rs similarity index 77% rename from src/contract/money/src/client/freeze_v1.rs rename to src/contract/money/src/client/token_freeze_v1.rs index 676fde8ab..d5366b8ae 100644 --- a/src/contract/money/src/client/freeze_v1.rs +++ b/src/contract/money/src/client/token_freeze_v1.rs @@ -28,10 +28,10 @@ use darkfi_sdk::{ use log::{debug, info}; use rand::rngs::OsRng; -use crate::model::MoneyFreezeParamsV1; +use crate::model::MoneyTokenFreezeParamsV1; -pub struct FreezeCallDebris { - pub params: MoneyFreezeParamsV1, +pub struct TokenFreezeCallDebris { + pub params: MoneyTokenFreezeParamsV1, pub proofs: Vec, } @@ -45,8 +45,8 @@ impl TokenFreezeRevealed { } } -/// Struct holding necessary information to build a `Money::FreezeV1` contract call. -pub struct FreezeCallBuilder { +/// Struct holding necessary information to build a `Money::TokenFreezeV1` contract call. +pub struct TokenFreezeCallBuilder { /// Mint authority keypair pub mint_authority: Keypair, /// `TokenFreeze_V1` zkas circuit ZkBinary @@ -55,22 +55,21 @@ pub struct FreezeCallBuilder { pub token_freeze_pk: ProvingKey, } -impl FreezeCallBuilder { - pub fn build(&self) -> Result { - debug!("Building Money::FreezeV1 contract call"); +impl TokenFreezeCallBuilder { + pub fn build(&self) -> Result { + info!("Building Money::TokenFreezeV1 contract call"); - // For the Freeze call, we just need to produce a valid signature, + // For the TokenFreeze call, we just need to produce a valid signature, // and enforce the correct derivation inside ZK. - - info!("Creating token freeze proof"); + debug!("Creating token freeze ZK proof"); let (proof, _public_inputs) = create_token_freeze_proof( &self.token_freeze_zkbin, &self.token_freeze_pk, &self.mint_authority, )?; - let params = MoneyFreezeParamsV1 { signature_public: self.mint_authority.public }; - let debris = FreezeCallDebris { params, proofs: vec![proof] }; + let params = MoneyTokenFreezeParamsV1 { signature_public: self.mint_authority.public }; + let debris = TokenFreezeCallDebris { params, proofs: vec![proof] }; Ok(debris) } } diff --git a/src/contract/money/src/client/mint_v1.rs b/src/contract/money/src/client/token_mint_v1.rs similarity index 92% rename from src/contract/money/src/client/mint_v1.rs rename to src/contract/money/src/client/token_mint_v1.rs index 47c96b49d..363da32c9 100644 --- a/src/contract/money/src/client/mint_v1.rs +++ b/src/contract/money/src/client/token_mint_v1.rs @@ -28,7 +28,7 @@ use darkfi_sdk::{ }, pasta::pallas, }; -use log::{debug, info}; +use log::info; use rand::rngs::OsRng; use crate::{ @@ -36,11 +36,11 @@ use crate::{ transfer_v1::{TransactionBuilderClearInputInfo, TransactionBuilderOutputInfo}, MoneyNote, }, - model::{ClearInput, MoneyMintParamsV1, Output}, + model::{ClearInput, MoneyTokenMintParamsV1, Output}, }; -pub struct MintCallDebris { - pub params: MoneyMintParamsV1, +pub struct TokenMintCallDebris { + pub params: MoneyTokenMintParamsV1, pub proofs: Vec, } @@ -69,8 +69,8 @@ impl TokenMintRevealed { } } -/// Struct holding necessary information to build a `Money::MintV1` contract call. -pub struct MintCallBuilder { +/// Struct holding necessary information to build a `Money::TokenMintV1` contract call. +pub struct TokenMintCallBuilder { /// Mint authority keypair pub mint_authority: Keypair, /// Recipient of the minted tokens @@ -87,9 +87,9 @@ pub struct MintCallBuilder { pub token_mint_pk: ProvingKey, } -impl MintCallBuilder { - pub fn build(&self) -> Result { - debug!("Building Money::MintV1 contract call"); +impl TokenMintCallBuilder { + pub fn build(&self) -> Result { + info!("Building Money::TokenMintV1 contract call"); assert!(self.amount != 0); // In this call, we will build one clear input and one anonymous output. @@ -162,8 +162,8 @@ impl MintCallBuilder { note: encrypted_note, }; - let params = MoneyMintParamsV1 { input: c_input, output: c_output }; - let debris = MintCallDebris { params, proofs: vec![proof] }; + let params = MoneyTokenMintParamsV1 { input: c_input, output: c_output }; + let debris = TokenMintCallDebris { params, proofs: vec![proof] }; Ok(debris) } } diff --git a/src/contract/money/src/entrypoint.rs b/src/contract/money/src/entrypoint.rs index 431600479..aada40131 100644 --- a/src/contract/money/src/entrypoint.rs +++ b/src/contract/money/src/entrypoint.rs @@ -28,8 +28,8 @@ use darkfi_serial::{deserialize, serialize, Encodable, WriteExt}; use crate::{ model::{ - MoneyFreezeUpdateV1, MoneyMintUpdateV1, MoneyStakeUpdateV1, MoneyTransferUpdateV1, - MoneyUnstakeUpdateV1, + MoneyStakeUpdateV1, MoneyTokenFreezeUpdateV1, MoneyTokenMintUpdateV1, + MoneyTransferUpdateV1, MoneyUnstakeUpdateV1, }, MoneyFunction, MONEY_CONTRACT_COINS_TREE, MONEY_CONTRACT_COIN_MERKLE_TREE, MONEY_CONTRACT_COIN_ROOTS_TREE, MONEY_CONTRACT_DB_VERSION, MONEY_CONTRACT_FAUCET_PUBKEYS, @@ -56,17 +56,18 @@ use genesis_mint_v1::{ money_genesis_mint_get_metadata_v1, money_genesis_mint_process_instruction_v1, }; -/// `Money::Mint` functions -mod mint_v1; -use mint_v1::{ - money_mint_get_metadata_v1, money_mint_process_instruction_v1, money_mint_process_update_v1, +/// `Money::TokenMint` functions +mod token_mint_v1; +use token_mint_v1::{ + money_token_mint_get_metadata_v1, money_token_mint_process_instruction_v1, + money_token_mint_process_update_v1, }; -/// `Money::Freeze` functions -mod freeze_v1; -use freeze_v1::{ - money_freeze_get_metadata_v1, money_freeze_process_instruction_v1, - money_freeze_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::Stake` functions @@ -198,13 +199,13 @@ fn get_metadata(cid: ContractId, ix: &[u8]) -> ContractResult { Ok(set_return_data(&metadata)?) } - MoneyFunction::MintV1 => { - let metadata = money_mint_get_metadata_v1(cid, call_idx, calls)?; + MoneyFunction::TokenMintV1 => { + let metadata = money_token_mint_get_metadata_v1(cid, call_idx, calls)?; Ok(set_return_data(&metadata)?) } - MoneyFunction::FreezeV1 => { - let metadata = money_freeze_get_metadata_v1(cid, call_idx, calls)?; + MoneyFunction::TokenFreezeV1 => { + let metadata = money_token_freeze_get_metadata_v1(cid, call_idx, calls)?; Ok(set_return_data(&metadata)?) } @@ -251,13 +252,13 @@ fn process_instruction(cid: ContractId, ix: &[u8]) -> ContractResult { Ok(set_return_data(&update_data)?) } - MoneyFunction::MintV1 => { - let update_data = money_mint_process_instruction_v1(cid, call_idx, calls)?; + MoneyFunction::TokenMintV1 => { + let update_data = money_token_mint_process_instruction_v1(cid, call_idx, calls)?; Ok(set_return_data(&update_data)?) } - MoneyFunction::FreezeV1 => { - let update_data = money_freeze_process_instruction_v1(cid, call_idx, calls)?; + MoneyFunction::TokenFreezeV1 => { + let update_data = money_token_freeze_process_instruction_v1(cid, call_idx, calls)?; Ok(set_return_data(&update_data)?) } @@ -292,19 +293,19 @@ fn process_update(cid: ContractId, update_data: &[u8]) -> ContractResult { } MoneyFunction::GenesisMintV1 => { - // GenesisMint uses the same update as normal Mint - let update: MoneyMintUpdateV1 = deserialize(&update_data[1..])?; - Ok(money_mint_process_update_v1(cid, update)?) + // FIXME: GenesisMint uses the same update as `TokenMintV1` + let update: MoneyTokenMintUpdateV1 = deserialize(&update_data[1..])?; + Ok(money_token_mint_process_update_v1(cid, update)?) } - MoneyFunction::MintV1 => { - let update: MoneyMintUpdateV1 = deserialize(&update_data[1..])?; - Ok(money_mint_process_update_v1(cid, update)?) + MoneyFunction::TokenMintV1 => { + let update: MoneyTokenMintUpdateV1 = deserialize(&update_data[1..])?; + Ok(money_token_mint_process_update_v1(cid, update)?) } - MoneyFunction::FreezeV1 => { - let update: MoneyFreezeUpdateV1 = deserialize(&update_data[1..])?; - Ok(money_freeze_process_update_v1(cid, update)?) + MoneyFunction::TokenFreezeV1 => { + let update: MoneyTokenFreezeUpdateV1 = deserialize(&update_data[1..])?; + Ok(money_token_freeze_process_update_v1(cid, update)?) } MoneyFunction::StakeV1 => { diff --git a/src/contract/money/src/entrypoint/genesis_mint_v1.rs b/src/contract/money/src/entrypoint/genesis_mint_v1.rs index f1eeb2aa8..5d54a0408 100644 --- a/src/contract/money/src/entrypoint/genesis_mint_v1.rs +++ b/src/contract/money/src/entrypoint/genesis_mint_v1.rs @@ -32,7 +32,7 @@ use darkfi_serial::{deserialize, serialize, Encodable, WriteExt}; use crate::{ error::MoneyError, - model::{MoneyMintParamsV1, MoneyMintUpdateV1}, + model::{MoneyTokenMintParamsV1, MoneyTokenMintUpdateV1}, MoneyFunction, MONEY_CONTRACT_COINS_TREE, MONEY_CONTRACT_ZKAS_MINT_NS_V1, }; @@ -43,7 +43,7 @@ pub(crate) fn money_genesis_mint_get_metadata_v1( calls: Vec, ) -> Result, ContractError> { let self_ = &calls[call_idx as usize]; - let params: MoneyMintParamsV1 = deserialize(&self_.data[1..])?; + let params: MoneyTokenMintParamsV1 = deserialize(&self_.data[1..])?; // Public inputs for the ZK proofs we have to verify let mut zk_public_inputs: Vec<(String, Vec)> = vec![]; @@ -80,7 +80,7 @@ pub(crate) fn money_genesis_mint_process_instruction_v1( calls: Vec, ) -> Result, ContractError> { let self_ = &calls[call_idx as usize]; - let params: MoneyMintParamsV1 = deserialize(&self_.data[1..])?; + let params: MoneyTokenMintParamsV1 = deserialize(&self_.data[1..])?; // Verify this contract call is verified against on genesis slot(0). let verifying_slot = get_verifying_slot(); @@ -123,9 +123,9 @@ pub(crate) fn money_genesis_mint_process_instruction_v1( } // Create a state update. We only need the new coin. - let update = MoneyMintUpdateV1 { coin: params.output.coin }; + let update = MoneyTokenMintUpdateV1 { coin: params.output.coin }; let mut update_data = vec![]; - update_data.write_u8(MoneyFunction::MintV1 as u8)?; + update_data.write_u8(MoneyFunction::TokenMintV1 as u8)?; update.encode(&mut update_data)?; Ok(update_data) diff --git a/src/contract/money/src/entrypoint/freeze_v1.rs b/src/contract/money/src/entrypoint/token_freeze_v1.rs similarity index 80% rename from src/contract/money/src/entrypoint/freeze_v1.rs rename to src/contract/money/src/entrypoint/token_freeze_v1.rs index f3bb0b439..25d8d9791 100644 --- a/src/contract/money/src/entrypoint/freeze_v1.rs +++ b/src/contract/money/src/entrypoint/token_freeze_v1.rs @@ -28,18 +28,18 @@ use darkfi_serial::{deserialize, serialize, Encodable, WriteExt}; use crate::{ error::MoneyError, - model::{MoneyFreezeParamsV1, MoneyFreezeUpdateV1}, + model::{MoneyTokenFreezeParamsV1, MoneyTokenFreezeUpdateV1}, MoneyFunction, MONEY_CONTRACT_TOKEN_FREEZE_TREE, MONEY_CONTRACT_ZKAS_TOKEN_FRZ_NS_V1, }; -/// `get_metadata` function for `Money::FreezeV1` -pub(crate) fn money_freeze_get_metadata_v1( +/// `get_metadata` function for `Money::TokenFreezeV1` +pub(crate) fn money_token_freeze_get_metadata_v1( _cid: ContractId, call_idx: u32, calls: Vec, ) -> Result, ContractError> { let self_ = &calls[call_idx as usize]; - let params: MoneyFreezeParamsV1 = deserialize(&self_.data[1..])?; + let params: MoneyTokenFreezeParamsV1 = deserialize(&self_.data[1..])?; // Public inputs for the ZK proofs we have to verify let mut zk_public_inputs: Vec<(String, Vec)> = vec![]; @@ -60,14 +60,14 @@ pub(crate) fn money_freeze_get_metadata_v1( Ok(metadata) } -/// `process_instruction` function for `Money::FreezeV1` -pub(crate) fn money_freeze_process_instruction_v1( +/// `process_instruction` function for `Money::TokenFreezeV1` +pub(crate) fn money_token_freeze_process_instruction_v1( cid: ContractId, call_idx: u32, calls: Vec, ) -> Result, ContractError> { let self_ = &calls[call_idx as usize]; - let params: MoneyFreezeParamsV1 = deserialize(&self_.data[1..])?; + let params: MoneyTokenFreezeParamsV1 = deserialize(&self_.data[1..])?; // We just check if the mint was already frozen beforehand let token_freeze_db = db_lookup(cid, MONEY_CONTRACT_TOKEN_FREEZE_TREE)?; @@ -78,22 +78,22 @@ pub(crate) fn money_freeze_process_instruction_v1( // Check that the mint is not frozen if db_contains_key(token_freeze_db, &serialize(&token_id))? { msg!("[MintV1] Error: Token mint for {} is frozen", token_id); - return Err(MoneyError::MintFrozen.into()) + return Err(MoneyError::TokenMintFrozen.into()) } // Create a state update. We only need the new coin. - let update = MoneyFreezeUpdateV1 { signature_public: params.signature_public }; + let update = MoneyTokenFreezeUpdateV1 { signature_public: params.signature_public }; let mut update_data = vec![]; - update_data.write_u8(MoneyFunction::FreezeV1 as u8)?; + update_data.write_u8(MoneyFunction::TokenFreezeV1 as u8)?; update.encode(&mut update_data)?; Ok(update_data) } -/// `process_update` function for `Money::FreezeV1` -pub(crate) fn money_freeze_process_update_v1( +/// `process_update` function for `Money::TokenFreezeV1` +pub(crate) fn money_token_freeze_process_update_v1( cid: ContractId, - update: MoneyFreezeUpdateV1, + update: MoneyTokenFreezeUpdateV1, ) -> ContractResult { let token_freeze_db = db_lookup(cid, MONEY_CONTRACT_TOKEN_FREEZE_TREE)?; diff --git a/src/contract/money/src/entrypoint/mint_v1.rs b/src/contract/money/src/entrypoint/token_mint_v1.rs similarity index 88% rename from src/contract/money/src/entrypoint/mint_v1.rs rename to src/contract/money/src/entrypoint/token_mint_v1.rs index 037020153..38d68e492 100644 --- a/src/contract/money/src/entrypoint/mint_v1.rs +++ b/src/contract/money/src/entrypoint/token_mint_v1.rs @@ -31,20 +31,20 @@ use darkfi_serial::{deserialize, serialize, Encodable, WriteExt}; use crate::{ error::MoneyError, - model::{MoneyMintParamsV1, MoneyMintUpdateV1}, + model::{MoneyTokenMintParamsV1, MoneyTokenMintUpdateV1}, MoneyFunction, MONEY_CONTRACT_COINS_TREE, MONEY_CONTRACT_COIN_MERKLE_TREE, MONEY_CONTRACT_COIN_ROOTS_TREE, MONEY_CONTRACT_INFO_TREE, MONEY_CONTRACT_TOKEN_FREEZE_TREE, MONEY_CONTRACT_ZKAS_TOKEN_MINT_NS_V1, }; -/// `get_metadata` function for `Money::MintV1` -pub(crate) fn money_mint_get_metadata_v1( +/// `get_metadata` function for `Money::TokenMintV1` +pub(crate) fn money_token_mint_get_metadata_v1( _cid: ContractId, call_idx: u32, calls: Vec, ) -> Result, ContractError> { let self_ = &calls[call_idx as usize]; - let params: MoneyMintParamsV1 = deserialize(&self_.data[1..])?; + let params: MoneyTokenMintParamsV1 = deserialize(&self_.data[1..])?; // Public inputs for the ZK proofs we have to verify let mut zk_public_inputs: Vec<(String, Vec)> = vec![]; @@ -82,14 +82,14 @@ pub(crate) fn money_mint_get_metadata_v1( Ok(metadata) } -/// `process_instruction` function for `Money::MintV1` -pub(crate) fn money_mint_process_instruction_v1( +/// `process_instruction` function for `Money::TokenMintV1` +pub(crate) fn money_token_mint_process_instruction_v1( cid: ContractId, call_idx: u32, calls: Vec, ) -> Result, ContractError> { let self_ = &calls[call_idx as usize]; - let params: MoneyMintParamsV1 = deserialize(&self_.data[1..])?; + let params: MoneyTokenMintParamsV1 = deserialize(&self_.data[1..])?; // We have to check if the token mint is frozen, and if by some chance // the minted coin has existed already. @@ -107,7 +107,7 @@ pub(crate) fn money_mint_process_instruction_v1( // Check that the mint is not frozen if db_contains_key(token_freeze_db, &serialize(&token_id))? { msg!("[MintV1] Error: Token mint for {} is frozen", token_id); - return Err(MoneyError::MintFrozen.into()) + return Err(MoneyError::TokenMintFrozen.into()) } // Check that the coin from the output hasn't existed before @@ -134,18 +134,18 @@ pub(crate) fn money_mint_process_instruction_v1( } // Create a state update. We only need the new coin. - let update = MoneyMintUpdateV1 { coin: params.output.coin }; + let update = MoneyTokenMintUpdateV1 { coin: params.output.coin }; let mut update_data = vec![]; - update_data.write_u8(MoneyFunction::MintV1 as u8)?; + update_data.write_u8(MoneyFunction::TokenMintV1 as u8)?; update.encode(&mut update_data)?; Ok(update_data) } -/// `process_update` function for `Money::MintV1` -pub(crate) fn money_mint_process_update_v1( +/// `process_update` function for `Money::TokenMintV1` +pub(crate) fn money_token_mint_process_update_v1( cid: ContractId, - update: MoneyMintUpdateV1, + update: MoneyTokenMintUpdateV1, ) -> ContractResult { // Grab all db handles we want to work on let info_db = db_lookup(cid, MONEY_CONTRACT_INFO_TREE)?; diff --git a/src/contract/money/src/error.rs b/src/contract/money/src/error.rs index e767a2a34..f27cbe957 100644 --- a/src/contract/money/src/error.rs +++ b/src/contract/money/src/error.rs @@ -74,7 +74,7 @@ pub enum MoneyError { TokenIdDoesNotDeriveFromMint, #[error("Token mint is frozen")] - MintFrozen, + TokenMintFrozen, #[error("Input used non-native token")] StakeInputNonNativeToken, @@ -136,7 +136,7 @@ impl From for ContractError { MoneyError::SpendHookNonZero => Self::Custom(15), MoneyError::SwapMerkleRootNotFound => Self::Custom(16), MoneyError::TokenIdDoesNotDeriveFromMint => Self::Custom(17), - MoneyError::MintFrozen => Self::Custom(18), + MoneyError::TokenMintFrozen => Self::Custom(18), MoneyError::StakeInputNonNativeToken => Self::Custom(19), MoneyError::StakeMissingSpendHook => Self::Custom(20), MoneyError::StakeMissingNullifier => Self::Custom(21), diff --git a/src/contract/money/src/lib.rs b/src/contract/money/src/lib.rs index 0ab80e5c3..ee39a97ff 100644 --- a/src/contract/money/src/lib.rs +++ b/src/contract/money/src/lib.rs @@ -24,12 +24,12 @@ use darkfi_sdk::error::ContractError; /// Functions available in the contract #[repr(u8)] pub enum MoneyFunction { - TransferV1 = 0x00, - OtcSwapV1 = 0x01, - GenesisMintV1 = 0x02, - MintV1 = 0x03, - FreezeV1 = 0x04, - //Fee = 0x05, + //Fee = 0x00, + GenesisMintV1 = 0x01, + TransferV1 = 0x02, + OtcSwapV1 = 0x03, + TokenMintV1 = 0x04, + TokenFreezeV1 = 0x05, StakeV1 = 0x06, UnstakeV1 = 0x07, } @@ -39,12 +39,12 @@ impl TryFrom for MoneyFunction { fn try_from(b: u8) -> core::result::Result { match b { - 0x00 => Ok(Self::TransferV1), - 0x01 => Ok(Self::OtcSwapV1), - 0x02 => Ok(Self::GenesisMintV1), - 0x03 => Ok(Self::MintV1), - 0x04 => Ok(Self::FreezeV1), - //0x05 => Ok(Self::Fee), + //0x00 => Ok(Self::Fee), + 0x01 => Ok(Self::GenesisMintV1), + 0x02 => Ok(Self::TransferV1), + 0x03 => Ok(Self::OtcSwapV1), + 0x04 => Ok(Self::TokenMintV1), + 0x05 => Ok(Self::TokenFreezeV1), 0x06 => Ok(Self::StakeV1), 0x07 => Ok(Self::UnstakeV1), _ => Err(ContractError::InvalidFunction), diff --git a/src/contract/money/src/model.rs b/src/contract/money/src/model.rs index f54b11dea..05180d264 100644 --- a/src/contract/money/src/model.rs +++ b/src/contract/money/src/model.rs @@ -117,33 +117,34 @@ pub struct MoneyTransferUpdateV1 { pub coins: Vec, } -/// Parameters for `Money::Mint` +/// Parameters for `Money::TokenMint` #[derive(Clone, Debug, SerialEncodable, SerialDecodable)] -pub struct MoneyMintParamsV1 { +pub struct MoneyTokenMintParamsV1 { /// Clear input pub input: ClearInput, /// Anonymous output pub output: Output, } -/// State update for `Money::Mint` +/// State update for `Money::TokenMint` #[derive(Clone, Debug, SerialEncodable, SerialDecodable)] -pub struct MoneyMintUpdateV1 { +pub struct MoneyTokenMintUpdateV1 { /// The newly minted coin pub coin: Coin, } -/// Parameters for `Money::Freeze` +/// Parameters for `Money::TokenFreeze` #[derive(Clone, Debug, SerialEncodable, SerialDecodable)] -pub struct MoneyFreezeParamsV1 { +pub struct MoneyTokenFreezeParamsV1 { /// Mint authority public key - /// We also use this to derive the token ID + /// + /// We use this to derive the token ID and verify the signature. pub signature_public: PublicKey, } -/// State update for `Money::Freeze` +/// State update for `Money::TokenFreeze` #[derive(Clone, Debug, SerialEncodable, SerialDecodable)] -pub struct MoneyFreezeUpdateV1 { +pub struct MoneyTokenFreezeUpdateV1 { /// Mint authority public key pub signature_public: PublicKey, } diff --git a/src/contract/money/tests/harness.rs b/src/contract/money/tests/harness.rs index b995057b7..b7058a97a 100644 --- a/src/contract/money/tests/harness.rs +++ b/src/contract/money/tests/harness.rs @@ -41,10 +41,10 @@ use rand::rngs::OsRng; use darkfi_money_contract::{ client::{ - freeze_v1::FreezeCallBuilder, mint_v1::MintCallBuilder, transfer_v1::TransferCallBuilder, - OwnCoin, + token_freeze_v1::TokenFreezeCallBuilder, token_mint_v1::TokenMintCallBuilder, + transfer_v1::TransferCallBuilder, OwnCoin, }, - model::{MoneyFreezeParamsV1, MoneyMintParamsV1, MoneyTransferParamsV1}, + model::{MoneyTokenFreezeParamsV1, MoneyTokenMintParamsV1, MoneyTransferParamsV1}, MoneyFunction, MONEY_CONTRACT_ZKAS_BURN_NS_V1, MONEY_CONTRACT_ZKAS_MINT_NS_V1, MONEY_CONTRACT_ZKAS_TOKEN_FRZ_NS_V1, MONEY_CONTRACT_ZKAS_TOKEN_MINT_NS_V1, }; @@ -202,11 +202,11 @@ impl MoneyTestHarness { mint_authority: Keypair, amount: u64, recipient: PublicKey, - ) -> Result<(Transaction, MoneyMintParamsV1)> { + ) -> Result<(Transaction, MoneyTokenMintParamsV1)> { let (token_mint_pk, token_mint_zkbin) = self.proving_keys.get(&MONEY_CONTRACT_ZKAS_TOKEN_MINT_NS_V1).unwrap(); - let builder = MintCallBuilder { + let builder = TokenMintCallBuilder { mint_authority, recipient, amount, @@ -218,7 +218,7 @@ impl MoneyTestHarness { let debris = builder.build()?; - let mut data = vec![MoneyFunction::MintV1 as u8]; + let mut data = vec![MoneyFunction::TokenMintV1 as u8]; debris.params.encode(&mut data)?; let calls = vec![ContractCall { contract_id: *MONEY_CONTRACT_ID, data }]; let proofs = vec![debris.proofs]; @@ -232,18 +232,18 @@ impl MoneyTestHarness { pub fn freeze_token( &self, mint_authority: Keypair, - ) -> Result<(Transaction, MoneyFreezeParamsV1)> { + ) -> Result<(Transaction, MoneyTokenFreezeParamsV1)> { let (token_freeze_pk, token_freeze_zkbin) = self.proving_keys.get(&MONEY_CONTRACT_ZKAS_TOKEN_FRZ_NS_V1).unwrap(); - let builder = FreezeCallBuilder { + let builder = TokenFreezeCallBuilder { mint_authority, token_freeze_zkbin: token_freeze_zkbin.clone(), token_freeze_pk: token_freeze_pk.clone(), }; let debris = builder.build()?; - let mut data = vec![MoneyFunction::FreezeV1 as u8]; + let mut data = vec![MoneyFunction::TokenFreezeV1 as u8]; debris.params.encode(&mut data)?; let calls = vec![ContractCall { contract_id: *MONEY_CONTRACT_ID, data }]; let proofs = vec![debris.proofs];