From 2b7a9d56164ac76f426bd06ca47dedf8bd181e5f Mon Sep 17 00:00:00 2001 From: Hussein Ait Lahcen Date: Mon, 9 Dec 2024 16:51:29 +0100 Subject: [PATCH 1/2] feat(tendermint-lc): refactor and port to union-ibc --- Cargo.lock | 29 + Cargo.toml | 2 +- .../light-clients/tendermint/Cargo.toml | 9 +- .../light-clients/tendermint/src/client.rs | 863 +++++++----------- .../light-clients/tendermint/src/contract.rs | 52 +- .../light-clients/tendermint/src/errors.rs | 18 +- flake.nix | 2 +- hubble/Cargo.toml | 2 +- lib/tendermint-light-client-types/Cargo.toml | 9 +- .../src/client_state.rs | 4 +- .../src/consensus_state.rs | 43 +- .../src/fraction.rs | 5 +- .../src/header.rs | 4 +- lib/tendermint-verifier/Cargo.toml | 2 +- lib/tendermint-verifier/src/utils.rs | 22 +- .../src/ibc/core/commitment/merkle_root.rs | 6 + .../modules/consensus/tendermint/Cargo.toml | 2 +- 17 files changed, 457 insertions(+), 617 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 81753a0fdc..b886d2097d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11846,10 +11846,39 @@ dependencies = [ "url", ] +[[package]] +name = "tendermint-light-client" +version = "0.1.0" +dependencies = [ + "base64 0.21.7", + "bytes", + "cometbft-types", + "cosmwasm-std 2.1.4", + "hex", + "ics23", + "lazy_static", + "prost 0.12.6", + "protos", + "schemars", + "serde", + "serde-json-wasm 1.0.1", + "serde-utils", + "serde_json", + "sha2 0.10.8", + "sha3 0.10.8", + "tendermint-light-client-types", + "tendermint-verifier", + "thiserror", + "union-ibc-light-client", + "union-ibc-msg", + "unionlabs", +] + [[package]] name = "tendermint-light-client-types" version = "0.1.0" dependencies = [ + "alloy", "cometbft-types", "hex-literal", "protos", diff --git a/Cargo.toml b/Cargo.toml index 2f4dc9a35f..9b21daeaf9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -90,7 +90,7 @@ members = [ # "cosmwasm/union-ibc/light-clients/scroll", - # "cosmwasm/union-ibc/light-clients/tendermint", + "cosmwasm/union-ibc/light-clients/tendermint", # "cosmwasm/union-ibc/light-clients/linea", diff --git a/cosmwasm/union-ibc/light-clients/tendermint/Cargo.toml b/cosmwasm/union-ibc/light-clients/tendermint/Cargo.toml index a4845265f5..fc992d28ea 100644 --- a/cosmwasm/union-ibc/light-clients/tendermint/Cargo.toml +++ b/cosmwasm/union-ibc/light-clients/tendermint/Cargo.toml @@ -17,7 +17,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] bytes = { workspace = true } -cosmwasm-std = { workspace = true, features = ["abort", "iterator"] } +cosmwasm-std = { version = "2.1.4", features = ["abort", "cosmwasm_2_1"] } hex = { workspace = true } prost = { workspace = true } protos = { workspace = true, features = ["proto_full", "std"] } @@ -30,11 +30,12 @@ sha3 = { workspace = true } thiserror = { workspace = true } cometbft-types = { workspace = true, features = ["proto", "hash"] } -ics008-wasm-client = { workspace = true } ics23 = { workspace = true } -tendermint-light-client-types = { workspace = true, features = ["proto"] } +tendermint-light-client-types = { workspace = true, features = ["ethabi", "serde"] } tendermint-verifier = { workspace = true } -unionlabs = { workspace = true, features = ["cosmwasm"] } +union-ibc-light-client = { workspace = true } +union-ibc-msg = { workspace = true } +unionlabs = { workspace = true } [dev-dependencies] base64 = { workspace = true } diff --git a/cosmwasm/union-ibc/light-clients/tendermint/src/client.rs b/cosmwasm/union-ibc/light-clients/tendermint/src/client.rs index 94a6e87ada..96fe29720e 100644 --- a/cosmwasm/union-ibc/light-clients/tendermint/src/client.rs +++ b/cosmwasm/union-ibc/light-clients/tendermint/src/client.rs @@ -1,40 +1,27 @@ use cometbft_types::types::{ commit::Commit, signed_header::SignedHeader, validator_set::ValidatorSet, }; -use cosmwasm_std::{Deps, DepsMut, Empty, Env}; -use ics008_wasm_client::{ - storage_utils::{ - read_client_state, read_consensus_state, read_subject_client_state, - read_substitute_client_state, read_substitute_consensus_state, save_client_state, - save_consensus_state, save_subject_client_state, save_subject_consensus_state, - }, - IbcClient, IbcClientError, Status, StorageState, WasmClientStateOf, WasmConsensusStateOf, - ZERO_HEIGHT, -}; +use cosmwasm_std::Empty; use ics23::ibc_api::SDK_SPECS; use tendermint_light_client_types::{ClientState, ConsensusState, Header}; use tendermint_verifier::types::SignatureVerifier; +use union_ibc_light_client::{IbcClient, IbcClientCtx, IbcClientError}; +use union_ibc_msg::lightclient::Status; use unionlabs::{ bounded::BoundedI64, - encoding::{DecodeAs, Proto}, - ensure, + encoding::{Bincode, DecodeAs, Proto}, google::protobuf::{duration::Duration, timestamp::Timestamp}, hash::{hash_v2::HexUnprefixed, H256}, ibc::core::{ - client::{genesis_metadata::GenesisMetadata, height::Height}, - commitment::{merkle_path::MerklePath, merkle_proof::MerkleProof, merkle_root::MerkleRoot}, + client::height::Height, + commitment::{merkle_path::MerklePath, merkle_proof::MerkleProof}, }, }; use crate::{ errors::{ Error, IbcHeightTooLargeForTendermintHeight, InvalidChainId, InvalidHeaderError, - InvalidHostTimestamp, MathOverflow, MerkleProofDecode, MigrateClientStoreError, - NegativeTimestamp, RevisionNumberMismatch, TrustedValidatorsMismatch, - }, - storage::{ - get_current_or_next_consensus_state_meta, get_current_or_prev_consensus_state_meta, - save_consensus_state_metadata, + MathOverflow, RevisionNumberMismatch, TrustedValidatorsMismatch, }, verifier::Ed25519Verifier, }; @@ -55,70 +42,78 @@ impl IbcClient for TendermintLightClient { type ConsensusState = ConsensusState; - type Encoding = Proto; + type StorageProof = MerkleProof; + + type Encoding = Bincode; fn verify_membership( - deps: Deps, - height: Height, - _delay_time_period: u64, - _delay_block_period: u64, - proof: Vec, - path: MerklePath, - value: StorageState, + ctx: IbcClientCtx, + height: u64, + key: Vec, + storage_proof: Self::StorageProof, + value: Vec, ) -> Result<(), IbcClientError> { - let consensus_state = read_consensus_state::(deps, &height)? - .ok_or(IbcClientError::ConsensusStateNotFound(height))?; - - let merkle_proof = MerkleProof::decode_as::(proof.as_ref()) - .map_err(|e| Error::from(MerkleProofDecode(e)))?; - - // TODO(aeryz): delay period check - - match value { - StorageState::Occupied(value) => ics23::ibc_api::verify_membership( - &merkle_proof, - &SDK_SPECS, - &consensus_state.data.root, - &path - .key_path - .into_iter() - .map(|s| s.into_bytes()) - .collect::>(), - value, - ), - StorageState::Empty => ics23::ibc_api::verify_non_membership( - &merkle_proof, - &SDK_SPECS, - &consensus_state.data.root, - &path - .key_path - .into_iter() - .map(|s| s.into_bytes()) - .collect::>(), - ), - } - .map_err(Error::VerifyMembership) - .map_err(Into::into) + let consensus_state = ctx.read_self_consensus_state(height)?; + + let path = MerklePath::decode_as::(&key).unwrap(); + // .map_err(|e| Self::Error::from(MerkleProofDecode(e)))?; + + ics23::ibc_api::verify_membership( + &storage_proof, + &SDK_SPECS, + &consensus_state.root, + &path + .key_path + .into_iter() + .map(|s| s.into_bytes()) + .collect::>(), + value, + ) + .map_err(Error::VerifyMembership)?; + + Ok(()) + } + + fn verify_non_membership( + ctx: IbcClientCtx, + height: u64, + key: Vec, + storage_proof: Self::StorageProof, + ) -> Result<(), IbcClientError> { + let consensus_state = ctx.read_self_consensus_state(height)?; + + let path = MerklePath::decode_as::(&key).unwrap(); + + ics23::ibc_api::verify_non_membership( + &storage_proof, + &SDK_SPECS, + &consensus_state.root, + &path + .key_path + .into_iter() + .map(|s| s.into_bytes()) + .collect::>(), + ) + .map_err(Error::VerifyMembership)?; + + Ok(()) } fn verify_header( - deps: Deps, - env: Env, + ctx: IbcClientCtx, mut header: Self::Header, - ) -> Result<(), IbcClientError> { + ) -> Result< + (u64, Self::ClientState, Self::ConsensusState), + union_ibc_light_client::IbcClientError, + > { set_total_voting_power(&mut header.validator_set).map_err(Error::from)?; set_total_voting_power(&mut header.trusted_validators).map_err(Error::from)?; - let client_state = read_client_state::(deps)?; - let consensus_state = read_consensus_state::(deps, &header.trusted_height)?.ok_or( - IbcClientError::ConsensusStateNotFound(header.trusted_height), - )?; + let mut client_state = ctx.read_self_client_state()?; + let consensus_state = ctx.read_self_consensus_state(header.trusted_height.height())?; - check_trusted_header( - &header, - consensus_state.data.next_validators_hash.as_encoding(), - ) - .map_err(Error::from)?; + check_trusted_header(&header, consensus_state.next_validators_hash.as_encoding()) + .map_err(Error::from)?; let revision_number = parse_revision_number(&header.signed_header.header.chain_id).ok_or( Error::from(InvalidChainId(header.signed_header.header.chain_id.clone())), @@ -141,16 +136,32 @@ impl IbcClient for TendermintLightClient { .expect("value is bounded >= 0; qed;"); if signed_height <= header.trusted_height.height() { - return Err(InvalidHeaderError::SignedHeaderHeightMustBeMoreRecent { - signed_height, - trusted_height: header.trusted_height.height(), - } - .into()); + return Err(IbcClientError::ClientSpecific( + InvalidHeaderError::SignedHeaderHeightMustBeMoreRecent { + signed_height, + trusted_height: header.trusted_height.height(), + } + .into(), + )); } + let block_timestamp = ctx.env.block.time; + + // FIXME: unionlabs is tied to cosmwasm <2, the TryFrom impl can't be used + let block_timestamp_proto = unionlabs::google::protobuf::timestamp::Timestamp { + seconds: i64::try_from(block_timestamp.seconds()) + .expect("impossible") + .try_into() + .expect("impossible"), + nanos: i32::try_from(block_timestamp.subsec_nanos()) + .expect("impossible") + .try_into() + .expect("impossible"), + }; + tendermint_verifier::verify::verify( &construct_partial_header( - client_state.data.chain_id, + client_state.chain_id.clone(), i64::try_from(header.trusted_height.height()) .map_err(|_| { Error::from(IbcHeightTooLargeForTendermintHeight( @@ -162,264 +173,75 @@ impl IbcClient for TendermintLightClient { "value is converted from u64, which is positive, \ and the expected bounded type is >= 0; qed;", ), - consensus_state.data.timestamp, - consensus_state.data.next_validators_hash, + consensus_state.timestamp, + consensus_state.next_validators_hash, ), &header.trusted_validators, &header.signed_header, &header.validator_set, - client_state.data.trusting_period, - env.block - .time - .try_into() - .map_err(|_| Error::from(InvalidHostTimestamp(env.block.time)))?, - client_state.data.max_clock_drift, - &client_state.data.trust_level, - &SignatureVerifier::new(Ed25519Verifier::new(deps)), + client_state.trusting_period, + block_timestamp_proto, + client_state.max_clock_drift, + &client_state.trust_level, + &SignatureVerifier::new(Ed25519Verifier::new(ctx.deps)), ) .map_err(Error::TendermintVerify)?; - Ok(()) - } - - fn verify_misbehaviour( - _deps: Deps, - _env: Env, - _misbehaviour: Self::Misbehaviour, - ) -> Result<(), IbcClientError> { - Err(Error::Unimplemented.into()) - } - - fn update_state( - mut deps: DepsMut, - _env: Env, - header: Self::Header, - ) -> Result, IbcClientError> { - let update_height = height_from_header(&header); - if read_consensus_state::(deps.as_ref(), &update_height)?.is_some() { - return Ok(vec![update_height]); - } - - // TODO(aeryz): prune oldest expired consensus state - - let mut client_state = read_client_state::(deps.as_ref())?; + let update_height = header + .signed_header + .header + .height + .inner() + .try_into() + .expect("impossible"); - if update_height > client_state.latest_height { - client_state.latest_height = update_height; - client_state.data.latest_height = update_height; + if client_state.latest_height.height() < update_height { + *client_state.latest_height.height_mut() = update_height; } - save_client_state::(deps.branch(), client_state); - save_consensus_state_metadata( - deps.branch(), - header.signed_header.header.time, - update_height, - ); - save_consensus_state::( - deps, - WasmConsensusStateOf:: { - data: ConsensusState { - timestamp: header.signed_header.header.time, - root: MerkleRoot { - hash: header.signed_header.header.app_hash.into_encoding(), - }, - next_validators_hash: header.signed_header.header.next_validators_hash, - }, - }, - &update_height, - ); - - Ok(vec![update_height]) + Ok((update_height, client_state, consensus_state)) } - fn update_state_on_misbehaviour( - _deps: DepsMut, - _env: Env, - _client_message: Vec, - ) -> Result<(), IbcClientError> { + fn misbehaviour( + _ctx: IbcClientCtx, + _misbehaviour: Self::Misbehaviour, + ) -> Result> { Err(Error::Unimplemented.into()) } - fn check_for_misbehaviour_on_header( - deps: Deps, - header: Self::Header, - ) -> Result> { - let height = height_from_header(&header); - - // If there is already a header at this height, it should be exactly the same as the header that - // we saved previously. If this is not the case, either the client is broken or the chain is - // broken. Because it should not be possible to have two distinct valid headers at a height. - if let Some(WasmConsensusStateOf:: { - data: - ConsensusState { - timestamp, - next_validators_hash, - root: MerkleRoot { hash }, - }, - }) = read_consensus_state::(deps, &height)? - { - if timestamp != header.signed_header.header.time - || hash != header.signed_header.header.app_hash - || next_validators_hash != header.signed_header.header.next_validators_hash - { - return Ok(true); - } - - // We don't need to check for previous or next consensus state since we know that we already - // saved this header correctly previously. - return Ok(false); - } - - if let Ok(Some((_, next_consensus_state))) = - get_current_or_next_consensus_state_meta(deps, height) - { - // next (in terms of height) consensus state must have a larger timestamp - if next_consensus_state.timestamp <= header.signed_header.header.time { - return Ok(true); - } - } - - if let Ok(Some((_, prev_consensus_state))) = - get_current_or_prev_consensus_state_meta(deps, height) - { - // previous (in terms of height) consensus state must have a smaller timestamp - if prev_consensus_state.timestamp >= header.signed_header.header.time { - return Ok(true); - } + fn status(client_state: &Self::ClientState) -> Status { + // FIXME: read latest consensus to verify if client expired + // if is_client_expired( + // &consensus_state.timestamp, + // client_state.trusting_period, + // env.block + // .time + // .try_into() + // .map_err(|_| Error::from(InvalidHostTimestamp(env.block.time)))?, + // ) { + // return Ok(Status::Expired); + // } + if client_state.frozen_height.unwrap_or_default().height() != 0 { + Status::Frozen + } else { + Status::Active } - - Ok(false) } - fn check_for_misbehaviour_on_misbehaviour( - _deps: Deps, - _misbehaviour: Self::Misbehaviour, - ) -> Result> { - Err(Error::Unimplemented.into()) + fn get_timestamp(consensus_state: &Self::ConsensusState) -> u64 { + consensus_state.timestamp.as_unix_nanos() } - fn verify_upgrade_and_update_state( - _deps: DepsMut, - _upgrade_client_state: Self::ClientState, - _upgrade_consensus_state: Self::ConsensusState, - _proof_upgrade_client: Vec, - _proof_upgrade_consensus_state: Vec, - ) -> Result<(), IbcClientError> { - Err(Error::Unimplemented.into()) + fn get_latest_height(client_state: &Self::ClientState) -> u64 { + client_state.latest_height.height() } - fn migrate_client_store( - mut deps: DepsMut, + fn verify_creation( + _client_state: &Self::ClientState, + _consensus_state: &Self::ConsensusState, ) -> Result<(), IbcClientError> { - let subject_client_state = read_subject_client_state::(deps.as_ref())?; - let substitute_client_state = read_substitute_client_state::(deps.as_ref())?; - - ensure( - substitute_client_state - .data - .frozen_height - .unwrap_or(ZERO_HEIGHT) - == ZERO_HEIGHT, - MigrateClientStoreError::SubstituteClientFrozen, - )?; - - ensure( - migrate_check_allowed_fields(&subject_client_state.data, &substitute_client_state.data), - MigrateClientStoreError::MigrateFieldsChanged, - )?; - - let substitute_consensus_state: WasmConsensusStateOf = - read_substitute_consensus_state(deps.as_ref(), &substitute_client_state.latest_height)? - .ok_or(IbcClientError::ConsensusStateNotFound( - substitute_client_state.latest_height, - ))?; - - save_consensus_state_metadata( - deps.branch(), - substitute_consensus_state.data.timestamp, - substitute_client_state.latest_height, - ); - - save_subject_consensus_state::( - deps.branch(), - substitute_consensus_state, - &substitute_client_state.latest_height, - ); - - let scs = substitute_client_state.data; - save_subject_client_state::( - deps, - WasmClientStateOf:: { - data: ClientState { - chain_id: scs.chain_id, - trusting_period: scs.trusting_period, - latest_height: scs.latest_height, - frozen_height: None, - ..subject_client_state.data - }, - checksum: subject_client_state.checksum, - latest_height: scs.latest_height, - }, - ); - Ok(()) } - - fn status( - deps: Deps, - env: &cosmwasm_std::Env, - ) -> Result> { - let client_state = read_client_state::(deps)?; - - // TODO(aeryz): when refactoring the tm client, we should consider making this non-optional - // because otherwise we always have to check if the inner height is zero. - if client_state.data.frozen_height.unwrap_or(ZERO_HEIGHT) != ZERO_HEIGHT { - return Ok(Status::Frozen); - } - - let Some(consensus_state) = - read_consensus_state::(deps, &client_state.latest_height)? - else { - return Ok(Status::Expired); - }; - - if is_client_expired( - &consensus_state.data.timestamp, - client_state.data.trusting_period, - env.block - .time - .try_into() - .map_err(|_| Error::from(InvalidHostTimestamp(env.block.time)))?, - ) { - return Ok(Status::Expired); - } - - Ok(Status::Active) - } - - fn export_metadata( - _deps: Deps, - _env: &cosmwasm_std::Env, - ) -> Result, IbcClientError> { - Ok(Vec::new()) - } - - fn timestamp_at_height( - deps: Deps, - height: Height, - ) -> Result> { - let timestamp = read_consensus_state::(deps, &height)? - .ok_or(IbcClientError::ConsensusStateNotFound(height))? - .data - .timestamp - .seconds - .inner(); - - timestamp - .try_into() - .map_err(|_| Error::from(NegativeTimestamp(timestamp))) - .map_err(Into::into) - } } pub fn set_total_voting_power(validator_set: &mut ValidatorSet) -> Result<(), MathOverflow> { @@ -434,17 +256,6 @@ pub fn set_total_voting_power(validator_set: &mut ValidatorSet) -> Result<(), Ma Ok(()) } -fn migrate_check_allowed_fields( - subject_client_state: &ClientState, - substitute_client_state: &ClientState, -) -> bool { - subject_client_state.trust_level == substitute_client_state.trust_level - && subject_client_state.unbonding_period == substitute_client_state.unbonding_period - && subject_client_state.max_clock_drift == substitute_client_state.max_clock_drift - && subject_client_state.proof_specs == substitute_client_state.proof_specs - && subject_client_state.upgrade_path == substitute_client_state.upgrade_path -} - pub fn construct_partial_header( chain_id: String, height: BoundedI64<0, { i64::MAX }>, @@ -522,206 +333,206 @@ pub fn parse_revision_number(chain_id: &str) -> Option { .map(|height_str| height_str.parse().ok())? } -#[cfg(test)] -mod tests { - use std::fs; - - use cosmwasm_std::{ - testing::{mock_dependencies, MockApi, MockQuerier, MockStorage}, - OwnedDeps, - }; - use ics008_wasm_client::{ - storage_utils::{ - consensus_db_key, read_subject_consensus_state, HOST_CLIENT_STATE_KEY, - SUBJECT_CLIENT_STORE_PREFIX, SUBSTITUTE_CLIENT_STORE_PREFIX, - }, - FROZEN_HEIGHT, - }; - use unionlabs::{encoding::EncodeAs, google::protobuf::any::Any}; - - use super::*; - - const INITIAL_CONSENSUS_STATE_HEIGHT: Height = Height::new_with_revision(1, 10); - - const INITIAL_SUBSTITUTE_CONSENSUS_STATE_HEIGHT: Height = Height::new_with_revision(1, 12); - - fn save_states_to_migrate_store( - deps: DepsMut, - subject_client_state: &WasmClientStateOf, - substitute_client_state: &WasmClientStateOf, - subject_consensus_state: &WasmConsensusStateOf, - substitute_consensus_state: &WasmConsensusStateOf, - ) { - deps.storage.set( - format!("{SUBJECT_CLIENT_STORE_PREFIX}{HOST_CLIENT_STATE_KEY}").as_bytes(), - &Any(subject_client_state.clone()).encode_as::(), - ); - deps.storage.set( - format!( - "{SUBJECT_CLIENT_STORE_PREFIX}{}", - consensus_db_key(&INITIAL_CONSENSUS_STATE_HEIGHT) - ) - .as_bytes(), - &Any(subject_consensus_state.clone()).encode_as::(), - ); - deps.storage.set( - format!("{SUBSTITUTE_CLIENT_STORE_PREFIX}{HOST_CLIENT_STATE_KEY}").as_bytes(), - &Any(substitute_client_state.clone()).encode_as::(), - ); - deps.storage.set( - format!( - "{SUBSTITUTE_CLIENT_STORE_PREFIX}{}", - consensus_db_key(&INITIAL_SUBSTITUTE_CONSENSUS_STATE_HEIGHT) - ) - .as_bytes(), - &Any(substitute_consensus_state.clone()).encode_as::(), - ); - } - - #[allow(clippy::type_complexity)] // it's fine bro - fn prepare_migrate_tests() -> ( - OwnedDeps, - WasmClientStateOf, - WasmConsensusStateOf, - WasmClientStateOf, - WasmConsensusStateOf, - ) { - ( - mock_dependencies(), - serde_json::from_str(&fs::read_to_string("src/test/client_state.json").unwrap()) - .unwrap(), - serde_json::from_str(&fs::read_to_string("src/test/consensus_state.json").unwrap()) - .unwrap(), - serde_json::from_str( - &fs::read_to_string("src/test/substitute_client_state.json").unwrap(), - ) - .unwrap(), - serde_json::from_str( - &fs::read_to_string("src/test/substitute_consensus_state.json").unwrap(), - ) - .unwrap(), - ) - } - - #[test] - fn migrate_client_store_works() { - let ( - mut deps, - mut wasm_client_state, - wasm_consensus_state, - substitute_wasm_client_state, - substitute_wasm_consensus_state, - ) = prepare_migrate_tests(); - - wasm_client_state.data.frozen_height = Some(FROZEN_HEIGHT); - - save_states_to_migrate_store( - deps.as_mut(), - &wasm_client_state, - &substitute_wasm_client_state, - &wasm_consensus_state, - &substitute_wasm_consensus_state, - ); - - TendermintLightClient::migrate_client_store(deps.as_mut()).unwrap(); - - let wasm_client_state: WasmClientStateOf = - read_subject_client_state::(deps.as_ref()).unwrap(); - // we didn't miss updating any fields - assert_eq!(wasm_client_state, substitute_wasm_client_state); - // client is unfrozen - assert_eq!(wasm_client_state.data.frozen_height, None); - - // the new consensus state is saved under the correct height - assert_eq!( - read_subject_consensus_state::( - deps.as_ref(), - &INITIAL_SUBSTITUTE_CONSENSUS_STATE_HEIGHT - ) - .unwrap() - .unwrap(), - substitute_wasm_consensus_state - ); - - // the new consensus state metadata is saved under substitute's latest height - assert_eq!( - get_current_or_next_consensus_state_meta( - deps.as_ref(), - INITIAL_SUBSTITUTE_CONSENSUS_STATE_HEIGHT - ) - .unwrap() - .unwrap() - .0, - substitute_wasm_client_state.latest_height - ); - } - - #[test] - fn migrate_client_store_fails_when_invalid_change() { - let ( - mut deps, - wasm_client_state, - wasm_consensus_state, - substitute_wasm_client_state, - substitute_wasm_consensus_state, - ) = prepare_migrate_tests(); - - macro_rules! modify_fns { - ($param:ident, $($m:expr), + $(,)?) => ([$(|$param: &mut ClientState| $m),+]) - } - - let modifications = modify_fns! { s, - s.trust_level.numerator ^= u64::MAX, - s.unbonding_period = Duration::new(s.unbonding_period.seconds().inner() + 1, 0).unwrap(), - s.max_clock_drift = Duration::new(s.max_clock_drift.seconds().inner() + 1, 0).unwrap(), - s.proof_specs.push(s.proof_specs[0].clone()), - s.upgrade_path.push(String::new()), - - }; - - for m in modifications { - let mut state = substitute_wasm_client_state.clone(); - m(&mut state.data); - - save_states_to_migrate_store( - deps.as_mut(), - &wasm_client_state, - &state, - &wasm_consensus_state, - &substitute_wasm_consensus_state, - ); - assert_eq!( - TendermintLightClient::migrate_client_store(deps.as_mut()), - Err( - Error::MigrateClientStore(MigrateClientStoreError::MigrateFieldsChanged).into() - ) - ); - } - } - - #[test] - fn migrate_client_store_fails_when_substitute_client_frozen() { - let ( - mut deps, - wasm_client_state, - wasm_consensus_state, - mut substitute_wasm_client_state, - substitute_wasm_consensus_state, - ) = prepare_migrate_tests(); - - substitute_wasm_client_state.data.frozen_height = Some(FROZEN_HEIGHT); - - save_states_to_migrate_store( - deps.as_mut(), - &wasm_client_state, - &substitute_wasm_client_state, - &wasm_consensus_state, - &substitute_wasm_consensus_state, - ); - - assert_eq!( - TendermintLightClient::migrate_client_store(deps.as_mut()), - Err(Error::MigrateClientStore(MigrateClientStoreError::SubstituteClientFrozen).into()) - ); - } -} +// #[cfg(test)] +// mod tests { +// use std::fs; + +// use cosmwasm_std::{ +// testing::{mock_dependencies, MockApi, MockQuerier, MockStorage}, +// OwnedDeps, +// }; +// use ics008_wasm_client::{ +// storage_utils::{ +// consensus_db_key, read_subject_consensus_state, HOST_CLIENT_STATE_KEY, +// SUBJECT_CLIENT_STORE_PREFIX, SUBSTITUTE_CLIENT_STORE_PREFIX, +// }, +// FROZEN_HEIGHT, +// }; +// use unionlabs::{encoding::EncodeAs, google::protobuf::any::Any}; + +// use super::*; + +// const INITIAL_CONSENSUS_STATE_HEIGHT: Height = Height::new_with_revision(1, 10); + +// const INITIAL_SUBSTITUTE_CONSENSUS_STATE_HEIGHT: Height = Height::new_with_revision(1, 12); + +// fn save_states_to_migrate_store( +// deps: DepsMut, +// subject_client_state: &WasmClientStateOf, +// substitute_client_state: &WasmClientStateOf, +// subject_consensus_state: &WasmConsensusStateOf, +// substitute_consensus_state: &WasmConsensusStateOf, +// ) { +// deps.storage.set( +// format!("{SUBJECT_CLIENT_STORE_PREFIX}{HOST_CLIENT_STATE_KEY}").as_bytes(), +// &Any(subject_client_state.clone()).encode_as::(), +// ); +// deps.storage.set( +// format!( +// "{SUBJECT_CLIENT_STORE_PREFIX}{}", +// consensus_db_key(&INITIAL_CONSENSUS_STATE_HEIGHT) +// ) +// .as_bytes(), +// &Any(subject_consensus_state.clone()).encode_as::(), +// ); +// deps.storage.set( +// format!("{SUBSTITUTE_CLIENT_STORE_PREFIX}{HOST_CLIENT_STATE_KEY}").as_bytes(), +// &Any(substitute_client_state.clone()).encode_as::(), +// ); +// deps.storage.set( +// format!( +// "{SUBSTITUTE_CLIENT_STORE_PREFIX}{}", +// consensus_db_key(&INITIAL_SUBSTITUTE_CONSENSUS_STATE_HEIGHT) +// ) +// .as_bytes(), +// &Any(substitute_consensus_state.clone()).encode_as::(), +// ); +// } + +// #[allow(clippy::type_complexity)] // it's fine bro +// fn prepare_migrate_tests() -> ( +// OwnedDeps, +// WasmClientStateOf, +// WasmConsensusStateOf, +// WasmClientStateOf, +// WasmConsensusStateOf, +// ) { +// ( +// mock_dependencies(), +// serde_json::from_str(&fs::read_to_string("src/test/client_state.json").unwrap()) +// .unwrap(), +// serde_json::from_str(&fs::read_to_string("src/test/consensus_state.json").unwrap()) +// .unwrap(), +// serde_json::from_str( +// &fs::read_to_string("src/test/substitute_client_state.json").unwrap(), +// ) +// .unwrap(), +// serde_json::from_str( +// &fs::read_to_string("src/test/substitute_consensus_state.json").unwrap(), +// ) +// .unwrap(), +// ) +// } + +// #[test] +// fn migrate_client_store_works() { +// let ( +// mut deps, +// mut wasm_client_state, +// wasm_consensus_state, +// substitute_wasm_client_state, +// substitute_wasm_consensus_state, +// ) = prepare_migrate_tests(); + +// wasm_client_state.frozen_height = Some(FROZEN_HEIGHT); + +// save_states_to_migrate_store( +// deps.as_mut(), +// &wasm_client_state, +// &substitute_wasm_client_state, +// &wasm_consensus_state, +// &substitute_wasm_consensus_state, +// ); + +// TendermintLightClient::migrate_client_store(deps.as_mut()).unwrap(); + +// let wasm_client_state: WasmClientStateOf = +// read_subject_client_state::(deps.as_ref()).unwrap(); +// // we didn't miss updating any fields +// assert_eq!(wasm_client_state, substitute_wasm_client_state); +// // client is unfrozen +// assert_eq!(wasm_client_state.frozen_height, None); + +// // the new consensus state is saved under the correct height +// assert_eq!( +// read_subject_consensus_state::( +// deps.as_ref(), +// &INITIAL_SUBSTITUTE_CONSENSUS_STATE_HEIGHT +// ) +// .unwrap() +// .unwrap(), +// substitute_wasm_consensus_state +// ); + +// // the new consensus state metadata is saved under substitute's latest height +// assert_eq!( +// get_current_or_next_consensus_state_meta( +// deps.as_ref(), +// INITIAL_SUBSTITUTE_CONSENSUS_STATE_HEIGHT +// ) +// .unwrap() +// .unwrap() +// .0, +// substitute_wasm_client_state.latest_height +// ); +// } + +// #[test] +// fn migrate_client_store_fails_when_invalid_change() { +// let ( +// mut deps, +// wasm_client_state, +// wasm_consensus_state, +// substitute_wasm_client_state, +// substitute_wasm_consensus_state, +// ) = prepare_migrate_tests(); + +// macro_rules! modify_fns { +// ($param:ident, $($m:expr), + $(,)?) => ([$(|$param: &mut ClientState| $m),+]) +// } + +// let modifications = modify_fns! { s, +// s.trust_level.numerator ^= u64::MAX, +// s.unbonding_period = Duration::new(s.unbonding_period.seconds().inner() + 1, 0).unwrap(), +// s.max_clock_drift = Duration::new(s.max_clock_drift.seconds().inner() + 1, 0).unwrap(), +// s.proof_specs.push(s.proof_specs[0].clone()), +// s.upgrade_path.push(String::new()), + +// }; + +// for m in modifications { +// let mut state = substitute_wasm_client_state.clone(); +// m(&mut state.data); + +// save_states_to_migrate_store( +// deps.as_mut(), +// &wasm_client_state, +// &state, +// &wasm_consensus_state, +// &substitute_wasm_consensus_state, +// ); +// assert_eq!( +// TendermintLightClient::migrate_client_store(deps.as_mut()), +// Err( +// Error::MigrateClientStore(MigrateClientStoreError::MigrateFieldsChanged).into() +// ) +// ); +// } +// } + +// #[test] +// fn migrate_client_store_fails_when_substitute_client_frozen() { +// let ( +// mut deps, +// wasm_client_state, +// wasm_consensus_state, +// mut substitute_wasm_client_state, +// substitute_wasm_consensus_state, +// ) = prepare_migrate_tests(); + +// substitute_wasm_client_state.frozen_height = Some(FROZEN_HEIGHT); + +// save_states_to_migrate_store( +// deps.as_mut(), +// &wasm_client_state, +// &substitute_wasm_client_state, +// &wasm_consensus_state, +// &substitute_wasm_consensus_state, +// ); + +// assert_eq!( +// TendermintLightClient::migrate_client_store(deps.as_mut()), +// Err(Error::MigrateClientStore(MigrateClientStoreError::SubstituteClientFrozen).into()) +// ); +// } +// } diff --git a/cosmwasm/union-ibc/light-clients/tendermint/src/contract.rs b/cosmwasm/union-ibc/light-clients/tendermint/src/contract.rs index ceef7b7383..c80fc6a7ad 100644 --- a/cosmwasm/union-ibc/light-clients/tendermint/src/contract.rs +++ b/cosmwasm/union-ibc/light-clients/tendermint/src/contract.rs @@ -1,46 +1,22 @@ -use cosmwasm_std::{entry_point, DepsMut, Env, MessageInfo, Response}; -use ics008_wasm_client::{ - define_cosmwasm_light_client_contract, - storage_utils::{save_proto_client_state, save_proto_consensus_state}, - InstantiateMsg, +use cosmwasm_std::{entry_point, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult}; +use union_ibc_light_client::{ + msg::{InstantiateMsg, QueryMsg}, + IbcClientError, }; -use protos::ibc::lightclients::wasm::v1::{ - ClientState as ProtoClientState, ConsensusState as ProtoConsensusState, -}; -use unionlabs::encoding::{DecodeAs, Proto}; -use crate::{client::TendermintLightClient, errors::Error}; +use crate::client::TendermintLightClient; -// NOTE(aeryz): the fact that the host module forces the light clients to store and use the wasm wrapping -// in the client state makes this code kinda messy. But this is going to be resolved in the future versions -// of IBC (probably v9). When that feature is implemented, we can move this to the ics008 macro. #[entry_point] pub fn instantiate( - mut deps: DepsMut, - _env: Env, - _info: MessageInfo, + deps: DepsMut, + env: Env, + info: MessageInfo, msg: InstantiateMsg, -) -> Result { - let client_state = - tendermint_light_client_types::ClientState::decode_as::(&msg.client_state) - .map_err(Error::ClientStateDecode)?; - - save_proto_consensus_state::( - deps.branch(), - ProtoConsensusState { - data: msg.consensus_state.to_vec(), - }, - &client_state.latest_height, - ); - save_proto_client_state::( - deps, - ProtoClientState { - data: msg.client_state.to_vec(), - checksum: msg.checksum.to_vec(), - latest_height: Some(client_state.latest_height.into()), - }, - ); - Ok(Response::default()) +) -> Result> { + union_ibc_light_client::instantiate(deps, env, info, msg) } -define_cosmwasm_light_client_contract!(TendermintLightClient, Tendermint); +#[entry_point] +pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { + union_ibc_light_client::query::(deps, env, msg).map_err(Into::into) +} diff --git a/cosmwasm/union-ibc/light-clients/tendermint/src/errors.rs b/cosmwasm/union-ibc/light-clients/tendermint/src/errors.rs index fb66822e75..fa8097fb5c 100644 --- a/cosmwasm/union-ibc/light-clients/tendermint/src/errors.rs +++ b/cosmwasm/union-ibc/light-clients/tendermint/src/errors.rs @@ -1,5 +1,5 @@ -use ics008_wasm_client::{IbcClient, IbcClientError}; use tendermint_light_client_types::{ClientState, Header}; +use union_ibc_light_client::IbcClientError; use unionlabs::{ encoding::{DecodeErrorOf, Proto}, hash::H256, @@ -133,22 +133,6 @@ impl From for IbcClientError { } } -// convenience -impl>> From for IbcClientError { - fn from(value: InvalidHeaderError) -> Self { - IbcClientError::ClientSpecific(T::Error::from(value)) - } -} - -// convenience -impl>> From - for IbcClientError -{ - fn from(value: MigrateClientStoreError) -> Self { - IbcClientError::ClientSpecific(T::Error::from(value)) - } -} - // would be nice, but both foreign types :( // impl From for IbcClientError { // fn from(value: ics23::ibc_api::VerifyMembershipError) -> Self { diff --git a/flake.nix b/flake.nix index 90741c1112..eeae4017cb 100644 --- a/flake.nix +++ b/flake.nix @@ -233,7 +233,7 @@ ./typescript-sdk/typescript-sdk.nix ./cosmwasm/union-ibc/light-clients/ethereum/ethereum-light-client.nix # ./cosmwasm/union-ibc/light-clients/cometbls/cometbls-light-client.nix - # ./cosmwasm/union-ibc/light-clients/tendermint/tendermint-light-client.nix + ./cosmwasm/union-ibc/light-clients/tendermint/tendermint-light-client.nix # ./cosmwasm/union-ibc/light-clients/scroll/scroll-light-client.nix # ./cosmwasm/union-ibc/light-clients/arbitrum/arbitrum-light-client.nix # ./light-clients/linea-light-client/linea-light-client.nix diff --git a/hubble/Cargo.toml b/hubble/Cargo.toml index f7e6edbb97..bdada1e788 100644 --- a/hubble/Cargo.toml +++ b/hubble/Cargo.toml @@ -56,7 +56,7 @@ serde = { workspace = true, features = ["derive"] } serde-aux = "4.5.0" serde_json = { workspace = true } sqlx = { workspace = true, features = ["postgres", "runtime-tokio", "tls-rustls", "time", "macros", "json", "bigdecimal"] } -tendermint-light-client-types = { workspace = true, features = ["proto"] } +tendermint-light-client-types = { workspace = true, features = ["proto", "serde"] } thiserror = { workspace = true } time = { workspace = true, features = ["serde"] } tokio = { workspace = true, features = ["full"] } diff --git a/lib/tendermint-light-client-types/Cargo.toml b/lib/tendermint-light-client-types/Cargo.toml index e699e9e627..0bee363f2d 100644 --- a/lib/tendermint-light-client-types/Cargo.toml +++ b/lib/tendermint-light-client-types/Cargo.toml @@ -4,15 +4,18 @@ name = "tendermint-light-client-types" version = "0.1.0" [dependencies] +alloy = { workspace = true, features = ["sol-types"], optional = true } cometbft-types.workspace = true -protos = { workspace = true, features = ["ibc+lightclients+tendermint+v1"] } -serde = { workspace = true, features = ["derive"] } +protos = { workspace = true, features = ["ibc+lightclients+tendermint+v1"], optional = true } +serde = { workspace = true, features = ["derive"], optional = true } thiserror = { workspace = true } unionlabs = { workspace = true } [features] default = ["proto"] -proto = ["unionlabs/proto", "cometbft-types/proto"] +ethabi = ["unionlabs/ethabi", "dep:alloy"] +proto = ["unionlabs/proto", "cometbft-types/proto", "dep:protos"] +serde = ["dep:serde"] [dev-dependencies] hex-literal = { workspace = true } diff --git a/lib/tendermint-light-client-types/src/client_state.rs b/lib/tendermint-light-client-types/src/client_state.rs index 4227262dbf..57e21c2349 100644 --- a/lib/tendermint-light-client-types/src/client_state.rs +++ b/lib/tendermint-light-client-types/src/client_state.rs @@ -1,4 +1,3 @@ -use serde::{Deserialize, Serialize}; use unionlabs::{ cosmos::ics23::proof_spec::ProofSpec, google::protobuf::duration::Duration, ibc::core::client::height::Height, @@ -6,7 +5,8 @@ use unionlabs::{ use crate::Fraction; -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ClientState { pub chain_id: String, pub trust_level: Fraction, diff --git a/lib/tendermint-light-client-types/src/consensus_state.rs b/lib/tendermint-light-client-types/src/consensus_state.rs index a840cc2ea2..e02245ee97 100644 --- a/lib/tendermint-light-client-types/src/consensus_state.rs +++ b/lib/tendermint-light-client-types/src/consensus_state.rs @@ -1,17 +1,56 @@ -use serde::{Deserialize, Serialize}; use unionlabs::{ google::protobuf::timestamp::Timestamp, hash::{hash_v2::HexUnprefixed, H256}, ibc::core::commitment::merkle_root::MerkleRoot, }; -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ConsensusState { pub timestamp: Timestamp, pub root: MerkleRoot, pub next_validators_hash: H256, } +#[cfg(feature = "ethabi")] +pub mod ethabi { + use alloy::sol_types::SolValue; + use unionlabs::impl_ethabi_via_try_from_into; + + use super::*; + + impl_ethabi_via_try_from_into!(ConsensusState => SolConsensusState); + + alloy::sol! { + struct SolConsensusState { + uint64 timestamp; + bytes32 root; + bytes32 nextValidatorsHash; + } + } + + impl From for SolConsensusState { + fn from(value: ConsensusState) -> Self { + Self { + timestamp: value.timestamp.as_unix_nanos(), + root: value.root.hash.get().into(), + nextValidatorsHash: value.next_validators_hash.get().into(), + } + } + } + + impl From for ConsensusState { + fn from(value: SolConsensusState) -> Self { + Self { + timestamp: Timestamp::try_from_unix_nanos(value.timestamp.into()) + .expect("impossible"), + root: H256::new(value.root.0).into(), + next_validators_hash: H256::new(value.nextValidatorsHash.0), + } + } + } +} + #[cfg(feature = "proto")] pub mod proto { use unionlabs::{ diff --git a/lib/tendermint-light-client-types/src/fraction.rs b/lib/tendermint-light-client-types/src/fraction.rs index 3f8ad8ac88..65187d6041 100644 --- a/lib/tendermint-light-client-types/src/fraction.rs +++ b/lib/tendermint-light-client-types/src/fraction.rs @@ -1,8 +1,7 @@ use core::num::NonZeroU64; -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Fraction { pub numerator: u64, pub denominator: NonZeroU64, diff --git a/lib/tendermint-light-client-types/src/header.rs b/lib/tendermint-light-client-types/src/header.rs index dab30f4b77..9e4e90752b 100644 --- a/lib/tendermint-light-client-types/src/header.rs +++ b/lib/tendermint-light-client-types/src/header.rs @@ -1,8 +1,8 @@ use cometbft_types::types::{signed_header::SignedHeader, validator_set::ValidatorSet}; -use serde::{Deserialize, Serialize}; use unionlabs::ibc::core::client::height::Height; -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Header { pub signed_header: SignedHeader, pub validator_set: ValidatorSet, diff --git a/lib/tendermint-verifier/Cargo.toml b/lib/tendermint-verifier/Cargo.toml index 7830780bc6..e7042d7837 100644 --- a/lib/tendermint-verifier/Cargo.toml +++ b/lib/tendermint-verifier/Cargo.toml @@ -19,7 +19,7 @@ prost = { workspace = true } protos = { workspace = true } serde-utils = { workspace = true } sha2 = { workspace = true } -tendermint-light-client-types = { workspace = true, features = ["proto"] } +tendermint-light-client-types = { workspace = true, features = ["proto", "serde"] } thiserror = { workspace = true } unionlabs = { workspace = true } diff --git a/lib/tendermint-verifier/src/utils.rs b/lib/tendermint-verifier/src/utils.rs index dd482bdc99..753098f97e 100644 --- a/lib/tendermint-verifier/src/utils.rs +++ b/lib/tendermint-verifier/src/utils.rs @@ -1,12 +1,9 @@ -use cometbft_types::{ - crypto::public_key::PublicKey, - types::{ - block_id::BlockId, canonical_block_id::CanonicalBlockId, - canonical_part_set_header::CanonicalPartSetHeader, canonical_vote::CanonicalVote, - commit::Commit, commit_sig::CommitSig, signed_header::SignedHeader, - signed_msg_type::SignedMsgType, simple_validator::SimpleValidator, validator::Validator, - validator_set::ValidatorSet, - }, +use cometbft_types::types::{ + block_id::BlockId, canonical_block_id::CanonicalBlockId, + canonical_part_set_header::CanonicalPartSetHeader, canonical_vote::CanonicalVote, + commit::Commit, commit_sig::CommitSig, signed_header::SignedHeader, + signed_msg_type::SignedMsgType, simple_validator::SimpleValidator, validator::Validator, + validator_set::ValidatorSet, }; use prost::Message; use unionlabs::{ @@ -72,12 +69,7 @@ pub fn validators_hash(validator_set: &ValidatorSet) -> H256 { .iter() .map(|validator| { SimpleValidator { - pub_key: match &validator.pub_key { - // hackerman - // https://github.com/unionlabs/cometbls/issues/86 - PublicKey::Bls12_381(key) => PublicKey::Bn254(key.clone()), - key => key.clone(), - }, + pub_key: validator.pub_key.clone(), voting_power: validator.voting_power.inner(), } .encode_as::() diff --git a/lib/unionlabs/src/ibc/core/commitment/merkle_root.rs b/lib/unionlabs/src/ibc/core/commitment/merkle_root.rs index 38a2b37521..8480573168 100644 --- a/lib/unionlabs/src/ibc/core/commitment/merkle_root.rs +++ b/lib/unionlabs/src/ibc/core/commitment/merkle_root.rs @@ -10,6 +10,12 @@ pub struct MerkleRoot { pub hash: H256, } +impl From> for MerkleRoot { + fn from(value: H256) -> Self { + Self { hash: value } + } +} + impl From for protos::ibc::core::commitment::v1::MerkleRoot { fn from(value: MerkleRoot) -> Self { Self { diff --git a/voyager/modules/consensus/tendermint/Cargo.toml b/voyager/modules/consensus/tendermint/Cargo.toml index 55f9cc8878..4eae571198 100644 --- a/voyager/modules/consensus/tendermint/Cargo.toml +++ b/voyager/modules/consensus/tendermint/Cargo.toml @@ -16,7 +16,7 @@ prost = { workspace = true } protos = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } -tendermint-light-client-types = { workspace = true, features = ["proto"] } +tendermint-light-client-types = { workspace = true, features = ["proto", "serde"] } thiserror = { workspace = true } tokio = { workspace = true } tracing = { workspace = true } From 8cda2284b3bf58e7c326a172914962d754d9c420 Mon Sep 17 00:00:00 2001 From: Hussein Ait Lahcen Date: Mon, 9 Dec 2024 16:53:43 +0100 Subject: [PATCH 2/2] chore: remove obsolete libwasmvm --- networks/simulation/simd.nix | 21 --------------------- tools/libwasmvm/libwasmvm.nix | 3 --- 2 files changed, 24 deletions(-) diff --git a/networks/simulation/simd.nix b/networks/simulation/simd.nix index 4316503acf..2fd57d433b 100644 --- a/networks/simulation/simd.nix +++ b/networks/simulation/simd.nix @@ -31,18 +31,6 @@ _: { let libwasmvm = self'.packages.libwasmvm-2_1_2; in - # libwasmvm = pkgs.stdenv.mkDerivation { - # name = "libwasmvm"; - # src = pkgs.fetchurl { - # url = "https://github.com/CosmWasm/wasmvm/releases/download/v2.2.0-rc.2/libwasmvm_muslc.x86_64.a"; - # hash = "sha256-LEl7UkbHIXpwxEfFARfH+wmQnsI+bkFRpN4+XynbgTQ="; - # }; - # dontUnpack = true; - # buildPhase = '' - # mkdir -p $out/lib/ - # cp $src $out/lib/libwasmvm.x86_64.a - # ''; - # }; if pkgs.stdenv.isLinux then { # Statically link if we're on linux @@ -54,15 +42,6 @@ _: { "-extldflags '-z noexecstack -static -L${goPkgs.musl}/lib -L${libwasmvm}/lib'" ]; } - # else if pkgs.stdenv.isDarwin then { - # # Dynamically link if we're on darwin by wrapping the program - # # such that the DYLD_LIBRARY_PATH includes libwasmvm - # buildInputs = [ pkgs.makeWrapper libwasmvm ]; - # postFixup = '' - # wrapProgram $out/bin/wasmd \ - # --set DYLD_LIBRARY_PATH ${(pkgs.lib.makeLibraryPath [ libwasmvm ])}; - # ''; - # } else else { } ) diff --git a/tools/libwasmvm/libwasmvm.nix b/tools/libwasmvm/libwasmvm.nix index cf43759281..723cbaaeb9 100644 --- a/tools/libwasmvm/libwasmvm.nix +++ b/tools/libwasmvm/libwasmvm.nix @@ -121,10 +121,7 @@ in { packages.libwasmvm = mkLibwasmvm_v1 inputs.wasmvm; - packages.libwasmvm-1_5_0 = mkLibwasmvm_v1 inputs.wasmvm-1_5_0; - packages.libwasmvm-2_0_0 = mkLibwasmvm_v1 inputs.wasmvm-2_0_0; packages.libwasmvm-2_1_2 = mkLibwasmvm_v2 inputs.wasmvm-2_1_2; packages.libwasmvm-2_1_3 = mkLibwasmvm_v2 inputs.wasmvm-2_1_3; - packages.libwasmvm-2_2_0 = mkLibwasmvm_v2 inputs.wasmvm-2_2_0; }; }