Skip to content

Commit

Permalink
contracts: use proper indexes in dao calls
Browse files Browse the repository at this point in the history
  • Loading branch information
aggstam committed Dec 18, 2023
1 parent 5711ea1 commit e13fba6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
22 changes: 15 additions & 7 deletions src/contract/dao/src/entrypoint/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,25 @@ pub(crate) fn dao_exec_process_instruction(
call_idx: u32,
calls: Vec<DarkLeaf<ContractCall>>,
) -> Result<Vec<u8>, ContractError> {
let self_ = &calls[call_idx as usize].data;
let params: DaoExecParams = deserialize(&self_.data[1..])?;
let self_ = &calls[call_idx as usize];
let params: DaoExecParams = deserialize(&self_.data.data[1..])?;

// ==========================================
// Enforce the transaction has correct format
// ==========================================
if calls.len() != 2 ||
call_idx != 1 ||
calls[0].data.contract_id != *MONEY_CONTRACT_ID ||
calls[0].data.data[0] != MoneyFunction::TransferV1 as u8
{
if call_idx == 0 {
msg!("[Dao::Exec] Error: child_call_idx will be out of bounds");
return Err(DaoError::ExecCallInvalidFormat.into())
}

let child_call_indexes = &self_.children_indexes;
if child_call_indexes.len() != 1 {
msg!("[Dao::Exec] Error: child_call_idx is missing");
return Err(DaoError::ExecCallInvalidFormat.into())
}
let child_call_idx = child_call_indexes[0];
let child = &calls[child_call_idx].data;
if child.contract_id != *MONEY_CONTRACT_ID || child.data[0] != MoneyFunction::TransferV1 as u8 {
msg!("[Dao::Exec] Error: Transaction has incorrect format");
return Err(DaoError::ExecCallInvalidFormat.into())
}
Expand Down
4 changes: 2 additions & 2 deletions src/contract/test-harness/src/vks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ use darkfi_serial::{deserialize, serialize};
use log::debug;

/// Update this if any circuits are changed
const VKS_HASH: &str = "5b6a294df23e26afc5ac0c277b77f4cbc65be9de42ecebe9bd535dc20640c2dd";
const PKS_HASH: &str = "c2cca69236857773424b976a2e049352771abe55d81a75a8e9c09106bb123ea6";
const VKS_HASH: &str = "2f00493f2d0ef54ef9a581c5fb833dd3d2ca6099583658c281fcd974455969f0";
const PKS_HASH: &str = "fa584cf5ddf2a6905ada0f461ba21d6e4611812872a043b9d061bc82c6923f4b";

fn pks_path(typ: &str) -> Result<PathBuf> {
let output = Command::new("git").arg("rev-parse").arg("--show-toplevel").output()?.stdout;
Expand Down

0 comments on commit e13fba6

Please sign in to comment.