From 5053e06632aa2636773cd3f006b426e342db4e45 Mon Sep 17 00:00:00 2001 From: Michal Nazarewicz Date: Fri, 20 Sep 2024 01:01:15 +0200 Subject: [PATCH 1/8] solana/app: remove obsolete documentation The documented approach is not being currently worked on and presence of the documentation serves only to confuse reader. Remove it. --- solana/app/README.md | 144 ------------------------------------------- 1 file changed, 144 deletions(-) delete mode 100644 solana/app/README.md diff --git a/solana/app/README.md b/solana/app/README.md deleted file mode 100644 index 68541fcc..00000000 --- a/solana/app/README.md +++ /dev/null @@ -1,144 +0,0 @@ -# Overview - -IBC on cosmos-sdk supports sets of applications, specifically ICS27 cross chain calls and CVM. - -This crate provides protocol and interfaces to support `ibc-app`s on Solana. - -## Why - -Set of features outlined here is solution for next set of problems: - -- each app needs its own arbitrary and dynamic set of accounts provided by relayer via additional separate TX calls -- solana hard limits on TX size, CPI depth, stack depth, heap size -- ability of apps to recover from failures, like finalize flows on timeouts -- ability to evolve/secure/deploy apps independently from ibc-core -- reducing chances user funds stuck on one of intermediate accounts to ensure protocols to be non custodial -- allowing user to have his own account abstraction on remote chain (aka virtual wallet) - -### Example - -CVM and ICS29 non custodial interchain acount abstrations. In both cases source to host chain call could look like in temrs of unique program instances (on example of exchange): - -```mermaid -sequenceDiagram - participant ibc-core - participant app - participant user - participant exchange - participant order-book - participant spl - participant system - - ibc-core->>app: call - app->>user: execute - user->>exchange: swap - exchange->>order-book: take - order-book->>spl: transfer - spl->>system: whatever -``` - -As you can this as per https://solana.com/pt/docs/programs/limitations : -- CPU max stack of 4 violated -- ibc-core client verification and packet proof mixed with user arbitrary execution, which will violate max compute budget in hard to handle way -- stack frame count also has changes to be violated -- max account even with LUT can be violated too for 3 exchanges - -So the only option split client state/packet from app execution. So this spec about that split. - -Another issue to consider, funds must not stuck on non user owned program account. - -This can be achived by ability of protocol to handle(and incetivise) ack/fail/timeout callbacks to source change, and/or avoiding making app program to both execute and receive funds. - -## Flows - -Here are two main flows outlined. One is goverment of app and usage of app. - -### Goverment of app - -1. Arbitrary solana account calls ibc-core -2. It registers self as port id and as owner of an app -3. After that it can upsert solana program to handle `ibc-app` protocol instuctions -4. `ibc-core` allows to store limited list of accounts which must always provided to app by `ibc-relayer`, usually it will be `ibc-core` accounts and some app `static accounts` - -### App protocol execution - -#### Main flow - -1. `ibc-relayer` delivers ibc packet prove to ibc-core -2. ibc-core identifiers that packet is registered for an ibc-app -3. ibc-core sets packet to `PRV` state -4. ibc-relayer uses port to program mapping in ibc-core to call ibc-app program. -5. ibc-relayer runs `(0)simulate` IX of app with `static accounts` and whole packet provided as input. -6. `(0)simulate` output events with accounts to be provided during `(1)execute`. `(0)simulate` can fail, so it will not mean that relayer cannot `(1)execute`. none or several events can be emited. -7. `ibc-relayer` calls `(1)execute` with all accouns from events (using LUT). -8. `(1)execute` calls `ibc-core` program with `FAIL` or `ACK` results (compatible with `ibc-go` appstack), from `PRV` packet moved to final state. -9. `ibc-core` checks that app is owner of packet. - -#### Callback flow - -In case of packet sent by app fails, it receives callback from `ibc-relayer`: - -- `(2)fail` with sequence id and error -- `(3)timeout` with sequence id - -Both also run `simulate` with proper flags. - -#### Instructions prefix - -`ibc-app` instructions are well define `borsh` encoded enum instuctions occupying indexes from 0 to 5 inclusive. `(4)dummy` and `(5)dummy` are for future use - -### Account discovery events from simulate - -Anchor format encoded events tell what accounts app will use. It is up to app to do Anchor compatible encoding (using anchor crate if needed, but not required). - -```json -// naming used to adhere that event is command for next step in flow -{ -"ExtendLookupTable" : { - new_addresses: ["pubkey1", .., "pubkeyN"] - } -} -``` - -This is one sided process to execute on Solana, so no need to have network connection counterparty. - -So really that can be standalone cranker process to do so. - -### Information interfaces - -`ibc-app` can(and need): - -- query state of previosly delivered packet by port/channel/sequence number -- query any next sequence id of packet to be send next over any port, - - -Here is example on how can operate using these interfaces: - -```mermaid -sequenceDiagram - participant source - - source->>relayer: create ICS20 and send to account abstraction - source->>relayer: create APP packet with ICS20 sequence number in data and send - relayer->>target: deliver APP packet - target->>app: fail if no ICS20 delivered - relayer->>target: deliver ICS20 - relayer->>target: deliver APP packet - target->>app: executed with success on behalf of account abstraction - relayer->>source: receive ACK/FAIL/TIMEOUT and handle cleanup/rollback -``` - -## References - -- https://github.com/cosmos/ibc-go/blob/main/proto/ibc/core/channel/v1/channel.proto means can access packet delivery status by port + channel and source sequence -- https://solana.com/ar/docs/programs/limitations has very hard limits -- https://github.com/osmosis-labs/osmosis/blob/main/cosmwasm/contracts/crosschain-swaps/README.md#error-handling tells for need for FAIL and ACK callbacks -- https://medium.com/the-interchain-foundation/introducing-the-callbacks-middleware-compose-smart-contracts-and-modules-with-ibc-6f3fb527e44a is bearish as requires 4 blocks instead of 2 to deliver packets -- https://github.com/cosmos/ibc-apps/tree/main/modules/ibc-hooks for WASM only, JSON only, spec and impl for call as single TX downstream from IBC deliver, does not have access to Incetives middleware (so cannot buy delivery) -- https://docs.solanalabs.com/proposals/versioned-transactions#lookup-table-re-initialization tells need to recreate LUTs on each delivery -- https://docs.solanalabs.com/proposals/versioned-transactions#other-proposals basically describes general relayer like documented above -- https://github.com/cosmos/ibc/blob/main/spec/app/ics-027-interchain-accounts/README.md prototype design of account abstractions and cross chain calls to use as basis, this documents allows to deliver this -- https://github.com/coral-xyz/anchor/blob/master/lang/attribute/event/src/lib.rs tells that can easy replace emit by Anchor with manual emit easy to save heap/CU usage later -- https://github.com/aleph-im/aleph-indexer-library/tree/main/packages/indexer-generator tells that DSL for Anchor events/state is useful for automagical indexing even if not use all parts of anchor -- https://github.com/cosmos/ibc/tree/main/spec/app/ics-029-fee-payment describes how to make delivery possible via incetives (deliver/ack/timeout/fail) and above document compatible with it. - From ca9dadb1f730183255cd88a500c4b178f54814fd Mon Sep 17 00:00:00 2001 From: Michal Nazarewicz Date: Tue, 24 Sep 2024 14:15:30 +0200 Subject: [PATCH 2/8] Update borsh dependency to address RUSTSEC-2023-0033 vulnerability (#394) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit borsh 0.10.3 is vulnerable to RUSTSEC-2023-0033. While this doesn’t directly affect us, update the dependency so we’re not even subject to this theoretical issue. --- Cargo.lock | 88 ++++++++++++++-------------- Cargo.toml | 2 +- solana/trie-geyser-plugin/Cargo.lock | 18 +++--- 3 files changed, 54 insertions(+), 54 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bfa1a78e..42ce74d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -326,7 +326,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4e2e5be518ec6053d90a2a7f26843dbee607583c779e6c8395951b9739bdfbe" dependencies = [ "anchor-syn 0.29.0", - "borsh-derive-internal 0.10.3", + "borsh-derive-internal 0.10.4", "proc-macro2", "quote", "syn 1.0.109", @@ -360,7 +360,7 @@ dependencies = [ "arrayref", "base64 0.13.1", "bincode", - "borsh 0.10.3", + "borsh 0.10.4", "bytemuck", "solana-program 2.0.0", "thiserror", @@ -384,7 +384,7 @@ dependencies = [ "arrayref", "base64 0.13.1", "bincode", - "borsh 0.10.3", + "borsh 0.10.4", "bytemuck", "getrandom 0.2.11", "solana-program 1.17.31", @@ -916,12 +916,12 @@ dependencies = [ [[package]] name = "borsh" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4114279215a005bc675e386011e594e1d9b800918cea18fcadadcce864a2046b" +checksum = "115e54d64eb62cdebad391c19efc9dce4981c690c85a33a12199d99bb9546fee" dependencies = [ - "borsh-derive 0.10.3", - "hashbrown 0.13.2", + "borsh-derive 0.10.4", + "hashbrown 0.11.2", ] [[package]] @@ -949,12 +949,12 @@ dependencies = [ [[package]] name = "borsh-derive" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0754613691538d51f329cce9af41d7b7ca150bc973056f1156611489475f54f7" +checksum = "831213f80d9423998dd696e2c5345aba6be7a0bd8cd19e31c5243e13df1cef89" dependencies = [ - "borsh-derive-internal 0.10.3", - "borsh-schema-derive-internal 0.10.3", + "borsh-derive-internal 0.10.4", + "borsh-schema-derive-internal 0.10.4", "proc-macro-crate 0.1.5", "proc-macro2", "syn 1.0.109", @@ -987,9 +987,9 @@ dependencies = [ [[package]] name = "borsh-derive-internal" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afb438156919598d2c7bad7e1c0adf3d26ed3840dbc010db1a882a65583ca2fb" +checksum = "65d6ba50644c98714aa2a70d13d7df3cd75cd2b523a2b452bf010443800976b3" dependencies = [ "proc-macro2", "quote", @@ -1009,9 +1009,9 @@ dependencies = [ [[package]] name = "borsh-schema-derive-internal" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634205cc43f74a1b9046ef87c4540ebda95696ec0f315024860cad7c5b0f5ccd" +checksum = "276691d96f063427be83e6692b86148e488ebba9f48f77788724ca027ba3b6d4" dependencies = [ "proc-macro2", "quote", @@ -1162,7 +1162,7 @@ dependencies = [ name = "cf-guest" version = "0.0.0" dependencies = [ - "borsh 0.10.3", + "borsh 0.10.4", "bytemuck", "derive_more", "guestchain", @@ -2244,7 +2244,7 @@ dependencies = [ name = "guestchain" version = "0.0.0" dependencies = [ - "borsh 0.10.3", + "borsh 0.10.4", "bytemuck", "derive_more", "ibc-core-client-context", @@ -2682,7 +2682,7 @@ version = "0.50.0" source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" dependencies = [ "base64 0.21.7", - "borsh 0.10.3", + "borsh 0.10.4", "derive_more", "displaydoc", "http 1.0.0", @@ -2711,7 +2711,7 @@ name = "ibc-app-transfer-types" version = "0.50.0" source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" dependencies = [ - "borsh 0.10.3", + "borsh 0.10.4", "derive_more", "displaydoc", "ibc-core", @@ -2752,7 +2752,7 @@ name = "ibc-client-tendermint-types" version = "0.50.0" source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" dependencies = [ - "borsh 0.10.3", + "borsh 0.10.4", "displaydoc", "ibc-core-client-types", "ibc-core-commitment-types", @@ -2825,7 +2825,7 @@ name = "ibc-core-channel-types" version = "0.50.0" source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" dependencies = [ - "borsh 0.10.3", + "borsh 0.10.4", "derive_more", "displaydoc", "ibc-core-client-types", @@ -2879,7 +2879,7 @@ name = "ibc-core-client-types" version = "0.50.0" source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" dependencies = [ - "borsh 0.10.3", + "borsh 0.10.4", "derive_more", "displaydoc", "ibc-core-commitment-types", @@ -2899,7 +2899,7 @@ name = "ibc-core-commitment-types" version = "0.50.0" source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" dependencies = [ - "borsh 0.10.3", + "borsh 0.10.4", "derive_more", "displaydoc", "ibc-primitives", @@ -2929,7 +2929,7 @@ name = "ibc-core-connection-types" version = "0.50.0" source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" dependencies = [ - "borsh 0.10.3", + "borsh 0.10.4", "derive_more", "displaydoc", "ibc-core-client-types", @@ -2966,7 +2966,7 @@ name = "ibc-core-handler-types" version = "0.50.0" source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" dependencies = [ - "borsh 0.10.3", + "borsh 0.10.4", "derive_more", "displaydoc", "ibc-core-channel-types", @@ -3008,7 +3008,7 @@ name = "ibc-core-host-cosmos" version = "0.50.0" source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" dependencies = [ - "borsh 0.10.3", + "borsh 0.10.4", "derive_more", "displaydoc", "ibc-app-transfer-types", @@ -3032,7 +3032,7 @@ name = "ibc-core-host-types" version = "0.50.0" source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" dependencies = [ - "borsh 0.10.3", + "borsh 0.10.4", "derive_more", "displaydoc", "ibc-primitives", @@ -3061,7 +3061,7 @@ name = "ibc-core-router-types" version = "0.50.0" source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" dependencies = [ - "borsh 0.10.3", + "borsh 0.10.4", "derive_more", "displaydoc", "ibc-core-host-types", @@ -3090,7 +3090,7 @@ name = "ibc-primitives" version = "0.50.0" source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" dependencies = [ - "borsh 0.10.3", + "borsh 0.10.4", "derive_more", "displaydoc", "ibc-proto", @@ -3110,7 +3110,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd4ee32b22d3b06f31529b956f4928e5c9a068d71e46cf6abfa19c31ca550553" dependencies = [ "base64 0.21.7", - "borsh 0.10.3", + "borsh 0.10.4", "bytes", "flex-error", "ics23", @@ -3432,7 +3432,7 @@ name = "lib" version = "0.0.0" dependencies = [ "base64 0.21.7", - "borsh 0.10.3", + "borsh 0.10.4", "bs58 0.5.1", "bytemuck", "derive_more", @@ -3704,7 +3704,7 @@ version = "3.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba8ee05284d79b367ae8966d558e1a305a781fc80c9df51f37775169117ba64f" dependencies = [ - "borsh 0.10.3", + "borsh 0.9.3", "num-derive 0.3.3", "num-traits", "solana-program 1.17.31", @@ -5059,7 +5059,7 @@ version = "0.0.0" dependencies = [ "ascii 1.1.0", "base64 0.21.7", - "borsh 0.10.3", + "borsh 0.10.4", "bytemuck", "derive_more", "hex-literal", @@ -5890,7 +5890,7 @@ dependencies = [ "bincode", "bitflags 2.6.0", "blake3", - "borsh 0.10.3", + "borsh 0.10.4", "borsh 0.9.3", "bs58 0.4.0", "bv", @@ -5943,7 +5943,7 @@ dependencies = [ "bincode", "bitflags 2.6.0", "blake3", - "borsh 0.10.3", + "borsh 0.10.4", "borsh 0.9.3", "borsh 1.5.1", "bs58 0.4.0", @@ -5998,7 +5998,7 @@ dependencies = [ "bincode", "bitflags 2.6.0", "blake3", - "borsh 0.10.3", + "borsh 0.10.4", "borsh 1.5.1", "bs58 0.5.1", "bv", @@ -6246,7 +6246,7 @@ dependencies = [ "base64 0.21.7", "bincode", "bitflags 2.6.0", - "borsh 0.10.3", + "borsh 0.10.4", "bs58 0.4.0", "bytemuck", "byteorder", @@ -6394,7 +6394,7 @@ name = "solana-signature-verifier" version = "0.0.3" dependencies = [ "base64 0.21.7", - "borsh 0.10.3", + "borsh 0.10.4", "bytemuck", "derive_more", "ed25519-dalek", @@ -6534,7 +6534,7 @@ dependencies = [ "Inflector", "base64 0.21.7", "bincode", - "borsh 0.10.3", + "borsh 0.10.4", "bs58 0.4.0", "lazy_static", "log", @@ -6799,7 +6799,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "992d9c64c2564cc8f63a4b508bf3ebcdf2254b0429b13cd1d31adb6162432a5f" dependencies = [ "assert_matches", - "borsh 0.10.3", + "borsh 0.10.4", "num-derive 0.4.1", "num-traits", "solana-program 1.17.31", @@ -6858,7 +6858,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2881dddfca792737c0706fa0175345ab282b1b0879c7d877bad129645737c079" dependencies = [ - "borsh 0.10.3", + "borsh 0.10.4", "bytemuck", "solana-program 1.17.31", "solana-zk-token-sdk 1.17.31", @@ -6998,7 +6998,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c16ce3ba6979645fb7627aa1e435576172dd63088dc7848cb09aa331fa1fe4f" dependencies = [ - "borsh 0.10.3", + "borsh 0.10.4", "solana-program 1.17.31", "spl-discriminator", "spl-pod", @@ -7642,7 +7642,7 @@ version = "0.0.0" dependencies = [ "ascii 1.1.0", "base64 0.21.7", - "borsh 0.10.3", + "borsh 0.10.4", "bytemuck", "derive_more", "hex-literal", @@ -7848,7 +7848,7 @@ dependencies = [ "anchor-lang 0.29.0", "anchor-spl", "base64 0.21.7", - "borsh 0.10.3", + "borsh 0.10.4", "bs58 0.5.1", "clap 4.4.18", "derive_more", diff --git a/Cargo.toml b/Cargo.toml index ed24d54a..b7a0bb55 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ arrayvec = "0.7.4" ascii = "1.1.0" base64 = { version = "0.21", default-features = false, features = ["alloc"] } blake3 = { version = "1.3.3", default-features = false } -borsh = { version = "0.10.3", default-features = false } +borsh = { version = "0.10.4", default-features = false } bs58 = { version = "0.5.0", default-features = false } bytemuck = { version = "1.14", default-features = false } chrono = { version = "0.4", default-features = false } diff --git a/solana/trie-geyser-plugin/Cargo.lock b/solana/trie-geyser-plugin/Cargo.lock index 4248462a..ad15f205 100644 --- a/solana/trie-geyser-plugin/Cargo.lock +++ b/solana/trie-geyser-plugin/Cargo.lock @@ -235,7 +235,7 @@ dependencies = [ "arrayref", "base64 0.13.1", "bincode", - "borsh 0.10.3", + "borsh 0.10.4", "bytemuck", "solana-program 2.0.0", "thiserror", @@ -596,9 +596,9 @@ dependencies = [ [[package]] name = "borsh" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4114279215a005bc675e386011e594e1d9b800918cea18fcadadcce864a2046b" +checksum = "115e54d64eb62cdebad391c19efc9dce4981c690c85a33a12199d99bb9546fee" dependencies = [ "borsh-derive 0.10.3", "hashbrown 0.13.2", @@ -833,7 +833,7 @@ dependencies = [ name = "cf-guest" version = "0.0.0" dependencies = [ - "borsh 0.10.3", + "borsh 0.10.4", "bytemuck", "derive_more", "guestchain", @@ -1620,7 +1620,7 @@ dependencies = [ name = "guestchain" version = "0.0.0" dependencies = [ - "borsh 0.10.3", + "borsh 0.10.4", "bytemuck", "derive_more", "ibc-core-client-context", @@ -2292,7 +2292,7 @@ name = "lib" version = "0.0.0" dependencies = [ "base64 0.21.7", - "borsh 0.10.3", + "borsh 0.10.4", "bs58 0.5.1", "bytemuck", "derive_more", @@ -3347,7 +3347,7 @@ version = "0.0.0" dependencies = [ "ascii 1.1.0", "base64 0.21.7", - "borsh 0.10.3", + "borsh 0.10.4", "bytemuck", "derive_more", "lib", @@ -3836,7 +3836,7 @@ dependencies = [ "bincode", "bitflags 2.6.0", "blake3", - "borsh 0.10.3", + "borsh 0.10.4", "borsh 0.9.3", "borsh 1.5.1", "bs58 0.4.0", @@ -3890,7 +3890,7 @@ dependencies = [ "bincode", "bitflags 2.6.0", "blake3", - "borsh 0.10.3", + "borsh 0.10.4", "borsh 0.9.3", "borsh 1.5.1", "bs58 0.4.0", From 13be90db829ac32433de1738673e4edd457f4a44 Mon Sep 17 00:00:00 2001 From: Dhruv D Jain Date: Wed, 16 Oct 2024 00:14:39 +0530 Subject: [PATCH 3/8] solana-ibc: add guest client and consensus states (#390) Adding guest client and consensus states so that the solana-ibc on the rollup can store them. The guest client and consensus state was previous removed since we used to store the wasm wrapped guest states. It was removed here https://github.com/ComposableFi/emulated-light-client/pull/255 and now its added again. --- .../programs/solana-ibc/src/client_state.rs | 66 +++++++++++++------ .../solana-ibc/src/client_state/impls.rs | 12 ++++ .../solana-ibc/src/consensus_state.rs | 39 +++++------ 3 files changed, 74 insertions(+), 43 deletions(-) diff --git a/solana/solana-ibc/programs/solana-ibc/src/client_state.rs b/solana/solana-ibc/programs/solana-ibc/src/client_state.rs index 9b10c32a..9b3970f0 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/client_state.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/client_state.rs @@ -15,6 +15,7 @@ pub enum AnyClientState { Tendermint(ibc::tm::ClientState), Wasm(ibc::wasm::ClientState), Rollup(cf_solana::ClientState), + Guest(cf_guest::ClientState), #[cfg(any(test, feature = "mocks"))] Mock(ibc::mock::MockClientState), } @@ -28,6 +29,7 @@ enum AnyClientStateTag { Tendermint = 0, Wasm = 1, Rollup = 2, + Guest = 3, #[cfg(any(test, feature = "mocks"))] Mock = 255, } @@ -40,6 +42,7 @@ impl AnyClientStateTag { AnyClientState::TENDERMINT_TYPE => Some(Self::Tendermint), AnyClientState::WASM_TYPE => Some(Self::Wasm), AnyClientState::ROLLUP_TYPE => Some(Self::Rollup), + AnyClientState::GUEST_TYPE => Some(Self::Guest), #[cfg(any(test, feature = "mocks"))] AnyClientState::MOCK_TYPE => Some(Self::Mock), _ => None, @@ -56,6 +59,8 @@ impl AnyClientState { /// Protobuf type URL for Rollup client state used in Any message. const ROLLUP_TYPE: &'static str = cf_solana::proto::ClientState::IBC_TYPE_URL; + /// Protobuf type URL for Guest client state used in Any message. + const GUEST_TYPE: &'static str = cf_guest::proto::ClientState::IBC_TYPE_URL; #[cfg(any(test, feature = "mocks"))] /// Protobuf type URL for Mock client state used in Any message. const MOCK_TYPE: &'static str = ibc::mock::MOCK_CLIENT_STATE_TYPE_URL; @@ -89,6 +94,11 @@ impl AnyClientState { Self::ROLLUP_TYPE, Protobuf::::encode_vec(state), ), + Self::Guest(state) => ( + AnyClientStateTag::Guest, + Self::GUEST_TYPE, + Protobuf::::encode_vec(state), + ), #[cfg(any(test, feature = "mocks"))] Self::Mock(state) => ( AnyClientStateTag::Mock, @@ -119,6 +129,11 @@ impl AnyClientState { .map_err(|err| err.to_string()) .map(Self::Rollup) } + AnyClientStateTag::Guest => { + Protobuf::::decode_vec(&value) + .map_err(|err| err.to_string()) + .map(Self::Guest) + } #[cfg(any(test, feature = "mocks"))] AnyClientStateTag::Mock => { Protobuf::::decode_vec(&value) @@ -135,21 +150,6 @@ impl From for AnyClientState { } } -impl From> - for AnyClientState -{ - fn from(state: cf_guest::ClientState) -> Self { - Self::from(ibc::wasm::ClientState { - data: prost::Message::encode_to_vec(&cf_guest::proto::Any::from( - &state, - )), - checksum: Default::default(), - latest_height: ibc::Height::new(1, u64::from(state.latest_height)) - .unwrap(), - }) - } -} - impl From for ibc::Any { fn from(value: AnyClientState) -> Self { let (_, type_url, value) = value.into_any(); @@ -231,11 +231,30 @@ impl ibc::tm::CommonContext for IbcStorage<'_, '_> { impl cf_guest::CommonContext for IbcStorage<'_, '_> { - type ConversionError = cf_guest::DecodeError; + type ConversionError = &'static str; type AnyClientState = AnyClientState; type AnyConsensusState = AnyConsensusState; fn host_metadata(&self) -> Result<(ibc::Timestamp, ibc::Height)> { + #[cfg(feature = "witness")] + { + let clock = + anchor_lang::solana_program::sysvar::clock::Clock::get() + .map_err(|e| ibc::ClientError::ClientSpecific { + description: e.to_string(), + })?; + + let slot = clock.slot; + let timestamp_sec = clock.unix_timestamp as u64; + + let timestamp = + ibc::Timestamp::from_nanoseconds(timestamp_sec * 10u64.pow(9)) + .map_err(|e| ibc::ClientError::ClientSpecific { + description: e.to_string(), + })?; + let height = ibc::Height::new(1, slot)?; + return Ok((timestamp, height)); + } let timestamp = self.borrow().chain.head()?.timestamp_ns.get(); let timestamp = ibc::Timestamp::from_nanoseconds(timestamp).map_err(|err| { @@ -331,11 +350,18 @@ impl cf_guest::CommonContext impl guestchain::Verifier for IbcStorage<'_, '_> { fn verify( &self, - _message: &[u8], - _pubkey: &sigverify::ed25519::PubKey, - _signature: &sigverify::ed25519::Signature, + message: &[u8], + pubkey: &sigverify::ed25519::PubKey, + signature: &sigverify::ed25519::Signature, ) -> bool { - unimplemented!() + let pubkey = pubkey.as_ref(); + let sig = signature.as_ref(); + if let Some(verifier) = crate::global().verifier() { + if verifier.verify(message, pubkey, sig).unwrap_or(false) { + return true; + } + } + false } } diff --git a/solana/solana-ibc/programs/solana-ibc/src/client_state/impls.rs b/solana/solana-ibc/programs/solana-ibc/src/client_state/impls.rs index 01a8bb30..b9524102 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/client_state/impls.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/client_state/impls.rs @@ -19,6 +19,7 @@ macro_rules! delegate { AnyClientState::Tendermint(cs) => cs.$name($($arg),*), AnyClientState::Wasm(_) => unimplemented!(), AnyClientState::Rollup(cs) => cs.$name($($arg),*), + AnyClientState::Guest(cs) => cs.$name($($arg),*), #[cfg(any(test, feature = "mocks"))] AnyClientState::Mock(cs) => cs.$name($($arg),*), } @@ -55,6 +56,7 @@ impl ibc::ClientStateCommon for AnyClientState { } AnyClientState::Wasm(_) => unimplemented!(), AnyClientState::Rollup(_) => unimplemented!(), + AnyClientState::Guest(_) => unimplemented!(), #[cfg(any(test, feature = "mocks"))] AnyClientState::Mock(cs) => cs.verify_upgrade_client( upgraded_client_state, @@ -89,6 +91,9 @@ impl ibc::ClientStateCommon for AnyClientState { AnyClientState::Rollup(cs) => { cs.verify_membership(prefix, proof, root, path, value) } + AnyClientState::Guest(cs) => { + cs.verify_membership(prefix, proof, root, path, value) + } #[cfg(any(test, feature = "mocks"))] AnyClientState::Mock(cs) => { cs.verify_membership(prefix, proof, root, path, value) @@ -115,6 +120,9 @@ impl ibc::ClientStateCommon for AnyClientState { AnyClientState::Rollup(cs) => { cs.verify_non_membership(prefix, proof, root, path) } + AnyClientState::Guest(cs) => { + cs.verify_non_membership(prefix, proof, root, path) + } #[cfg(any(test, feature = "mocks"))] AnyClientState::Mock(cs) => { cs.verify_non_membership(prefix, proof, root, path) @@ -143,6 +151,9 @@ impl<'a, 'b> ibc::ClientStateValidation> for AnyClientState { AnyClientState::Rollup(cs) => { cs.verify_client_message(ctx, client_id, client_message) } + AnyClientState::Guest(cs) => { + cs.verify_client_message(ctx, client_id, client_message) + } #[cfg(any(test, feature = "mocks"))] AnyClientState::Mock(cs) => { cs.verify_client_message(ctx, client_id, client_message) @@ -167,6 +178,7 @@ impl<'a, 'b> ibc::ClientStateValidation> for AnyClientState { } AnyClientState::Wasm(_) => unimplemented!(), AnyClientState::Rollup(_) => unimplemented!(), + AnyClientState::Guest(_) => unimplemented!(), #[cfg(any(test, feature = "mocks"))] AnyClientState::Mock(_) => unimplemented!(), } diff --git a/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs b/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs index 17a5bd55..ffc7bfb9 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs @@ -16,6 +16,7 @@ pub enum AnyConsensusState { Tendermint(ibc::tm::ConsensusState), Wasm(ibc::wasm::ConsensusState), Rollup(cf_solana::ConsensusState), + Guest(cf_guest::ConsensusState), #[cfg(any(test, feature = "mocks"))] Mock(ibc::mock::MockConsensusState), } @@ -27,6 +28,7 @@ enum AnyConsensusStateTag { Tendermint = 0, Wasm = 1, Rollup = 2, + Guest = 3, #[cfg(any(test, feature = "mocks"))] Mock = 255, } @@ -39,6 +41,7 @@ impl AnyConsensusStateTag { AnyConsensusState::TENDERMINT_TYPE => Some(Self::Tendermint), AnyConsensusState::WASM_TYPE => Some(Self::Wasm), AnyConsensusState::ROLLUP_TYPE => Some(Self::Rollup), + AnyConsensusState::GUEST_TYPE => Some(Self::Guest), #[cfg(any(test, feature = "mocks"))] AnyConsensusState::MOCK_TYPE => Some(Self::Mock), _ => None, @@ -55,6 +58,9 @@ impl AnyConsensusState { /// Protobuf type URL for Rollup consensus state used in Any message. const ROLLUP_TYPE: &'static str = cf_solana::proto::ConsensusState::IBC_TYPE_URL; + /// Protobuf type URL for Guest consensus state used in Any message. + const GUEST_TYPE: &'static str = + cf_guest::proto::ConsensusState::IBC_TYPE_URL; #[cfg(any(test, feature = "mocks"))] /// Protobuf type URL for Mock consensus state used in Any message. const MOCK_TYPE: &'static str = ibc::mock::MOCK_CONSENSUS_STATE_TYPE_URL; @@ -88,6 +94,11 @@ impl AnyConsensusState { Self::ROLLUP_TYPE, Protobuf::::encode_vec(state), ), + AnyConsensusState::Guest(state) => ( + AnyConsensusStateTag::Guest, + Self::GUEST_TYPE, + Protobuf::::encode_vec(state), + ), #[cfg(any(test, feature = "mocks"))] AnyConsensusState::Mock(state) => ( AnyConsensusStateTag::Mock, @@ -118,6 +129,11 @@ impl AnyConsensusState { .map_err(|err| err.to_string()) .map(Self::Rollup) } + AnyConsensusStateTag::Guest => { + Protobuf::::decode_vec(&value) + .map_err(|err| err.to_string()) + .map(Self::Guest) + } #[cfg(any(test, feature = "mocks"))] AnyConsensusStateTag::Mock => { Protobuf::::decode_vec(&value) @@ -128,35 +144,12 @@ impl AnyConsensusState { } } - impl From for AnyConsensusState { fn from(state: ibc::tm::types::ConsensusState) -> Self { Self::Tendermint(state.into()) } } -impl From for AnyConsensusState { - fn from(state: cf_guest::ConsensusState) -> Self { - Self::from(ibc::wasm::ConsensusState { - data: prost::Message::encode_to_vec(&cf_guest::proto::Any::from( - &state, - )), - timestamp_ns: state.timestamp_ns.get(), - }) - } -} - -impl TryFrom for cf_guest::ConsensusState { - type Error = cf_guest::DecodeError; - fn try_from(state: AnyConsensusState) -> Result { - use prost::Message; - let state = ibc::wasm::ConsensusState::try_from(state) - .map_err(|_| cf_guest::DecodeError::BadMessage)?; - let any = cf_guest::proto::Any::decode(state.data.as_slice())?; - cf_guest::ConsensusState::try_from(any) - } -} - impl Protobuf for AnyConsensusState {} impl TryFrom for AnyConsensusState { From d84dc54dc5b14d8676af6e9186ca57ecc31a05f7 Mon Sep 17 00:00:00 2001 From: Dhruv D Jain Date: Wed, 16 Oct 2024 00:15:05 +0530 Subject: [PATCH 4/8] solana-ibc: update ibc so that it contains the entrypoint filter (#395) Updating ibc so that we process tm verification only if client is tendermint. More information can be found here: https://github.com/mina86/ibc-rs/pull/2 . But the revision used is `e1be8c9292c82c1e7c158067f0014fb292ee652d` which skips tendermint verification if the header is none. --- Cargo.lock | 58 +++++++++++++++++++++++++++--------------------------- Cargo.toml | 22 ++++++++++----------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 42ce74d7..8084abd5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2656,7 +2656,7 @@ dependencies = [ [[package]] name = "ibc" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "ibc-apps", "ibc-clients", @@ -2669,7 +2669,7 @@ dependencies = [ [[package]] name = "ibc-app-nft-transfer" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "ibc-app-nft-transfer-types", "ibc-core", @@ -2679,7 +2679,7 @@ dependencies = [ [[package]] name = "ibc-app-nft-transfer-types" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "base64 0.21.7", "borsh 0.10.4", @@ -2699,7 +2699,7 @@ dependencies = [ [[package]] name = "ibc-app-transfer" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "ibc-app-transfer-types", "ibc-core", @@ -2709,7 +2709,7 @@ dependencies = [ [[package]] name = "ibc-app-transfer-types" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "borsh 0.10.4", "derive_more", @@ -2724,7 +2724,7 @@ dependencies = [ [[package]] name = "ibc-apps" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "ibc-app-nft-transfer", "ibc-app-transfer", @@ -2733,7 +2733,7 @@ dependencies = [ [[package]] name = "ibc-client-tendermint" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "derive_more", "ibc-client-tendermint-types", @@ -2750,7 +2750,7 @@ dependencies = [ [[package]] name = "ibc-client-tendermint-types" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "borsh 0.10.4", "displaydoc", @@ -2769,7 +2769,7 @@ dependencies = [ [[package]] name = "ibc-client-wasm-types" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "base64 0.21.7", "displaydoc", @@ -2783,7 +2783,7 @@ dependencies = [ [[package]] name = "ibc-clients" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "ibc-client-tendermint", "ibc-client-wasm-types", @@ -2792,7 +2792,7 @@ dependencies = [ [[package]] name = "ibc-core" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "ibc-core-channel", "ibc-core-client", @@ -2808,7 +2808,7 @@ dependencies = [ [[package]] name = "ibc-core-channel" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "ibc-core-channel-types", "ibc-core-client", @@ -2823,7 +2823,7 @@ dependencies = [ [[package]] name = "ibc-core-channel-types" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "borsh 0.10.4", "derive_more", @@ -2846,7 +2846,7 @@ dependencies = [ [[package]] name = "ibc-core-client" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "ibc-client-tendermint-types", "ibc-core-client-context", @@ -2860,7 +2860,7 @@ dependencies = [ [[package]] name = "ibc-core-client-context" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "derive_more", "displaydoc", @@ -2877,7 +2877,7 @@ dependencies = [ [[package]] name = "ibc-core-client-types" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "borsh 0.10.4", "derive_more", @@ -2897,7 +2897,7 @@ dependencies = [ [[package]] name = "ibc-core-commitment-types" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "borsh 0.10.4", "derive_more", @@ -2915,7 +2915,7 @@ dependencies = [ [[package]] name = "ibc-core-connection" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "ibc-core-client", "ibc-core-connection-types", @@ -2927,7 +2927,7 @@ dependencies = [ [[package]] name = "ibc-core-connection-types" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "borsh 0.10.4", "derive_more", @@ -2948,7 +2948,7 @@ dependencies = [ [[package]] name = "ibc-core-handler" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "ibc-client-tendermint-types", "ibc-core-channel", @@ -2964,7 +2964,7 @@ dependencies = [ [[package]] name = "ibc-core-handler-types" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "borsh 0.10.4", "derive_more", @@ -2988,7 +2988,7 @@ dependencies = [ [[package]] name = "ibc-core-host" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "derive_more", "displaydoc", @@ -3006,7 +3006,7 @@ dependencies = [ [[package]] name = "ibc-core-host-cosmos" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "borsh 0.10.4", "derive_more", @@ -3030,7 +3030,7 @@ dependencies = [ [[package]] name = "ibc-core-host-types" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "borsh 0.10.4", "derive_more", @@ -3045,7 +3045,7 @@ dependencies = [ [[package]] name = "ibc-core-router" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "derive_more", "displaydoc", @@ -3059,7 +3059,7 @@ dependencies = [ [[package]] name = "ibc-core-router-types" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "borsh 0.10.4", "derive_more", @@ -3078,7 +3078,7 @@ dependencies = [ [[package]] name = "ibc-derive" version = "0.6.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "proc-macro2", "quote", @@ -3088,7 +3088,7 @@ dependencies = [ [[package]] name = "ibc-primitives" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "borsh 0.10.4", "derive_more", @@ -3127,7 +3127,7 @@ dependencies = [ [[package]] name = "ibc-testkit" version = "0.50.0" -source = "git+https://github.com/mina86/ibc-rs?rev=f07276383091f75b7ee8bff6fd434f8214ac5054#f07276383091f75b7ee8bff6fd434f8214ac5054" +source = "git+https://github.com/mina86/ibc-rs?rev=e1be8c9292c82c1e7c158067f0014fb292ee652d#e1be8c9292c82c1e7c158067f0014fb292ee652d" dependencies = [ "derive_more", "displaydoc", diff --git a/Cargo.toml b/Cargo.toml index b7a0bb55..8f82cf92 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,17 +56,17 @@ hex-literal = "0.4.1" rayon = "1.10.0" # Use unreleased ibc-rs which supports custom verifier. -ibc = { git = "https://github.com/mina86/ibc-rs", rev = "f07276383091f75b7ee8bff6fd434f8214ac5054", default-features = false, features = ["borsh", "serde"] } -ibc-client-tendermint-types = { git = "https://github.com/mina86/ibc-rs", rev = "f07276383091f75b7ee8bff6fd434f8214ac5054", default-features = false } -ibc-core-channel-types = { git = "https://github.com/mina86/ibc-rs", rev = "f07276383091f75b7ee8bff6fd434f8214ac5054", default-features = false } -ibc-core-client-context = { git = "https://github.com/mina86/ibc-rs", rev = "f07276383091f75b7ee8bff6fd434f8214ac5054", default-features = false } -ibc-core-client-types = { git = "https://github.com/mina86/ibc-rs", rev = "f07276383091f75b7ee8bff6fd434f8214ac5054", default-features = false } -ibc-core-commitment-types = { git = "https://github.com/mina86/ibc-rs", rev = "f07276383091f75b7ee8bff6fd434f8214ac5054", default-features = false } -ibc-core-connection-types = { git = "https://github.com/mina86/ibc-rs", rev = "f07276383091f75b7ee8bff6fd434f8214ac5054", default-features = false } -ibc-core-host = { git = "https://github.com/mina86/ibc-rs", rev = "f07276383091f75b7ee8bff6fd434f8214ac5054", default-features = false } -ibc-core-host-types = { git = "https://github.com/mina86/ibc-rs", rev = "f07276383091f75b7ee8bff6fd434f8214ac5054", default-features = false } -ibc-primitives = { git = "https://github.com/mina86/ibc-rs", rev = "f07276383091f75b7ee8bff6fd434f8214ac5054", default-features = false } -ibc-testkit = { git = "https://github.com/mina86/ibc-rs", rev = "f07276383091f75b7ee8bff6fd434f8214ac5054", default-features = false } +ibc = { git = "https://github.com/mina86/ibc-rs", rev = "e1be8c9292c82c1e7c158067f0014fb292ee652d", default-features = false, features = ["borsh", "serde"] } +ibc-client-tendermint-types = { git = "https://github.com/mina86/ibc-rs", rev = "e1be8c9292c82c1e7c158067f0014fb292ee652d", default-features = false } +ibc-core-channel-types = { git = "https://github.com/mina86/ibc-rs", rev = "e1be8c9292c82c1e7c158067f0014fb292ee652d", default-features = false } +ibc-core-client-context = { git = "https://github.com/mina86/ibc-rs", rev = "e1be8c9292c82c1e7c158067f0014fb292ee652d", default-features = false } +ibc-core-client-types = { git = "https://github.com/mina86/ibc-rs", rev = "e1be8c9292c82c1e7c158067f0014fb292ee652d", default-features = false } +ibc-core-commitment-types = { git = "https://github.com/mina86/ibc-rs", rev = "e1be8c9292c82c1e7c158067f0014fb292ee652d", default-features = false } +ibc-core-connection-types = { git = "https://github.com/mina86/ibc-rs", rev = "e1be8c9292c82c1e7c158067f0014fb292ee652d", default-features = false } +ibc-core-host = { git = "https://github.com/mina86/ibc-rs", rev = "e1be8c9292c82c1e7c158067f0014fb292ee652d", default-features = false } +ibc-core-host-types = { git = "https://github.com/mina86/ibc-rs", rev = "e1be8c9292c82c1e7c158067f0014fb292ee652d", default-features = false } +ibc-primitives = { git = "https://github.com/mina86/ibc-rs", rev = "e1be8c9292c82c1e7c158067f0014fb292ee652d", default-features = false } +ibc-testkit = { git = "https://github.com/mina86/ibc-rs", rev = "e1be8c9292c82c1e7c158067f0014fb292ee652d", default-features = false } ibc-proto = { version = "0.41.0", default-features = false } insta = { version = "1.34.0" } From 8ff95be23aaa91927eb1b1795c7927e11487cf39 Mon Sep 17 00:00:00 2001 From: Dhruv D Jain Date: Wed, 16 Oct 2024 01:01:30 +0530 Subject: [PATCH 5/8] light-clients: update revision number for cf-guest and cf-solana to 1 (#392) This is to increase compatibility with other libraries which fail to properly decode proto3 message with missing revision number field (missing fields should be decoded as zero in proto3). --- common/cf-guest/src/client/impls.rs | 2 +- common/cf-solana/src/client/impls.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common/cf-guest/src/client/impls.rs b/common/cf-guest/src/client/impls.rs index 6b698e13..d5175f8b 100644 --- a/common/cf-guest/src/client/impls.rs +++ b/common/cf-guest/src/client/impls.rs @@ -270,7 +270,7 @@ where ctx.store_consensus_state( ibc::path::ClientConsensusStatePath::new( client_id.clone(), - 0, + 1, u64::from(self.latest_height), ), consensus_state.into(), diff --git a/common/cf-solana/src/client/impls.rs b/common/cf-solana/src/client/impls.rs index 4f0ab53c..7b82d837 100644 --- a/common/cf-solana/src/client/impls.rs +++ b/common/cf-solana/src/client/impls.rs @@ -188,7 +188,7 @@ where ctx.store_consensus_state( ibc::path::ClientConsensusStatePath::new( client_id.clone(), - 0, + 1, self.latest_slot.get(), ), consensus_state.into(), From 00c29e47330615ef788f1e32efd96cf06ac58bba Mon Sep 17 00:00:00 2001 From: Dhruv D Jain Date: Wed, 16 Oct 2024 01:02:43 +0530 Subject: [PATCH 6/8] solana-ibc: return status as active if client state not found (#391) If the client state is not found when finding the status, it means that a new client is getting created in which case, we should return the status as active unless the client state is already frozen ( which is checked before ). --- common/cf-guest/src/client/impls.rs | 5 +++++ common/cf-solana/src/client/impls.rs | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/common/cf-guest/src/client/impls.rs b/common/cf-guest/src/client/impls.rs index d5175f8b..1ee7b8a2 100644 --- a/common/cf-guest/src/client/impls.rs +++ b/common/cf-guest/src/client/impls.rs @@ -384,6 +384,11 @@ where Err(ibc::ClientError::ConsensusStateNotFound { .. }) => { return Ok(ibc::Status::Expired) } + // If the client state is not found, then a new client is going to be created and since its known from + // above that the client state is not frozen, we return the client state as active. + Err(ibc::ClientError::ClientStateNotFound { .. }) => { + return Ok(ibc::Status::Active) + } Err(err) => return Err(err), }; diff --git a/common/cf-solana/src/client/impls.rs b/common/cf-solana/src/client/impls.rs index 7b82d837..b9946249 100644 --- a/common/cf-solana/src/client/impls.rs +++ b/common/cf-solana/src/client/impls.rs @@ -168,7 +168,6 @@ impl ibc::ClientStateCommon for ClientState { } } - impl ibc::ClientStateExecution for ClientState where E: ibc::ExecutionContext + ibc::ClientExecutionContext + CommonContext, @@ -299,6 +298,11 @@ where Err(ibc::ClientError::ConsensusStateNotFound { .. }) => { return Ok(ibc::Status::Expired) } + // If the client state is not found, then a new client is going to be created and since its known from + // above that the client state is not frozen, we return the client state as active. + Err(ibc::ClientError::ClientStateNotFound { .. }) => { + return Ok(ibc::Status::Active) + } Err(err) => return Err(err), }; @@ -311,7 +315,6 @@ where } } - impl ClientState { pub fn do_update_state( &self, @@ -511,12 +514,10 @@ impl ClientState { } } - fn error(msg: impl ToString) -> ibc::ClientError { ibc::ClientError::Other { description: msg.to_string() } } - /// Checks client id’s client type is what’s expected and then parses the id as /// `ClientIdx`. /// @@ -536,7 +537,6 @@ fn parse_client_id(client_id: &ibc::ClientId) -> Result { Err(ibc::ClientError::ClientSpecific { description }) } - #[test] fn test_verify_client_type() { use core::str::FromStr; From 80e1e576a1274cf896e7fee94e511f17753c24ca Mon Sep 17 00:00:00 2001 From: Dhruv D Jain Date: Wed, 16 Oct 2024 18:08:01 +0530 Subject: [PATCH 7/8] solana-ibc: write local consensus state when witness feature is enabled (#398) Local consensus state is required for establishing connections. It is required only to establish connection after which it wont be required. So we store the consensus state every time trie changes for a maximum of 64 states. --------- Co-authored-by: Michal Nazarewicz --- .../solana-ibc/programs/solana-ibc/src/lib.rs | 17 +++++++++++++++++ .../programs/solana-ibc/src/storage.rs | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/solana/solana-ibc/programs/solana-ibc/src/lib.rs b/solana/solana-ibc/programs/solana-ibc/src/lib.rs index 843e02bf..9341c689 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/lib.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/lib.rs @@ -402,11 +402,28 @@ pub mod solana_ibc { let height = store.borrow().chain.head()?.block_height; // height just before the data is added to the trie. msg!("Current Block height {}", height); + let previous_root = *store.borrow().provable.hash(); ::ibc::core::entrypoint::dispatch(&mut store, &mut router, message) .map_err(error::Error::ContextError) .map_err(move |err| error!((&err)))?; + #[cfg(feature = "witness")] + { + let root = store.borrow().provable.hash().clone(); + if previous_root != root { + msg!("Writing local consensus state"); + let clock = Clock::get()?; + let slot = clock.slot; + let timestamp = clock.unix_timestamp as u64; + store + .borrow_mut() + .private + .add_local_consensus_state(slot, timestamp, root) + .unwrap(); + } + } + Ok(()) } diff --git a/solana/solana-ibc/programs/solana-ibc/src/storage.rs b/solana/solana-ibc/programs/solana-ibc/src/storage.rs index a57fac5c..ace3cb77 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/storage.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/storage.rs @@ -1,6 +1,8 @@ use alloc::rc::Rc; use core::cell::RefCell; use core::num::NonZeroU64; +#[cfg(feature = "witness")] +use std::collections::VecDeque; use anchor_lang::prelude::*; use borsh::maybestd::io; @@ -313,6 +315,9 @@ pub struct PrivateStorage { // Fee to be charged for each transfer pub fee_in_lamports: u64, + + #[cfg(feature = "witness")] + pub local_consensus_state: VecDeque<(u64, u64, CryptoHash)>, } #[derive(Clone, Debug, borsh::BorshSerialize, borsh::BorshDeserialize)] @@ -387,6 +392,20 @@ impl PrivateStorage { client_id: client_id.clone(), }) } + + #[cfg(feature = "witness")] + pub fn add_local_consensus_state( + &mut self, + slot: u64, + timestamp: u64, + trie_root: CryptoHash, + ) -> Result<(), ibc::ClientError> { + if self.local_consensus_state.len() == MAX_CONSENSUS_STATES { + self.local_consensus_state.pop_front(); + } + self.local_consensus_state.push_back((slot, timestamp, trie_root)); + Ok(()) + } } /// Provable storage, i.e. the trie, held in an account. From 4c5428d44cd7095bed839fbdfdd730c8b022cc02 Mon Sep 17 00:00:00 2001 From: Michal Nazarewicz Date: Wed, 16 Oct 2024 17:00:34 +0200 Subject: [PATCH 8/8] Various minor clippy fixes (#399) Mostly address `cargo clippy --fix` with some other minor modifications. The biggest refactoring is `host_metadata` method in `client_state.rs` (but of course no behaviour changes). --- common/memory/src/lib.rs | 8 ++-- common/sealable-trie/src/bits.rs | 1 + common/sealable-trie/src/bits/ext_key.rs | 1 - common/sealable-trie/src/trie/tests.rs | 10 ++++- common/trie-geyser/src/api.rs | 13 +++--- solana/signature-verifier/src/api.rs | 3 +- .../programs/solana-ibc/src/client_state.rs | 44 +++++++------------ .../solana-ibc/src/client_state/impls.rs | 6 +-- .../solana-ibc/programs/solana-ibc/src/lib.rs | 2 +- .../programs/solana-ibc/src/tests.rs | 1 + 10 files changed, 41 insertions(+), 48 deletions(-) diff --git a/common/memory/src/lib.rs b/common/memory/src/lib.rs index 643a3dbe..5339eb9d 100644 --- a/common/memory/src/lib.rs +++ b/common/memory/src/lib.rs @@ -409,8 +409,8 @@ mod test_write_log { fn test_free_commit() { let (mut alloc, ptrs) = make_allocator(); let mut wlog = WriteLog::new(&mut alloc); - for num in 5..10 { - wlog.free(ptrs[num]); + for ptr in &ptrs[5..10] { + wlog.free(*ptr); } assert_nodes(10, wlog.allocator(), &ptrs, 0); wlog.commit(); @@ -421,8 +421,8 @@ mod test_write_log { fn test_free_rollback() { let (mut alloc, ptrs) = make_allocator(); let mut wlog = WriteLog::new(&mut alloc); - for num in 5..10 { - wlog.free(ptrs[num]); + for ptr in &ptrs[5..10] { + wlog.free(*ptr); } assert_nodes(10, wlog.allocator(), &ptrs, 0); core::mem::drop(wlog); diff --git a/common/sealable-trie/src/bits.rs b/common/sealable-trie/src/bits.rs index 18fe1918..7585ec95 100644 --- a/common/sealable-trie/src/bits.rs +++ b/common/sealable-trie/src/bits.rs @@ -1005,6 +1005,7 @@ mod test_pop { } #[test] + #[allow(clippy::just_underscores_and_digits)] fn test_pop_back_slice() { let bytes = [ 7, 182, 182, 167, 177, 247, 171, 255, 255, 255, 0, 0, 0, 0, 0, 0, diff --git a/common/sealable-trie/src/bits/ext_key.rs b/common/sealable-trie/src/bits/ext_key.rs index b5910254..07c6385d 100644 --- a/common/sealable-trie/src/bits/ext_key.rs +++ b/common/sealable-trie/src/bits/ext_key.rs @@ -266,7 +266,6 @@ fn test_decode() { #[track_caller] fn test(length: u16, offset: U3, bad: &[u8], good: &[u8]) { - let offset = U3::try_from(offset).unwrap(); let num = length * 8 + u16::from(offset); let bad = [&num.to_be_bytes()[..], bad].concat(); assert_eq!(None, ExtKey::decode(&bad, 0)); diff --git a/common/sealable-trie/src/trie/tests.rs b/common/sealable-trie/src/trie/tests.rs index 71adf11a..892f2c87 100644 --- a/common/sealable-trie/src/trie/tests.rs +++ b/common/sealable-trie/src/trie/tests.rs @@ -385,7 +385,7 @@ fn stress_test_iter() { } } -#[derive(Clone, Eq, Ord)] +#[derive(Clone, Eq)] struct Key { len: u8, buf: [u8; 35], @@ -425,9 +425,15 @@ impl core::cmp::PartialEq for Key { fn eq(&self, other: &Self) -> bool { self.as_bytes() == other.as_bytes() } } +impl core::cmp::Ord for Key { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.as_bytes().cmp(other.as_bytes()) + } +} + impl core::cmp::PartialOrd for Key { fn partial_cmp(&self, other: &Self) -> Option { - self.as_bytes().partial_cmp(other.as_bytes()) + Some(self.cmp(other)) } } diff --git a/common/trie-geyser/src/api.rs b/common/trie-geyser/src/api.rs index f722d8d0..61bd16f3 100644 --- a/common/trie-geyser/src/api.rs +++ b/common/trie-geyser/src/api.rs @@ -51,19 +51,16 @@ fn test_slot_data_serialisation() { ); let mut proof = proof::MerkleProof::default(); - let level = [ - CryptoHash::test(10).into(), - CryptoHash::test(11).into(), - CryptoHash::test(12).into(), - ]; + let level = + [CryptoHash::test(10), CryptoHash::test(11), CryptoHash::test(12)]; proof.push_level(&level, 1); let data = SlotData { delta_hash_proof: proof::DeltaHashProof { - parent_blockhash: CryptoHash::test(101).into(), - accounts_delta_hash: CryptoHash::test(102).into(), + parent_blockhash: CryptoHash::test(101), + accounts_delta_hash: CryptoHash::test(102), num_sigs: 103, - blockhash: CryptoHash::test(104).into(), + blockhash: CryptoHash::test(104), epoch_accounts_hash: None, }, witness_proof: proof::AccountProof { account_hash_data, proof }, diff --git a/solana/signature-verifier/src/api.rs b/solana/signature-verifier/src/api.rs index aaf64e1b..7e9ca73d 100644 --- a/solana/signature-verifier/src/api.rs +++ b/solana/signature-verifier/src/api.rs @@ -121,7 +121,8 @@ impl<'a, 'info> SignaturesAccount<'a, 'info> { #[cfg(any(test, not(feature = "library")))] pub(crate) fn write_count_and_sort(&self, count: u32) -> Result { let mut data = self.0.try_borrow_mut_data()?; - let (head, tail) = stdx::split_at_mut::<4, _>(&mut *data) + #[allow(clippy::explicit_auto_deref)] + let (head, tail) = stdx::split_at_mut::<4, _>(*data) .ok_or(ProgramError::AccountDataTooSmall)?; let entries = stdx::as_chunks_mut::<{ SignatureHash::SIZE }, _>(tail) .0 diff --git a/solana/solana-ibc/programs/solana-ibc/src/client_state.rs b/solana/solana-ibc/programs/solana-ibc/src/client_state.rs index 9b3970f0..9d388467 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/client_state.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/client_state.rs @@ -1,5 +1,7 @@ use anchor_lang::prelude::borsh; use anchor_lang::prelude::borsh::maybestd::io; +use anchor_lang::solana_program::sysvar::clock::Clock; +use anchor_lang::solana_program::sysvar::Sysvar; use crate::consensus_state::AnyConsensusState; use crate::ibc; @@ -236,35 +238,21 @@ impl cf_guest::CommonContext type AnyConsensusState = AnyConsensusState; fn host_metadata(&self) -> Result<(ibc::Timestamp, ibc::Height)> { - #[cfg(feature = "witness")] - { - let clock = - anchor_lang::solana_program::sysvar::clock::Clock::get() - .map_err(|e| ibc::ClientError::ClientSpecific { - description: e.to_string(), - })?; - - let slot = clock.slot; - let timestamp_sec = clock.unix_timestamp as u64; - - let timestamp = - ibc::Timestamp::from_nanoseconds(timestamp_sec * 10u64.pow(9)) - .map_err(|e| ibc::ClientError::ClientSpecific { - description: e.to_string(), - })?; - let height = ibc::Height::new(1, slot)?; - return Ok((timestamp, height)); - } - let timestamp = self.borrow().chain.head()?.timestamp_ns.get(); - let timestamp = - ibc::Timestamp::from_nanoseconds(timestamp).map_err(|err| { - ibc::ClientError::Other { description: err.to_string() } + let (timestamp_ns, height) = if cfg!(feature = "witness") { + let clock = Clock::get().map_err(|e| { + ibc::ClientError::ClientSpecific { description: e.to_string() } })?; - - let height = u64::from(self.borrow().chain.head()?.block_height); - let height = ibc::Height::new(1, height)?; - - Ok((timestamp, height)) + (clock.unix_timestamp as u64 * 10u64.pow(9), clock.slot) + } else { + self.borrow().chain.head().map(|head| { + (head.timestamp_ns.get(), head.block_height.into()) + })? + }; + let timestamp = ibc::Timestamp::from_nanoseconds(timestamp_ns) + .map_err(|e| ibc::ClientError::ClientSpecific { + description: e.to_string(), + })?; + Ok((timestamp, ibc::Height::new(1, height)?)) } fn set_client_state( diff --git a/solana/solana-ibc/programs/solana-ibc/src/client_state/impls.rs b/solana/solana-ibc/programs/solana-ibc/src/client_state/impls.rs index b9524102..d78948ac 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/client_state/impls.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/client_state/impls.rs @@ -394,7 +394,7 @@ fn test_merkle_hash() { assert_eq!(theirs.leaf_hash(input), ours.leaf_hash(input)); } - let foo = Sha256::digest(b"foo"); - let bar = Sha256::digest(b"bar"); - assert_eq!(theirs.inner_hash(foo, bar), ours.inner_hash(foo, bar)); + let one = Sha256::digest(b"foo"); + let two = Sha256::digest(b"bar"); + assert_eq!(theirs.inner_hash(one, two), ours.inner_hash(one, two)); } diff --git a/solana/solana-ibc/programs/solana-ibc/src/lib.rs b/solana/solana-ibc/programs/solana-ibc/src/lib.rs index 9341c689..085db5c4 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/lib.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/lib.rs @@ -410,7 +410,7 @@ pub mod solana_ibc { #[cfg(feature = "witness")] { - let root = store.borrow().provable.hash().clone(); + let root = *store.borrow().provable.hash(); if previous_root != root { msg!("Writing local consensus state"); let clock = Clock::get()?; diff --git a/solana/solana-ibc/programs/solana-ibc/src/tests.rs b/solana/solana-ibc/programs/solana-ibc/src/tests.rs index 0f7ed436..7c7fde80 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/tests.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/tests.rs @@ -903,6 +903,7 @@ fn max_timeout_height() -> ibc::TimeoutHeight { ibc::TimeoutHeight::At(ibc::Height::new(u64::MAX, u64::MAX).unwrap()) } +#[allow(clippy::too_many_arguments)] fn construct_packet_from_denom( base_denom: &str, port_id: ibc::PortId,