Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
411 changes: 381 additions & 30 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ members = [
"cosmwasm/ibc-union/lightclient/parlia",
"cosmwasm/ibc-union/lightclient/trusted-mpt",
"cosmwasm/ibc-union/lightclient/attested",
"cosmwasm/ibc-union/lightclient/starknet",
"cosmwasm/ibc-union/lightclient/state-lens-ics23-mpt",
# "cosmwasm/ibc-union/lightclient/state-lens-ics23-smt",
"cosmwasm/ibc-union/lightclient/state-lens-ics23-ics23",
Expand Down Expand Up @@ -210,6 +211,7 @@ members = [
"voyager/plugins/event-source/evm",
# "voyager/plugins/event-source/movement",
"voyager/plugins/event-source/sui",
"voyager/plugins/event-source/starknet",

"voyager/plugins/transaction/cosmos",
"voyager/plugins/transaction/evm",
Expand Down Expand Up @@ -295,6 +297,8 @@ members = [
"cosmwasm/pausable",
"cosmwasm/gatekeeper",
"cosmwasm/proxy-account-factory",
"lib/starknet-verifier",
"lib/starknet-types",
]

[workspace.package]
Expand Down Expand Up @@ -410,6 +414,7 @@ osmosis-tokenfactory-token-minter = { path = "cosmwasm/osmosis-tokenfact
parlia-light-client-types = { path = "lib/parlia-light-client-types", default-features = false }
parlia-types = { path = "lib/parlia-types", default-features = false }
parlia-verifier = { path = "lib/parlia-verifier", default-features = false }
pathfinder-crypto = { version = "0.21.3", default-features = false }
pausable = { path = "cosmwasm/pausable", default-features = false }
pg-queue = { path = "lib/pg-queue", default-features = false }
protos = { path = "generated/rust/protos", default-features = false }
Expand All @@ -419,6 +424,10 @@ serde-utils = { path = "lib/serde-utils", default-
solidity-slot = { path = "lib/solidity-slot", default-features = false }
ssz = { path = "lib/ssz", default-features = false }
ssz-derive = { path = "lib/ssz-derive", default-features = false }
starknet-light-client-types = { path = "lib/starknet-light-client-types", default-features = false }
starknet-storage-verifier = { path = "lib/starknet-storage-verifier", default-features = false }
starknet-types = { path = "lib/starknet-types", default-features = false }
starknet-verifier = { path = "lib/starknet-verifier", default-features = false }
state-lens-ics23-ics23-light-client-types = { path = "lib/state-lens-ics23-ics23-light-client-types", default-features = false }
state-lens-ics23-mpt-light-client = { path = "cosmwasm/ibc-union/lightclient/state-lens-ics23-mpt", default-features = false }
state-lens-ics23-mpt-light-client-types = { path = "lib/state-lens-ics23-mpt-light-client-types", default-features = false }
Expand Down Expand Up @@ -468,7 +477,6 @@ wasm-client-type = { path = "lib/wasm-client-type", def
# =====================
# external dependencies
# =====================

alloy = { version = "1.0", default-features = false }
alloy-primitives = { version = "1.1", default-features = false }
alloy-sol-types = { version = "1.1", default-features = true }
Expand Down Expand Up @@ -520,6 +528,7 @@ reqwest = { version = "0.11.27", default-features = false }
reth-ipc = { git = "https://github.com/paradigmxyz/reth", default-features = false }
ripemd = { version = "0.1.3", default-features = false }
rlp = { version = "0.5.2", default-features = false }
ruint = { version = "1.17.0", default-features = false }
schemars = { version = "0.8.22", default-features = false }
serde = { version = "1.0.219", default-features = false }
serde-json-wasm = { version = "1.0.1", default-features = false }
Expand All @@ -528,7 +537,7 @@ serde_with = { version = "3.12.0", default-features = false, featu
sha2 = { version = "0.10.9", default-features = false }
sha3 = { version = "0.10.8", default-features = false }
sqlx = { version = "0.7.4", default-features = false }
starknet-core = { version = "0.16.0", default-features = false }
starknet = { version = "0.17.0", default-features = false }
starknet-crypto = { version = "0.8.1", default-features = false }
static_assertions = { git = "https://github.com/nvzqz/static-assertions" } # https://github.com/nvzqz/static-assertions/pull/28
strum = { version = "0.27", default-features = false }
Expand Down
1 change: 0 additions & 1 deletion cosmwasm/ibc-union/lightclient/base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ evm-storage-verifier = { workspace = true }
frissitheto = { workspace = true }
ibc-union-light-client = { workspace = true }
ibc-union-msg = { workspace = true }
ics23 = { workspace = true }
serde = { workspace = true, features = ["derive"] }
thiserror = { workspace = true }
unionlabs = { workspace = true }
33 changes: 33 additions & 0 deletions cosmwasm/ibc-union/lightclient/starknet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
name = "starknet-light-client"
version = "0.0.0"

authors = { workspace = true }
edition = { workspace = true }
license-file = "LICENSE"
publish = { workspace = true }
repository = { workspace = true }

[lints]
workspace = true

[package.metadata.crane]
test-include = []

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
cosmwasm-std = { workspace = true }
embed-commit = { workspace = true }
ethereum-light-client = { workspace = true }
frissitheto = { workspace = true }
ibc-union-light-client = { workspace = true }
ibc-union-msg = { workspace = true }
serde = { workspace = true, features = ["derive"] }
starknet-light-client-types = { workspace = true, features = ["serde", "ethabi", "bincode"] }
starknet-storage-verifier = { workspace = true }
starknet-types = { workspace = true }
starknet-verifier = { workspace = true }
thiserror = { workspace = true }
unionlabs = { workspace = true }
59 changes: 59 additions & 0 deletions cosmwasm/ibc-union/lightclient/starknet/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
License text copyright (c) 2020 MariaDB Corporation Ab, All Rights Reserved.
"Business Source License" is a trademark of MariaDB Corporation Ab.

Parameters

Licensor: Union.fi, Labs Inc.
Licensed Work: All files under this license file's directory/subdirectories.
The Licensed Work is (c) 2025 Union.fi, Labs Inc.
Change Date: Four years from the date the Licensed Work is published.
Change License: Apache-2.0


For information about alternative licensing arrangements for the Licensed Work,
please contact [email protected].

Notice

Business Source License 1.1

Terms

The Licensor hereby grants you the right to copy, modify, create derivative
works, redistribute, and make non-production use of the Licensed Work. The
Licensor may make an Additional Use Grant, above, permitting limited production use.

Effective on the Change Date, or the fourth anniversary of the first publicly
available distribution of a specific version of the Licensed Work under this
License, whichever comes first, the Licensor hereby grants you rights under
the terms of the Change License, and the rights granted in the paragraph
above terminate.

If your use of the Licensed Work does not comply with the requirements
currently in effect as described in this License, you must purchase a
commercial license from the Licensor, its affiliated entities, or authorized
resellers, or you must refrain from using the Licensed Work.

All copies of the original and modified Licensed Work, and derivative works
of the Licensed Work, are subject to this License. This License applies
separately for each version of the Licensed Work and the Change Date may vary
for each version of the Licensed Work released by Licensor.

You must conspicuously display this License on each original or modified copy
of the Licensed Work. If you receive the Licensed Work in original or
modified form from a third party, the terms and conditions set forth in this
License apply to your use of that work.

Any use of the Licensed Work in violation of this License will automatically
terminate your rights under this License for the current and all other
versions of the Licensed Work.

This License does not grant you any right in any trademark or logo of
Licensor or its affiliates (provided that you may use a trademark or logo of
Licensor as expressly required by this License).

TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
TITLE.
162 changes: 162 additions & 0 deletions cosmwasm/ibc-union/lightclient/starknet/src/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
use cosmwasm_std::{Addr, Empty, ensure};
use ethereum_light_client::client::EthereumLightClient;
use ibc_union_light_client::{
ClientCreationResult, IbcClient, IbcClientCtx, IbcClientError, StateUpdate,
spec::{Status, Timestamp},
};
use starknet_light_client_types::{ClientState, ConsensusState, Header, StorageProof};
use starknet_storage_verifier::{Membership, PoseidonHash};
use starknet_types::Felt;
use unionlabs::encoding::Bincode;

use crate::errors::Error;

pub struct StarknetLightClient;

impl IbcClient for StarknetLightClient {
type Error = Error;

type Header = Header;

type Misbehaviour = ();

type ClientState = ClientState;

type ConsensusState = ConsensusState;

type Encoding = Bincode;

type CustomQuery = Empty;

type StorageProof = StorageProof;

fn verify_membership(
ctx: IbcClientCtx<Self>,
height: u64,
key: Vec<u8>,
storage_proof: Self::StorageProof,
value: Vec<u8>,
) -> Result<(), IbcClientError<Self>> {
let consensus_state = ctx.read_self_consensus_state(height)?;

let res = starknet_storage_verifier::verify_proof::<PoseidonHash>(
consensus_state.ibc_storage_root,
commitment_key(&key),
Felt::from_be_bytes(
value
.try_into()
.map_err(|bz: Vec<u8>| Error::InvalidProofValue(bz.into()))?,
),
&storage_proof.nodes,
)
.map_err(Into::<Error>::into)?;

ensure!(matches!(res, Membership::Membership), Error::InvalidProof);

Ok(())
}

fn verify_non_membership(
ctx: IbcClientCtx<Self>,
height: u64,
key: Vec<u8>,
storage_proof: Self::StorageProof,
) -> Result<(), IbcClientError<Self>> {
let consensus_state = ctx.read_self_consensus_state(height)?;

let res = starknet_storage_verifier::verify_proof::<PoseidonHash>(
consensus_state.ibc_storage_root,
commitment_key(&key),
Felt::ZERO,
&storage_proof.nodes,
)
.map_err(Into::<Error>::into)?;

ensure!(
matches!(res, Membership::NonMembership),
Error::InvalidProof
);

Ok(())
}

fn get_timestamp(consensus_state: &Self::ConsensusState) -> Timestamp {
consensus_state.timestamp
}

fn get_latest_height(ClientState::V1(client_state): &Self::ClientState) -> u64 {
client_state.latest_height
}

fn get_counterparty_chain_id(ClientState::V1(client_state): &Self::ClientState) -> String {
client_state.chain_id.to_string()
}

fn status(ctx: IbcClientCtx<Self>, client_state: &Self::ClientState) -> Status {
let _ = client_state;
let _ = ctx;
// FIXME: expose the ctx to this call to allow threading this call to L1
// client. generally, we want to thread if a client is an L2 so always
// provide the ctx?
Status::Active
}

fn verify_creation(
_caller: Addr,
_client_state: &Self::ClientState,
_consensus_state: &Self::ConsensusState,
_relayer: Addr,
) -> Result<ClientCreationResult<Self>, IbcClientError<Self>> {
Ok(ClientCreationResult::new())
}

fn verify_header(
ctx: IbcClientCtx<Self>,
_caller: Addr,
header: Self::Header,
_relayer: Addr,
) -> Result<StateUpdate<Self>, IbcClientError<Self>> {
let ClientState::V1(mut client_state) = ctx.read_self_client_state()?;

let l1_consensus_state = ctx
.read_consensus_state::<EthereumLightClient>(
client_state.l1_client_id,
header.l1_height,
)
.map_err(Into::<Error>::into)?;

starknet_verifier::verify_header(&client_state, &header, l1_consensus_state.state_root)
.map_err(Into::<Error>::into)?;

let update_height = header.l2_block.block_number.try_into().expect("impossible");

let consensus_state = ConsensusState {
timestamp: Timestamp::from_secs(header.l2_block.block_timestamp),
// TODO: What do we want to store here?
global_root: header.l2_block.contracts_trie_root,
ibc_storage_root: header.l2_ibc_contract_proof.contract_leaf_data.storage_root,
};

let state_update = StateUpdate::new(update_height, consensus_state);

if client_state.latest_height < update_height {
client_state.latest_height = update_height;
Ok(state_update.overwrite_client_state(ClientState::V1(client_state)))
} else {
Ok(state_update)
}
}

fn misbehaviour(
_ctx: IbcClientCtx<Self>,
_caller: Addr,
_misbehaviour: Self::Misbehaviour,
_relayer: Addr,
) -> Result<Self::ClientState, IbcClientError<Self>> {
Err(Error::Unimplemented.into())
}
}

fn commitment_key(key: &[u8]) -> Felt {
todo!()
}
1 change: 1 addition & 0 deletions cosmwasm/ibc-union/lightclient/starknet/src/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ibc_union_light_client::entrypoints!(crate::client::StarknetLightClient);
33 changes: 33 additions & 0 deletions cosmwasm/ibc-union/lightclient/starknet/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use ethereum_light_client::client::EthereumLightClient;
use ibc_union_light_client::IbcClientError;
use unionlabs::primitives::Bytes;

use crate::client::StarknetLightClient;

#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("unimplemented")]
Unimplemented,

#[error(transparent)]
Verify(#[from] starknet_verifier::Error),

#[error(transparent)]
Proof(#[from] starknet_storage_verifier::Error),

#[error(transparent)]
EthereumLightClient(#[from] IbcClientError<EthereumLightClient>),

#[error("invalid proof")]
InvalidProof,

#[error("invalid proof value: {0}")]
InvalidProofValue(Bytes),
}

// required for IbcClient trait
impl From<Error> for IbcClientError<StarknetLightClient> {
fn from(value: Error) -> Self {
IbcClientError::ClientSpecific(value)
}
}
3 changes: 3 additions & 0 deletions cosmwasm/ibc-union/lightclient/starknet/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod client;
pub mod contract;
pub mod errors;
Loading
Loading