Selaa lähdekoodia

dao::auth_xfer(): check sibling is money::xfer()

x 2 vuotta sitten
vanhempi
sitoutus
a1117f7a0f

+ 2 - 5
src/contract/dao/src/client/mod.rs

@@ -21,17 +21,14 @@ pub use mint::{make_mint_call, DaoInfo};
 
 /// Provides core structs for DAO::propose()
 ///
-/// * `DaoProposalInfo` is the main info about the proposal.
 /// * `DaoProposeStakeInput` are the staking inputs used to meet the `proposer_limit` threshold.
 /// * `DaoProposeCall` is what creates the call data used on chain.
-/// * `DaoProposeNote` is the secret shared info transmitted between DAO members.
 pub mod propose;
-pub use propose::{DaoProposeCall, DaoProposeNote, DaoProposeStakeInput};
+pub use propose::{DaoProposeCall, DaoProposeStakeInput};
 
 /// Provides core structs for DAO::vote()
 ///
-/// * `DaoVoteInfo` is the main info about the vote.
-/// * `DaoVoteStakeInput` are the staking inputs used in actual voting.
+/// * `DaoVoteInput` are the inputs used in actual voting.
 /// * `DaoVoteCall` is what creates the call data used on chain.
 /// * `DaoVoteNote` is the secret shared info transmitted between DAO members.
 pub mod vote;

+ 2 - 7
src/contract/dao/src/client/propose.rs

@@ -37,11 +37,6 @@ use darkfi::{
 
 use crate::model::{Dao, DaoProposal, DaoProposeParams, DaoProposeParamsInput, VecAuthCallCommit};
 
-#[derive(SerialEncodable, SerialDecodable)]
-pub struct DaoProposeNote {
-    pub proposal: DaoProposal,
-}
-
 pub struct DaoProposeStakeInput {
     pub secret: SecretKey,
     pub note: darkfi_money_contract::client::MoneyNote,
@@ -206,8 +201,8 @@ impl DaoProposeCall {
             .expect("DAO::propose() proving error!");
         proofs.push(main_proof);
 
-        let note = DaoProposeNote { proposal: self.proposal };
-        let enc_note = AeadEncryptedNote::encrypt(&note, &self.dao.public_key, &mut OsRng).unwrap();
+        let enc_note =
+            AeadEncryptedNote::encrypt(&self.proposal, &self.dao.public_key, &mut OsRng).unwrap();
         let params = DaoProposeParams {
             dao_merkle_root: self.dao_merkle_root,
             proposal_bulla,

+ 12 - 0
src/contract/dao/src/entrypoint/auth_xfer.rs

@@ -55,6 +55,18 @@ pub(crate) fn dao_authxfer_process_instruction(
     call_idx: u32,
     calls: Vec<DarkLeaf<ContractCall>>,
 ) -> Result<Vec<u8>, ContractError> {
+    let sibling_idx = call_idx + 1;
+    let xfer_call = &calls[sibling_idx as usize].data;
+
+    if xfer_call.contract_id != *MONEY_CONTRACT_ID {
+        return Err(DaoError::AuthXferSiblingWrongContractId.into())
+    }
+
+    let xfer_call_function_code = xfer_call.data[0];
+    if xfer_call_function_code != MoneyFunction::TransferV1 as u8 {
+        return Err(DaoError::AuthXferSiblingWrongFunctionCode.into())
+    }
+
     let mut update_data = vec![];
     update_data.write_u8(DaoFunction::AuthMoneyTransfer as u8)?;
     Ok(update_data)

+ 8 - 0
src/contract/dao/src/error.rs

@@ -67,6 +67,12 @@ pub enum DaoError {
 
     #[error("Vote commitments mismatch")]
     VoteCommitMismatch,
+
+    #[error("Sibling contract ID is not money::transfer()")]
+    AuthXferSiblingWrongContractId,
+
+    #[error("Sibling function code is not money::transfer()")]
+    AuthXferSiblingWrongFunctionCode,
 }
 
 impl From<DaoError> for ContractError {
@@ -88,6 +94,8 @@ impl From<DaoError> for ContractError {
             DaoError::ExecCallOutputsLenNot2 => Self::Custom(14),
             DaoError::ExecCallValueMismatch => Self::Custom(15),
             DaoError::VoteCommitMismatch => Self::Custom(16),
+            DaoError::AuthXferSiblingWrongContractId => Self::Custom(17),
+            DaoError::AuthXferSiblingWrongFunctionCode => Self::Custom(18),
         }
     }
 }