Skip to content

Commit

Permalink
Merge branch 'main' into stacks_ampd
Browse files Browse the repository at this point in the history
  • Loading branch information
raress96 committed Oct 29, 2024
2 parents 18d8a71 + 340975d commit 371da05
Show file tree
Hide file tree
Showing 46 changed files with 928 additions and 1,564 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ on:
- gateway
- multisig
- multisig-prover
- nexus-gateway
- rewards
- service-registry
- voting-verifier
Expand Down Expand Up @@ -45,7 +44,6 @@ jobs:
["gateway"]="gateway,/(major)|(major-gateway)|(major-contracts)/,/(minor)|(minor-gateway)|(minor-contracts)/,contracts/gateway packages"
["multisig"]="multisig,/(major)|(major-multisig)|(major-contracts)/,/(minor)|(minor-multisig)|(minor-contracts)/,contracts/multisig packages"
["multisig-prover"]="multisig-prover,/(major)|(major-multisig-prover)|(major-contracts)/,/(minor)|(minor-multisig-prover)|(minor-contracts)/,contracts/multisig-prover packages"
["nexus-gateway"]="nexus-gateway,/(major)|(major-nexus-gateway)|(major-contracts)/,/(minor)|(minor-nexus-gateway)|(minor-contracts)/,contracts/nexus-gateway packages"
["rewards"]="rewards,/(major)|(major-rewards)|(major-contracts)/,/(minor)|(minor-rewards)|(minor-contracts)/,contracts/rewards packages"
["service-registry"]="service-registry,/(major)|(major-service-registry)|(major-contracts)/,/(minor)|(minor-service-registry)|(minor-contracts)/,contracts/service-registry packages"
["voting-verifier"]="voting-verifier,/(major)|(major-voting-verifier)|(major-contracts)/,/(minor)|(minor-voting-verifier)|(minor-contracts)/,contracts/voting-verifier packages"
Expand Down
32 changes: 2 additions & 30 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ assert_ok = "1.0"
axelar-wasm-std = { version = "^1.0.0", path = "packages/axelar-wasm-std" }
axelar-wasm-std-derive = { version = "^1.0.0", path = "packages/axelar-wasm-std-derive" }
axelarnet-gateway = { version = "^1.0.0", path = "contracts/axelarnet-gateway" }
nexus-gateway = { version = "^1.0.0", path = "contracts/nexus-gateway" }
bcs = "0.1.5"
client = { version = "^1.0.0", path = "packages/client" }
coordinator = { version = "^1.0.0", path = "contracts/coordinator" }
Expand Down Expand Up @@ -54,7 +53,7 @@ quote = "1.0.36"
rand = "0.8.5"
report = { version = "^1.0.0", path = "packages/report" }
rewards = { version = "^1.1.0", path = "contracts/rewards" }
router = { version = "^1.0.0", path = "contracts/router" }
router = { version = "^1.0.1", path = "contracts/router" }
router-api = { version = "^1.0.0", path = "packages/router-api" }
schemars = "0.8.10"
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ contracts and `ampd` that work well together.
| gateway | 0.2.3 |
| multisig-prover | 0.6.0 |
| multisig | 0.4.1 |
| nexus-gateway | 0.3.0 |
| rewards | 0.4.0 |
| router | 0.4.0 |
| service-registry | 0.4.1 |
Expand Down
104 changes: 46 additions & 58 deletions ampd/src/stellar/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,80 +2,70 @@ use std::str::FromStr;

use axelar_wasm_std::voting::Vote;
use stellar::WeightedSigners;
use stellar_xdr::curr::{ContractEventBody, ScAddress, ScSymbol, ScVal, StringM};
use stellar_xdr::curr::{BytesM, ContractEventBody, ScAddress, ScBytes, ScSymbol, ScVal, StringM};

use crate::handlers::stellar_verify_msg::Message;
use crate::handlers::stellar_verify_verifier_set::VerifierSetConfirmation;
use crate::stellar::http_client::TxResponse;

const TOPIC_CALLED: &str = "called";
const TOPIC_ROTATED: &str = "rotated";
const TOPIC_CONTRACT_CALLED: &str = "contract_called";
const TOPIC_SIGNERS_ROTATED: &str = "signers_rotated";

impl PartialEq<ContractEventBody> for Message {
fn eq(&self, event: &ContractEventBody) -> bool {
let ContractEventBody::V0(body) = event;

if body.topics.len() != 3 {
if body.topics.len() != 5 {
return false;
}

let [symbol, source_address, payload_hash] = &body.topics[..] else {
let [symbol, source_address, destination_chain, destination_address, payload_hash] =
&body.topics[..]
else {
return false;
};

let expected_topic: ScVal =
ScSymbol(StringM::from_str(TOPIC_CALLED).expect("must convert str to ScSymbol")).into();

let (dest_chain, dest_address) = match &body.data {
ScVal::Vec(Some(data)) if data.len() == 3 => {
let [dest_chain, dest_address, _] = &data[..] else {
return false;
};
(dest_chain, dest_address)
}
_ => return false,
};
let expected_topic: ScVal = ScSymbol(
StringM::from_str(TOPIC_CONTRACT_CALLED).expect("must convert str to ScSymbol"),
)
.into();

expected_topic == *symbol
&& (ScVal::Address(self.source_address.clone()) == *source_address)
&& (ScVal::Bytes(self.payload_hash.clone()) == *payload_hash)
&& (ScVal::String(self.destination_chain.clone()) == *dest_chain)
&& (ScVal::String(self.destination_address.clone()) == *dest_address)
&& (ScVal::String(self.destination_chain.clone()) == *destination_chain)
&& (ScVal::String(self.destination_address.clone()) == *destination_address)
}
}

impl PartialEq<ContractEventBody> for VerifierSetConfirmation {
fn eq(&self, event: &ContractEventBody) -> bool {
let ContractEventBody::V0(body) = event;

if body.topics.len() != 1 {
if body.topics.len() != 3 {
return false;
}

let [symbol] = &body.topics[..] else {
let [symbol, _, signers_hash] = &body.topics[..] else {
return false;
};

let expected_topic: ScVal =
ScSymbol(StringM::from_str(TOPIC_ROTATED).expect("must convert str to ScSymbol"))
.into();

let rotated_signers = match &body.data {
ScVal::Vec(Some(data)) if data.len() == 1 => {
let [rotated_signers] = &data[..] else {
return false;
};
rotated_signers.clone()
}
_ => return false,
};
let expected_topic: ScVal = ScSymbol(
StringM::from_str(TOPIC_SIGNERS_ROTATED).expect("must convert str to ScSymbol"),
)
.into();

WeightedSigners::try_from(&self.verifier_set)
let Some(weighted_signers_hash) = WeightedSigners::try_from(&self.verifier_set)
.ok()
.and_then(|signers| ScVal::try_from(signers).ok())
.map_or(false, |signers: ScVal| {
symbol == &expected_topic && signers == rotated_signers
})
.and_then(|weighted_signers| weighted_signers.hash().ok())
.and_then(|signers_hash| BytesM::try_from(signers_hash).ok())
.map(ScBytes)
.map(ScVal::Bytes)
else {
return false;
};

&expected_topic == symbol && &weighted_signers_hash == signers_hash
}
}

Expand Down Expand Up @@ -147,14 +137,14 @@ mod test {
use stellar::WeightedSigners;
use stellar_xdr::curr::{
AccountId, BytesM, ContractEvent, ContractEventBody, ContractEventType, ContractEventV0,
PublicKey, ScAddress, ScBytes, ScString, ScSymbol, ScVal, ScVec, StringM, Uint256,
PublicKey, ScAddress, ScBytes, ScString, ScSymbol, ScVal, StringM, Uint256,
};

use crate::handlers::stellar_verify_msg::Message;
use crate::handlers::stellar_verify_verifier_set::VerifierSetConfirmation;
use crate::stellar::http_client::TxResponse;
use crate::stellar::verifier::{
verify_message, verify_verifier_set, TOPIC_CALLED, TOPIC_ROTATED,
verify_message, verify_verifier_set, TOPIC_CONTRACT_CALLED, TOPIC_SIGNERS_ROTATED,
};
use crate::types::{EVMAddress, Hash};
use crate::PREFIX;
Expand Down Expand Up @@ -317,21 +307,15 @@ mod test {

let event_body = ContractEventBody::V0(ContractEventV0 {
topics: vec![
ScVal::Symbol(ScSymbol(StringM::from_str(TOPIC_CALLED).unwrap())),
ScVal::Symbol(ScSymbol(StringM::from_str(TOPIC_CONTRACT_CALLED).unwrap())),
ScVal::Address(msg.source_address.clone()),
ScVal::String(msg.destination_chain.clone()),
ScVal::String(msg.destination_address.clone()),
ScVal::Bytes(msg.payload_hash.clone()),
]
.try_into()
.unwrap(),
data: ScVal::Vec(Some(
vec![
ScVal::String(msg.destination_chain.clone()),
ScVal::String(msg.destination_address.clone()),
ScVal::String(StringM::from_str("payload").unwrap().into()),
]
.try_into()
.unwrap(),
)),
data: ScVal::Bytes(BytesM::try_from("payload".as_bytes()).unwrap().into()),
});

let event = ContractEvent {
Expand Down Expand Up @@ -372,19 +356,23 @@ mod test {
},
};

let weighted_signers: ScVal =
let weighted_signers_hash = BytesM::try_from(
WeightedSigners::try_from(&verifier_set_confirmation.verifier_set)
.unwrap()
.try_into()
.unwrap();
.hash()
.unwrap(),
)
.unwrap();

let event_body = ContractEventBody::V0(ContractEventV0 {
topics: vec![ScVal::Symbol(ScSymbol(
StringM::from_str(TOPIC_ROTATED).unwrap(),
))]
topics: vec![
ScVal::Symbol(ScSymbol(StringM::from_str(TOPIC_SIGNERS_ROTATED).unwrap())),
ScVal::U64(1),
ScVal::Bytes(ScBytes(weighted_signers_hash)),
]
.try_into()
.unwrap(),
data: ScVal::Vec(Some(ScVec::try_from(vec![weighted_signers]).unwrap())),
data: ().into(),
});

let event = ContractEvent {
Expand Down
2 changes: 1 addition & 1 deletion contracts/axelarnet-gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ cw2 = { workspace = true }
error-stack = { workspace = true }
itertools = { workspace = true }
msgs-derive = { workspace = true }
nexus-gateway = { workspace = true, features = ["library"] }
report = { workspace = true }
router-api = { workspace = true }
serde = { workspace = true }
Expand All @@ -51,6 +50,7 @@ thiserror = { workspace = true }

[dev-dependencies]
assert_ok = { workspace = true }
axelar-core-std = { workspace = true, features = ["test"] }
cw-multi-test = { workspace = true }
goldie = { workspace = true }
hex = { workspace = true }
Expand Down
21 changes: 16 additions & 5 deletions contracts/axelarnet-gateway/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ use axelar_wasm_std::error::ContractError;
use axelar_wasm_std::{address, FnExt, IntoContractError};
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{to_json_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response};
use error_stack::ResultExt;
use cosmwasm_std::{
to_json_binary, Addr, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response, Storage,
};
use error_stack::{Report, ResultExt};

use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use crate::state::{self, Config};
Expand Down Expand Up @@ -70,7 +72,7 @@ pub fn execute(
info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response<nexus::execute::Message>, ContractError> {
match msg.ensure_permissions(deps.storage, &info.sender)? {
match msg.ensure_permissions(deps.storage, &info.sender, match_nexus)? {
ExecuteMsg::CallContract {
destination_chain,
destination_address,
Expand All @@ -86,11 +88,16 @@ pub fn execute(
},
)
.change_context(Error::CallContract),
ExecuteMsg::RouteMessages(msgs) => execute::route_messages(deps.storage, info.sender, msgs)
.change_context(Error::RouteMessages),
ExecuteMsg::RouteMessages(msgs) => {
execute::route_messages(deps.storage, deps.querier, info.sender, msgs)
.change_context(Error::RouteMessages)
}
ExecuteMsg::Execute { cc_id, payload } => {
execute::execute(deps, cc_id, payload).change_context(Error::Execute)
}
ExecuteMsg::RouteMessagesFromNexus(msgs) => {
Ok(execute::route_messages_from_nexus(deps.storage, msgs)?)
}
}?
.then(Ok)
}
Expand All @@ -111,6 +118,10 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result<Binary, ContractErr
.then(Ok)
}

fn match_nexus(storage: &dyn Storage, _: &ExecuteMsg) -> Result<Addr, Report<Error>> {
Ok(state::load_config(storage).nexus)
}

#[cfg(test)]
mod tests {
use assert_ok::assert_ok;
Expand Down
Loading

0 comments on commit 371da05

Please sign in to comment.