Skip to content

Commit

Permalink
Merge pull request many-things#82 from yorhodes/audit-reverts
Browse files Browse the repository at this point in the history
Audit reverts
  • Loading branch information
byeongsu-hong authored Jan 10, 2024
2 parents b26a6f5 + 3b191c2 commit 9cda304
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 115 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ panic = "abort"
rpath = false

[workspace.package]
version = "0.0.6-rc7"
version = "0.0.6-rc6"
authors = [
"byeongsu-hong <hong@byeongsu.dev>",
"Eric <hashableric@gmail.com>",
Expand Down
18 changes: 5 additions & 13 deletions contracts/isms/aggregate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use cw_storage_plus::Item;
use hpl_interface::{
ism::{
aggregate::{AggregateIsmQueryMsg, ExecuteMsg, InstantiateMsg, IsmsResponse, QueryMsg},
IsmQueryMsg, IsmType, ModuleTypeResponse, ModulesAndThresholdResponse, VerifyResponse,
IsmQueryMsg, IsmType, ModuleTypeResponse, VerifyInfoResponse, VerifyResponse,
},
to_binary,
types::{bech32_decode, AggregateMetadata},
Expand Down Expand Up @@ -100,11 +100,6 @@ pub fn execute(
Ok(Response::new()
.add_event(new_event("set_isms").add_attribute("isms", isms.join(","))))
}
ExecuteMsg::SimulateVerify { metadata, message } => {
verify(deps.as_ref(), metadata, message)?;

Ok(Response::new())
}
}
}

Expand All @@ -122,7 +117,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result<QueryResponse, Contr
})
}),
Verify { metadata, message } => to_binary(verify(deps, metadata, message)),
ModulesAndThreshold { message } => to_binary(modules_and_threshold(deps, message)),
VerifyInfo { message } => to_binary(verify_info(deps, message)),
},

QueryMsg::AggregateIsm(msg) => match msg {
Expand Down Expand Up @@ -164,13 +159,10 @@ fn verify(
})
}

fn modules_and_threshold(
deps: Deps,
_message: HexBinary,
) -> Result<ModulesAndThresholdResponse, ContractError> {
Ok(ModulesAndThresholdResponse {
fn verify_info(deps: Deps, _message: HexBinary) -> Result<VerifyInfoResponse, ContractError> {
Ok(VerifyInfoResponse {
threshold: THRESHOLD.load(deps.storage)?,
modules: ISMS
validators: ISMS
.load(deps.storage)?
.into_iter()
.map(|v| Ok(bech32_decode(v.as_str())?.into()))
Expand Down
12 changes: 3 additions & 9 deletions contracts/isms/multisig/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,10 @@ pub fn execute(

Ok(Response::new().add_event(
Event::new("ism_multisig_unset_domain")
.add_attribute("sender", info.sender)
.add_attribute("sener", info.sender)
.add_attribute("domain", domain.to_string()),
))
}

SimulateVerify { metadata, message } => {
crate::query::verify_message(deps.as_ref(), metadata, message)?;

Ok(Response::new())
}
}
}

Expand All @@ -121,9 +115,9 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result<QueryResponse, Contr
metadata: raw_metadata,
message: raw_message,
} => to_binary(query::verify_message(deps, raw_metadata, raw_message)),
ModulesAndThreshold {
VerifyInfo {
message: raw_message,
} => to_binary(query::modules_and_threshold(deps, raw_message)),
} => to_binary(query::get_verify_info(deps, raw_message)),
},
QueryMsg::MultisigIsm(msg) => match msg {
MultisigIsmQueryMsg::EnrolledValidators { domain } => to_binary({
Expand Down
16 changes: 8 additions & 8 deletions contracts/isms/multisig/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_std::{Deps, HexBinary};
use hpl_interface::{
ism::{IsmType, ModuleTypeResponse, ModulesAndThresholdResponse, VerifyResponse},
ism::{IsmType, ModuleTypeResponse, VerifyInfoResponse, VerifyResponse},
types::{eth_addr, eth_hash, Message, MessageIdMultisigIsmMetadata},
};

Expand Down Expand Up @@ -60,18 +60,18 @@ pub fn verify_message(
})
}

pub fn modules_and_threshold(
pub fn get_verify_info(
deps: Deps,
raw_message: HexBinary,
) -> Result<ModulesAndThresholdResponse, ContractError> {
) -> Result<VerifyInfoResponse, ContractError> {
let message: Message = raw_message.into();

let threshold = THRESHOLD.load(deps.storage, message.origin_domain)?;
let validators = VALIDATORS.load(deps.storage, message.origin_domain)?;

Ok(ModulesAndThresholdResponse {
Ok(VerifyInfoResponse {
threshold,
modules: validators,
validators,
})
}

Expand All @@ -87,7 +87,7 @@ mod test {
use k256::{ecdsa::SigningKey, elliptic_curve::rand_core::OsRng};
use rstest::rstest;

use super::{get_module_type, modules_and_threshold, verify_message};
use super::{get_module_type, get_verify_info, verify_message};

#[test]
fn test_get_module_type() {
Expand Down Expand Up @@ -155,9 +155,9 @@ mod test {
.unwrap();
THRESHOLD.save(deps.as_mut().storage, 26658, &1u8).unwrap();

let info = modules_and_threshold(deps.as_ref(), raw_message).unwrap();
let info = get_verify_info(deps.as_ref(), raw_message).unwrap();

assert_eq!(info.modules, vec![addr]);
assert_eq!(info.validators, vec![addr]);
assert_eq!(info.threshold, 1);
}
}
17 changes: 2 additions & 15 deletions contracts/isms/routing/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,6 @@ pub fn execute(
),
))
}
SimulateVerify { metadata, message } => {
let decoded = Message::from(message.clone());

let ism = MODULES
.may_load(deps.storage, decoded.origin_domain)?
.ok_or(ContractError::RouteNotFound {})?;

let _: VerifyResponse = deps
.querier
.query_wasm_smart(ism, &IsmQueryMsg::Verify { metadata, message }.wrap())?;

Ok(Response::new())
}
}
}

Expand All @@ -135,7 +122,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result<QueryResponse, Contr

Ok(to_json_binary(&verify_resp)?)
}
ModulesAndThreshold { message } => {
VerifyInfo { message } => {
let decoded = Message::from(message.clone());

let ism = MODULES
Expand All @@ -144,7 +131,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result<QueryResponse, Contr

let verify_resp: VerifyResponse = deps
.querier
.query_wasm_smart(ism, &IsmQueryMsg::ModulesAndThreshold { message })?;
.query_wasm_smart(ism, &IsmQueryMsg::VerifyInfo { message })?;

Ok(to_json_binary(&verify_resp)?)
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/mocks/mock-ism/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cosmwasm_std::{
};
use cw2::set_contract_version;
use hpl_interface::ism::{
ExpectedIsmQueryMsg, IsmQueryMsg, IsmType, ModulesAndThresholdResponse, VerifyResponse,
ExpectedIsmQueryMsg, IsmQueryMsg, IsmType, VerifyInfoResponse, VerifyResponse,
};

use crate::{CONTRACT_NAME, CONTRACT_VERSION};
Expand Down Expand Up @@ -57,9 +57,9 @@ pub fn query(_deps: Deps, _env: Env, msg: ExpectedIsmQueryMsg) -> StdResult<Quer
ExpectedIsmQueryMsg::Ism(msg) => match msg {
ModuleType {} => Ok(to_json_binary(&IsmType::Null)?),
Verify { .. } => Ok(to_json_binary(&VerifyResponse { verified: true })?),
ModulesAndThreshold { .. } => Ok(to_json_binary(&ModulesAndThresholdResponse {
VerifyInfo { .. } => Ok(to_json_binary(&VerifyInfoResponse {
threshold: 1u8,
modules: vec![],
validators: vec![],
})?),
},
}
Expand Down
23 changes: 3 additions & 20 deletions packages/interface/src/ism/aggregate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::HexBinary;

use crate::ownable::{OwnableMsg, OwnableQueryMsg};

Expand All @@ -16,15 +15,7 @@ pub struct InstantiateMsg {
pub enum ExecuteMsg {
Ownable(OwnableMsg),

SimulateVerify {
metadata: HexBinary,
message: HexBinary,
},

SetIsms {
isms: Vec<String>,
threshold: u8,
},
SetIsms { isms: Vec<String>, threshold: u8 },
}

#[cw_serde]
Expand Down Expand Up @@ -56,18 +47,10 @@ mod test {
use cosmwasm_std::HexBinary;

use super::*;
use crate::{
ism::{ExpectedIsmMsg, IsmQueryMsg},
msg_checker,
};
use crate::{ism::IsmQueryMsg, msg_checker};

#[test]
fn test_ism_interface() {
let _checked: ExecuteMsg = msg_checker(ExpectedIsmMsg::SimulateVerify {
metadata: HexBinary::default(),
message: HexBinary::default(),
});

let _checked: QueryMsg = msg_checker(IsmQueryMsg::ModuleType {}.wrap());
let _checked: QueryMsg = msg_checker(
IsmQueryMsg::Verify {
Expand All @@ -77,7 +60,7 @@ mod test {
.wrap(),
);
let _checked: QueryMsg = msg_checker(
IsmQueryMsg::ModulesAndThreshold {
IsmQueryMsg::VerifyInfo {
message: HexBinary::default(),
}
.wrap(),
Expand Down
16 changes: 4 additions & 12 deletions packages/interface/src/ism/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ pub enum IsmType {
CcipRead = 7,
}

#[cw_serde]
pub enum ExpectedIsmMsg {
SimulateVerify {
metadata: HexBinary,
message: HexBinary,
},
}

#[cw_serde]
#[derive(QueryResponses)]
pub enum IsmQueryMsg {
Expand All @@ -38,8 +30,8 @@ pub enum IsmQueryMsg {
message: HexBinary,
},

#[returns(ModulesAndThresholdResponse)]
ModulesAndThreshold { message: HexBinary },
#[returns(VerifyInfoResponse)]
VerifyInfo { message: HexBinary },
}

impl IsmQueryMsg {
Expand Down Expand Up @@ -87,9 +79,9 @@ pub struct VerifyResponse {
}

#[cw_serde]
pub struct ModulesAndThresholdResponse {
pub struct VerifyInfoResponse {
pub threshold: u8,
pub modules: Vec<HexBinary>,
pub validators: Vec<HexBinary>,
}

#[cw_serde]
Expand Down
16 changes: 3 additions & 13 deletions packages/interface/src/ism/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::ownable::{OwnableMsg, OwnableQueryMsg};

use super::IsmQueryMsg;
#[allow(unused_imports)]
use super::{ModuleTypeResponse, ModulesAndThresholdResponse, VerifyResponse};
use super::{ModuleTypeResponse, VerifyInfoResponse, VerifyResponse};

#[cw_serde]
pub struct InstantiateMsg {
Expand All @@ -22,11 +22,6 @@ pub struct ValidatorSet {
pub enum ExecuteMsg {
Ownable(OwnableMsg),

SimulateVerify {
metadata: HexBinary,
message: HexBinary,
},

SetValidators {
domain: u32,
threshold: u8,
Expand Down Expand Up @@ -62,15 +57,10 @@ pub struct EnrolledValidatorsResponse {
#[cfg(test)]
mod test {
use super::*;
use crate::{ism::ExpectedIsmMsg, msg_checker};
use crate::msg_checker;

#[test]
fn test_ism_interface() {
let _checked: ExecuteMsg = msg_checker(ExpectedIsmMsg::SimulateVerify {
metadata: HexBinary::default(),
message: HexBinary::default(),
});

let _checked: QueryMsg = msg_checker(IsmQueryMsg::ModuleType {}.wrap());
let _checked: QueryMsg = msg_checker(
IsmQueryMsg::Verify {
Expand All @@ -80,7 +70,7 @@ mod test {
.wrap(),
);
let _checked: QueryMsg = msg_checker(
IsmQueryMsg::ModulesAndThreshold {
IsmQueryMsg::VerifyInfo {
message: HexBinary::default(),
}
.wrap(),
Expand Down
25 changes: 4 additions & 21 deletions packages/interface/src/ism/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,8 @@ pub struct InstantiateMsg {
pub enum ExecuteMsg {
Ownable(OwnableMsg),

SimulateVerify {
metadata: HexBinary,
message: HexBinary,
},

Set {
ism: IsmSet,
},
Unset {
domains: Vec<u32>,
},
Set { ism: IsmSet },
Unset { domains: Vec<u32> },
}

#[cw_serde]
Expand Down Expand Up @@ -62,18 +53,10 @@ mod test {
use cosmwasm_std::HexBinary;

use super::*;
use crate::{
ism::{ExpectedIsmMsg, IsmQueryMsg},
msg_checker,
};
use crate::{ism::IsmQueryMsg, msg_checker};

#[test]
fn test_ism_interface() {
let _checked: ExecuteMsg = msg_checker(ExpectedIsmMsg::SimulateVerify {
metadata: HexBinary::default(),
message: HexBinary::default(),
});

let _checked: QueryMsg = msg_checker(IsmQueryMsg::ModuleType {}.wrap());
let _checked: QueryMsg = msg_checker(
IsmQueryMsg::Verify {
Expand All @@ -83,7 +66,7 @@ mod test {
.wrap(),
);
let _checked: QueryMsg = msg_checker(
IsmQueryMsg::ModulesAndThreshold {
IsmQueryMsg::VerifyInfo {
message: HexBinary::default(),
}
.wrap(),
Expand Down

0 comments on commit 9cda304

Please sign in to comment.