diff --git a/.changelog/unreleased/breaking-changes/997-minimize-prost-dependency.md b/.changelog/unreleased/breaking-changes/997-minimize-prost-dependency.md new file mode 100644 index 000000000..a1e20886d --- /dev/null +++ b/.changelog/unreleased/breaking-changes/997-minimize-prost-dependency.md @@ -0,0 +1,5 @@ +- [`ibc`] Minimize `prost` dependency by introducing `ToVec` trait + - Now `prost` is only imported in `ibc-primitives` crate + - Remove error variants originating from `prost` (Breaking change) + - Eliminate the need for the `bytes` dependency + ([\#997](https://github.com/cosmos/ibc-rs/issues/997)) diff --git a/.changelog/unreleased/improvements/997-minimize-prost-dependency.md b/.changelog/unreleased/improvements/997-minimize-prost-dependency.md deleted file mode 100644 index eb5cabc3d..000000000 --- a/.changelog/unreleased/improvements/997-minimize-prost-dependency.md +++ /dev/null @@ -1,2 +0,0 @@ -- [`ibc-primitives`] Minimize `prost` dependency by introducing `ToVec` trait - ([\#997](https://github.com/cosmos/ibc-rs/issues/997)) diff --git a/Cargo.toml b/Cargo.toml index 2bfc3974a..bda0b4595 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,19 +48,14 @@ authors = ["Informal Systems "] [workspace.dependencies] # external dependencies borsh = { version = "0.10", default-features = false } -bytes = { version = "1.5.0", default-features = false } displaydoc = { version = "0.2", default-features = false } derive_more = { version = "0.99.17", default-features = false, features = ["from", "into", "display", "try_into"] } -num-traits = { version = "0.2.17", default-features = false } -primitive-types = { version = "0.12.2", default-features = false, features = ["serde_no_std"] } -prost = { version = "0.12", default-features = false } rstest = "0.18.2" schemars = { version = "0.8.15" } sha2 = { version = "0.10.8", default-features = false } serde = { version = "1.0", default-features = false } serde_json = { package = "serde-json-wasm", version = "1.0.0" , default-features = false } subtle-encoding = { version = "0.5", default-features = false } -time = { version = ">=0.3.0, <0.3.31", default-features = false } # ibc dependencies ibc = { version = "0.48.1", path = "./ibc", default-features = false } @@ -92,7 +87,6 @@ ibc-client-tendermint-types = { version = "0.48.1", path = "./ibc-clients/ics07- ibc-app-transfer-types = { version = "0.48.1", path = "./ibc-apps/ics20-transfer/types", default-features = false } ibc-proto = { version = "0.39.1", default-features = false } -ics23 = { version = "0.11", default-features = false } # cosmos dependencies tendermint = { version = "0.34.0", default-features = false } diff --git a/ci/cw-check/Cargo.lock b/ci/cw-check/Cargo.lock index 65c2e8007..def22f0ff 100644 --- a/ci/cw-check/Cargo.lock +++ b/ci/cw-check/Cargo.lock @@ -619,7 +619,6 @@ dependencies = [ "parity-scale-codec", "primitive-types", "scale-info", - "schemars", "serde", "uint", ] @@ -657,7 +656,6 @@ dependencies = [ "ibc-core-host", "ibc-core-router", "ibc-primitives", - "prost", ] [[package]] @@ -673,7 +671,6 @@ dependencies = [ "ibc-primitives", "ibc-proto", "parity-scale-codec", - "prost", "scale-info", "schemars", "serde", @@ -692,7 +689,6 @@ dependencies = [ "ibc-core-handler-types", "ibc-core-host", "ibc-primitives", - "prost", ] [[package]] @@ -707,7 +703,6 @@ dependencies = [ "ibc-core-host-types", "ibc-derive", "ibc-primitives", - "prost", "subtle-encoding", "tendermint", ] @@ -723,7 +718,6 @@ dependencies = [ "ibc-primitives", "ibc-proto", "parity-scale-codec", - "prost", "scale-info", "schemars", "serde", @@ -741,7 +735,6 @@ dependencies = [ "ibc-proto", "ics23", "parity-scale-codec", - "prost", "scale-info", "schemars", "serde", @@ -757,7 +750,6 @@ dependencies = [ "ibc-core-handler-types", "ibc-core-host", "ibc-primitives", - "prost", ] [[package]] @@ -772,7 +764,6 @@ dependencies = [ "ibc-primitives", "ibc-proto", "parity-scale-codec", - "prost", "scale-info", "schemars", "serde", @@ -809,7 +800,6 @@ dependencies = [ "ibc-primitives", "ibc-proto", "parity-scale-codec", - "prost", "scale-info", "schemars", "serde", @@ -831,7 +821,6 @@ dependencies = [ "ibc-core-handler-types", "ibc-core-host-types", "ibc-primitives", - "prost", "subtle-encoding", ] @@ -858,7 +847,6 @@ dependencies = [ "ibc-core-host-types", "ibc-core-router-types", "ibc-primitives", - "prost", "subtle-encoding", ] @@ -873,7 +861,6 @@ dependencies = [ "ibc-proto", "ics23", "parity-scale-codec", - "prost", "scale-info", "schemars", "serde", @@ -909,9 +896,9 @@ dependencies = [ [[package]] name = "ibc-proto" -version = "0.38.0" +version = "0.39.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93cbf4cbe9e5113cc7c70f3208a7029b2205c629502cbb2ae7ea0a09a97d3005" +checksum = "c8a8b1356652b9f160f5a010dd6b084675b8a28e163bf2b41ca5abecf27d9701" dependencies = [ "base64 0.21.2", "bytes", @@ -1161,9 +1148,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.12.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fdd22f3b9c31b53c060df4a0613a1c7f062d4115a2b984dd15b1858f7e340d" +checksum = "146c289cda302b98a28d40c8b3b90498d6e526dd24ac2ecea73e4e491685b94a" dependencies = [ "bytes", "prost-derive", @@ -1171,9 +1158,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.12.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "265baba7fabd416cf5078179f7d2cbeca4ce7a9041111900675ea7c4cb8a4c32" +checksum = "efb6c9a1dd1def8e2124d17e83a20af56f1570d6c2d2bd9e266ccb768df3840e" dependencies = [ "anyhow", "itertools", diff --git a/ci/no-std-check/Cargo.lock b/ci/no-std-check/Cargo.lock index ff8c1e715..6404bfca4 100644 --- a/ci/no-std-check/Cargo.lock +++ b/ci/no-std-check/Cargo.lock @@ -1262,7 +1262,6 @@ dependencies = [ "ibc-core-handler-types", "ibc-core-host", "ibc-primitives", - "prost", "serde", "tendermint", "tendermint-light-client-verifier", @@ -1272,14 +1271,12 @@ dependencies = [ name = "ibc-client-tendermint-types" version = "0.48.1" dependencies = [ - "bytes", "displaydoc", "ibc-core-client-types", "ibc-core-commitment-types", "ibc-core-host-types", "ibc-primitives", "ibc-proto", - "prost", "serde", "tendermint", "tendermint-light-client-verifier", @@ -1319,7 +1316,6 @@ dependencies = [ "ibc-core-host", "ibc-core-router", "ibc-primitives", - "prost", ] [[package]] @@ -1334,7 +1330,6 @@ dependencies = [ "ibc-core-host-types", "ibc-primitives", "ibc-proto", - "prost", "serde", "sha2 0.10.8", "subtle-encoding", @@ -1351,7 +1346,6 @@ dependencies = [ "ibc-core-handler-types", "ibc-core-host", "ibc-primitives", - "prost", ] [[package]] @@ -1366,7 +1360,6 @@ dependencies = [ "ibc-core-host-types", "ibc-derive", "ibc-primitives", - "prost", "subtle-encoding", "tendermint", ] @@ -1381,7 +1374,6 @@ dependencies = [ "ibc-core-host-types", "ibc-primitives", "ibc-proto", - "prost", "serde", "subtle-encoding", "tendermint", @@ -1396,7 +1388,6 @@ dependencies = [ "ibc-primitives", "ibc-proto", "ics23", - "prost", "serde", "subtle-encoding", ] @@ -1410,7 +1401,6 @@ dependencies = [ "ibc-core-handler-types", "ibc-core-host", "ibc-primitives", - "prost", ] [[package]] @@ -1424,7 +1414,6 @@ dependencies = [ "ibc-core-host-types", "ibc-primitives", "ibc-proto", - "prost", "serde", "subtle-encoding", "tendermint", @@ -1458,7 +1447,6 @@ dependencies = [ "ibc-core-router-types", "ibc-primitives", "ibc-proto", - "prost", "serde", "subtle-encoding", "tendermint", @@ -1478,7 +1466,6 @@ dependencies = [ "ibc-core-handler-types", "ibc-core-host-types", "ibc-primitives", - "prost", "subtle-encoding", ] @@ -1498,7 +1485,6 @@ dependencies = [ "ibc-core-host-types", "ibc-primitives", "ibc-proto", - "prost", "serde", "sha2 0.10.8", "subtle-encoding", @@ -1525,7 +1511,6 @@ dependencies = [ "ibc-core-host-types", "ibc-core-router-types", "ibc-primitives", - "prost", "subtle-encoding", ] @@ -1539,7 +1524,6 @@ dependencies = [ "ibc-primitives", "ibc-proto", "ics23", - "prost", "serde", "subtle-encoding", "tendermint", diff --git a/ibc-apps/ics20-transfer/types/Cargo.toml b/ibc-apps/ics20-transfer/types/Cargo.toml index 150ba8d63..2706d19c5 100644 --- a/ibc-apps/ics20-transfer/types/Cargo.toml +++ b/ibc-apps/ics20-transfer/types/Cargo.toml @@ -22,7 +22,7 @@ all-features = true borsh = { workspace = true, optional = true } derive_more = { workspace = true } displaydoc = { workspace = true } -primitive-types = { workspace = true } +primitive-types = { version = "0.12.2", default-features = false, features = ["serde_no_std"] } schemars = { workspace = true, optional = true } serde = { workspace = true, optional = true } uint = { version = "0.9", default-features = false } @@ -51,15 +51,15 @@ std = [ "ibc-proto/std", ] serde = [ - "dep:serde", + "dep:serde", "ibc-core/serde", - "ibc-proto/serde", + "ibc-proto/serde", ] schema = [ - "dep:schemars", - "ibc-core/schema", + "dep:schemars", + "ibc-core/schema", "ibc-proto/json-schema", - "serde", + "serde", "std" ] borsh = [ @@ -68,8 +68,8 @@ borsh = [ "ibc-proto/borsh" ] parity-scale-codec = [ - "dep:parity-scale-codec", - "dep:scale-info", + "dep:parity-scale-codec", + "dep:scale-info", "ibc-core/parity-scale-codec", "ibc-proto/parity-scale-codec" ] diff --git a/ibc-apps/ics20-transfer/types/src/lib.rs b/ibc-apps/ics20-transfer/types/src/lib.rs index 2cc84f2fe..fd510cc9f 100644 --- a/ibc-apps/ics20-transfer/types/src/lib.rs +++ b/ibc-apps/ics20-transfer/types/src/lib.rs @@ -40,9 +40,10 @@ pub(crate) mod serializers; pub mod error; mod memo; pub use memo::*; +/// Re-exports `U256` from `primitive-types` crate for convenience. +pub use primitive_types::U256; -/// Re-exports ICS-20 token transfer proto types from the `ibc-proto` crate -/// for added convenience +/// Re-exports ICS-20 token transfer proto types from the `ibc-proto` crate. pub mod proto { pub use ibc_proto::ibc::apps::transfer; } diff --git a/ibc-clients/ics07-tendermint/src/client_state.rs b/ibc-clients/ics07-tendermint/src/client_state.rs index 8797ad3bb..35ac0ac09 100644 --- a/ibc-clients/ics07-tendermint/src/client_state.rs +++ b/ibc-clients/ics07-tendermint/src/client_state.rs @@ -26,7 +26,6 @@ use ibc_core_commitment_types::commitment::{ CommitmentPrefix, CommitmentProofBytes, CommitmentRoot, }; use ibc_core_commitment_types::merkle::{apply_prefix, MerkleProof}; -use ibc_core_commitment_types::proto::v1::MerkleProof as RawMerkleProof; use ibc_core_host::types::identifiers::{ClientId, ClientType}; use ibc_core_host::types::path::{ ClientConsensusStatePath, ClientStatePath, Path, UpgradeClientPath, @@ -199,9 +198,8 @@ impl ClientStateCommon for ClientState { value: Vec, ) -> Result<(), ClientError> { let merkle_path = apply_prefix(prefix, vec![path.to_string()]); - let merkle_proof: MerkleProof = RawMerkleProof::try_from(proof.clone()) - .map_err(ClientError::InvalidCommitmentProof)? - .into(); + let merkle_proof = + MerkleProof::try_from(proof.clone()).map_err(ClientError::InvalidCommitmentProof)?; merkle_proof .verify_membership( @@ -222,9 +220,8 @@ impl ClientStateCommon for ClientState { path: Path, ) -> Result<(), ClientError> { let merkle_path = apply_prefix(prefix, vec![path.to_string()]); - let merkle_proof: MerkleProof = RawMerkleProof::try_from(proof.clone()) - .map_err(ClientError::InvalidCommitmentProof)? - .into(); + let merkle_proof = + MerkleProof::try_from(proof.clone()).map_err(ClientError::InvalidCommitmentProof)?; merkle_proof .verify_non_membership(&self.0.proof_specs, root.clone().into(), merkle_path) diff --git a/ibc-clients/ics07-tendermint/types/Cargo.toml b/ibc-clients/ics07-tendermint/types/Cargo.toml index 3676b799c..085ca4fad 100644 --- a/ibc-clients/ics07-tendermint/types/Cargo.toml +++ b/ibc-clients/ics07-tendermint/types/Cargo.toml @@ -20,9 +20,7 @@ all-features = true [dependencies] # external dependencies borsh = { workspace = true, optional = true } -bytes = { workspace = true } displaydoc = { workspace = true } -prost = { workspace = true } serde = { workspace = true, optional = true } # ibc dependencies @@ -48,9 +46,7 @@ tendermint-rpc = { workspace = true } [features] default = ["std"] std = [ - "bytes/std", "displaydoc/std", - "prost/std", "serde/std", "serde_json/std", "ibc-core-client-types/std", diff --git a/ibc-clients/ics07-tendermint/types/src/client_state.rs b/ibc-clients/ics07-tendermint/types/src/client_state.rs index ba323a400..b1f755711 100644 --- a/ibc-clients/ics07-tendermint/types/src/client_state.rs +++ b/ibc-clients/ics07-tendermint/types/src/client_state.rs @@ -15,7 +15,6 @@ use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::core::client::v1::Height as RawHeight; use ibc_proto::ibc::lightclients::tendermint::v1::ClientState as RawTmClientState; use ibc_proto::Protobuf; -use prost::Message; use tendermint::chain::id::MAX_LENGTH as MaxChainIdLen; use tendermint::trust_threshold::TrustThresholdFraction as TendermintTrustThresholdFraction; use tendermint_light_client_verifier::options::Options; @@ -346,20 +345,16 @@ impl TryFrom for ClientState { type Error = ClientError; fn try_from(raw: Any) -> Result { - use core::ops::Deref; - - use bytes::Buf; - - fn decode_client_state(buf: B) -> Result { - RawTmClientState::decode(buf) - .map_err(Error::Decode)? - .try_into() + fn decode_client_state(value: &[u8]) -> Result { + let client_state = + Protobuf::::decode(value).map_err(|e| ClientError::Other { + description: e.to_string(), + })?; + Ok(client_state) } match raw.type_url.as_str() { - TENDERMINT_CLIENT_STATE_TYPE_URL => { - decode_client_state(raw.value.deref()).map_err(Into::into) - } + TENDERMINT_CLIENT_STATE_TYPE_URL => decode_client_state(&raw.value), _ => Err(ClientError::UnknownClientStateType { client_state_type: raw.type_url, }), diff --git a/ibc-clients/ics07-tendermint/types/src/consensus_state.rs b/ibc-clients/ics07-tendermint/types/src/consensus_state.rs index d8ac3aaa5..e48b016c3 100644 --- a/ibc-clients/ics07-tendermint/types/src/consensus_state.rs +++ b/ibc-clients/ics07-tendermint/types/src/consensus_state.rs @@ -106,21 +106,16 @@ impl TryFrom for ConsensusState { type Error = ClientError; fn try_from(raw: Any) -> Result { - use core::ops::Deref; - - use bytes::Buf; - use prost::Message; - - fn decode_consensus_state(buf: B) -> Result { - RawConsensusState::decode(buf) - .map_err(Error::Decode)? - .try_into() + fn decode_consensus_state(value: &[u8]) -> Result { + let client_state = + Protobuf::::decode(value).map_err(|e| ClientError::Other { + description: e.to_string(), + })?; + Ok(client_state) } match raw.type_url.as_str() { - TENDERMINT_CONSENSUS_STATE_TYPE_URL => { - decode_consensus_state(raw.value.deref()).map_err(Into::into) - } + TENDERMINT_CONSENSUS_STATE_TYPE_URL => decode_consensus_state(&raw.value), _ => Err(ClientError::UnknownConsensusStateType { consensus_state_type: raw.type_url, }), diff --git a/ibc-clients/ics07-tendermint/types/src/error.rs b/ibc-clients/ics07-tendermint/types/src/error.rs index 661b116a5..0bc1dd918 100644 --- a/ibc-clients/ics07-tendermint/types/src/error.rs +++ b/ibc-clients/ics07-tendermint/types/src/error.rs @@ -55,8 +55,6 @@ pub enum Error { InvalidRawHeader(TendermintError), /// invalid raw misbehaviour: `{reason}` InvalidRawMisbehaviour { reason: String }, - /// decode error: `{0}` - Decode(prost::DecodeError), /// given other previous updates, header timestamp should be at most `{max}`, but was `{actual}` HeaderTimestampTooHigh { actual: String, max: String }, /// given other previous updates, header timestamp should be at least `{min}`, but was `{actual}` @@ -104,7 +102,6 @@ impl std::error::Error for Error { Self::InvalidHeader { error: e, .. } => Some(e), Self::InvalidTendermintTrustThreshold(e) => Some(e), Self::InvalidRawHeader(e) => Some(e), - Self::Decode(e) => Some(e), _ => None, } } diff --git a/ibc-clients/ics07-tendermint/types/src/header.rs b/ibc-clients/ics07-tendermint/types/src/header.rs index f70b6f812..4872f9419 100644 --- a/ibc-clients/ics07-tendermint/types/src/header.rs +++ b/ibc-clients/ics07-tendermint/types/src/header.rs @@ -4,7 +4,6 @@ use alloc::string::ToString; use core::fmt::{Display, Error as FmtError, Formatter}; use core::str::FromStr; -use bytes::Buf; use ibc_core_client_types::error::ClientError; use ibc_core_client_types::Height; use ibc_core_host_types::identifiers::ChainId; @@ -14,7 +13,6 @@ use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::lightclients::tendermint::v1::Header as RawHeader; use ibc_proto::Protobuf; use pretty::{PrettySignedHeader, PrettyValidatorSet}; -use prost::Message; use tendermint::block::signed_header::SignedHeader; use tendermint::chain::Id as TmChainId; use tendermint::validator::Set as ValidatorSet; @@ -189,10 +187,14 @@ impl TryFrom for Header { type Error = ClientError; fn try_from(raw: Any) -> Result { - use core::ops::Deref; - + fn decode_header(value: &[u8]) -> Result { + let header = Protobuf::::decode(value).map_err(|e| ClientError::Other { + description: e.to_string(), + })?; + Ok(header) + } match raw.type_url.as_str() { - TENDERMINT_HEADER_TYPE_URL => decode_header(raw.value.deref()).map_err(Into::into), + TENDERMINT_HEADER_TYPE_URL => decode_header(&raw.value), _ => Err(ClientError::UnknownHeaderType { header_type: raw.type_url, }), @@ -209,10 +211,6 @@ impl From
for Any { } } -fn decode_header(buf: B) -> Result { - RawHeader::decode(buf).map_err(Error::Decode)?.try_into() -} - impl From
for RawHeader { fn from(value: Header) -> Self { RawHeader { diff --git a/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs b/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs index 010b2a40f..f3013378e 100644 --- a/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs +++ b/ibc-clients/ics07-tendermint/types/src/misbehaviour.rs @@ -1,13 +1,11 @@ //! Defines the misbehaviour type for the tendermint light client -use bytes::Buf; use ibc_core_client_types::error::ClientError; use ibc_core_host_types::identifiers::ClientId; use ibc_primitives::prelude::*; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::lightclients::tendermint::v1::Misbehaviour as RawMisbehaviour; use ibc_proto::Protobuf; -use prost::Message; use crate::error::Error; use crate::header::Header; @@ -112,18 +110,15 @@ impl TryFrom for Misbehaviour { type Error = ClientError; fn try_from(raw: Any) -> Result { - use core::ops::Deref; - - fn decode_misbehaviour(buf: B) -> Result { - RawMisbehaviour::decode(buf) - .map_err(Error::Decode)? - .try_into() + fn decode_misbehaviour(value: &[u8]) -> Result { + let misbehaviour = + Protobuf::::decode(value).map_err(|e| ClientError::Other { + description: e.to_string(), + })?; + Ok(misbehaviour) } - match raw.type_url.as_str() { - TENDERMINT_MISBEHAVIOUR_TYPE_URL => { - decode_misbehaviour(raw.value.deref()).map_err(Into::into) - } + TENDERMINT_MISBEHAVIOUR_TYPE_URL => decode_misbehaviour(&raw.value), _ => Err(ClientError::UnknownMisbehaviourType { misbehaviour_type: raw.type_url, }), diff --git a/ibc-core/ics02-client/types/Cargo.toml b/ibc-core/ics02-client/types/Cargo.toml index 8b01bbca1..5069cd604 100644 --- a/ibc-core/ics02-client/types/Cargo.toml +++ b/ibc-core/ics02-client/types/Cargo.toml @@ -22,7 +22,6 @@ all-features = true borsh = { workspace = true, optional = true } derive_more = { workspace = true } displaydoc = { workspace = true } -prost = { workspace = true } schemars = { workspace = true, optional = true } serde = { workspace = true, optional = true } subtle-encoding = { workspace = true } @@ -44,7 +43,6 @@ scale-info = { workspace = true, optional = true } default = ["std"] std = [ "displaydoc/std", - "prost/std", "serde/std", "subtle-encoding/std", "ibc-core-commitment-types/std", diff --git a/ibc-core/ics02-client/types/src/error.rs b/ibc-core/ics02-client/types/src/error.rs index 27cf5304b..57352297d 100644 --- a/ibc-core/ics02-client/types/src/error.rs +++ b/ibc-core/ics02-client/types/src/error.rs @@ -58,8 +58,6 @@ pub enum ClientError { MissingRawConsensusState, /// invalid client id in the update client message: `{0}` InvalidMsgUpdateClientId(IdentifierError), - /// decode error: `{0}` - Decode(prost::DecodeError), /// invalid client identifier error: `{0}` InvalidClientIdentifier(IdentifierError), /// invalid raw header error: `{reason}` diff --git a/ibc-core/ics03-connection/types/Cargo.toml b/ibc-core/ics03-connection/types/Cargo.toml index 9f1f7379b..536069db7 100644 --- a/ibc-core/ics03-connection/types/Cargo.toml +++ b/ibc-core/ics03-connection/types/Cargo.toml @@ -22,7 +22,6 @@ all-features = true borsh = { workspace = true, optional = true } derive_more = { workspace = true } displaydoc = { workspace = true } -prost = { workspace = true } schemars = { workspace = true, optional = true } serde = { workspace = true, optional = true } subtle-encoding = { workspace = true } @@ -45,7 +44,6 @@ scale-info = { workspace = true, optional = true } default = ["std"] std = [ "displaydoc/std", - "prost/std", "subtle-encoding/std", "serde/std", "ibc-core-client-types/std", diff --git a/ibc-core/ics04-channel/types/Cargo.toml b/ibc-core/ics04-channel/types/Cargo.toml index bbd34da60..97395dfb5 100644 --- a/ibc-core/ics04-channel/types/Cargo.toml +++ b/ibc-core/ics04-channel/types/Cargo.toml @@ -22,7 +22,6 @@ all-features = true borsh = { workspace = true, optional = true } derive_more = { workspace = true } displaydoc = { workspace = true } -prost = { workspace = true } sha2 = { workspace = true } schemars = { workspace = true, optional = true } serde = { workspace = true, optional = true } @@ -47,7 +46,6 @@ scale-info = { workspace = true, optional = true } default = ["std"] std = [ "displaydoc/std", - "prost/std", "sha2/std", "serde/std", "subtle-encoding/std", diff --git a/ibc-core/ics23-commitment/types/Cargo.toml b/ibc-core/ics23-commitment/types/Cargo.toml index f29aff6c0..fbda6e24d 100644 --- a/ibc-core/ics23-commitment/types/Cargo.toml +++ b/ibc-core/ics23-commitment/types/Cargo.toml @@ -22,15 +22,14 @@ all-features = true borsh = { workspace = true, optional = true } derive_more = { workspace = true } displaydoc = { workspace = true } -prost = { workspace = true } schemars = { workspace = true, optional = true } serde = { workspace = true, optional = true } subtle-encoding = { workspace = true } # ibc dependencies ibc-proto = { workspace = true } -ibc-primitives = {workspace = true } -ics23 = { workspace = true, features = ["host-functions"] } +ibc-primitives = { workspace = true } +ics23 = { version = "0.11", default-features = false, features = ["host-functions"] } # parity dependencies parity-scale-codec = { workspace = true, optional = true } @@ -40,7 +39,6 @@ scale-info = { workspace = true, optional = true } default = ["std"] std = [ "displaydoc/std", - "prost/std", "serde/std", "subtle-encoding/std", "ibc-primitives/std", diff --git a/ibc-core/ics23-commitment/types/src/commitment.rs b/ibc-core/ics23-commitment/types/src/commitment.rs index 0969c565c..009a78f2c 100644 --- a/ibc-core/ics23-commitment/types/src/commitment.rs +++ b/ibc-core/ics23-commitment/types/src/commitment.rs @@ -4,7 +4,9 @@ use core::convert::TryFrom; use core::fmt; use ibc_primitives::prelude::*; +use ibc_primitives::ToVec; use ibc_proto::ibc::core::commitment::v1::MerkleProof as RawMerkleProof; +use ibc_proto::Protobuf; use subtle_encoding::{Encoding, Hex}; use super::merkle::MerkleProof; @@ -109,10 +111,7 @@ impl TryFrom for CommitmentProofBytes { type Error = CommitmentError; fn try_from(proof: RawMerkleProof) -> Result { - let mut buf = Vec::new(); - prost::Message::encode(&proof, &mut buf) - .map_err(|e| Self::Error::EncodingFailure(e.to_string()))?; - buf.try_into() + proof.to_vec().try_into() } } @@ -124,14 +123,14 @@ impl TryFrom for CommitmentProofBytes { } } -impl TryFrom for RawMerkleProof { +impl TryFrom for MerkleProof { type Error = CommitmentError; fn try_from(value: CommitmentProofBytes) -> Result { let value: Vec = value.into(); - let res: RawMerkleProof = prost::Message::decode(value.as_ref()) - .map_err(CommitmentError::InvalidRawMerkleProof)?; - Ok(res) + let merkle_proof = Protobuf::::decode(value.as_ref()) + .map_err(|e| CommitmentError::DecodingFailure(e.to_string()))?; + Ok(merkle_proof) } } diff --git a/ibc-core/ics23-commitment/types/src/error.rs b/ibc-core/ics23-commitment/types/src/error.rs index 3b7b17575..88625226f 100644 --- a/ibc-core/ics23-commitment/types/src/error.rs +++ b/ibc-core/ics23-commitment/types/src/error.rs @@ -2,14 +2,9 @@ use displaydoc::Display; use ibc_primitives::prelude::*; -use prost::DecodeError; #[derive(Debug, Display)] pub enum CommitmentError { - /// invalid raw merkle proof error: `{0}` - InvalidRawMerkleProof(DecodeError), - /// failed to decode commitment proof error: `{0}` - CommitmentProofDecodingFailed(DecodeError), /// empty commitment prefix EmptyCommitmentPrefix, /// empty merkle proof @@ -28,15 +23,9 @@ pub enum CommitmentError { VerificationFailure, /// encoded commitment prefix is not a valid hex string: `{0}` EncodingFailure(String), + /// decoding commitment proof bytes failed: `{0}` + DecodingFailure(String), } #[cfg(feature = "std")] -impl std::error::Error for CommitmentError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - match &self { - Self::InvalidRawMerkleProof(e) => Some(e), - Self::CommitmentProofDecodingFailed(e) => Some(e), - _ => None, - } - } -} +impl std::error::Error for CommitmentError {} diff --git a/ibc-core/ics23-commitment/types/src/merkle.rs b/ibc-core/ics23-commitment/types/src/merkle.rs index 50e711c1d..3e0624968 100644 --- a/ibc-core/ics23-commitment/types/src/merkle.rs +++ b/ibc-core/ics23-commitment/types/src/merkle.rs @@ -7,6 +7,7 @@ use ibc_proto::ics23::{ calculate_existence_root, verify_membership, verify_non_membership, CommitmentProof, NonExistenceProof, }; +use ibc_proto::Protobuf; use crate::commitment::{CommitmentPrefix, CommitmentRoot}; use crate::error::CommitmentError; @@ -31,14 +32,15 @@ pub struct MerkleProof { pub proofs: Vec, } -/// Convert to ics23::CommitmentProof -/// The encoding and decoding shouldn't fail since ics23::CommitmentProof and ibc_proto::ics23::CommitmentProof should be the same -/// Ref. -impl From for MerkleProof { - fn from(proof: RawMerkleProof) -> Self { - Self { +impl Protobuf for MerkleProof {} + +impl TryFrom for MerkleProof { + type Error = CommitmentError; + + fn try_from(proof: RawMerkleProof) -> Result { + Ok(Self { proofs: proof.proofs, - } + }) } } diff --git a/ibc-core/ics25-handler/types/Cargo.toml b/ibc-core/ics25-handler/types/Cargo.toml index 5d92949e3..59c663903 100644 --- a/ibc-core/ics25-handler/types/Cargo.toml +++ b/ibc-core/ics25-handler/types/Cargo.toml @@ -22,7 +22,6 @@ all-features = true borsh = { workspace = true, optional = true } derive_more = { workspace = true } displaydoc = { workspace = true } -prost = { workspace = true } serde = { workspace = true, optional = true } schemars = { workspace = true, optional = true } subtle-encoding = { workspace = true } @@ -48,7 +47,6 @@ scale-info = { workspace = true, optional = true } default = ["std"] std = [ "displaydoc/std", - "prost/std", "serde/std", "subtle-encoding/std", "ibc-core-client-types/std", diff --git a/ibc-core/ics25-handler/types/src/events.rs b/ibc-core/ics25-handler/types/src/events.rs index 78c98acbd..ab3c4b0c7 100644 --- a/ibc-core/ics25-handler/types/src/events.rs +++ b/ibc-core/ics25-handler/types/src/events.rs @@ -28,8 +28,6 @@ pub enum Error { Channel(channel_error::ChannelError), /// parsing timestamp error: `{0}` Timestamp(ParseTimestampError), - /// decoding protobuf error: `{0}` - Decode(prost::DecodeError), /// incorrect event type: `{event}` IncorrectEventType { event: String }, /// module event cannot use core event types: `{event:?}` @@ -45,7 +43,6 @@ impl std::error::Error for Error { Self::Connection(e) => Some(e), Self::Channel(e) => Some(e), Self::Timestamp(e) => Some(e), - Self::Decode(e) => Some(e), _ => None, } } diff --git a/ibc-core/ics26-routing/types/Cargo.toml b/ibc-core/ics26-routing/types/Cargo.toml index 8974821ea..3b1e4e15e 100644 --- a/ibc-core/ics26-routing/types/Cargo.toml +++ b/ibc-core/ics26-routing/types/Cargo.toml @@ -22,7 +22,6 @@ all-features = true borsh = { workspace = true, optional = true } derive_more = { workspace = true } displaydoc = { workspace = true } -prost = { workspace = true } schemars = { workspace = true, optional = true } serde = { workspace = true, optional = true } subtle-encoding = { workspace = true } @@ -31,7 +30,6 @@ subtle-encoding = { workspace = true } ibc-core-host-types = { workspace = true } ibc-primitives = { workspace = true } ibc-proto = {workspace = true } -ics23 = { workspace = true } # cosmos dependencies tendermint = { workspace = true } @@ -44,13 +42,11 @@ scale-info = { workspace = true, optional = true } default = ["std"] std = [ "displaydoc/std", - "prost/std", "serde/std", "subtle-encoding/std", "ibc-primitives/std", "ibc-core-host-types/std", "ibc-proto/std", - "ics23/std", "tendermint/std", ] serde = [ @@ -59,7 +55,6 @@ serde = [ "ibc-core-host-types/serde", "ibc-primitives/serde", "ibc-proto/serde", - "ics23/serde", ] borsh = [ "dep:borsh", diff --git a/ibc-primitives/Cargo.toml b/ibc-primitives/Cargo.toml index 74f685233..149e4a55c 100644 --- a/ibc-primitives/Cargo.toml +++ b/ibc-primitives/Cargo.toml @@ -22,10 +22,10 @@ all-features = true borsh = { workspace = true, optional = true } derive_more = { workspace = true } displaydoc = { workspace = true } -prost = { workspace = true } +prost = { version = "0.12", default-features = false } schemars = { workspace = true, optional = true } serde = { workspace = true, optional = true } -time = { workspace = true } +time = { version = ">=0.3.0, <0.3.31", default-features = false } # ibc dependencies ibc-proto = { workspace = true } diff --git a/ibc-testkit/Cargo.toml b/ibc-testkit/Cargo.toml index b2cd443b1..e020657a6 100644 --- a/ibc-testkit/Cargo.toml +++ b/ibc-testkit/Cargo.toml @@ -18,12 +18,9 @@ description = """ [dependencies] # external dependencies borsh = { workspace = true, optional = true } -bytes = { workspace = true } derive_more = { workspace = true } displaydoc = { workspace = true } parking_lot = { version = "0.12.1", default-features = false } -primitive-types = { workspace = true } -prost = { workspace = true } schemars = { workspace = true, optional = true } serde = { workspace = true, optional = true } serde_json = { workspace = true, optional = true } @@ -48,7 +45,6 @@ test-log = { version = "0.2.13", features = ["trace"] } [features] default = ["std"] std = [ - "prost/std", "serde/std", "tracing/std", "tracing-subscriber/std", diff --git a/ibc-testkit/src/fixtures/core/client/mod.rs b/ibc-testkit/src/fixtures/core/client/mod.rs index e6807a097..2f3c477d4 100644 --- a/ibc-testkit/src/fixtures/core/client/mod.rs +++ b/ibc-testkit/src/fixtures/core/client/mod.rs @@ -18,8 +18,8 @@ mod tests { use ibc::core::client::types::Height; use ibc::core::host::types::identifiers::*; use ibc::primitives::prelude::*; + use ibc::primitives::ToVec; use ibc_proto::google::protobuf::Any; - use prost::Message; use tendermint::abci::Event as AbciEvent; use crate::fixtures::clients::mock::dummy_new_mock_header; @@ -70,7 +70,7 @@ mod tests { client_type.clone(), consensus_height, consensus_heights, - header.encode_to_vec(), + header.to_vec(), ) .into(), expected_keys: expected_keys.clone(), diff --git a/ibc-testkit/src/hosts/block.rs b/ibc-testkit/src/hosts/block.rs index 9ce08cdce..526ca1784 100644 --- a/ibc-testkit/src/hosts/block.rs +++ b/ibc-testkit/src/hosts/block.rs @@ -11,6 +11,7 @@ use ibc::core::host::types::identifiers::ChainId; use ibc::core::primitives::prelude::*; use ibc::core::primitives::Timestamp; use ibc::primitives::proto::{Any, Protobuf}; +use ibc::primitives::ToVec; use tendermint::block::Header as TmHeader; use tendermint::validator::Set as ValidatorSet; use tendermint_testgen::light_block::TmLightBlock; @@ -233,8 +234,6 @@ impl TryFrom for HostBlock { impl From for Any { fn from(value: HostBlock) -> Self { fn encode_light_block(light_block: SyntheticTmBlock) -> Vec { - use prost::Message; - let SyntheticTmBlock { trusted_height, trusted_next_validators, @@ -247,7 +246,7 @@ impl From for Any { trusted_height: Some(trusted_height.into()), trusted_validators: Some(trusted_next_validators.into()), } - .encode_to_vec() + .to_vec() } match value { diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs b/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs index 5be183162..34a387a34 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/client_state.rs @@ -101,21 +101,15 @@ impl TryFrom for MockClientState { type Error = ClientError; fn try_from(raw: Any) -> Result { - use core::ops::Deref; - - use bytes::Buf; - use prost::Message; - - fn decode_client_state(buf: B) -> Result { - RawMockClientState::decode(buf) - .map_err(ClientError::Decode)? - .try_into() + fn decode_client_state(value: &[u8]) -> Result { + let client_state = + Protobuf::::decode(value).map_err(|e| ClientError::Other { + description: e.to_string(), + })?; + Ok(client_state) } - match raw.type_url.as_str() { - MOCK_CLIENT_STATE_TYPE_URL => { - decode_client_state(raw.value.deref()).map_err(Into::into) - } + MOCK_CLIENT_STATE_TYPE_URL => decode_client_state(&raw.value), _ => Err(ClientError::UnknownClientStateType { client_state_type: raw.type_url, }), diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs b/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs index fa0451ebe..8a2e31e58 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs @@ -63,21 +63,17 @@ impl TryFrom for MockConsensusState { type Error = ClientError; fn try_from(raw: Any) -> Result { - use core::ops::Deref; - - use bytes::Buf; - use prost::Message; - - fn decode_consensus_state(buf: B) -> Result { - RawMockConsensusState::decode(buf) - .map_err(ClientError::Decode)? - .try_into() + fn decode_consensus_state(value: &[u8]) -> Result { + let mock_consensus_state = + Protobuf::::decode(value).map_err(|e| { + ClientError::Other { + description: e.to_string(), + } + })?; + Ok(mock_consensus_state) } - match raw.type_url.as_str() { - MOCK_CONSENSUS_STATE_TYPE_URL => { - decode_consensus_state(raw.value.deref()).map_err(Into::into) - } + MOCK_CONSENSUS_STATE_TYPE_URL => decode_consensus_state(&raw.value), _ => Err(ClientError::UnknownConsensusStateType { consensus_state_type: raw.type_url, }), diff --git a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs index 85dd8bceb..f0769e4df 100644 --- a/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs +++ b/ibc-testkit/src/testapp/ibc/clients/mock/misbehaviour.rs @@ -1,4 +1,3 @@ -use bytes::Buf; use ibc::core::client::types::error::ClientError; use ibc::core::host::types::identifiers::ClientId; use ibc::core::primitives::prelude::*; @@ -53,20 +52,15 @@ impl TryFrom for Misbehaviour { type Error = ClientError; fn try_from(raw: Any) -> Result { - use core::ops::Deref; - - fn decode_misbehaviour(buf: B) -> Result { - use prost::Message; - - RawMisbehaviour::decode(buf) - .map_err(ClientError::Decode)? - .try_into() + fn decode_misbehaviour(value: &[u8]) -> Result { + let raw_misbehaviour = + Protobuf::::decode(value).map_err(|e| ClientError::Other { + description: e.to_string(), + })?; + Ok(raw_misbehaviour) } - match raw.type_url.as_str() { - MOCK_MISBEHAVIOUR_TYPE_URL => { - decode_misbehaviour(raw.value.deref()).map_err(Into::into) - } + MOCK_MISBEHAVIOUR_TYPE_URL => decode_misbehaviour(&raw.value), _ => Err(ClientError::UnknownMisbehaviourType { misbehaviour_type: raw.type_url, }), diff --git a/ibc-testkit/tests/core/ics02_client/update_client.rs b/ibc-testkit/tests/core/ics02_client/update_client.rs index 1011b7a3c..9ef713dd9 100644 --- a/ibc-testkit/tests/core/ics02_client/update_client.rs +++ b/ibc-testkit/tests/core/ics02_client/update_client.rs @@ -20,6 +20,7 @@ use ibc::core::host::types::path::ClientConsensusStatePath; use ibc::core::host::ValidationContext; use ibc::core::primitives::{downcast, Timestamp}; use ibc::primitives::proto::Any; +use ibc::primitives::ToVec; use ibc_testkit::fixtures::core::context::MockContextConfig; use ibc_testkit::fixtures::core::signer::dummy_account_id; use ibc_testkit::hosts::block::{HostBlock, HostType}; @@ -31,7 +32,6 @@ use ibc_testkit::testapp::ibc::clients::mock::misbehaviour::Misbehaviour as Mock use ibc_testkit::testapp::ibc::clients::AnyConsensusState; use ibc_testkit::testapp::ibc::core::router::MockRouter; use ibc_testkit::testapp::ibc::core::types::{MockClientConfig, MockContext}; -use prost::Message; use tendermint_testgen::Validator as TestgenValidator; use test_log::test; @@ -686,7 +686,7 @@ fn test_update_client_events() { assert_eq!(update_client_event.client_type(), &mock_client_type()); assert_eq!(update_client_event.consensus_height(), &height); assert_eq!(update_client_event.consensus_heights(), &vec![height]); - assert_eq!(update_client_event.header(), &header.encode_to_vec()); + assert_eq!(update_client_event.header(), &header.to_vec()); } fn ensure_misbehaviour(ctx: &MockContext, client_id: &ClientId, client_type: &ClientType) { diff --git a/ibc-testkit/tests/core/router.rs b/ibc-testkit/tests/core/router.rs index 68969ba0f..327c09642 100644 --- a/ibc-testkit/tests/core/router.rs +++ b/ibc-testkit/tests/core/router.rs @@ -1,7 +1,7 @@ use ibc::apps::transfer::handler::send_transfer; use ibc::apps::transfer::types::error::TokenTransferError; use ibc::apps::transfer::types::msgs::transfer::MsgTransfer; -use ibc::apps::transfer::types::BaseCoin; +use ibc::apps::transfer::types::{BaseCoin, U256}; use ibc::core::channel::types::error::ChannelError; use ibc::core::channel::types::msgs::{ ChannelMsg, MsgAcknowledgement, MsgChannelCloseConfirm, MsgChannelCloseInit, MsgChannelOpenAck, @@ -40,7 +40,6 @@ use ibc_testkit::testapp::ibc::clients::mock::consensus_state::MockConsensusStat use ibc_testkit::testapp::ibc::clients::mock::header::MockHeader; use ibc_testkit::testapp::ibc::core::router::MockRouter; use ibc_testkit::testapp::ibc::core::types::MockContext; -use primitive_types::U256; use test_log::test; #[test]