Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F/injective protos #146

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[workspace]
members = [
"contracts/core/*",
"contracts/hooks/*",
"contracts/igps/*",
"contracts/isms/*",
"contracts/mocks/*",
"contracts/warp/*",
"packages/*",
"integration-test",
"contracts/core/*",
"contracts/hooks/*",
"contracts/igps/*",
"contracts/isms/*",
"contracts/mocks/*",
"contracts/warp/*",
"packages/*",
"integration-test",
]
resolver = "2"

Expand All @@ -27,11 +27,11 @@ panic = "abort"
rpath = false

[workspace.package]
version = "0.0.6"
version = "0.0.7"
authors = [
"byeongsu-hong <[email protected]>",
"Eric <[email protected]>",
"Steve <[email protected]>",
"byeongsu-hong <[email protected]>",
"Eric <[email protected]>",
"Steve <[email protected]>",
]
edition = "2021"
license = "Apache-2.0"
Expand Down Expand Up @@ -68,7 +68,7 @@ serde_json = "1.0.96"
serde-json-wasm = "1.0.0"
schemars = "0.8.12"
prost = { version = "0.12.1", default-features = false, features = [
"prost-derive",
"prost-derive",
] }
prost-types = { version = "0.12.1", default-features = false }
hex-literal = { version = "0.4.1" }
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ optimize:
docker run --rm -v "$(PWD)":/code \
--mount type=volume,source="$(BASE)_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/optimizer:0.15.0
cosmwasm/optimizer:0.16.1

optimize-fast:
cargo cw-optimizoor
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

## Prerequisites

- rename
- foundry
- rust (wasm32-wasm32-unknown target)
- go 1.20 or higher
- llvm-cov
Expand Down
41 changes: 41 additions & 0 deletions context/injective-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "v0.0.7",
"artifacts": {
"hpl_hook_aggregate": 381,
"hpl_hook_fee": 382,
"hpl_hook_merkle": 383,
"hpl_hook_pausable": 384,
"hpl_hook_routing": 385,
"hpl_hook_routing_custom": 386,
"hpl_hook_routing_fallback": 387,
"hpl_igp": 388,
"hpl_igp_oracle": 389,
"hpl_ism_aggregate": 390,
"hpl_ism_multisig": 1183,
"hpl_ism_pausable": 392,
"hpl_ism_routing": 393,
"hpl_mailbox": 394,
"hpl_test_mock_hook": 395,
"hpl_test_mock_ism": 396,
"hpl_test_mock_msg_receiver": 397,
"hpl_validator_announce": 398,
"hpl_warp_cw20": 399,
"hpl_warp_native": 400
},
"deployments": {
"core": {
"mailbox": {
"type": "hpl_mailbox",
"address": "inj1palm2wtp6urg0c6j4f2ukv5u5ahdcrqek0sapt"
},
"validator_announce": {
"type": "hpl_validator_announce",
"address": "inj1r7eztvhul0n4uc22r438m6tl7dezgthdw2cjjx"
}
},
"isms": {
"type": "hpl_ism_multisig",
"address": "inj17hfpmd6yqy3gs4sxc0hh779k3nvldu5rpjkepn"
}
}
}
2 changes: 1 addition & 1 deletion contracts/igps/core/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn instantiate(

GAS_TOKEN.save(deps.storage, &msg.gas_token)?;
HRP.save(deps.storage, &msg.hrp)?;
DEFAULT_GAS_USAGE.save(deps.storage, &msg.default_gas_usage)?;
DEFAULT_GAS_USAGE.save(deps.storage, &msg.default_gas_usage.into())?;

Ok(Response::new().add_event(
new_event("initialize")
Expand Down
4 changes: 2 additions & 2 deletions contracts/igps/core/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cosmwasm_std::{
from_json,
testing::{mock_info, MockApi, MockQuerier, MockStorage},
Addr, Coin, Deps, DepsMut, Empty, Env, HexBinary, MessageInfo, OwnedDeps, Response,
Addr, Coin, Deps, DepsMut, Empty, Env, HexBinary, MessageInfo, OwnedDeps, Response, Uint128,
};
use hpl_interface::{
hook::PostDispatchMsg,
Expand Down Expand Up @@ -54,7 +54,7 @@ impl IGP {
owner: owner.to_string(),
gas_token: gas_token.to_string(),
beneficiary: beneficiary.to_string(),
default_gas_usage: 250_000,
default_gas_usage: Uint128::from(250_000u128),
},
)
}
Expand Down
60 changes: 55 additions & 5 deletions contracts/isms/multisig/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashSet;

use cosmwasm_std::{Deps, HexBinary};
use hpl_interface::{
ism::{IsmType, ModuleTypeResponse, VerifyInfoResponse, VerifyResponse},
Expand Down Expand Up @@ -35,20 +37,25 @@ pub fn verify_message(

let hashed_message = eth_hash(multisig_hash)?;

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

let mut matched_validators = HashSet::new();

for signature in metadata.signatures {
let signature = signature.as_slice();
let pubkey = deps.api.secp256k1_recover_pubkey(
let signer_pubkey = deps.api.secp256k1_recover_pubkey(
&hashed_message,
&signature[..64],
signature[64] - 27,
)?;

if validators.contains(&eth_addr(pubkey.into())?) {
let signer_addr = eth_addr(signer_pubkey.into())?;

if validators.contains(&signer_addr) && !matched_validators.contains(&signer_addr) {
threshold -= 1;
matched_validators.insert(signer_addr);

if threshold == 0 {
break;
}
Expand Down Expand Up @@ -81,7 +88,7 @@ mod test {
use cosmwasm_std::{testing::mock_dependencies, HexBinary};
use hpl_interface::{
ism::{IsmType, ModuleTypeResponse, VerifyResponse},
types::{eth_addr, Message},
types::{eth_addr, Message, MessageIdMultisigIsmMetadata},
};
use ibcx_test_utils::hex;
use k256::{ecdsa::SigningKey, elliptic_curve::rand_core::OsRng};
Expand All @@ -104,7 +111,7 @@ mod test {
#[rstest]
#[case(
hex("0000000000000068220000000000000000000000000d1255b09d94659bb0888e0aa9fca60245ce402a0000682155208cd518cffaac1b5d8df216a9bd050c9a03f0d4f3ba88e5268ac4cd12ee2d68656c6c6f"),
hex("986a1625d44e4b3969b08a5876171b2b4fcdf61b3e5c70a86ad17b304f17740a9f45d99ea6bec61392a47684f4e5d1416ddbcb5fdef0f132c27d7034e9bbff1c00000000ba9911d78ec6d561413e3589f920388cbd7554fbddd8ce50739337250853ec3577a51fa40e727c05b50f15db13f5aad5857c89d432644be48d70325ea83fdb6c1c"),
hex("986a1625d44e4b3969b08a5876171b2b4fcdf61b3e5c70a86ad17b304f17740a9f45d99ea6bec61392a47684f4e5d1416ddbcb5fdef0f132c27d7034e9bbff1c00000000ba9911d78ec6d561413e3589f920388cbd7554fbddd8ce50739337250853ec3577a51fa40e727c05b50f15db13f5aad5857c89d432644be48d70325ea83fdb6c1c"),
vec![
hex("122e0663ccc190266427e7fc0ed6589b5d7d36db"),
hex("01d7525e91dfc3f594fd366aad70f956b398de9e"),
Expand Down Expand Up @@ -139,6 +146,49 @@ mod test {
assert_eq!(res, VerifyResponse { verified: true });
}

#[test]
fn test_verify_prevent_reuse_of_validator_signature() {
let mut deps = mock_dependencies();

let threshold = 2u8;
let validators = vec![
hex("ebc301013b6cd2548e347c28d2dc43ec20c068f2"),
hex("315db9868fc8813b221b1694f8760ece39f45447"),
hex("17517c98358c5937c5d9ee47ce1f5b4c2b7fc9f5"),
];

let message = Message {
version: 3,
nonce: 36,
origin_domain: 80001,
sender: hex("00000000000000000000000004980c17e2ce26578c82f81207e706e4505fae3b"),
dest_domain: 43113,
recipient: hex("0000000000000000000000000b1c1b54f45e02552331d3106e71f5e0b573d5d4"),
body: hex("48656c6c6f21"),
};

let metadata = MessageIdMultisigIsmMetadata {
origin_merkle_tree: hex("0000000000000000000000009af85731edd41e2e50f81ef8a0a69d2fb836edf9"),
merkle_root: hex("a84430f822e0e9b5942faace72bd5b97f0b59a58a9b8281231d9e5c393b5859c"),
merkle_index: hex("00000024"),
signatures: [
// same signature
hex("539feceace17782697e29e74151006dc7b47227cf48aba02926336cb5f7fa38b3d05e8293045f7b5811eda3ae8aa070116bb5fbf57c79e143a69e909df90cefa1b"),
hex("539feceace17782697e29e74151006dc7b47227cf48aba02926336cb5f7fa38b3d05e8293045f7b5811eda3ae8aa070116bb5fbf57c79e143a69e909df90cefa1b")
].to_vec()
};

VALIDATORS
.save(deps.as_mut().storage, message.origin_domain, &validators)
.unwrap();
THRESHOLD
.save(deps.as_mut().storage, message.origin_domain, &threshold)
.unwrap();

let res = verify_message(deps.as_ref(), metadata.into(), message.into()).unwrap();
assert_eq!(res, VerifyResponse { verified: false });
}

#[test]
fn test_get_verify_info() {
let raw_message = hex("0000000000000068220000000000000000000000000d1255b09d94659bb0888e0aa9fca60245ce402a0000682155208cd518cffaac1b5d8df216a9bd050c9a03f0d4f3ba88e5268ac4cd12ee2d68656c6c6f");
Expand Down
66 changes: 37 additions & 29 deletions contracts/warp/native/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,55 +1,63 @@
[package]
name = "hpl-warp-native"
version.workspace = true
authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
homepage.workspace = true
authors.workspace = true
documentation.workspace = true
keywords.workspace = true
edition.workspace = true
homepage.workspace = true
keywords.workspace = true
license.workspace = true
name = "hpl-warp-native"
repository.workspace = true
version.workspace = true

[lib]
crate-type = ["cdylib", "rlib"]
crate-type = [ "cdylib", "rlib" ]

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
backtraces = [ "cosmwasm-std/backtraces" ]
# use library feature to disable all instantiate/execute/query exports
library = []
default = [ "osmosis" ]
library = [ ]

injective = [ ]
osmosis = [ ]

[package.metadata.optimizer]
builds = [ { name = "injective", features = [ "injective" ], default-features = false }, { name = "osmosis", features = [ "osmosis" ], default-features = false } ]
default-build = true

[dependencies]
cosmwasm-std.workspace = true
cosmwasm-schema.workspace = true
cosmwasm-std.workspace = true
cosmwasm-storage.workspace = true
cosmwasm-schema.workspace = true

cw-storage-plus.workspace = true
cw-utils.workspace = true
cw2.workspace = true
cw-utils.workspace = true
cw2.workspace = true

sha2.workspace = true
ripemd.workspace = true
sha2.workspace = true

bech32.workspace = true
schemars.workspace = true
prost.workspace = true
prost-types.workspace = true
serde.workspace = true
bech32.workspace = true
prost.workspace = true
prost-types.workspace = true
schemars.workspace = true
serde.workspace = true
serde-json-wasm.workspace = true

thiserror.workspace = true

hpl-utils.workspace = true
hpl-connection.workspace = true
hpl-ownable.workspace = true
hpl-router.workspace = true
hpl-interface.workspace = true
hpl-interface.workspace = true
hpl-ownable.workspace = true
hpl-router.workspace = true
hpl-utils.workspace = true

[dev-dependencies]
serde-json-wasm.workspace = true

anyhow.workspace = true
ibcx-test-utils.workspace = true
rstest.workspace = true
anyhow.workspace = true
k256.workspace = true
sha3.workspace = true
k256.workspace = true
rstest.workspace = true
sha3.workspace = true
Loading