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

ics-cf-solana light-client: header verification & client update; protobuf impl #510

Open
wants to merge 21 commits into
base: hyperspace-solana
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4f7e924
Implement header verification & client update
vmarkushin Aug 5, 2024
c1942e9
Fix doc type
vmarkushin Aug 8, 2024
f8b6ab9
Add `PreCheckedShreds` type that provides some guarantees for the rec…
vmarkushin Aug 8, 2024
999e51d
Check for misbehavior when an update from the past received
vmarkushin Aug 8, 2024
e7efb3f
Remove unnecessary checks of Shreds that were already done by `PreChe…
vmarkushin Aug 8, 2024
311cf7d
Remove usage of `PK` generic parameter
vmarkushin Aug 8, 2024
b5d9b0c
Add some todos
vmarkushin Aug 8, 2024
37afb2f
Make shreds verification code look nicer
vmarkushin Aug 8, 2024
b172be3
Fix iterator loop
vmarkushin Aug 8, 2024
65b5bd0
Rewrite Header proto decoding using iterators
vmarkushin Aug 8, 2024
673fd8a
Optimize collection
vmarkushin Aug 8, 2024
eb250e9
Update light-clients/icsxx-cf-solana/src/client.rs
vmarkushin Aug 12, 2024
8787431
Add a TODO
vmarkushin Aug 12, 2024
687e9b3
Feature-gate CfClient in pallet-ibc
vmarkushin Aug 12, 2024
1f97d39
Fix tests compilation and add a test for decoding shreds
vmarkushin Aug 12, 2024
976d8d9
Refactor and optimize `TryFrom<Vec<Shred>>`` for `PreCheckedShreds`
vmarkushin Aug 12, 2024
d3964b5
Add check for all the shreds being data in PreCheckedShreds
vmarkushin Aug 12, 2024
1ceff4e
Extract check for misbehaviour for header method
vmarkushin Aug 12, 2024
f014eb5
Use u64 instead of Duration and Timestamp
vmarkushin Aug 12, 2024
0738a5b
Merge remote-tracking branch 'origin/vmarkushin/cf-solana-client-upda…
vmarkushin Aug 12, 2024
dcaea3c
Merge branch 'refs/heads/hyperspace-solana' into vmarkushin/cf-solana…
vmarkushin Aug 12, 2024
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
598 changes: 498 additions & 100 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ ibc-core-host = { git = "https://github.com/mina86/ibc-rs", rev = "2b50319f3460d
ibc-core-host-types = { git = "https://github.com/mina86/ibc-rs", rev = "2b50319f3460d03e8781e5a834c4b56bdcfdc5bc", default-features = false }
ibc-primitives = { git = "https://github.com/mina86/ibc-rs", rev = "2b50319f3460d03e8781e5a834c4b56bdcfdc5bc", default-features = false }
ibc-testkit = { git = "https://github.com/mina86/ibc-rs", rev = "2b50319f3460d03e8781e5a834c4b56bdcfdc5bc", default-features = false }
solana-sdk = { git = "https://github.com/ComposableFi/mantis-solana", rev = "d92c52575aaf430ca1f06bc2589f26b0fedde7bf" }
mina86 marked this conversation as resolved.
Show resolved Hide resolved

# ibc-testkit = { git = "https://github.com/mina86/ibc-rs", rev = "6015aea441d4660f7f7ecd89b5e770a993448089" }
#ibc = { path = "../ibc-rs-mina/ibc" }
#ibc-app-nft-transfer = { path = "../ibc-rs-mina/ibc-apps/ics721-nft-transfer" }
Expand Down
165 changes: 83 additions & 82 deletions contracts/pallet-ibc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@ homepage = "https://composable.finance"
name = "pallet-ibc"
version = "0.0.1"
authors = [
"Seun Lanlege <[email protected]>",
"David Salami <[email protected]>",
"Seun Lanlege <[email protected]>",
"David Salami <[email protected]>",
]

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[package.metadata.cargo-udeps.ignore]
normal = [
"frame-benchmarking",
"pallet-ibc-ping",
"balances",
"pallet-assets",
"simple-iavl",
"frame-benchmarking",
"pallet-ibc-ping",
"balances",
"pallet-assets",
"simple-iavl",
]

[dependencies]
# crates.io
log = { version = "0.4.0", default-features = false }
serde = { version = "1.0.136", default-features = false, features = ["derive"] }
scale-info = { version = "2.1.1", default-features = false, features = [
"derive",
"derive",
] }
serde_json = { version = "1.0.45", default-features = false }
sha2 = { version = "0.10.2", default-features = false }
derive_more = { version = "0.99.17", default-features = false, features = [
"from",
"display",
"from",
"display",
] }
borsh = { version = "0.10.3", default-features = false }
# substrate
Expand All @@ -52,7 +52,8 @@ ics23 = { git = "https://github.com/cosmos/ics23", rev = "74ce807b7be39a7e0afb4e

#guest-chain
cf-guest = { path = "../../light-clients/cf-guest" }
guestchain = { git = "https://github.com/composableFi/emulated-light-client/" , default-features = false }
icsxx-cf-solana = { path = "../../light-clients/icsxx-cf-solana" }
guestchain = { git = "https://github.com/composableFi/emulated-light-client/", default-features = false }
ed25519-dalek = { version = "2.1.1", default-features = false, features = ["pkcs8"] }

grandpa-client-primitives = { package = "grandpa-light-client-primitives", path = "../../algorithms/grandpa/primitives", default-features = false }
Expand Down Expand Up @@ -81,7 +82,7 @@ sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch =
simple-iavl = { path = "simple-iavl", default-features = false }
sp-consensus-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false, optional = true }
finality-grandpa = { version = "0.16.2", features = [
"derive-codec",
"derive-codec",
], default-features = false, optional = true }

[dependencies.ibc]
Expand Down Expand Up @@ -131,79 +132,79 @@ features = ["mocks"]
default = ["std"]
testing = ["ibc/mocks"]
std = [
"codec/std",
"log/std",
"scale-info/std",
"serde/std",
"serde_json/std",
"sha2/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"sp-runtime/std",
"sp-core/std",
"sp-std/std",
"sp-io/std",
"sp-trie/std",
"balances/std",
"cumulus-primitives-core/std",
"pallet-assets/std",
"ibc/std",
"ibc-proto/std",
"ibc-primitives/std",
"parachain-info/std",
"grandpa-client-primitives/std",
"beefy-client-primitives/std",
"light-client-common/std",
"ics10-grandpa/std",
"ics11-beefy/std",
"ics07-tendermint/std",
"sp-consensus-grandpa/std",
"sp-consensus-grandpa/std",
"finality-grandpa/std",
"hex/std",
"pallet-timestamp/std",
"ics08-wasm/std",
"pallet-ibc-ping?/std",
"simple-iavl/std",
"chrono/std",
"ics23/std",
"orml-tokens/std",
"orml-traits/std",
"pallet-aura?/std",
"pallet-membership?/std",
"prost/std",
"sp-consensus-aura?/std",
"sp-consensus-slots?/std",
"sp-keystore/std",
"tendermint/std",
"codec/std",
"log/std",
"scale-info/std",
"serde/std",
"serde_json/std",
"sha2/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"sp-runtime/std",
"sp-core/std",
"sp-std/std",
"sp-io/std",
"sp-trie/std",
"balances/std",
"cumulus-primitives-core/std",
"pallet-assets/std",
"ibc/std",
"ibc-proto/std",
"ibc-primitives/std",
"parachain-info/std",
"grandpa-client-primitives/std",
"beefy-client-primitives/std",
"light-client-common/std",
"ics10-grandpa/std",
"ics11-beefy/std",
"ics07-tendermint/std",
"sp-consensus-grandpa/std",
"sp-consensus-grandpa/std",
"finality-grandpa/std",
"hex/std",
"pallet-timestamp/std",
"ics08-wasm/std",
"pallet-ibc-ping?/std",
"simple-iavl/std",
"chrono/std",
"ics23/std",
"orml-tokens/std",
"orml-traits/std",
"pallet-aura?/std",
"pallet-membership?/std",
"prost/std",
"sp-consensus-aura?/std",
"sp-consensus-slots?/std",
"sp-keystore/std",
"tendermint/std",
]

runtime-benchmarks = [
"frame-benchmarking",
"pallet-ibc-ping",
"frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"hex-literal",
"pallet-assets/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-aura",
"pallet-membership",
"pallet-assets",
"balances",
"sp-consensus-slots",
"sp-consensus-aura/serde",
"sp-consensus-aura/std",
"ibc-primitives/runtime-benchmarks",
"sp-consensus-grandpa",
"finality-grandpa",
"pallet-ibc-ping/runtime-benchmarks",
"frame-benchmarking?/runtime-benchmarks",
"orml-tokens/runtime-benchmarks",
"pallet-assets?/runtime-benchmarks",
"balances?/runtime-benchmarks",
"pallet-membership?/runtime-benchmarks",
"sp-runtime/runtime-benchmarks"
"frame-benchmarking",
"pallet-ibc-ping",
"frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"hex-literal",
"pallet-assets/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-aura",
"pallet-membership",
"pallet-assets",
"balances",
"sp-consensus-slots",
"sp-consensus-aura/serde",
"sp-consensus-aura/std",
"ibc-primitives/runtime-benchmarks",
"sp-consensus-grandpa",
"finality-grandpa",
"pallet-ibc-ping/runtime-benchmarks",
"frame-benchmarking?/runtime-benchmarks",
"orml-tokens/runtime-benchmarks",
"pallet-assets?/runtime-benchmarks",
"balances?/runtime-benchmarks",
"pallet-membership?/runtime-benchmarks",
"sp-runtime/runtime-benchmarks"
]

try-runtime = ["frame-support/try-runtime"]
16 changes: 16 additions & 0 deletions contracts/pallet-ibc/src/light_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ use ics11_beefy::{
client_message::BEEFY_CLIENT_MESSAGE_TYPE_URL, client_state::BEEFY_CLIENT_STATE_TYPE_URL,
consensus_state::BEEFY_CONSENSUS_STATE_TYPE_URL,
};
use icsxx_cf_solana::{
CF_SOLANA_CLIENT_MESSAGE_TYPE_URL, CF_SOLANA_CLIENT_STATE_TYPE_URL,
CF_SOLANA_CONSENSUS_STATE_TYPE_URL, CF_SOLANA_HEADER_TYPE_URL, CF_SOLANA_MISBEHAVIOUR_TYPE_URL,
};
use prost::Message;
use sp_core::{crypto::ByteArray, ed25519, H256};
use sp_runtime::{
Expand Down Expand Up @@ -333,6 +337,7 @@ pub enum AnyClient {
Tendermint(ics07_tendermint::client_def::TendermintClient<HostFunctionsManager>),
Wasm(ics08_wasm::client_def::WasmClient<AnyClient, AnyClientState, AnyConsensusState>),
Guest(cf_guest::client_def::GuestClient<PubKey>),
CfSolana(icsxx_cf_solana::client_def::CfSolanaClient<PubKey>),
vmarkushin marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(any(test, feature = "testing"))]
Mock(ibc::mock::client_def::MockClient),
}
Expand All @@ -344,6 +349,7 @@ pub enum AnyUpgradeOptions {
Tendermint(ics07_tendermint::client_state::UpgradeOptions),
Wasm(Box<Self>),
Guest(cf_guest::client::UpgradeOptions),
CfSolana(icsxx_cf_solana::client::UpgradeOptions),
#[cfg(any(test, feature = "testing"))]
Mock(()),
}
Expand All @@ -360,6 +366,8 @@ pub enum AnyClientState {
Wasm(ics08_wasm::client_state::ClientState<AnyClient, Self, AnyConsensusState>),
#[ibc(proto_url = "GUEST_CLIENT_STATE_TYPE_URL")]
Guest(cf_guest::ClientState<PubKey>),
#[ibc(proto_url = "CF_SOLANA_CLIENT_STATE_TYPE_URL")]
CfSolana(icsxx_cf_solana::ClientState<PubKey>),
#[cfg(any(test, feature = "testing"))]
#[ibc(proto_url = "MOCK_CLIENT_STATE_TYPE_URL")]
Mock(ibc::mock::client_state::MockClientState),
Expand Down Expand Up @@ -435,6 +443,8 @@ pub enum AnyConsensusState {
Wasm(ics08_wasm::consensus_state::ConsensusState<Self>),
#[ibc(proto_url = "GUEST_CONSENSUS_STATE_TYPE_URL")]
Guest(cf_guest::ConsensusState),
#[ibc(proto_url = "CF_SOLANA_CONSENSUS_STATE_TYPE_URL")]
CfSolana(icsxx_cf_solana::ConsensusState),
#[cfg(any(test, feature = "testing"))]
#[ibc(proto_url = "MOCK_CONSENSUS_STATE_TYPE_URL")]
Mock(ibc::mock::client_state::MockConsensusState),
Expand Down Expand Up @@ -462,6 +472,8 @@ pub enum AnyClientMessage {
Wasm(ics08_wasm::client_message::ClientMessage<Self>),
#[ibc(proto_url = "GUEST_CLIENT_MESSAGE_TYPE_URL")]
Guest(cf_guest::ClientMessage<PubKey>),
#[ibc(proto_url = "CF_SOLANA_CLIENT_MESSAGE_TYPE_URL")]
CfSolana(icsxx_cf_solana::ClientMessage<PubKey>),
#[cfg(any(test, feature = "testing"))]
#[ibc(proto_url = "MOCK_CLIENT_MESSAGE_TYPE_URL")]
Mock(ibc::mock::header::MockClientMessage),
Expand Down Expand Up @@ -573,6 +585,10 @@ impl From<AnyClientMessage> for Any {
type_url: GUEST_CLIENT_MESSAGE_TYPE_URL.to_string(),
value: msg.encode_vec().expect("encode_vec failed"),
},
AnyClientMessage::CfSolana(msg) => Any {
type_url: CF_SOLANA_CLIENT_MESSAGE_TYPE_URL.to_string(),
value: msg.encode_to_vec().expect("encode_vec failed"),
},
#[cfg(any(test, feature = "testing"))]
AnyClientMessage::Mock(_msg) => panic!("MockHeader can't be serialized"),
}
Expand Down
1 change: 1 addition & 0 deletions light-clients/ics07-tendermint/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use ibc::{
};

pub const TENDERMINT_CLIENT_STATE_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.ClientState";

#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)]
pub struct ClientState<H> {
pub chain_id: ChainId,
Expand Down
16 changes: 13 additions & 3 deletions light-clients/icsxx-cf-solana/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ edition = "2021"
borsh = "0.10"
bytemuck = { version = "1.14", default-features = false, features = ["must_cast"] }
derive_more = { version = "0.99", features = ["from"], default-features = false }
prost = { version = "0.11", features = ["prost-derive"], default-features = false }
prost-12 = { package = "prost", version = "0.12", default-features = false }
prost = { version = "0.12", features = ["prost-derive"], default-features = false }
prost-11 = { package = "prost", version = "0.11", default-features = false }
ed25519-consensus = { version = "2", default-features = false }
serde = { version = "1.0", default-features = false, features = ["derive"] }
proto-utils = { git = "https://github.com/composableFi/emulated-light-client", default-features = false }
num_enum = { version = "0.7.3", default-features = false }
static_assertions = "1.1.0"
assert_matches = "1.5.0"
rand_chacha = { version = "0.3.1", default-features = false }
rand = { version = "0.8.5", default-features = false }

# New IBC
ibc-core-client-context = { git = "https://github.com/mina86/ibc-rs", rev = "6015aea441d4660f7f7ecd89b5e770a993448089", default-features = false }
Expand All @@ -33,9 +39,13 @@ trie-ids = { git = "https://github.com/ComposableFi/emulated-light-client/", def
sealable-trie = { git = "https://github.com/ComposableFi/emulated-light-client/", features = ["borsh"], default-features = false }
stdx = { git = "https://github.com/ComposableFi/emulated-light-client/", default-features = false }
cf-guest-upstream = { package = "cf-guest", git = "https://github.com/ComposableFi/emulated-light-client/", default-features = false }
bitflags = "2.4.2"
solana-sdk = { git = "https://github.com/ComposableFi/mantis-solana", rev = "d92c52575aaf430ca1f06bc2589f26b0fedde7bf" }
itertools = "0.11.0"
bincode = "1.3.3"

[build-dependencies]
prost-build = { version = "0.11", default-features = false }
prost-build = { version = "0.12", default-features = false }

[dev-dependencies]
insta = { version = "1.34.0" }
Expand Down
6 changes: 6 additions & 0 deletions light-clients/icsxx-cf-solana/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() -> std::io::Result<()> {
prost_build::Config::new()
.enable_type_names()
.include_file("messages.rs")
.compile_protos(&["src/proto/cf-solana.proto"], &["src/proto/"])
}
Loading