From e13fba6a9f06f5616c96cbff4ed4b43591b5a685 Mon Sep 17 00:00:00 2001 From: aggstam Date: Mon, 18 Dec 2023 16:45:41 +0200 Subject: [PATCH] contracts: use proper indexes in dao calls --- src/contract/dao/src/entrypoint/exec.rs | 22 +++++++++++++++------- src/contract/test-harness/src/vks.rs | 4 ++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/contract/dao/src/entrypoint/exec.rs b/src/contract/dao/src/entrypoint/exec.rs index 87edd0c118b9..0e42d2e3905c 100644 --- a/src/contract/dao/src/entrypoint/exec.rs +++ b/src/contract/dao/src/entrypoint/exec.rs @@ -101,17 +101,25 @@ pub(crate) fn dao_exec_process_instruction( call_idx: u32, calls: Vec>, ) -> Result, 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()) } diff --git a/src/contract/test-harness/src/vks.rs b/src/contract/test-harness/src/vks.rs index 635a1fd7958c..6d9d4e2ae276 100644 --- a/src/contract/test-harness/src/vks.rs +++ b/src/contract/test-harness/src/vks.rs @@ -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 { let output = Command::new("git").arg("rev-parse").arg("--show-toplevel").output()?.stdout;