contracts: use DarkLeaf in calls vec

This commit is contained in:
aggstam
2023-12-18 16:01:31 +02:00
parent e7857b0a30
commit a84a3e3f70
21 changed files with 110 additions and 90 deletions

View File

@@ -26,6 +26,7 @@ use darkfi_money_contract::{
};
use darkfi_sdk::{
crypto::{ContractId, MerkleTree},
dark_tree::DarkLeaf,
db::{db_init, db_lookup, db_set, zkas_db_set},
error::{ContractError, ContractResult},
msg,
@@ -171,13 +172,13 @@ fn init_contract(cid: ContractId, _ix: &[u8]) -> ContractResult {
/// for verifying signatures and zk proofs. The payload given here are all the
/// contract calls in the transaction.
fn get_metadata(cid: ContractId, ix: &[u8]) -> ContractResult {
let (call_idx, calls): (u32, Vec<ContractCall>) = deserialize(ix)?;
let (call_idx, calls): (u32, Vec<DarkLeaf<ContractCall>>) = deserialize(ix)?;
if call_idx >= calls.len() as u32 {
msg!("Error: call_idx >= calls.len()");
return Err(ContractError::Internal)
}
match ConsensusFunction::try_from(calls[call_idx as usize].data[0])? {
match ConsensusFunction::try_from(calls[call_idx as usize].data.data[0])? {
ConsensusFunction::GenesisStakeV1 => {
// We pass everything into the correct function, and it will return
// the metadata for us, which we can then copy into the host with
@@ -209,13 +210,13 @@ fn get_metadata(cid: ContractId, ix: &[u8]) -> ContractResult {
/// if everything is successful. This step should happen **after** the host
/// has successfully verified the metadata from `get_metadata()`.
fn process_instruction(cid: ContractId, ix: &[u8]) -> ContractResult {
let (call_idx, calls): (u32, Vec<ContractCall>) = deserialize(ix)?;
let (call_idx, calls): (u32, Vec<DarkLeaf<ContractCall>>) = deserialize(ix)?;
if call_idx >= calls.len() as u32 {
msg!("Error: call_idx >= calls.len()");
return Err(ContractError::Internal)
}
match ConsensusFunction::try_from(calls[call_idx as usize].data[0])? {
match ConsensusFunction::try_from(calls[call_idx as usize].data.data[0])? {
ConsensusFunction::GenesisStakeV1 => {
// Again, we pass everything into the correct function.
// If it executes successfully, we'll get a state update

View File

@@ -24,6 +24,7 @@ use darkfi_money_contract::{
};
use darkfi_sdk::{
crypto::{pasta_prelude::*, pedersen_commitment_u64, ContractId, MerkleNode, DARK_TOKEN_ID},
dark_tree::DarkLeaf,
db::{db_contains_key, db_lookup, db_set},
error::{ContractError, ContractResult},
merkle_add, msg,
@@ -46,9 +47,9 @@ use crate::{
pub(crate) fn consensus_genesis_stake_get_metadata_v1(
_cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: ConsensusGenesisStakeParamsV1 = deserialize(&self_.data[1..])?;
// Public inputs for the ZK proofs we have to verify
@@ -79,9 +80,9 @@ pub(crate) fn consensus_genesis_stake_get_metadata_v1(
pub(crate) fn consensus_genesis_stake_process_instruction_v1(
cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: ConsensusGenesisStakeParamsV1 = deserialize(&self_.data[1..])?;
// Verify this contract call is verified on the genesis slot (0).

View File

@@ -25,6 +25,7 @@ use darkfi_money_contract::{
use darkfi_sdk::{
blockchain::Slot,
crypto::{pasta_prelude::*, pedersen_commitment_u64, poseidon_hash, ContractId, MerkleNode},
dark_tree::DarkLeaf,
db::{db_contains_key, db_lookup, db_set},
error::{ContractError, ContractResult},
merkle_add, msg,
@@ -47,9 +48,9 @@ use crate::{
pub(crate) fn consensus_proposal_get_metadata_v1(
_cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: ConsensusProposalParamsV1 = deserialize(&self_.data[1..])?;
// Public inputs for the ZK proofs we have to verify
@@ -150,9 +151,9 @@ pub(crate) fn consensus_proposal_get_metadata_v1(
pub(crate) fn consensus_proposal_process_instruction_v1(
cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: ConsensusProposalParamsV1 = deserialize(&self_.data[1..])?;
let input = &params.input;
let output = &params.output;

View File

@@ -27,6 +27,7 @@ use darkfi_money_contract::{
};
use darkfi_sdk::{
crypto::{pasta_prelude::*, ContractId, MerkleNode, PublicKey, MONEY_CONTRACT_ID},
dark_tree::DarkLeaf,
db::{db_contains_key, db_lookup, db_set},
error::{ContractError, ContractResult},
merkle_add, msg,
@@ -42,9 +43,9 @@ use crate::ConsensusFunction;
pub(crate) fn consensus_stake_get_metadata_v1(
_cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: ConsensusStakeParamsV1 = deserialize(&self_.data[1..])?;
// Public inputs for the ZK proofs we have to verify
@@ -79,9 +80,9 @@ pub(crate) fn consensus_stake_get_metadata_v1(
pub(crate) fn consensus_stake_process_instruction_v1(
cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: ConsensusStakeParamsV1 = deserialize(&self_.data[1..])?;
// Check previous call is money contract
@@ -93,7 +94,7 @@ pub(crate) fn consensus_stake_process_instruction_v1(
// Verify previous call corresponds to Money::StakeV1
let previous_call_idx = call_idx - 1;
let previous = &calls[previous_call_idx as usize];
let previous = &calls[previous_call_idx as usize].data;
if previous.contract_id.inner() != MONEY_CONTRACT_ID.inner() {
msg!("[ConsensusStakeV1] Error: Previous contract call is not money contract");
return Err(MoneyError::StakePreviousCallNotMoneyContract.into())

View File

@@ -25,6 +25,7 @@ use darkfi_money_contract::{
};
use darkfi_sdk::{
crypto::{pasta_prelude::*, ContractId, MerkleNode},
dark_tree::DarkLeaf,
db::{db_contains_key, db_lookup, db_set},
error::{ContractError, ContractResult},
merkle_add, msg,
@@ -44,9 +45,9 @@ use crate::{
pub(crate) fn consensus_unstake_request_get_metadata_v1(
_cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: ConsensusUnstakeReqParamsV1 = deserialize(&self_.data[1..])?;
let input = &params.input;
let output = &params.output;
@@ -100,9 +101,9 @@ pub(crate) fn consensus_unstake_request_get_metadata_v1(
pub(crate) fn consensus_unstake_request_process_instruction_v1(
cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: ConsensusUnstakeReqParamsV1 = deserialize(&self_.data[1..])?;
let input = &params.input;
let output = &params.output;

View File

@@ -24,6 +24,7 @@ use darkfi_money_contract::{
};
use darkfi_sdk::{
crypto::{pasta_prelude::*, ContractId, MONEY_CONTRACT_ID},
dark_tree::DarkLeaf,
db::{db_contains_key, db_lookup, db_set},
error::{ContractError, ContractResult},
msg,
@@ -39,9 +40,9 @@ use crate::{error::ConsensusError, model::GRACE_PERIOD, ConsensusFunction};
pub(crate) fn consensus_unstake_get_metadata_v1(
_cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: ConsensusUnstakeParamsV1 = deserialize(&self_.data[1..])?;
let input = &params.input;
@@ -82,9 +83,9 @@ pub(crate) fn consensus_unstake_get_metadata_v1(
pub(crate) fn consensus_unstake_process_instruction_v1(
cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: ConsensusUnstakeParamsV1 = deserialize(&self_.data[1..])?;
let input = &params.input;
@@ -104,7 +105,7 @@ pub(crate) fn consensus_unstake_process_instruction_v1(
return Err(MoneyError::CallIdxOutOfBounds.into())
}
let next = &calls[next_call_idx as usize];
let next = &calls[next_call_idx as usize].data;
if next.contract_id.inner() != MONEY_CONTRACT_ID.inner() {
msg!("[ConsensusUnstakeV1] Error: Next contract call is not money contract");
return Err(MoneyError::UnstakeNextCallNotMoneyContract.into())

View File

@@ -20,6 +20,7 @@ use std::io::Cursor;
use darkfi_sdk::{
crypto::{ContractId, MerkleTree},
dark_tree::DarkLeaf,
db::{db_get, db_init, db_lookup, db_set, zkas_db_set},
error::{ContractError, ContractResult},
msg,
@@ -142,13 +143,13 @@ fn init_contract(cid: ContractId, _ix: &[u8]) -> ContractResult {
/// for verifying signatures and ZK proofs. The payload given here are all the
/// contract calls in the transaction.
fn get_metadata(cid: ContractId, ix: &[u8]) -> ContractResult {
let (call_idx, calls): (u32, Vec<ContractCall>) = deserialize(ix)?;
let (call_idx, calls): (u32, Vec<DarkLeaf<ContractCall>>) = deserialize(ix)?;
if call_idx >= calls.len() as u32 {
msg!("[DAO:get_metadata()] Error: call_idx >= calls.len()");
return Err(ContractError::Internal)
}
match DaoFunction::try_from(calls[call_idx as usize].data[0])? {
match DaoFunction::try_from(calls[call_idx as usize].data.data[0])? {
DaoFunction::Mint => {
let metadata = dao_mint_get_metadata(cid, call_idx, calls)?;
Ok(set_return_data(&metadata)?)
@@ -174,13 +175,13 @@ fn get_metadata(cid: ContractId, ix: &[u8]) -> ContractResult {
/// This function verifies a state transition and produces a state update
/// if everything is successful.
fn process_instruction(cid: ContractId, ix: &[u8]) -> ContractResult {
let (call_idx, calls): (u32, Vec<ContractCall>) = deserialize(ix)?;
let (call_idx, calls): (u32, Vec<DarkLeaf<ContractCall>>) = deserialize(ix)?;
if call_idx >= calls.len() as u32 {
msg!("[DAO::process_instruction()] Error: call_idx >= calls.len()");
return Err(ContractError::Internal)
}
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let func = DaoFunction::try_from(self_.data[0])?;
if calls.len() != 1 {

View File

@@ -19,6 +19,7 @@
use darkfi_money_contract::{model::MoneyTransferParamsV1, MoneyFunction};
use darkfi_sdk::{
crypto::{contract_id::MONEY_CONTRACT_ID, pasta_prelude::*, ContractId, PublicKey},
dark_tree::DarkLeaf,
db::{db_del, db_get, db_lookup},
error::{ContractError, ContractResult},
msg,
@@ -37,15 +38,15 @@ use crate::{
pub(crate) fn dao_exec_get_metadata(
cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
assert_eq!(call_idx, 1);
assert_eq!(calls.len(), 2);
let money_call = &calls[0];
let money_call = &calls[0].data;
let money_xfer_params: MoneyTransferParamsV1 = deserialize(&money_call.data[1..])?;
let dao_call = &calls[1];
let dao_call = &calls[1].data;
let dao_exec_params: DaoExecParams = deserialize(&dao_call.data[1..])?;
// Public inputs for the ZK proofs we have to verify
@@ -98,9 +99,9 @@ pub(crate) fn dao_exec_get_metadata(
pub(crate) fn dao_exec_process_instruction(
cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: DaoExecParams = deserialize(&self_.data[1..])?;
// ==========================================
@@ -108,14 +109,14 @@ pub(crate) fn dao_exec_process_instruction(
// ==========================================
if calls.len() != 2 ||
call_idx != 1 ||
calls[0].contract_id != *MONEY_CONTRACT_ID ||
calls[0].data[0] != MoneyFunction::TransferV1 as u8
calls[0].data.contract_id != *MONEY_CONTRACT_ID ||
calls[0].data.data[0] != MoneyFunction::TransferV1 as u8
{
msg!("[Dao::Exec] Error: Transaction has incorrect format");
return Err(DaoError::ExecCallInvalidFormat.into())
}
let mt_params: MoneyTransferParamsV1 = deserialize(&calls[0].data[1..])?;
let mt_params: MoneyTransferParamsV1 = deserialize(&calls[0].data.data[1..])?;
// MoneyTransfer should all have the same user_data set.
// We check this by ensuring that user_data_enc is also the same for all inputs.

View File

@@ -18,6 +18,7 @@
use darkfi_sdk::{
crypto::{ContractId, MerkleNode, PublicKey},
dark_tree::DarkLeaf,
db::{db_contains_key, db_lookup, db_set},
error::{ContractError, ContractResult},
merkle_add, msg,
@@ -38,9 +39,9 @@ use crate::{
pub(crate) fn dao_mint_get_metadata(
_cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: DaoMintParams = deserialize(&self_.data[1..])?;
// Public inputs for the ZK proofs we have to verify
@@ -68,9 +69,9 @@ pub(crate) fn dao_mint_get_metadata(
pub(crate) fn dao_mint_process_instruction(
cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: DaoMintParams = deserialize(&self_.data[1..])?;
// Check the DAO bulla doesn't already exist

View File

@@ -21,6 +21,7 @@ use darkfi_money_contract::{
};
use darkfi_sdk::{
crypto::{contract_id::MONEY_CONTRACT_ID, pasta_prelude::*, ContractId, MerkleNode, PublicKey},
dark_tree::DarkLeaf,
db::{db_contains_key, db_get, db_lookup, db_set},
error::{ContractError, ContractResult},
msg,
@@ -40,9 +41,9 @@ use crate::{
pub(crate) fn dao_propose_get_metadata(
_cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: DaoProposeParams = deserialize(&self_.data[1..])?;
if params.inputs.is_empty() {
@@ -103,9 +104,9 @@ pub(crate) fn dao_propose_get_metadata(
pub(crate) fn dao_propose_process_instruction(
cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: DaoProposeParams = deserialize(&self_.data[1..])?;
// Check the Merkle roots for the input coins are valid

View File

@@ -19,6 +19,7 @@
use darkfi_money_contract::MONEY_CONTRACT_NULLIFIERS_TREE;
use darkfi_sdk::{
crypto::{contract_id::MONEY_CONTRACT_ID, pasta_prelude::*, ContractId, PublicKey},
dark_tree::DarkLeaf,
db::{db_contains_key, db_get, db_lookup, db_set},
error::{ContractError, ContractResult},
msg,
@@ -38,9 +39,9 @@ use crate::{
pub(crate) fn dao_vote_get_metadata(
_cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: DaoVoteParams = deserialize(&self_.data[1..])?;
if params.inputs.is_empty() {
@@ -110,9 +111,9 @@ pub(crate) fn dao_vote_get_metadata(
pub(crate) fn dao_vote_process_instruction(
cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: DaoVoteParams = deserialize(&self_.data[1..])?;
// Check proposal bulla exists

View File

@@ -18,6 +18,7 @@
use darkfi_sdk::{
crypto::{pasta_prelude::Field, ContractId, MerkleNode, MerkleTree, PublicKey},
dark_tree::DarkLeaf,
db::{db_init, db_lookup, db_set, zkas_db_set},
error::{ContractError, ContractResult},
msg,
@@ -185,13 +186,13 @@ fn init_contract(cid: ContractId, ix: &[u8]) -> ContractResult {
/// for verifying signatures and zk proofs. The payload given here are all the
/// contract calls in the transaction.
fn get_metadata(cid: ContractId, ix: &[u8]) -> ContractResult {
let (call_idx, calls): (u32, Vec<ContractCall>) = deserialize(ix)?;
let (call_idx, calls): (u32, Vec<DarkLeaf<ContractCall>>) = deserialize(ix)?;
if call_idx >= calls.len() as u32 {
msg!("Error: call_idx >= calls.len()");
return Err(ContractError::Internal)
}
match MoneyFunction::try_from(calls[call_idx as usize].data[0])? {
match MoneyFunction::try_from(calls[call_idx as usize].data.data[0])? {
MoneyFunction::TransferV1 => {
// We pass everything into the correct function, and it will return
// the metadata for us, which we can then copy into the host with
@@ -242,13 +243,13 @@ fn get_metadata(cid: ContractId, ix: &[u8]) -> ContractResult {
/// if everything is successful. This step should happen **after** the host
/// has successfully verified the metadata from `get_metadata()`.
fn process_instruction(cid: ContractId, ix: &[u8]) -> ContractResult {
let (call_idx, calls): (u32, Vec<ContractCall>) = deserialize(ix)?;
let (call_idx, calls): (u32, Vec<DarkLeaf<ContractCall>>) = deserialize(ix)?;
if call_idx >= calls.len() as u32 {
msg!("Error: call_idx >= calls.len()");
return Err(ContractError::Internal)
}
match MoneyFunction::try_from(calls[call_idx as usize].data[0])? {
match MoneyFunction::try_from(calls[call_idx as usize].data.data[0])? {
MoneyFunction::TransferV1 => {
// Again, we pass everything into the correct function.
// If it executes successfully, we'll get a state update

View File

@@ -21,6 +21,7 @@ use darkfi_sdk::{
pasta_prelude::*, pedersen_commitment_u64, poseidon_hash, ContractId, MerkleNode,
DARK_TOKEN_ID,
},
dark_tree::DarkLeaf,
db::{db_contains_key, db_lookup, db_set},
error::{ContractError, ContractResult},
merkle_add, msg,
@@ -42,9 +43,9 @@ use crate::{
pub(crate) fn money_genesis_mint_get_metadata_v1(
_cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: MoneyGenesisMintParamsV1 = deserialize(&self_.data[1..])?;
// Public inputs for the ZK proofs we have to verify
@@ -77,9 +78,9 @@ pub(crate) fn money_genesis_mint_get_metadata_v1(
pub(crate) fn money_genesis_mint_process_instruction_v1(
cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: MoneyGenesisMintParamsV1 = deserialize(&self_.data[1..])?;
// Verify this contract call is verified against on genesis slot(0).

View File

@@ -22,6 +22,7 @@ use darkfi_sdk::{
pasta_prelude::*, pedersen_commitment_u64, poseidon_hash, ContractId, MerkleNode,
DARK_TOKEN_ID,
},
dark_tree::DarkLeaf,
db::{db_contains_key, db_lookup, db_set},
error::{ContractError, ContractResult},
merkle_add, msg,
@@ -43,9 +44,9 @@ use crate::{
pub(crate) fn money_pow_reward_get_metadata_v1(
_cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: MoneyPoWRewardParamsV1 = deserialize(&self_.data[1..])?;
// Public inputs for the ZK proofs we have to verify
@@ -78,9 +79,9 @@ pub(crate) fn money_pow_reward_get_metadata_v1(
pub(crate) fn money_pow_reward_process_instruction_v1(
cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: MoneyPoWRewardParamsV1 = deserialize(&self_.data[1..])?;
// Verify this contract call is verified against a slot(block height) before PoS transition,

View File

@@ -18,6 +18,7 @@
use darkfi_sdk::{
crypto::{pasta_prelude::*, poseidon_hash, ContractId, CONSENSUS_CONTRACT_ID, DARK_TOKEN_ID},
dark_tree::DarkLeaf,
db::{db_contains_key, db_lookup, db_set},
error::{ContractError, ContractResult},
msg,
@@ -37,9 +38,9 @@ use crate::{
pub(crate) fn money_stake_get_metadata_v1(
_cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: MoneyStakeParamsV1 = deserialize(&self_.data[1..])?;
let input = &params.input;
@@ -83,9 +84,9 @@ pub(crate) fn money_stake_get_metadata_v1(
pub(crate) fn money_stake_process_instruction_v1(
cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: MoneyStakeParamsV1 = deserialize(&self_.data[1..])?;
// Access the necessary databases where there is information to
@@ -133,7 +134,7 @@ pub(crate) fn money_stake_process_instruction_v1(
}
// Verify next call corresponds to Consensus::StakeV1 (0x01)
let next = &calls[next_call_idx as usize];
let next = &calls[next_call_idx as usize].data;
if next.contract_id.inner() != CONSENSUS_CONTRACT_ID.inner() {
msg!("[MoneyStakeV1] Error: Next contract call is not consensus contract");
return Err(MoneyError::StakeNextCallNotConsensusContract.into())

View File

@@ -18,6 +18,7 @@
use darkfi_sdk::{
crypto::{pasta_prelude::*, ContractId},
dark_tree::DarkLeaf,
db::{db_contains_key, db_lookup},
error::{ContractError, ContractResult},
msg,
@@ -38,7 +39,7 @@ use crate::{
pub(crate) fn money_otcswap_get_metadata_v1(
cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
// In here we can use the same function as we use in `TransferV1`.
money_transfer_get_metadata_v1(cid, call_idx, calls)
@@ -48,9 +49,9 @@ pub(crate) fn money_otcswap_get_metadata_v1(
pub(crate) fn money_otcswap_process_instruction_v1(
cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: MoneyTransferParamsV1 = deserialize(&self_.data[1..])?;
// The atomic swap is able to use the same parameters as `TransferV1`.

View File

@@ -18,6 +18,7 @@
use darkfi_sdk::{
crypto::{ContractId, PublicKey, TokenId},
dark_tree::DarkLeaf,
db::{db_contains_key, db_lookup, db_set},
error::{ContractError, ContractResult},
msg,
@@ -36,9 +37,9 @@ use crate::{
pub(crate) fn money_token_freeze_get_metadata_v1(
_cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: MoneyTokenFreezeParamsV1 = deserialize(&self_.data[1..])?;
// Public inputs for the ZK proofs we have to verify
@@ -68,9 +69,9 @@ pub(crate) fn money_token_freeze_get_metadata_v1(
pub(crate) fn money_token_freeze_process_instruction_v1(
cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: MoneyTokenFreezeParamsV1 = deserialize(&self_.data[1..])?;
// We just check if the mint was already frozen beforehand

View File

@@ -20,6 +20,7 @@ use darkfi_sdk::{
crypto::{
pasta_prelude::*, pedersen_commitment_u64, poseidon_hash, ContractId, MerkleNode, TokenId,
},
dark_tree::DarkLeaf,
db::{db_contains_key, db_lookup, db_set},
error::{ContractError, ContractResult},
merkle_add, msg,
@@ -40,9 +41,9 @@ use crate::{
pub(crate) fn money_token_mint_get_metadata_v1(
_cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: MoneyTokenMintParamsV1 = deserialize(&self_.data[1..])?;
// Public inputs for the ZK proofs we have to verify
@@ -84,9 +85,9 @@ pub(crate) fn money_token_mint_get_metadata_v1(
pub(crate) fn money_token_mint_process_instruction_v1(
cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: MoneyTokenMintParamsV1 = deserialize(&self_.data[1..])?;
// We have to check if the token mint is frozen, and if by some chance

View File

@@ -21,6 +21,7 @@ use darkfi_sdk::{
pasta_prelude::*, pedersen_commitment_u64, poseidon_hash, ContractId, MerkleNode,
PublicKey, DARK_TOKEN_ID,
},
dark_tree::DarkLeaf,
db::{db_contains_key, db_get, db_lookup, db_set},
error::{ContractError, ContractResult},
merkle_add, msg,
@@ -42,9 +43,9 @@ use crate::{
pub(crate) fn money_transfer_get_metadata_v1(
_cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: MoneyTransferParamsV1 = deserialize(&self_.data[1..])?;
// Public inputs for the ZK proofs we have to verify
@@ -106,9 +107,9 @@ pub(crate) fn money_transfer_get_metadata_v1(
pub(crate) fn money_transfer_process_instruction_v1(
cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: MoneyTransferParamsV1 = deserialize(&self_.data[1..])?;
if params.clear_inputs.len() + params.inputs.len() < 1 {
@@ -193,7 +194,7 @@ pub(crate) fn money_transfer_process_instruction_v1(
return Err(MoneyError::CallIdxOutOfBounds.into())
}
let next = &calls[next_call_idx as usize];
let next = &calls[next_call_idx as usize].data;
if next.contract_id.inner() != input.spend_hook {
msg!("[TransferV1] Error: Invoked contract call does not match spend hook in input {}", i);
return Err(MoneyError::SpendHookMismatch.into())

View File

@@ -21,6 +21,7 @@ use darkfi_sdk::{
pasta_prelude::*, poseidon_hash, ContractId, MerkleNode, PublicKey, CONSENSUS_CONTRACT_ID,
DARK_TOKEN_ID,
},
dark_tree::DarkLeaf,
db::{db_contains_key, db_lookup, db_set},
error::{ContractError, ContractResult},
merkle_add, msg,
@@ -41,9 +42,9 @@ use crate::{
pub(crate) fn money_unstake_get_metadata_v1(
_cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: MoneyUnstakeParamsV1 = deserialize(&self_.data[1..])?;
// Public inputs for the ZK proofs we have to verify
@@ -76,9 +77,9 @@ pub(crate) fn money_unstake_get_metadata_v1(
pub(crate) fn money_unstake_process_instruction_v1(
cid: ContractId,
call_idx: u32,
calls: Vec<ContractCall>,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize];
let self_ = &calls[call_idx as usize].data;
let params: MoneyUnstakeParamsV1 = deserialize(&self_.data[1..])?;
let input = &params.input;
let output = &params.output;
@@ -102,7 +103,7 @@ pub(crate) fn money_unstake_process_instruction_v1(
}
let previous_call_idx = call_idx - 1;
let previous = &calls[previous_call_idx as usize];
let previous = &calls[previous_call_idx as usize].data;
if previous.contract_id.inner() != CONSENSUS_CONTRACT_ID.inner() {
msg!("[MoneyUnstakeV1] Error: Previous contract call is not consensus contract");
return Err(MoneyError::UnstakePreviousCallNotConsensusContract.into())

View File

@@ -48,8 +48,8 @@ use darkfi_serial::{deserialize, serialize};
use log::debug;
/// Update this if any circuits are changed
const VKS_HASH: &str = "ac136b465c4df655d9e77f59884a105f5ade175681ba9cf1cc5abd69ad0f17f8";
const PKS_HASH: &str = "0e6eeccea48a982ff40fc66b94af9c60efd69e827985e3d5e93c49d679a4f6d8";
const VKS_HASH: &str = "5b6a294df23e26afc5ac0c277b77f4cbc65be9de42ecebe9bd535dc20640c2dd";
const PKS_HASH: &str = "c2cca69236857773424b976a2e049352771abe55d81a75a8e9c09106bb123ea6";
fn pks_path(typ: &str) -> Result<PathBuf> {
let output = Command::new("git").arg("rev-parse").arg("--show-toplevel").output()?.stdout;