Skip to content

Commit 13dfd5a

Browse files
authored
Merge branch 'feat/solana' into vaporif/bump-solana-deps
2 parents fe37b8e + c67c52f commit 13dfd5a

File tree

7 files changed

+60
-4
lines changed

7 files changed

+60
-4
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/tendermint-light-client/membership/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ edition = { workspace = true }
66
repository = { workspace = true }
77
license = { workspace = true }
88

9+
[features]
10+
solana = ["dep:tendermint-light-client-solana"]
11+
912
[dependencies]
1013
ibc-core-commitment-types = { workspace = true }
1114
ibc-core-host-types = { workspace = true }
1215
thiserror = { workspace = true }
16+
tendermint-light-client-solana = { workspace = true, optional = true }
1317

1418
[dev-dependencies]
1519
serde = { workspace = true, features = ["derive"] }

packages/tendermint-light-client/membership/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
use ibc_core_commitment_types::{
66
commitment::CommitmentRoot,
77
merkle::{MerklePath, MerkleProof},
8-
proto::ics23::HostFunctionsManager,
98
specs::ProofSpecs,
109
};
1110
use ibc_core_host_types::path::PathBytes;
1211

12+
#[cfg(feature = "solana")]
13+
type HostFunctions = tendermint_light_client_solana::SolanaHostFunctionsManager;
14+
#[cfg(not(feature = "solana"))]
15+
type HostFunctions = ibc_core_commitment_types::proto::ics23::HostFunctionsManager;
16+
1317
/// Key-value pair for membership/non-membership proofs
1418
#[derive(Clone, Debug)]
1519
pub struct KVPair {
@@ -84,15 +88,15 @@ pub fn membership(
8488

8589
if kv_pair.is_non_membership() {
8690
merkle_proof
87-
.verify_non_membership::<HostFunctionsManager>(
91+
.verify_non_membership::<HostFunctions>(
8892
&ProofSpecs::cosmos(),
8993
commitment_root.clone().into(),
9094
merkle_path,
9195
)
9296
.map_err(|_| MembershipError::NonMembershipVerificationFailed)?;
9397
} else {
9498
merkle_proof
95-
.verify_membership::<HostFunctionsManager>(
99+
.verify_membership::<HostFunctions>(
96100
&ProofSpecs::cosmos(),
97101
commitment_root.clone().into(),
98102
merkle_path,

packages/tendermint-light-client/solana/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ tendermint-light-client-verifier = { workspace = true }
1111
brine-ed25519 = { workspace = true, features = ["std"] }
1212
sha2 = { workspace = true }
1313
solana-program = { version = "2.3", default-features = false }
14+
ibc-core-commitment-types = { workspace = true }
15+
ics23 = { workspace = true }
1416

packages/tendermint-light-client/solana/src/lib.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! 2. solana-ibc-types/src/borsh_header.rs `conversions::commit_to_borsh()`
88
//! Pre-sort signatures before serialization (saves ~60-80k CU on-chain for 100 validators)
99
10+
use ibc_core_commitment_types::proto::ics23::HostFunctionsManager;
1011
use tendermint::crypto::signature::Error;
1112
use tendermint::{PublicKey, Signature};
1213
use tendermint_light_client_verifier::{
@@ -195,3 +196,41 @@ impl tendermint::merkle::MerkleHash for SolanaSha256 {
195196
self.0.inner_hash(left, right)
196197
}
197198
}
199+
200+
/// Solana-optimized host functions for ICS-23 Merkle proof verification
201+
#[derive(Clone, Debug, Default, PartialEq, Eq)]
202+
pub struct SolanaHostFunctionsManager;
203+
204+
impl ics23::HostFunctionsProvider for SolanaHostFunctionsManager {
205+
fn sha2_256(message: &[u8]) -> [u8; 32] {
206+
solana_program::hash::hash(message).to_bytes()
207+
}
208+
209+
fn sha2_512(message: &[u8]) -> [u8; 64] {
210+
HostFunctionsManager::sha2_512(message)
211+
}
212+
213+
fn sha2_512_truncated(message: &[u8]) -> [u8; 32] {
214+
HostFunctionsManager::sha2_512_truncated(message)
215+
}
216+
217+
fn keccak_256(message: &[u8]) -> [u8; 32] {
218+
solana_program::keccak::hash(message).to_bytes()
219+
}
220+
221+
fn ripemd160(message: &[u8]) -> [u8; 20] {
222+
HostFunctionsManager::ripemd160(message)
223+
}
224+
225+
fn blake2b_512(message: &[u8]) -> [u8; 64] {
226+
HostFunctionsManager::blake2b_512(message)
227+
}
228+
229+
fn blake2s_256(message: &[u8]) -> [u8; 32] {
230+
HostFunctionsManager::blake2s_256(message)
231+
}
232+
233+
fn blake3(message: &[u8]) -> [u8; 32] {
234+
HostFunctionsManager::blake3(message)
235+
}
236+
}

programs/solana/Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

programs/solana/programs/ics07-tendermint/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ solana-ibc-types = { workspace = true, features = ["light-client"] }
3535
solana-program.workspace = true
3636

3737
tendermint-light-client-update-client = { workspace = true, features = ["solana"] }
38-
tendermint-light-client-membership.workspace = true
38+
tendermint-light-client-membership = { workspace = true, features = ["solana"] }
3939
tendermint-light-client-misbehaviour.workspace = true
4040
tendermint-light-client-solana = { workspace = true }
4141

0 commit comments

Comments
 (0)