Skip to content

Commit

Permalink
Merge branch 'main' into link_custom_tokens_refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcobb23 authored Jan 9, 2025
2 parents 52aa3ac + a7cb956 commit 482b8bf
Show file tree
Hide file tree
Showing 15 changed files with 858 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-contracts-and-push-to-r2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ jobs:
fi
mkdir -p "../${crate_version}"
cp "$wasm_file" "../${crate_version}/${crate_name}.wasm"
cp "$wasm_file" "../${crate_version}/${crate_name//-/_}.wasm"
cp "$checksum_file" "../${crate_version}/"
gpg --armor --detach-sign ../${crate_version}/${crate_name}.wasm
gpg --armor --detach-sign ../${crate_version}/${crate_name//-/_}.wasm
gpg --armor --detach-sign ../${crate_version}/checksums.txt
echo "release-artifacts-dir=./${crate_version}" >> $GITHUB_OUTPUT
Expand Down
52 changes: 52 additions & 0 deletions Cargo.lock

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

26 changes: 18 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[workspace]
members = [
"ampd",
"contracts/*",
"external-gateways/*",
"integration-tests",
"packages/*"
"ampd",
"contracts/*",
"external-gateways/*",
"integration-tests",
"packages/*",
]
resolver = "2"

Expand All @@ -13,8 +13,12 @@ rust-version = "1.78.0" # be sure there is an optimizer release supporting this
edition = "2021"

[workspace.dependencies]
alloy-primitives = { version = "0.7.6", default-features = false, features = ["std"] }
alloy-sol-types = { version = "0.7.6", default-features = false, features = ["std"] }
alloy-primitives = { version = "0.7.6", default-features = false, features = [
"std",
] }
alloy-sol-types = { version = "0.7.6", default-features = false, features = [
"std",
] }
anyhow = "1.0.89"
assert_ok = "1.0"
axelar-wasm-std = { version = "^1.0.0", path = "packages/axelar-wasm-std" }
Expand All @@ -33,7 +37,9 @@ cw-utils = "2.0.0"
cw2 = "2.0.0"
ed25519-dalek = { version = "2.1.1", default-features = false }
error-stack = { version = "0.4.0", features = ["eyre"] }
ethers-contract = { version = "2.0.14", default-features = false, features = ["abigen"] }
ethers-contract = { version = "2.0.14", default-features = false, features = [
"abigen",
] }
ethers-core = "2.0.14"
events = { version = "^1.0.0", path = "packages/events" }
events-derive = { version = "^1.0.0", path = "packages/events-derive" }
Expand Down Expand Up @@ -72,6 +78,10 @@ stellar-xdr = { version = "21.2.0" }
strum = { version = "0.25", default-features = false, features = ["derive"] }
sui-gateway = { version = "^1.0.0", path = "packages/sui-gateway" }
sui-types = { version = "^1.0.0", path = "packages/sui-types" }
starknet-checked-felt = { version = "^1.0.0", path = "packages/starknet-checked-felt" }
starknet-types-core = { version = "0.1.7" }
starknet-core = "0.12.0"
starknet-providers = "0.12.0"
syn = "2.0.92"
thiserror = "1.0.61"
tofn = { version = "1.1" }
Expand Down
1 change: 1 addition & 0 deletions contracts/router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ thiserror = { workspace = true }
assert_ok = { workspace = true }
axelar-core-std = { workspace = true, features = ["test"] }
cw-multi-test = { workspace = true }
goldie = { workspace = true }
hex = { version = "0.4.3", default-features = false }
integration-tests = { workspace = true }
rand = { workspace = true }
Expand Down
15 changes: 15 additions & 0 deletions contracts/router/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1823,4 +1823,19 @@ mod test {
)
.is_ok());
}

#[test]
fn chain_info_fails_on_unregistered_chain() {
let deps = setup();
let unregistered_chain: ChainName = "unregistered".parse().unwrap();

// Ensure that the error message doesn't change unexpectedly since the relayer depends on it
let err = query(
deps.as_ref(),
mock_env(),
QueryMsg::ChainInfo(unregistered_chain),
)
.unwrap_err();
goldie::assert!(err.to_string());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
chain is not found
6 changes: 2 additions & 4 deletions contracts/voting-verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ rust-version = { workspace = true }
edition = { workspace = true }
description = "Voting verifier contract"

exclude = [
"contract.wasm",
"hash.txt"
]
exclude = ["contract.wasm", "hash.txt"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
Expand Down Expand Up @@ -58,6 +55,7 @@ integration-tests = { workspace = true }
multisig = { workspace = true, features = ["test", "library"] }
rand = { workspace = true }
sha3 = { workspace = true }
starknet-checked-felt = { workspace = true }

[lints]
workspace = true
83 changes: 81 additions & 2 deletions contracts/voting-verifier/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ mod test {
use assert_ok::assert_ok;
use axelar_wasm_std::address::AddressFormat;
use axelar_wasm_std::msg_id::{
Base58SolanaTxSignatureAndEventIndex, Base58TxDigestAndEventIndex, HexTxHash,
HexTxHashAndEventIndex, MessageIdFormat,
Base58SolanaTxSignatureAndEventIndex, Base58TxDigestAndEventIndex,
FieldElementAndEventIndex, HexTxHash, HexTxHashAndEventIndex, MessageIdFormat,
};
use axelar_wasm_std::voting::Vote;
use axelar_wasm_std::{
Expand All @@ -143,6 +143,7 @@ mod test {
AuthorizationState, BondingState, Verifier, WeightedVerifier, VERIFIER_WEIGHT,
};
use sha3::{Digest, Keccak256, Keccak512};
use starknet_checked_felt::CheckedFelt;

use super::*;
use crate::error::ContractError;
Expand Down Expand Up @@ -241,6 +242,17 @@ mod test {

fn message_id(id: &str, index: u64, msg_id_format: &MessageIdFormat) -> nonempty::String {
match msg_id_format {
MessageIdFormat::FieldElementAndEventIndex => {
let mut id_bytes: [u8; 32] = Keccak256::digest(id.as_bytes()).into();
id_bytes[0] = 0; // felt is ~31 bytes
FieldElementAndEventIndex {
tx_hash: CheckedFelt::try_from(&id_bytes).unwrap(),
event_index: index,
}
.to_string()
.parse()
.unwrap()
}
MessageIdFormat::HexTxHashAndEventIndex => HexTxHashAndEventIndex {
tx_hash: Keccak256::digest(id.as_bytes()).into(),
event_index: index,
Expand Down Expand Up @@ -355,10 +367,53 @@ mod test {
address_format: AddressFormat::Eip55,
should_fail: true,
},
TestCase {
source_gateway_address:
// 63 chars
"0x06cdc5221388566e09e1a9be3dcfd4b1bbb4abf98296bb4674401a79373cce5"
.to_string()
.to_lowercase(),
address_format: AddressFormat::Starknet,
should_fail: true,
},
TestCase {
source_gateway_address:
// 62 chars
"0x6cdc5221388566e09e1a9be3dcfd4b1bbb4abf98296bb4674401a79373cce5"
.to_string()
.to_lowercase(),
address_format: AddressFormat::Starknet,
should_fail: true,
},
TestCase {
source_gateway_address:
// 64 chars, but out of prime field range
"0xff6cdc5221388566e09e1a9be3dcfd4b1bbb4abf98296bb4674401a79373cce5"
.to_string()
.to_lowercase(),
address_format: AddressFormat::Starknet,
should_fail: true,
},
TestCase {
source_gateway_address:
"0x006cdc5221388566e09e1a9be3dcfd4b1bbb4abf98296bb4674401a79373cce5"
.to_string()
.to_lowercase(),
address_format: AddressFormat::Starknet,
should_fail: false,
},
TestCase {
source_gateway_address: "0x4F4495243837681061C4743b74B3eEdf548D56A5"
.to_string()
.to_lowercase(),
address_format: AddressFormat::Starknet,
should_fail: true,
},
TestCase {
source_gateway_address:
"0xdb1473ed56ddede13225b99d779ebf9d9011874e26acbb8bfec8b6a43d0fbcaa"
.to_string()
.to_uppercase(),
address_format: AddressFormat::Sui,
should_fail: true,
},
Expand Down Expand Up @@ -499,6 +554,29 @@ mod test {
);
}

#[test]
fn should_fail_if_messages_have_hex_msg_id_but_contract_expects_field_element() {
let msg_id_format = MessageIdFormat::FieldElementAndEventIndex;
let verifiers = verifiers(2);
let mut deps = setup(verifiers.clone(), &msg_id_format);

let messages = messages(1, &MessageIdFormat::HexTxHashAndEventIndex);
let msg = ExecuteMsg::VerifyMessages(messages.clone());
let api = deps.api;

let err = execute(
deps.as_mut(),
mock_env(),
message_info(&api.addr_make(SENDER), &[]),
msg,
)
.unwrap_err();
assert_contract_err_strings_equal(
err,
ContractError::InvalidMessageID(messages[0].cc_id.message_id.to_string()),
);
}

#[test]
fn should_fail_if_messages_have_hex_msg_id_but_contract_expects_base58() {
let msg_id_format = MessageIdFormat::Base58TxDigestAndEventIndex;
Expand Down Expand Up @@ -880,6 +958,7 @@ mod test {
[
(v, s, MessageIdFormat::HexTxHashAndEventIndex),
(v, s, MessageIdFormat::Base58TxDigestAndEventIndex),
(v, s, MessageIdFormat::FieldElementAndEventIndex),
]
})
.collect::<Vec<_>>();
Expand Down
14 changes: 12 additions & 2 deletions contracts/voting-verifier/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::str::FromStr;
use std::vec::Vec;

use axelar_wasm_std::msg_id::{
Base58SolanaTxSignatureAndEventIndex, Base58TxDigestAndEventIndex, Bech32mFormat, HexTxHash,
HexTxHashAndEventIndex, MessageIdFormat,
Base58SolanaTxSignatureAndEventIndex, Base58TxDigestAndEventIndex, Bech32mFormat,
FieldElementAndEventIndex, HexTxHash, HexTxHashAndEventIndex, MessageIdFormat,
};
use axelar_wasm_std::voting::{PollId, Vote};
use axelar_wasm_std::{nonempty, VerificationStatus};
Expand Down Expand Up @@ -160,6 +160,16 @@ fn parse_message_id(
.map_err(|_| ContractError::InvalidMessageID(message_id.to_string()))?,
))
}
MessageIdFormat::FieldElementAndEventIndex => {
let id = FieldElementAndEventIndex::from_str(message_id)
.map_err(|_| ContractError::InvalidMessageID(message_id.to_string()))?;

Ok((
id.tx_hash_as_hex(),
u32::try_from(id.event_index)
.map_err(|_| ContractError::InvalidMessageID(message_id.to_string()))?,
))
}
MessageIdFormat::HexTxHashAndEventIndex => {
let id = HexTxHashAndEventIndex::from_str(message_id)
.map_err(|_| ContractError::InvalidMessageID(message_id.to_string()))?;
Expand Down
11 changes: 6 additions & 5 deletions packages/axelar-wasm-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ rust-version = { workspace = true }
edition = { workspace = true }
description = "Axelar cosmwasm standard library crate"

exclude = [
"contract.wasm",
"hash.txt"
]
exclude = ["contract.wasm", "hash.txt"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
Expand Down Expand Up @@ -39,14 +36,18 @@ into-inner-derive = { workspace = true }
itertools = { workspace = true }
lazy_static = "1.4.0"
num-traits = { workspace = true }
regex = { version = "1.10.0", default-features = false, features = ["perf", "std"] }
regex = { version = "1.10.0", default-features = false, features = [
"perf",
"std",
] }
report = { workspace = true }
schemars = "0.8.10"
semver = { workspace = true }
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
serde_json = "1.0.89"
serde_with = { version = "3.11.0", features = ["macros"] }
sha3 = { workspace = true }
starknet-checked-felt = { workspace = true }
stellar-xdr = { workspace = true }
strum = { workspace = true }
sui-types = { workspace = true }
Expand Down
Loading

0 comments on commit 482b8bf

Please sign in to comment.