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

Signature verification 2.x line #550

Merged
merged 12 commits into from
Nov 3, 2023
Merged
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
365 changes: 88 additions & 277 deletions orchestrator/Cargo.lock

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions orchestrator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Also, the name was changed from orchestrator to gravity_bridge.
[package]
name = "gravity_bridge"
version = "2.0.4"
version = "2.0.5"
authors = ["PeggyJV"]
license = "Apache-2.0"
edition = "2018"
Expand All @@ -28,18 +28,17 @@ members = [
"gravity_abi",
]

[workspace.dependencies]
clarity = "0.4.16"

[dependencies]
orchestrator = { path = "./orchestrator" }
cosmos_gravity = { path = "./cosmos_gravity" }
ethereum_gravity = { path = "./ethereum_gravity" }
gravity_utils = { path = "./gravity_utils" }
gravity_proto_build = { path = "./gravity_proto_build" }
test_runner = { path = "./test_runner" }
gravity_proto = { path = "./gravity_proto" }
register_delegate_keys = { path = "./register_delegate_keys" }
gorc = { path = "./gorc" }
relayer = { path = "./relayer" }
gravity_abi_build = { path = "./gravity_abi_build" }
gravity_abi = { path = "./gravity_abi" }

[features]
Expand All @@ -48,5 +47,4 @@ ethermint = [
"cosmos_gravity/ethermint",
"relayer/ethermint",
"gorc/ethermint",
"register_delegate_keys/ethermint",
]
2 changes: 1 addition & 1 deletion orchestrator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Reference: https://www.lpalmieri.com/posts/fast-rust-docker-builds/

FROM rust:1.63 as cargo-chef-rust
FROM rust:1.68 as cargo-chef-rust
RUN cargo install cargo-chef --version 0.1.51

FROM cargo-chef-rust as planner
Expand Down
5 changes: 2 additions & 3 deletions orchestrator/cosmos_gravity/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cosmos_gravity"
version = "2.0.4"
version = "2.0.5"
authors = ["Justin Kilpatrick <justin@althea.net>"]
edition = "2018"

Expand All @@ -13,12 +13,11 @@ gravity_proto = {path = "../gravity_proto/"}

deep_space = { git = "https://github.com/iqlusioninc/deep_space/", branch = "master" }
ethers = { git = "https://github.com/iqlusioninc/ethers-rs.git", branch="zaki/error_abi_support", features = ["abigen"] }
clarity = "0.4.11"
clarity.workspace = true
serde = "1.0"
log = "0.4"
sha3 = "0.9"
tokio = "1.4"
web30 = "0.15.4"
tonic = "0.4"
cosmos-sdk-proto = "0.6.3"
prost = "0.7"
Expand Down
4 changes: 2 additions & 2 deletions orchestrator/cosmos_gravity/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::collections::BTreeMap;

use crate::crypto::PrivateKey as CosmosPrivateKey;

lazy_static!{
lazy_static! {
static ref DENOM_REGEX: Regex = Regex::new("^[a-zA-Z][a-zA-Z0-9/-]{2,127}$").unwrap();
}

Expand Down Expand Up @@ -247,7 +247,7 @@ pub fn ethereum_event_messages(
// be rejected by the chain when processed.
pub fn denom_string(input_denom: String) -> String {
if !DENOM_REGEX.is_match(input_denom.as_str()) {
return "invalid".to_string()
return "invalid".to_string();
}

input_denom
Expand Down
31 changes: 31 additions & 0 deletions orchestrator/cosmos_gravity/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use clarity::Signature;
use deep_space::address::Address;
use ethers::types::Address as EthAddress;
use gravity_proto::gravity::query_client::QueryClient as GravityQueryClient;
Expand Down Expand Up @@ -63,6 +64,16 @@ pub async fn get_all_valset_confirms(
let confirms = request.into_inner().signatures;
let mut parsed_confirms = Vec::new();
for item in confirms {
if let Err(e) = Signature::from_bytes(&item.signature)?.error_check() {
warn!(
"ignoring valset confirmation with invalid signature from {}",
item.ethereum_signer
);
debug!("reason given for invalid signature: {e:?}");

continue;
}

parsed_confirms.push(ValsetConfirmResponse::from_proto(item)?)
}
Ok(parsed_confirms)
Expand Down Expand Up @@ -124,6 +135,16 @@ pub async fn get_transaction_batch_signatures(
let batch_confirms = request.into_inner().signatures;
let mut out = Vec::new();
for confirm in batch_confirms {
if let Err(e) = Signature::from_bytes(&confirm.signature)?.error_check() {
warn!(
"ignoring batch confirmation with invalid signature from {}",
confirm.ethereum_signer
);
debug!("reason given for invalid signature: {e:?}");

continue;
}

out.push(BatchConfirmResponse::from_proto(confirm)?)
}
Ok(out)
Expand Down Expand Up @@ -179,6 +200,16 @@ pub async fn get_logic_call_signatures(
let call_confirms = request.into_inner().signatures;
let mut out = Vec::new();
for confirm in call_confirms {
if let Err(e) = Signature::from_bytes(&confirm.signature)?.error_check() {
warn!(
"ignoring logic call confirmation with invalid signature from {}",
confirm.ethereum_signer
);
debug!("reason given for invalid signature: {e:?}");

continue;
}

out.push(LogicCallConfirmResponse::from_proto(confirm)?)
}
Ok(out)
Expand Down
2 changes: 1 addition & 1 deletion orchestrator/cosmos_gravity/src/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,4 @@ fn log_send_error(messages: &Vec<Msg>, err: GravityError) {
msg_types,
err
);
}
}
5 changes: 1 addition & 4 deletions orchestrator/ethereum_gravity/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ethereum_gravity"
version = "0.1.0"
version = "2.0.5"
authors = ["Justin Kilpatrick <justin@althea.net>"]
edition = "2018"

Expand All @@ -12,8 +12,5 @@ gravity_utils = { path = "../gravity_utils" }

deep_space = { git = "https://github.com/iqlusioninc/deep_space/", branch = "master" }
ethers = { git = "https://github.com/iqlusioninc/ethers-rs.git", branch = "zaki/error_abi_support", features = ["abigen"] }
clarity = "0.4.11"
web30 = "0.15.4"
log = "0.4"
sha3 = "0.9"
tokio = "1.13.0"
5 changes: 3 additions & 2 deletions orchestrator/ethereum_gravity/src/logic_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use gravity_abi::gravity::*;
use gravity_utils::ethereum::{bytes_to_hex_str, vec_u8_to_fixed_32};
use gravity_utils::types::*;
use gravity_utils::{error::GravityError, message_signatures::encode_logic_call_confirm_hashed};
use std::{result::Result, time::Duration, collections::HashMap};
use std::{collections::HashMap, result::Result, time::Duration};

/// this function generates an appropriate Ethereum transaction
/// to submit the provided logic call
Expand Down Expand Up @@ -262,7 +262,8 @@ impl LogicCallSkips {
if id_skips.is_none() {
// first time we've seen this invalidation id, start at 2 skips
let new_id_skips = HashMap::from([(call.invalidation_nonce, new_skip_state)]);
self.skip_map.insert(call.invalidation_id.clone(), new_id_skips);
self.skip_map
.insert(call.invalidation_id.clone(), new_id_skips);
} else {
let id_skips = id_skips.unwrap();
let skip_state = id_skips.get_mut(&call.invalidation_nonce);
Expand Down
79 changes: 43 additions & 36 deletions orchestrator/ethereum_gravity/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ethers::prelude::*;
use ethers::types::Address as EthAddress;
use gravity_abi::gravity::*;
use gravity_utils::error::GravityError;
use gravity_utils::ethereum::{downcast_to_u64, vec_u8_to_fixed_32, hex_str_to_bytes};
use gravity_utils::ethereum::{downcast_to_u64, hex_str_to_bytes, vec_u8_to_fixed_32};
use gravity_utils::types::{decode_gravity_error, GravityContractError};
use std::result::Result;

Expand Down Expand Up @@ -199,15 +199,23 @@ pub fn handle_contract_error(gravity_error: GravityError) -> bool {
if gravity_contract_error.is_some() {
match gravity_contract_error.unwrap() {
GravityContractError::InvalidLogicCallNonce(nonce_error) => {
info!("LogicCall already processed, skipping until observed on chain: {}", nonce_error.message());
info!(
"LogicCall already processed, skipping until observed on chain: {}",
nonce_error.message()
);
return true;
}
GravityContractError::LogicCallTimedOut(timeout_error) => {
info!("LogicCall is timed out, will be skipped until timeout on chain: {}", timeout_error.message());
info!(
"LogicCall is timed out, will be skipped until timeout on chain: {}",
timeout_error.message()
);
return true;
}
// TODO(bolten): implement other cases if necessary
_ => { error!("Unspecified gravity contract error: {}", error_string) }
_ => {
error!("Unspecified gravity contract error: {}", error_string)
}
}
} else {
error!("Non-gravity contract error: {}", error_string);
Expand All @@ -220,48 +228,47 @@ pub fn handle_contract_error(gravity_error: GravityError) -> bool {
// results in this nightmare
pub fn extract_gravity_contract_error(gravity_error: GravityError) -> Option<GravityContractError> {
match gravity_error {
GravityError::EthersContractError(ce) => {
match ce {
ethers::contract::ContractError::MiddlewareError(me) => {
match me {
ethers::middleware::signer::SignerMiddlewareError::MiddlewareError(sme) => {
match sme {
ethers::providers::ProviderError::JsonRpcClientError(jrpce) => {
if jrpce.is::<ethers::providers::HttpClientError>() {
let httpe = *jrpce.downcast::<ethers::providers::HttpClientError>().unwrap();
match httpe {
ethers::providers::HttpClientError::JsonRpcError(jre) => {
if jre.code == 3 && jre.data.is_some() {
let data = jre.data.unwrap();
if data.is_string() {
let data_bytes = hex_str_to_bytes(data.as_str().unwrap());
if data_bytes.is_ok() {
decode_gravity_error(data_bytes.unwrap())
} else {
None
}
} else {
None
}
GravityError::EthersContractError(ce) => match ce {
ethers::contract::ContractError::MiddlewareError(me) => match me {
ethers::middleware::signer::SignerMiddlewareError::MiddlewareError(sme) => {
match sme {
ethers::providers::ProviderError::JsonRpcClientError(jrpce) => {
if jrpce.is::<ethers::providers::HttpClientError>() {
let httpe = *jrpce
.downcast::<ethers::providers::HttpClientError>()
.unwrap();
match httpe {
ethers::providers::HttpClientError::JsonRpcError(jre) => {
if jre.code == 3 && jre.data.is_some() {
let data = jre.data.unwrap();
if data.is_string() {
let data_bytes =
hex_str_to_bytes(data.as_str().unwrap());
if data_bytes.is_ok() {
decode_gravity_error(data_bytes.unwrap())
} else {
None
}
} else {
None
}
_ => None
} else {
None
}
} else {
None
}
_ => None,
}
_ => None
} else {
None
}
}
_ => None
_ => None,
}
}
_ => None
}
}
_ => None
_ => None,
},
_ => None,
},
_ => None,
}
}
6 changes: 1 addition & 5 deletions orchestrator/gorc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "gorc"
authors = []
version = "2.0.4"
version = "2.0.5"
edition = "2021"
rust-version = "1.63"

Expand Down Expand Up @@ -31,16 +31,12 @@ rand_core = { version = "0.6", features = ["std"] }
openssl-probe = "0.1.4"

abscissa_tokio = { version = "0.6.0", features = ["actix"] }
web30 = "0.15"
tokio = "1"
tonic = "0.4"
toml = "0.5"
env_logger = "0.8"
log = "0.4"

prost = "0.7"
bytes = "1"
proc-macro2 = "1.0.28"

[dependencies.abscissa_core]
version = "0.6.0"
Expand Down
2 changes: 1 addition & 1 deletion orchestrator/gravity_abi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod erc20;
pub mod gravity;
pub mod gravity;
8 changes: 2 additions & 6 deletions orchestrator/gravity_utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gravity_utils"
version = "0.1.0"
version = "2.0.5"
authors = ["Justin Kilpatrick <justin@althea.net>"]
edition = "2018"

Expand All @@ -12,8 +12,7 @@ gravity_proto = { path = "../gravity_proto/" }
cosmos-sdk-proto = "0.6.3"
deep_space = { git = "https://github.com/iqlusioninc/deep_space/", branch = "master" }
ethers = { git = "https://github.com/iqlusioninc/ethers-rs.git", branch = "zaki/error_abi_support", features = ["abigen"] }
web30 = "0.15"
clarity = "0.4.11"
clarity.workspace = true
lazy_static = "1.4.0"
num256 = "0.3"
serde_derive = "1.0"
Expand All @@ -25,9 +24,6 @@ num-bigint = "0.4"
log = "0.4"
url = "2"
sha3 = "0.9"
tiny-bip39 = "0.8.0"
bitcoin = { version = "=0.27", features = ["use-serde"] }
hdpath = { version = "0.6.0", features = ["with-bitcoin"] }
rustc-hex = "2.1.0"

[dev_dependencies]
Expand Down
Loading
Loading