Skip to content

Commit

Permalink
feat(minor-ampd): stellar verify messages
Browse files Browse the repository at this point in the history
  • Loading branch information
haiyizxx committed Sep 3, 2024
1 parent 13390b9 commit 4f5d910
Show file tree
Hide file tree
Showing 13 changed files with 753 additions and 262 deletions.
328 changes: 70 additions & 258 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ interchain-token-service = { version = "^0.1.0", path = "interchain-token-servic
goldie = { version = "0.5" }
axelarnet-gateway = { version = "^0.1.0", path = "contracts/axelarnet-gateway" }
cw-multi-test = "1.2.0"
stellar-xdr = { version = "21.2.0" }

[workspace.lints.clippy]
arithmetic_side_effects = "deny"
Expand Down
11 changes: 9 additions & 2 deletions ampd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ enum-display-derive = "0.1.1"
error-stack = { workspace = true }
ethers-contract = { workspace = true }
ethers-core = { workspace = true }
ethers-providers = { version = "2.0.13", default-features = false, features = ["rustls"] }
ethers-providers = { version = "2.0.13", default-features = false, features = [
"rustls",
] }
events = { workspace = true }
events-derive = { workspace = true }
evm-gateway = { workspace = true }
Expand All @@ -48,9 +50,13 @@ serde_json = { workspace = true }
serde_with = "3.2.0"
service-registry = { workspace = true }
sha3 = { workspace = true }
stellar-rs = "0.3.2"
stellar-xdr = { workspace = true, features = ["serde_json"] }
sui-gateway = { workspace = true }
sui-json-rpc-types = { git = "https://github.com/mystenlabs/sui", tag = "mainnet-v1.26.2" }
sui-types = { git = "https://github.com/mystenlabs/sui", features = ["test-utils"], tag = "mainnet-v1.26.2" }
sui-types = { git = "https://github.com/mystenlabs/sui", features = [
"test-utils",
], tag = "mainnet-v1.26.2" }
# Need to switch to our own fork of tendermint and tendermint-rpc due to event attribute value being nullable.
# Can switch back once https://github.com/informalsystems/tendermint-rs/issues/1216 is resolved.
# The fix for the issue is at https://github.com/axelarnetwork/tendermint-rs/commit/e97033e20e660a7e707ea86db174ec047bbba50d.
Expand All @@ -74,6 +80,7 @@ valuable-serde = { version = "0.1.0", features = ["std"] }
voting-verifier = { workspace = true }

[dev-dependencies]
ed25519-dalek = { workspace = true, features = ["rand_core"] }
elliptic-curve = "0.13.5"
generic-array = "0.14.7"
multisig = { workspace = true, features = ["test", "library"] }
Expand Down
14 changes: 13 additions & 1 deletion ampd/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ mod tests {
type = 'MvxVerifierSetVerifier'
cosmwasm_contract = '{}'
proxy_url = 'http://localhost:7545'
[[handlers]]
type = 'StellarMsgVerifier'
cosmwasm_contract = '{}'
http_url = 'http://localhost:8000'
",
TMAddress::random(PREFIX),
TMAddress::random(PREFIX),
Expand All @@ -129,10 +134,11 @@ mod tests {
TMAddress::random(PREFIX),
TMAddress::random(PREFIX),
TMAddress::random(PREFIX),
TMAddress::random(PREFIX),
);

let cfg: Config = toml::from_str(config_str.as_str()).unwrap();
assert_eq!(cfg.handlers.len(), 8);
assert_eq!(cfg.handlers.len(), 9);
}

#[test]
Expand Down Expand Up @@ -324,6 +330,12 @@ mod tests {
),
proxy_url: Url::from_str("http://127.0.0.1").unwrap(),
},
HandlerConfig::StellarMsgVerifier {
cosmwasm_contract: TMAddress::from(
AccountId::new("axelar", &[0u8; 32]).unwrap(),
),
http_url: Url::from_str("http://127.0.0.1").unwrap(),
},
],
..Config::default()
}
Expand Down
21 changes: 21 additions & 0 deletions ampd/src/handlers/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ pub enum Config {
cosmwasm_contract: TMAddress,
proxy_url: Url,
},
StellarMsgVerifier {
cosmwasm_contract: TMAddress,
http_url: Url,
},
}

fn validate_multisig_signer_config<'de, D>(configs: &[Config]) -> Result<(), D::Error>
Expand Down Expand Up @@ -182,6 +186,22 @@ where
}
}

fn validate_stellar_msg_verifier_config<'de, D>(configs: &[Config]) -> Result<(), D::Error>
where
D: Deserializer<'de>,
{
match configs
.iter()
.filter(|config| matches!(config, Config::StellarMsgVerifier { .. }))
.count()
{
count if count > 1 => Err(de::Error::custom(
"only one Stellar msg verifier config is allowed",
)),
_ => Ok(()),
}
}

pub fn deserialize_handler_configs<'de, D>(deserializer: D) -> Result<Vec<Config>, D::Error>
where
D: Deserializer<'de>,
Expand All @@ -195,6 +215,7 @@ where
validate_sui_verifier_set_verifier_config::<D>(&configs)?;
validate_mvx_msg_verifier_config::<D>(&configs)?;
validate_mvx_worker_set_verifier_config::<D>(&configs)?;
validate_stellar_msg_verifier_config::<D>(&configs)?;

Ok(configs)
}
Expand Down
9 changes: 9 additions & 0 deletions ampd/src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod evm_verify_verifier_set;
pub mod multisig;
pub mod mvx_verify_msg;
pub mod mvx_verify_verifier_set;
pub(crate) mod stellar_verify_msg;
pub mod sui_verify_msg;
pub mod sui_verify_verifier_set;

Expand All @@ -18,6 +19,7 @@ mod tests {
use tendermint::abci;

use crate::types::TMAddress;
use crate::PREFIX;

/// Convert a CosmWasm event into an ABCI event
pub fn into_structured_event(
Expand All @@ -41,4 +43,11 @@ mod tests {
.try_into()
.expect("should convert to ABCI event")
}

pub fn participants(n: u8, verifier: Option<TMAddress>) -> Vec<TMAddress> {
(0..n)
.map(|_| TMAddress::random(PREFIX))
.chain(verifier)
.collect()
}
}
Loading

0 comments on commit 4f5d910

Please sign in to comment.