Skip to content

Commit

Permalink
governance: validate client ID earlier than component/view.rs (#4859)
Browse files Browse the repository at this point in the history
## Describe your changes

This PR modifies the governance code to check the IBC `ClientId` is
valid prior to creating the `Proposal` domain type

## Checklist before requesting a review

- [x] If this code contains consensus-breaking changes, I have added the
"consensus-breaking" label. Otherwise, I declare my belief that there
are not consensus-breaking changes, for the following reason:

> This validation is already performed, just later in the handling of
the `Proposal` in `component/view.rs`
  • Loading branch information
redshiftzero authored Sep 24, 2024
1 parent c0e4403 commit 0f133aa
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crates/core/component/governance/src/proposal.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Context;
use bytes::Bytes;
use ibc_types::core::client::ClientId;
use serde::{Deserialize, Serialize};
use std::str::FromStr;

Expand Down Expand Up @@ -144,6 +145,9 @@ impl TryFrom<pb::Proposal> for Proposal {
if freeze_ibc_client.client_id.len() > 128 {
anyhow::bail!("client ID must be less than 128 bytes");
}
// Validation: Check the client ID is valid using the validation inside `ClientId::from_str`.
ClientId::from_str(&freeze_ibc_client.client_id)
.map_err(|e| anyhow::anyhow!("invalid client id: {e}"))?;
ProposalPayload::FreezeIbcClient {
client_id: freeze_ibc_client.client_id,
}
Expand All @@ -153,6 +157,9 @@ impl TryFrom<pb::Proposal> for Proposal {
if unfreeze_ibc_client.client_id.len() > 128 {
anyhow::bail!("client ID must be less than 128 bytes");
}
// Validation: Check the client ID is valid using the validation inside `ClientId::from_str`.
ClientId::from_str(&unfreeze_ibc_client.client_id)
.map_err(|e| anyhow::anyhow!("invalid client id: {e}"))?;
ProposalPayload::UnfreezeIbcClient {
client_id: unfreeze_ibc_client.client_id,
}
Expand Down

0 comments on commit 0f133aa

Please sign in to comment.