Skip to content

Commit

Permalink
fix: suspect every metadata existence and format
Browse files Browse the repository at this point in the history
Signed-off-by: Shunkichi Sato <[email protected]>
  • Loading branch information
s8sato committed Nov 11, 2024
1 parent 35b3865 commit 8ff9018
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions crates/iroha_executor/src/default/isi/multisig/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,33 @@
use alloc::collections::{btree_map::BTreeMap, btree_set::BTreeSet};

use iroha_smart_contract::data_model::query::error::QueryExecutionFail;

use super::*;

fn metadata_conversion_error(_err: serde_json::Error) -> ValidationFail {
ValidationFail::QueryFailed(QueryExecutionFail::Conversion(
"multisig account metadata malformed".into(),
))
}

impl VisitExecute for MultisigPropose {
fn visit<V: Execute + Visit + ?Sized>(&self, executor: &mut V) {
let proposer = executor.context().authority.clone();
let target_account = self.account.clone();
let host = executor.host();
let instructions_hash = HashOf::new(&self.instructions);
let multisig_role = multisig_role_for(&target_account);
let is_downward_proposal = host
.query_single(FindAccountMetadata::new(
proposer.clone(),
SIGNATORIES.parse().unwrap(),
))
.map_or(false, |proposer_signatories| {
proposer_signatories
.try_into_any::<BTreeMap<AccountId, u8>>()
.dbg_unwrap()
.contains_key(&target_account)
});
let is_downward_proposal = match host.query_single(FindAccountMetadata::new(
proposer.clone(),
SIGNATORIES.parse().unwrap(),
)) {
Ok(json) => match json.try_into_any::<BTreeMap<AccountId, u8>>() {
Ok(proposer_signatories) => proposer_signatories.contains_key(&target_account),
_ => deny!(executor, "proposer metadata malformed"),
},
_ => false,
};
let has_multisig_role = host
.query(FindRolesByAccountId::new(proposer))
.filter_with(|role_id| role_id.eq(multisig_role))
Expand Down Expand Up @@ -56,10 +63,9 @@ impl VisitExecute for MultisigPropose {
.query_single(FindAccountMetadata::new(
target_account.clone(),
SIGNATORIES.parse().unwrap(),
))
.dbg_unwrap()
))?
.try_into_any()
.dbg_unwrap();
.map_err(metadata_conversion_error)?;
let now_ms: u64 = executor
.context()
.curr_block
Expand Down Expand Up @@ -143,41 +149,37 @@ impl VisitExecute for MultisigApprove {
.query_single(FindAccountMetadata::new(
target_account.clone(),
SIGNATORIES.parse().unwrap(),
))
.dbg_unwrap()
))?
.try_into_any()
.dbg_unwrap();
.map_err(metadata_conversion_error)?;
let quorum: u16 = host
.query_single(FindAccountMetadata::new(
target_account.clone(),
QUORUM.parse().unwrap(),
))
.dbg_unwrap()
))?
.try_into_any()
.dbg_unwrap();
.map_err(metadata_conversion_error)?;
let transaction_ttl_ms: u64 = host
.query_single(FindAccountMetadata::new(
target_account.clone(),
TRANSACTION_TTL_MS.parse().unwrap(),
))
.dbg_unwrap()
))?
.try_into_any()
.dbg_unwrap();
.map_err(metadata_conversion_error)?;
let instructions: Vec<InstructionBox> = host
.query_single(FindAccountMetadata::new(
target_account.clone(),
instructions_key(&instructions_hash),
))?
.try_into_any()
.dbg_unwrap();
.map_err(metadata_conversion_error)?;
let proposed_at_ms: u64 = host
.query_single(FindAccountMetadata::new(
target_account.clone(),
proposed_at_ms_key(&instructions_hash),
))
.dbg_unwrap()
))?
.try_into_any()
.dbg_unwrap();
.map_err(metadata_conversion_error)?;
let now_ms: u64 = executor
.context()
.curr_block
Expand All @@ -189,10 +191,9 @@ impl VisitExecute for MultisigApprove {
.query_single(FindAccountMetadata::new(
target_account.clone(),
approvals_key(&instructions_hash),
))
.dbg_unwrap()
))?
.try_into_any()
.dbg_unwrap();
.map_err(metadata_conversion_error)?;

approvals.insert(approver);

Expand Down

0 comments on commit 8ff9018

Please sign in to comment.