Skip to content

Commit

Permalink
Merge remote-tracking branch 'up/master' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
mina86 committed Oct 16, 2024
2 parents aa5528a + 80e1e57 commit 49b32a1
Show file tree
Hide file tree
Showing 14 changed files with 304 additions and 318 deletions.
146 changes: 73 additions & 73 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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" }
Expand Down
7 changes: 6 additions & 1 deletion common/cf-guest/src/client/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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),
};

Expand Down
12 changes: 6 additions & 6 deletions common/cf-solana/src/client/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ impl ibc::ClientStateCommon for ClientState {
}
}


impl<E> ibc::ClientStateExecution<E> for ClientState
where
E: ibc::ExecutionContext + ibc::ClientExecutionContext + CommonContext,
Expand All @@ -188,7 +187,7 @@ where
ctx.store_consensus_state(
ibc::path::ClientConsensusStatePath::new(
client_id.clone(),
0,
1,
self.latest_slot.get(),
),
consensus_state.into(),
Expand Down Expand Up @@ -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),
};

Expand All @@ -311,7 +315,6 @@ where
}
}


impl ClientState {
pub fn do_update_state(
&self,
Expand Down Expand Up @@ -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`.
///
Expand All @@ -536,7 +537,6 @@ fn parse_client_id(client_id: &ibc::ClientId) -> Result<trie_ids::ClientIdx> {
Err(ibc::ClientError::ClientSpecific { description })
}


#[test]
fn test_verify_client_type() {
use core::str::FromStr;
Expand Down
144 changes: 0 additions & 144 deletions solana/app/README.md

This file was deleted.

66 changes: 46 additions & 20 deletions solana/solana-ibc/programs/solana-ibc/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub enum AnyClientState {
Tendermint(ibc::tm::ClientState),
Wasm(ibc::wasm::ClientState),
Rollup(cf_solana::ClientState),
Guest(cf_guest::ClientState<sigverify::ed25519::PubKey>),
#[cfg(any(test, feature = "mocks"))]
Mock(ibc::mock::MockClientState),
}
Expand All @@ -28,6 +29,7 @@ enum AnyClientStateTag {
Tendermint = 0,
Wasm = 1,
Rollup = 2,
Guest = 3,
#[cfg(any(test, feature = "mocks"))]
Mock = 255,
}
Expand All @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -89,6 +94,11 @@ impl AnyClientState {
Self::ROLLUP_TYPE,
Protobuf::<cf_solana::proto::ClientState>::encode_vec(state),
),
Self::Guest(state) => (
AnyClientStateTag::Guest,
Self::GUEST_TYPE,
Protobuf::<cf_guest::proto::ClientState>::encode_vec(state),
),
#[cfg(any(test, feature = "mocks"))]
Self::Mock(state) => (
AnyClientStateTag::Mock,
Expand Down Expand Up @@ -119,6 +129,11 @@ impl AnyClientState {
.map_err(|err| err.to_string())
.map(Self::Rollup)
}
AnyClientStateTag::Guest => {
Protobuf::<cf_guest::proto::ClientState>::decode_vec(&value)
.map_err(|err| err.to_string())
.map(Self::Guest)
}
#[cfg(any(test, feature = "mocks"))]
AnyClientStateTag::Mock => {
Protobuf::<ibc::mock::ClientStatePB>::decode_vec(&value)
Expand All @@ -135,21 +150,6 @@ impl From<ibc::tm::types::ClientState> for AnyClientState {
}
}

impl<PK: guestchain::PubKey> From<cf_guest::ClientState<PK>>
for AnyClientState
{
fn from(state: cf_guest::ClientState<PK>) -> 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<AnyClientState> for ibc::Any {
fn from(value: AnyClientState) -> Self {
let (_, type_url, value) = value.into_any();
Expand Down Expand Up @@ -231,11 +231,30 @@ impl ibc::tm::CommonContext for IbcStorage<'_, '_> {
impl cf_guest::CommonContext<sigverify::ed25519::PubKey>
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()

Check failure on line 242 in solana/solana-ibc/programs/solana-ibc/src/client_state.rs

View workflow job for this annotation

GitHub Actions / clippy

no function or associated item named `get` found for struct `anchor_lang::prelude::Clock` in the current scope

error[E0599]: no function or associated item named `get` found for struct `anchor_lang::prelude::Clock` in the current scope --> solana/solana-ibc/programs/solana-ibc/src/client_state.rs:242:68 | 242 | anchor_lang::solana_program::sysvar::clock::Clock::get() | ^^^ function or associated item not found in `Clock` | = help: items from traits can only be used if the trait is in scope help: the following trait is implemented but not in scope; perhaps add a `use` for it: | 1 + use anchor_lang::prelude::SolanaSysvar; |
.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();

Check failure on line 258 in solana/solana-ibc/programs/solana-ibc/src/client_state.rs

View workflow job for this annotation

GitHub Actions / clippy

unreachable statement

error: unreachable statement --> solana/solana-ibc/programs/solana-ibc/src/client_state.rs:258:9 | 256 | return Ok((timestamp, height)); | ------------------------------ any code following this expression is unreachable 257 | } 258 | let timestamp = self.borrow().chain.head()?.timestamp_ns.get(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement | = note: `-D unreachable-code` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(unreachable_code)]`
let timestamp =
ibc::Timestamp::from_nanoseconds(timestamp).map_err(|err| {
Expand Down Expand Up @@ -331,11 +350,18 @@ impl cf_guest::CommonContext<sigverify::ed25519::PubKey>
impl guestchain::Verifier<sigverify::ed25519::PubKey> 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
}
}

Expand Down
Loading

0 comments on commit 49b32a1

Please sign in to comment.