Skip to content

Commit

Permalink
cometbls wasm membership verification (closes #514) (#1084)
Browse files Browse the repository at this point in the history
Implements #514 

1. Implemented a new `ics23` library to do (non)membership verification
with tests.
2. Integrated the library into cometbls light client to support
membership verification.
3. Bumped `ics23` revision in `flake.nix` and regenerated proto for
ics23. (we were missing a field)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
  - Updated search functionality in the app.
- **Documentation**
  - Updated dictionary with new terms.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
aeryz authored Jan 8, 2024
2 parents 0a181a9 + 37eab01 commit 0995c0d
Show file tree
Hide file tree
Showing 36 changed files with 1,527 additions and 110 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"lib/pg-queue",
"lib/serde-utils",
"lib/unionlabs",
"lib/ics23",
"lib/*/fuzz",
"tools/generate-rust-sol-bindings",
"light-clients/*",
Expand Down Expand Up @@ -64,6 +65,7 @@ ucs01-relay-api = { path = "cosmwasm/ucs01-relay-api", default-features = false
voyager-message = { path = "voyager/voyager-message", default-features = false }
derive_more = { version = "0.99.17", default-features = false }
ucs01-relay = { path = "cosmwasm/ucs01-relay", default-features = false }
ics23 = { path = "lib/ics23", default-features = false }

# external dependencies

Expand All @@ -75,6 +77,7 @@ ethers = { git = "https://github.com/unionlabs/ethers-rs", branch = "ethers-core
ethers-contract-derive = { git = "https://github.com/unionlabs/ethers-rs", branch = "ethers-core-wasm", default-features = false }
ethers-core = { git = "https://github.com/unionlabs/ethers-rs", branch = "ethers-core-wasm", default-features = false }
ethers-contract-abigen = { git = "https://github.com/unionlabs/ethers-rs", branch = "ethers-core-wasm", default-features = false }
sha2 = { version = "0.10.7", default-features = false }

# ethers = { path = "/home/ben/projects/union/ethers-rs/ethers", default-features = false }
# ethers-contract-derive = { path = "/home/ben/projects/union/ethers-rs/ethers-contract/ethers-contract-derive", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion cosmwasm/ucs01-relay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ schemars = "0.8"
semver = "1"
serde = { version = "1.0", default-features = false, features = ["derive"] }
thiserror = { version = "1.0" }
sha2 = { version = "0.10", default-features = false }
sha2.workspace = true
hex = { version = "0.4", default-features = false }
token-factory-api = { workspace = true }
ucs01-relay-api = { workspace = true }
7 changes: 7 additions & 0 deletions dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ groupkeeper
groupmodule
hasher
hasura
hdata
healthcheck
healthz
heredocs
Expand Down Expand Up @@ -420,9 +421,11 @@ lockb
logformat
logline
logtostderr
lspec
lzrndrpkvsjqgk
mapstructure
maxdome
maxp
maxpeers
mdsvex
merkle
Expand All @@ -433,6 +436,7 @@ milagro
mimc
miminum
miniserve
minp
mintkeeper
minttypes
miri
Expand Down Expand Up @@ -531,6 +535,7 @@ pubkey
pubkey's
pubkeys
publint
pvalue
pxplusqx
pxqx
pxrx
Expand Down Expand Up @@ -620,6 +625,7 @@ subdetail
submessage
submessages
submsg
subroot
subsec
substituters
substores
Expand Down Expand Up @@ -730,6 +736,7 @@ valnode
valoper
valoperpub
valset
varint
vercel
verison
verkle
Expand Down
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
flake = false;
};
ics23 = {
url = "github:cosmos/ics23?rev=b1abd8678aab07165efd453c96796a179eb3131f";
url = "github:cosmos/ics23?rev=74ce807b7be39a7e0afb4e2efb8e28a57965f57b";
flake = false;
};
cosmosproto = {
Expand Down
5 changes: 5 additions & 0 deletions generated/rust/src/cosmos.ics23.v1.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/chain-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ tracing = "0.1.37"
tokio = { version = "1.32.0", default-features = false }
typenum = { version = "1.16.0", default-features = false, features = ["const-generics", "no_std"] }
prost = "0.11.0"
sha2 = "0.10.6"
sha2.workspace = true
chrono = { version = "0.4.26", default-features = false, features = ["alloc"] }
reqwest = "0.11.20"
serde_json = "1.0.107"
thiserror = "1.0.49"
crossbeam-queue = "0.3.8"
num_enum = "0.7.0"
dashmap = "5.5.3"
ics23.workspace = true
47 changes: 2 additions & 45 deletions lib/chain-utils/src/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ use std::{num::ParseIntError, sync::Arc};

use bip32::secp256k1::ecdsa;
use futures::{stream, Future, FutureExt, Stream, StreamExt};
use ics23::ibc_api::SDK_SPECS;
use serde::{Deserialize, Serialize};
use tendermint_rpc::{Client, WebSocketClient, WebSocketClientUrl};
use unionlabs::{
bounded::{BoundedI32, BoundedI64},
cosmos::ics23::{
hash_op::HashOp, inner_spec::InnerSpec, leaf_op::LeafOp, length_op::LengthOp,
proof_spec::ProofSpec,
},
encoding::Proto,
events::{IbcEvent, TryFromTendermintEventError, WriteAcknowledgement},
google::protobuf::{any::Any, duration::NANOS_PER_SECOND},
Expand Down Expand Up @@ -208,47 +205,7 @@ impl Chain for Cosmos {
revision_number: self.chain_revision,
revision_height: height.value(),
},
proof_specs: [
ProofSpec {
leaf_spec: LeafOp {
hash: HashOp::Sha256,
prehash_key: HashOp::NoHash,
prehash_value: HashOp::Sha256,
length: LengthOp::VarProto,
prefix: vec![0],
},
inner_spec: InnerSpec {
child_order: vec![0, 1],
child_size: 33,
min_prefix_length: 4,
max_prefix_length: 12,
empty_child: vec![],
hash: HashOp::Sha256,
},
max_depth: 0,
min_depth: 0,
},
ProofSpec {
leaf_spec: LeafOp {
hash: HashOp::Sha256,
prehash_key: HashOp::NoHash,
prehash_value: HashOp::Sha256,
length: LengthOp::VarProto,
prefix: [0].into(),
},
inner_spec: InnerSpec {
child_order: [0, 1].into(),
child_size: 32,
min_prefix_length: 1,
max_prefix_length: 1,
empty_child: [].into(),
hash: HashOp::Sha256,
},
max_depth: 0,
min_depth: 0,
},
]
.into(),
proof_specs: SDK_SPECS.into(),
upgrade_path: vec!["upgrade".into(), "upgradedIBCState".into()],
allow_update_after_expiry: false,
allow_update_after_misbehavior: false,
Expand Down
2 changes: 1 addition & 1 deletion lib/ethereum-verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ milagro_bls = { workspace = true, default-features = false }
primitive-types = { version = "0.12.1", default-features = false, features = ["rlp"] }
rlp = { version = "0.5.2", default-features = false, features = ["derive"] }
serde = { version = "1.0.103", default-features = false, features = ["derive", "alloc"] }
sha2 = { version = "0.10", default-features = false }
sha2.workspace = true
sha3 = { version = "0.10", default-features = false }
trie-db = { version = "0.27.1", default-features = false }
typenum = { version = "1.16.0", features = ["const-generics", "no_std"] }
Expand Down
7 changes: 3 additions & 4 deletions lib/ics-008-wasm-client/src/ibc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, StdError};
use protos::ibc::core::client::v1::GenesisMetadata;
use unionlabs::{
ibc::{
core::client::height::Height,
core::{client::height::Height, commitment::merkle_path::MerklePath},
lightclients::wasm::{client_state::ClientState, consensus_state::ConsensusState},
},
Proto, TryFromProto, TryFromProtoBytesError, TryFromProtoErrorOf,
};

use crate::{
msg::{MerklePath, QueryMsg},
CheckForMisbehaviourResult, EmptyResult, Error, ExportMetadataResult, Status, StatusResult,
SudoMsg, TimestampAtHeightResult, UpdateStateResult,
msg::QueryMsg, CheckForMisbehaviourResult, EmptyResult, Error, ExportMetadataResult, Status,
StatusResult, SudoMsg, TimestampAtHeightResult, UpdateStateResult,
};

pub enum StorageState {
Expand Down
7 changes: 1 addition & 6 deletions lib/ics-008-wasm-client/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use protos::ibc::{
},
};
use serde::{Deserialize, Serialize};
use unionlabs::ibc::core::client::height::Height;
use unionlabs::ibc::core::{client::height::Height, commitment::merkle_path::MerklePath};

// TODO(aeryz): Handle all these properly
#[derive(Debug, Serialize, Deserialize)]
Expand All @@ -23,11 +23,6 @@ pub struct ClientMessage {
pub data: Binary,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct MerklePath {
pub key_path: Vec<String>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct EmptyResult {}

Expand Down
17 changes: 17 additions & 0 deletions lib/ics23/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "ics23"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
unionlabs = { workspace = true, default-features = false }
thiserror = { version = "1.0", package = "thiserror-core", default-features = false }
prost = { version = "0.11.9", default-features = false, features = ["std"] }
sha2.workspace = true
ripemd = { version = "0.1.3", default-features = false }
serde-utils.workspace = true

[dev-dependencies]
hex-literal = "0.4.1"
Loading

0 comments on commit 0995c0d

Please sign in to comment.