Skip to content

Commit

Permalink
Fix evidence submission (#3612)
Browse files Browse the repository at this point in the history
* Fix evidence submission by using fix in custom branch tendermint-rs

* Check that evidence command saw the evidence in the block

* Skip submitting evidence if client is already frozen or expired

* Skip frozen clients

* Add more delay in standard misbehaviour test

* Use latest tendermint-rs
  • Loading branch information
romac authored Sep 26, 2023
1 parent b1a2db5 commit fd26a58
Show file tree
Hide file tree
Showing 19 changed files with 244 additions and 96 deletions.
32 changes: 16 additions & 16 deletions Cargo.lock

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

21 changes: 14 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ overflow-checks = true

[patch.crates-io]
ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs.git", branch = "ccv-protos" }
# tendermint = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" }
# tendermint-rpc = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" }
# tendermint-proto = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" }
# tendermint-light-client = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" }
# tendermint-light-client-verifier = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" }
# tendermint-light-client-detector = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" }
# tendermint-testgen = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" }
# tendermint = { path = "../tendermint-rs/tendermint" }
# tendermint-rpc = { path = "../tendermint-rs/rpc" }
# tendermint-proto = { path = "../tendermint-rs/proto" }
# tendermint-light-client = { path = "../tendermint-rs/light-client" }
# tendermint-light-client-verifier = { path = "../tendermint-rs/light-client-verifier" }
# tendermint-light-client-detector = { path = "../tendermint-rs/light-client-detector" }
# tendermint-testgen = { path = "../tendermint-rs/testgen" }
# tendermint = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "fix-evidence" }
# tendermint-rpc = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "fix-evidence" }
# tendermint-proto = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "fix-evidence" }
# tendermint-light-client = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "fix-evidence" }
# tendermint-light-client-verifier = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "fix-evidence" }
# tendermint-light-client-detector = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "fix-evidence" }
# tendermint-testgen = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "fix-evidence" }
16 changes: 14 additions & 2 deletions ci/misbehaviour-ics/double_sign_test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#!/bin/bash
# shellcheck disable=2086,2004

set -eux
set -eu

DEBUG=${DEBUG:-false}

if [ "$DEBUG" = true ]; then
set -x
fi

# User balance of stake tokens
USER_COINS="100000000000stake"
Expand All @@ -13,10 +19,16 @@ NODE_IP="127.0.0.1"
# Home directory
HOME_DIR="/tmp/hermes-ics-double-sign"

# Hermes debug
if [ "$DEBUG" = true ]; then
HERMES_DEBUG="--debug=rpc"
else
HERMES_DEBUG=""
fi
# Hermes config
HERMES_CONFIG="$HOME_DIR/hermes.toml"
# Hermes binary
HERMES_BIN="cargo run -q --bin hermes -- --config $HERMES_CONFIG"
HERMES_BIN="cargo run -q --bin hermes -- $HERMES_DEBUG --config $HERMES_CONFIG"

# Validator moniker
MONIKERS=("coordinator" "alice" "bob")
Expand Down
27 changes: 24 additions & 3 deletions ci/misbehaviour-ics/light_client_attack_test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#!/bin/bash
# shellcheck disable=2086
set -eux

set -eu

DEBUG=${DEBUG:-false}

if [ "$DEBUG" = true ]; then
set -x
fi

diag() {
echo ">>
Expand All @@ -22,12 +28,19 @@ NODE_IP="127.0.0.1"
# Home directory
HOME_DIR="/tmp/hermes-ics-misbehaviour"

# Hermes debug
if [ "$DEBUG" = true ]; then
HERMES_DEBUG="--debug=rpc"
else
HERMES_DEBUG=""
fi

# Hermes config
HERMES_CONFIG="$HOME_DIR/hermes.toml"
HERMES_CONFIG_FORK="$HOME_DIR/hermes-fork.toml"
# Hermes binary
HERMES_BIN="cargo run -q --bin hermes -- --config $HERMES_CONFIG"
HERMES_BIN_FORK="cargo run -q --bin hermes -- --config $HERMES_CONFIG_FORK"
HERMES_BIN="cargo run -q --bin hermes -- $HERMES_DEBUG --config $HERMES_CONFIG"
HERMES_BIN_FORK="cargo run -q --bin hermes -- $HERMES_DEBUG --config $HERMES_CONFIG_FORK"

# Validator moniker
MONIKER="coordinator"
Expand Down Expand Up @@ -469,3 +482,11 @@ else
fi

sleep 10

if grep -q "found light client attack evidence" ${HOME_DIR}/hermes-evidence-logs.txt; then
diag "Evidence found, success!"
else
diag "Evidence not found, aborting."
exit 1
fi

2 changes: 1 addition & 1 deletion ci/misbehaviour/misbehaviour_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ info "Update client on ibc-0 against the forked chain ibc-1-f"
$HERMES --config config_fork.toml update client --client 07-tendermint-0 --host-chain ibc-0

info "Wait for chain ibc-1 to stop..."
sleep 5
sleep 10

info "Killing Hermes"
kill -9 "$HERMES_PID"
Expand Down
2 changes: 1 addition & 1 deletion crates/chain-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ description = """
[dependencies]
ibc-proto = { version = "0.33.0" }
ibc-relayer-types = { version = "0.25.0", path = "../relayer-types" }
tendermint-rpc = { version = "0.33.0", features = [
tendermint-rpc = { version = "0.33.2", features = [
"http-client",
"websocket-client",
] }
Expand Down
6 changes: 3 additions & 3 deletions crates/relayer-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ tracing = "0.1.36"
tracing-subscriber = { version = "0.3.14", features = ["fmt", "env-filter", "json"]}
time = "0.3"
[dependencies.tendermint]
version = "0.33.0"
version = "0.33.2"
features = ["secp256k1"]

[dependencies.tendermint-rpc]
version = "0.33.0"
version = "0.33.2"
features = ["http-client", "websocket-client"]

[dependencies.tendermint-light-client-verifier]
version = "0.33.0"
version = "0.33.2"

[dependencies.abscissa_core]
version = "=0.6.0"
Expand Down
39 changes: 28 additions & 11 deletions crates/relayer-cli/src/commands/evidence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use ibc_relayer_types::applications::ics28_ccv::msgs::ccv_double_voting::MsgSubm
use ibc_relayer_types::applications::ics28_ccv::msgs::ccv_misbehaviour::MsgSubmitIcsConsumerMisbehaviour;
use ibc_relayer_types::clients::ics07_tendermint::header::Header as TendermintHeader;
use ibc_relayer_types::clients::ics07_tendermint::misbehaviour::Misbehaviour as TendermintMisbehaviour;
use ibc_relayer_types::core::ics02_client::client_state::ClientState;
use ibc_relayer_types::core::ics02_client::height::Height;
use ibc_relayer_types::core::ics02_client::msgs::misbehaviour::MsgSubmitMisbehaviour;
use ibc_relayer_types::core::ics24_host::identifier::{ChainId, ClientId};
Expand Down Expand Up @@ -128,7 +129,7 @@ fn monitor_misbehaviours(
// target_height: 1
// iterations: 200

debug!(
info!(
"checking past {check_past_blocks} blocks for misbehaviour evidence: {}..{}",
latest_height, target_height
);
Expand Down Expand Up @@ -195,13 +196,13 @@ fn check_misbehaviour_at(
match evidence {
tendermint::evidence::Evidence::DuplicateVote(dv) => {
warn!("found duplicate vote evidence");
debug!("{dv:#?}");
trace!("{dv:#?}");

handle_duplicate_vote(rt.clone(), chain, key_name, *dv)?;
}
tendermint::evidence::Evidence::LightClientAttack(lc) => {
warn!("found light client attack evidence");
debug!("{lc:#?}");
trace!("{lc:#?}");

handle_light_client_attack(rt.clone(), chain, key_name, *lc)?;
}
Expand Down Expand Up @@ -426,25 +427,36 @@ fn submit_light_client_attack_evidence(
);

let signer = counterparty.get_signer()?;

let common_height = Height::from_tm(evidence.common_height, chain.id());

if counterparty_client.is_frozen() {
warn!(
"skipping client `{}` on chain `{}` as it is already frozen",
counterparty_client_id,
counterparty.id()
);

return Ok(());
}

let mut msgs = match counterparty_client.wait_and_build_update_client(common_height) {
Ok(msgs) => msgs,

Err(e) => {
warn!(
"failed to build update client message for client `{}` on chain `{}`: {e}",
"skipping update client message for client `{}` on chain `{}`",
counterparty_client_id,
counterparty.id()
);
warn!("reason: failed to build update client message: {e}");

warn!("skipping update client message");
vec![]
}
};

if is_counterparty_provider(chain, counterparty) {
info!(
"submitting CCV misbehaviour for client `{}` on provider chain `{}`",
"will submit CCV misbehaviour for client `{}` on provider chain `{}`",
counterparty_client_id,
counterparty.id(),
);
Expand All @@ -459,7 +471,7 @@ fn submit_light_client_attack_evidence(
};

info!(
"submitting IBC misbehaviour for client `{}` on chain `{}`",
"will submit IBC misbehaviour for client `{}` on chain `{}`",
counterparty_client_id,
counterparty.id(),
);
Expand Down Expand Up @@ -561,17 +573,22 @@ fn fetch_all_counterparty_clients(
let client_state = match client_state {
Ok((client_state, _)) => client_state,
Err(e) => {
warn!(
error!(
"failed to fetch client state for counterparty client {client_id}, skipping..."
);
warn!("reason: {e}");
error!("reason: {e}");

continue;
}
};

let counterparty_chain_id = client_state.chain_id();
debug!("found counterparty client with id {client_id} on counterparty chain {counterparty_chain_id}");
info!("found counterparty client with id {client_id} on counterparty chain {counterparty_chain_id}");

if client_state.is_frozen() {
info!("counterparty client {client_id} is already frozen, skipping...");
continue;
}

counterparty_clients.push((counterparty_chain_id, client_id.clone()));
}
Expand Down
12 changes: 6 additions & 6 deletions crates/relayer-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,24 @@ num-rational = "0.4.1"
regex = "1"

[dependencies.tendermint]
version = "0.33.0"
version = "0.33.2"
features = ["clock"]

[dependencies.tendermint-proto]
version = "0.33.0"
version = "0.33.2"

[dependencies.tendermint-light-client-verifier]
version = "0.33.0"
version = "0.33.2"
features = ["rust-crypto"]

[dependencies.tendermint-testgen]
version = "0.33.0"
version = "0.33.2"
optional = true

[dev-dependencies]
env_logger = "0.10.0"
tracing = { version = "0.1.36", default-features = false }
tracing-subscriber = { version = "0.3.14", features = ["fmt", "env-filter", "json"] }
test-log = { version = "0.2.10", features = ["trace"] }
tendermint-rpc = { version = "0.33.0", features = ["http-client", "websocket-client"] }
tendermint-testgen = { version = "0.33.0" } # Needed for generating (synthetic) light blocks.
tendermint-rpc = { version = "0.33.2", features = ["http-client", "websocket-client"] }
tendermint-testgen = { version = "0.33.2" } # Needed for generating (synthetic) light blocks.
Loading

0 comments on commit fd26a58

Please sign in to comment.