Skip to content

Commit

Permalink
Merge branch 'main' into feat/bcs-msg-to-sign
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcobb23 committed Sep 22, 2023
2 parents e39d69f + ff60415 commit d54be13
Show file tree
Hide file tree
Showing 47 changed files with 1,220 additions and 1,271 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/codecov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ on:
pull_request:
push:
branches:
- 'main'
- 'releases/**'
- main
- releases/**

jobs:
coverage:
Expand Down Expand Up @@ -35,6 +35,9 @@ jobs:

- name: Generate code coverage
run: cargo llvm-cov --workspace --lcov --output-path lcov.info
env:
RUSTFLAGS: --cfg tracing_unstable
RUST_BACKTRACE: 1

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 16 additions & 18 deletions ampd/src/evm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ pub enum ChainName {
Other(String),
}

impl PartialEq<connection_router::types::ChainName> for ChainName {
fn eq(&self, other: &connection_router::types::ChainName) -> bool {
impl PartialEq<connection_router::state::ChainName> for ChainName {
fn eq(&self, other: &connection_router::state::ChainName) -> bool {
self.to_string().eq_ignore_ascii_case(&other.to_string())
}
}
Expand All @@ -44,28 +44,26 @@ impl ChainName {

#[cfg(test)]
mod tests {
use crate::evm;
use connection_router::state::ChainName;
use std::str::FromStr;

use crate::evm::ChainName;

#[test]
fn chain_name_partial_eq() {
let chain_name = ChainName::Ethereum;
let chain_name = evm::ChainName::Ethereum;

assert!(chain_name == connection_router::types::ChainName::from_str("Ethereum").unwrap());
assert!(chain_name == connection_router::types::ChainName::from_str("ETHEREUM").unwrap());
assert!(chain_name == connection_router::types::ChainName::from_str("ethereum").unwrap());
assert!(chain_name == connection_router::types::ChainName::from_str("ethEReum").unwrap());
assert!(chain_name != connection_router::types::ChainName::from_str("Ethereum-1").unwrap());
assert_eq!(chain_name, ChainName::from_str("Ethereum").unwrap());
assert_eq!(chain_name, ChainName::from_str("ETHEREUM").unwrap());
assert_eq!(chain_name, ChainName::from_str("ethereum").unwrap());
assert_eq!(chain_name, ChainName::from_str("ethEReum").unwrap());
assert_ne!(chain_name, ChainName::from_str("Ethereum-1").unwrap());

let chain_name = ChainName::Other("avalanche".into());
let chain_name = evm::ChainName::Other("avalanche".into());

assert!(chain_name == connection_router::types::ChainName::from_str("Avalanche").unwrap());
assert!(chain_name == connection_router::types::ChainName::from_str("AVALANCHE").unwrap());
assert!(chain_name == connection_router::types::ChainName::from_str("avalanche").unwrap());
assert!(chain_name == connection_router::types::ChainName::from_str("avaLAnche").unwrap());
assert!(
chain_name != connection_router::types::ChainName::from_str("Avalanche-2").unwrap()
);
assert_eq!(chain_name, ChainName::from_str("Avalanche").unwrap());
assert_eq!(chain_name, ChainName::from_str("AVALANCHE").unwrap());
assert_eq!(chain_name, ChainName::from_str("avalanche").unwrap());
assert_eq!(chain_name, ChainName::from_str("avaLAnche").unwrap());
assert_ne!(chain_name, ChainName::from_str("Avalanche-2").unwrap());
}
}
36 changes: 19 additions & 17 deletions ampd/src/handlers/evm_verify_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tracing::{info, info_span};
use valuable::Valuable;

use axelar_wasm_std::voting::PollID;
use connection_router::types::ID_SEPARATOR;
use connection_router::state::ID_SEPARATOR;
use events::Error::EventTypeMismatch;
use events_derive::try_from;
use voting_verifier::msg::ExecuteMsg;
Expand All @@ -32,7 +32,7 @@ pub struct Message {
pub tx_id: Hash,
pub event_index: u64,
pub destination_address: String,
pub destination_chain: connection_router::types::ChainName,
pub destination_chain: connection_router::state::ChainName,
pub source_address: EVMAddress,
pub payload_hash: Hash,
}
Expand All @@ -43,7 +43,7 @@ struct PollStartedEvent {
#[serde(rename = "_contract_address")]
contract_address: TMAddress,
poll_id: PollID,
source_chain: connection_router::types::ChainName,
source_chain: connection_router::state::ChainName,
source_gateway_address: EVMAddress,
confirmation_height: u64,
messages: Vec<Message>,
Expand Down Expand Up @@ -233,7 +233,7 @@ mod tests {

use events::Error::{DeserializationFailed, EventTypeMismatch};
use events::Event;
use voting_verifier::events::{MessageByTxEvent, PollMetadata, PollStarted};
use voting_verifier::events::{PollMetadata, PollStarted, TxEventConfirmation};

use crate::types::{EVMAddress, Hash};

Expand All @@ -244,7 +244,9 @@ mod tests {
metadata: PollMetadata {
poll_id: "100".parse().unwrap(),
source_chain: "ethereum".parse().unwrap(),
source_gateway_address: "0x4f4495243837681061c4743b74eedf548d5686a5".into(),
source_gateway_address: "0x4f4495243837681061c4743b74eedf548d5686a5"
.parse()
.unwrap(),
confirmation_height: 15,
expires_at: 100,
participants: vec![
Expand All @@ -260,28 +262,28 @@ mod tests {
],
},
messages: vec![
MessageByTxEvent {
tx_id: format!("0x{:x}", Hash::random()),
TxEventConfirmation {
tx_id: format!("0x{:x}", Hash::random()).parse().unwrap(),
event_index: 0,
source_address: format!("0x{:x}", EVMAddress::random()),
source_address: format!("0x{:x}", EVMAddress::random()).parse().unwrap(),
destination_chain: "ethereum".parse().unwrap(),
destination_address: format!("0x{:x}", EVMAddress::random()),
destination_address: format!("0x{:x}", EVMAddress::random()).parse().unwrap(),
payload_hash: HexBinary::from(Hash::random().as_bytes()),
},
MessageByTxEvent {
tx_id: format!("0x{:x}", Hash::random()),
TxEventConfirmation {
tx_id: format!("0x{:x}", Hash::random()).parse().unwrap(),
event_index: 1,
source_address: format!("0x{:x}", EVMAddress::random()),
source_address: format!("0x{:x}", EVMAddress::random()).parse().unwrap(),
destination_chain: "ethereum".parse().unwrap(),
destination_address: format!("0x{:x}", EVMAddress::random()),
destination_address: format!("0x{:x}", EVMAddress::random()).parse().unwrap(),
payload_hash: HexBinary::from(Hash::random().as_bytes()),
},
MessageByTxEvent {
tx_id: format!("0x{:x}", Hash::random()),
TxEventConfirmation {
tx_id: format!("0x{:x}", Hash::random()).parse().unwrap(),
event_index: 10,
source_address: format!("0x{:x}", EVMAddress::random()),
source_address: format!("0x{:x}", EVMAddress::random()).parse().unwrap(),
destination_chain: "ethereum".parse().unwrap(),
destination_address: format!("0x{:x}", EVMAddress::random()),
destination_address: format!("0x{:x}", EVMAddress::random()).parse().unwrap(),
payload_hash: HexBinary::from(Hash::random().as_bytes()),
},
],
Expand Down
10 changes: 6 additions & 4 deletions ampd/src/handlers/evm_verify_worker_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use events::Error::EventTypeMismatch;
use events_derive::try_from;

use axelar_wasm_std::voting::PollID;
use connection_router::types::ID_SEPARATOR;
use connection_router::state::ID_SEPARATOR;
use voting_verifier::msg::ExecuteMsg;

use crate::event_processor::EventHandler;
Expand Down Expand Up @@ -43,7 +43,7 @@ struct PollStartedEvent {
contract_address: TMAddress,
worker_set: WorkerSetConfirmation,
poll_id: PollID,
source_chain: connection_router::types::ChainName,
source_chain: connection_router::state::ChainName,
source_gateway_address: EVMAddress,
confirmation_height: u64,
participants: Vec<TMAddress>,
Expand Down Expand Up @@ -216,7 +216,7 @@ mod tests {
fn get_poll_started_event() -> Event {
let poll_started = PollStarted::WorkerSet {
worker_set: WorkerSetConfirmation {
tx_id: format!("0x{:x}", Hash::random()),
tx_id: format!("0x{:x}", Hash::random()).parse().unwrap(),
event_index: 100,
operators: Operators {
threshold: 40u64.into(),
Expand All @@ -239,7 +239,9 @@ mod tests {
metadata: PollMetadata {
poll_id: "100".parse().unwrap(),
source_chain: "ethereum".parse().unwrap(),
source_gateway_address: "0x4f4495243837681061c4743b74eedf548d5686a5".into(),
source_gateway_address: "0x4f4495243837681061c4743b74eedf548d5686a5"
.parse()
.unwrap(),
confirmation_height: 15,
expires_at: 100,
participants: vec![
Expand Down
1 change: 1 addition & 0 deletions contracts/aggregate-verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ schemars = "0.8.10"
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
serde_json = "1.0.89"
thiserror = { workspace = true }
voting-verifier = { workspace = true, features = ["library"] }

[dev-dependencies]
cw-multi-test = "0.15.1"
31 changes: 11 additions & 20 deletions contracts/aggregate-verifier/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use connection_router::state::CrossChainId;
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
Expand All @@ -6,15 +7,14 @@ use cosmwasm_std::{
};
use cw_utils::{parse_reply_execute_data, MsgExecuteContractResponse};

use voting_verifier::msg as voting_msg;

use crate::{
error::ContractError,
msg::{ExecuteMsg, InstantiateMsg, QueryMsg},
state::{Config, CONFIG},
};

use connection_router::msg;
use connection_router::state;

use self::execute::verify_messages;

#[cfg_attr(not(feature = "library"), entry_point)]
Expand All @@ -38,28 +38,21 @@ pub fn execute(
msg: ExecuteMsg,
) -> Result<Response, axelar_wasm_std::ContractError> {
match msg {
ExecuteMsg::VerifyMessages { messages } => {
// todo: this conversion can go away once the message types are merged
let msgs = messages
.into_iter()
.map(state::Message::try_from)
.collect::<Result<Vec<state::Message>, _>>()?;

verify_messages(deps, msgs)
}
ExecuteMsg::VerifyMessages { messages } => verify_messages(deps, messages),
}
.map_err(axelar_wasm_std::ContractError::from)
}

pub mod execute {

use cosmwasm_std::{to_binary, SubMsg, WasmMsg};

use connection_router::state::NewMessage;

use super::*;

pub fn verify_messages(
deps: DepsMut,
msgs: Vec<state::Message>,
msgs: Vec<NewMessage>,
) -> Result<Response, ContractError> {
// Simply pass through to a single verifier for now. If there are multiple verification
// methods in the future, as well as support for a callback when a message is actually
Expand All @@ -68,9 +61,7 @@ pub mod execute {
Ok(Response::new().add_submessage(SubMsg::reply_on_success(
WasmMsg::Execute {
contract_addr: verifier.to_string(),
msg: to_binary(&ExecuteMsg::VerifyMessages {
messages: msgs.into_iter().map(msg::Message::from).collect(),
})?,
msg: to_binary(&voting_msg::ExecuteMsg::VerifyMessages { messages: msgs })?,
funds: vec![],
},
VERIFY_REPLY,
Expand All @@ -90,7 +81,7 @@ pub fn reply(
match parse_reply_execute_data(reply) {
Ok(MsgExecuteContractResponse { data: Some(data) }) => {
// check format of data
let _: Vec<(String, bool)> = from_binary(&data)?;
let _: Vec<(CrossChainId, bool)> = from_binary(&data)?;

// only one verifier, so just return the response as is
Ok(Response::new().set_data(data))
Expand All @@ -109,11 +100,11 @@ pub fn reply(
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::IsVerified { messages: _ } => {
QueryMsg::IsVerified { messages } => {
let verifier = CONFIG.load(deps.storage)?.verifier;
deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
contract_addr: verifier.to_string(),
msg: to_binary(&msg)?,
msg: to_binary(&voting_msg::QueryMsg::IsVerified { messages })?,
}))
}
}
Expand Down
7 changes: 3 additions & 4 deletions contracts/aggregate-verifier/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use connection_router::msg::Message;
use connection_router::state::NewMessage;
use cosmwasm_schema::cw_serde;

#[cw_serde]
Expand All @@ -8,12 +8,11 @@ pub struct InstantiateMsg {

#[cw_serde]
pub enum ExecuteMsg {
// Returns a vector of (String,bool) tuples for each passed in message, consisting of message ID and current verification status
// Permissionless
VerifyMessages { messages: Vec<Message> },
VerifyMessages { messages: Vec<NewMessage> },
}

#[cw_serde]
pub enum QueryMsg {
IsVerified { messages: Vec<Message> },
IsVerified { messages: Vec<NewMessage> },
}
20 changes: 9 additions & 11 deletions contracts/aggregate-verifier/tests/mock.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use aggregate_verifier::error::ContractError;
use connection_router::msg::Message;
use connection_router::state::{CrossChainId, NewMessage};
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{to_binary, Addr, DepsMut, Env, MessageInfo, Response};
use cw_multi_test::{App, ContractWrapper, Executor};
use cw_storage_plus::Map;

const MOCK_VOTING_VERIFIER_MESSAGES: Map<String, bool> = Map::new("voting_verifier_messages");
const MOCK_VOTING_VERIFIER_MESSAGES: Map<CrossChainId, bool> = Map::new("voting_verifier_messages");

#[cw_serde]
pub enum MockVotingVerifierExecuteMsg {
VerifyMessages { messages: Vec<Message> },
MessagesVerified { messages: Vec<Message> },
VerifyMessages { messages: Vec<NewMessage> },
MessagesVerified { messages: Vec<NewMessage> },
}

#[cw_serde]
Expand All @@ -26,18 +26,16 @@ pub fn mock_verifier_execute(
MockVotingVerifierExecuteMsg::VerifyMessages { messages } => {
let mut res = vec![];
for m in messages {
let m = connection_router::state::Message::try_from(m).unwrap();
match MOCK_VOTING_VERIFIER_MESSAGES.may_load(deps.storage, m.id.to_string())? {
Some(b) => res.push((m.id.to_string(), b)),
None => res.push((m.id.to_string(), false)),
match MOCK_VOTING_VERIFIER_MESSAGES.may_load(deps.storage, m.cc_id.clone())? {
Some(b) => res.push((m.cc_id, b)),
None => res.push((m.cc_id, false)),
}
}
Ok(Response::new().set_data(to_binary(&res)?))
}
MockVotingVerifierExecuteMsg::MessagesVerified { messages } => {
for m in messages {
let m = connection_router::state::Message::try_from(m).unwrap();
MOCK_VOTING_VERIFIER_MESSAGES.save(deps.storage, m.id.to_string(), &true)?;
MOCK_VOTING_VERIFIER_MESSAGES.save(deps.storage, m.cc_id, &true)?;
}
Ok(Response::new())
}
Expand All @@ -47,7 +45,7 @@ pub fn mock_verifier_execute(
pub fn mark_messages_as_verified(
app: &mut App,
voting_verifier_address: Addr,
msgs: Vec<connection_router::msg::Message>,
msgs: Vec<NewMessage>,
) {
app.execute_contract(
Addr::unchecked("relayer"),
Expand Down
Loading

0 comments on commit d54be13

Please sign in to comment.