From 70363b4e9db234e4441cffd5f18d74072e0034a3 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Mon, 1 Apr 2024 22:45:17 +0200 Subject: [PATCH 1/9] feat: implement execute and query handlers --- src/contract.rs | 21 ++++++++++++++------- src/handlers.rs | 4 ++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/contract.rs b/src/contract.rs index 3d2f7ef..e5515b3 100644 --- a/src/contract.rs +++ b/src/contract.rs @@ -1,6 +1,6 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult}; +use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult}; // use cw2::set_contract_version; @@ -33,17 +33,24 @@ pub fn instantiate( #[cfg_attr(not(feature = "library"), entry_point)] pub fn execute( - _deps: DepsMut<'_>, - _env: Env, + deps: DepsMut<'_>, + env: Env, _info: MessageInfo, - _msg: SudoMsg, + msg: SudoMsg, ) -> Result { - unimplemented!() + let mut ctx = RollkitContext::new_mut(deps, env)?; + + let data = ctx.sudo(msg)?; + + Ok(Response::default().set_data(data)) } #[cfg_attr(not(feature = "library"), entry_point)] -pub fn query(_deps: Deps<'_>, _env: Env, _msg: QueryMsg) -> StdResult { - unimplemented!() +pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> StdResult { + let ctx = RollkitContext::new_ref(deps, env)?; + + ctx.query(msg) + .map_err(|e| StdError::generic_err(e.to_string())) } #[cfg(test)] diff --git a/src/handlers.rs b/src/handlers.rs index 50bdfed..6fea755 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -16,9 +16,9 @@ use crate::{ impl<'a, C: ClientType<'a>> Context<'a, C> { pub fn instantiate(&mut self, msg: InstantiateMsg) -> Result { - let any = Any::decode(&mut msg.client_state.as_slice())?; + let any_client_state = Any::decode(&mut msg.client_state.as_slice())?; - let client_state = C::ClientState::try_from(any)?; + let client_state = C::ClientState::try_from(any_client_state)?; let any_consensus_state = Any::decode(&mut msg.consensus_state.as_slice())?; From a5717015abd4b49bd08642157f4598a068a73a8a Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Mon, 1 Apr 2024 23:18:00 +0200 Subject: [PATCH 2/9] fix command --- .github/workflows/test.yml | 2 +- src/msg.rs | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 134a404..11d1571 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: - name: Run unit tests uses: actions-rs/cargo@v1 with: - command: unit-test + command: test args: --locked env: RUST_BACKTRACE: 1 diff --git a/src/msg.rs b/src/msg.rs index 95fa937..0f57379 100644 --- a/src/msg.rs +++ b/src/msg.rs @@ -8,8 +8,6 @@ use cosmwasm_schema::cw_serde; use serde::de::Error; use serde::{Deserialize, Deserializer, Serialize, Serializer}; -//use ibc_clients::wasm_types::client_message::ClientMessage; - use ibc_core::client::types::error::ClientError; use ibc_core::client::types::proto::v1::Height as RawHeight; use ibc_core::client::types::Height; From a4a8adbc714ef5a361b49530980233b554d6e8ac Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Mon, 1 Apr 2024 23:35:41 +0200 Subject: [PATCH 3/9] add todos --- src/handlers.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/handlers.rs b/src/handlers.rs index 6fea755..41c0ca0 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -58,9 +58,13 @@ impl<'a, C: ClientType<'a>> Context<'a, C> { client_state.update_state_on_misbehaviour(self, &client_id, any_client_msg)?; + // TODO: delete consensus state at misbehaviour height + ContractResult::success() } SudoMsg::VerifyMembership(msg) => { + // TODO: check DA light client is active + let msg = VerifyMembershipMsg::try_from(msg)?; let client_cons_state_path = ClientConsensusStatePath::new( @@ -82,6 +86,8 @@ impl<'a, C: ClientType<'a>> Context<'a, C> { ContractResult::success() } SudoMsg::VerifyNonMembership(msg) => { + // TODO: check DA light client is active + let msg = VerifyNonMembershipMsg::try_from(msg)?; let client_cons_state_path = ClientConsensusStatePath::new( @@ -172,6 +178,8 @@ impl<'a, C: ClientType<'a>> Context<'a, C> { client_state.verify_client_message(self, &client_id, any_client_msg)?; + // TODO: in case client message is a header, verify header proof and block data proof on the DA light client + QueryResponse::success() } QueryMsg::CheckForMisbehaviour(msg) => { @@ -185,6 +193,8 @@ impl<'a, C: ClientType<'a>> Context<'a, C> { let result = client_state.check_for_misbehaviour(self, &client_id, any_client_msg)?; + // TODO: handle fraud proofs + QueryResponse::success().misbehaviour(result) } }; From 7592b1b84ecd17730a4a4958d879ff4aee381473 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Mon, 1 Apr 2024 23:49:37 +0200 Subject: [PATCH 4/9] lint --- src/handlers.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/handlers.rs b/src/handlers.rs index 41c0ca0..33cf5d1 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -64,7 +64,8 @@ impl<'a, C: ClientType<'a>> Context<'a, C> { } SudoMsg::VerifyMembership(msg) => { // TODO: check DA light client is active - + // TODO: assert(processedTime + clientState.fraudPeriod > currentTimestamp()) + let msg = VerifyMembershipMsg::try_from(msg)?; let client_cons_state_path = ClientConsensusStatePath::new( @@ -87,7 +88,8 @@ impl<'a, C: ClientType<'a>> Context<'a, C> { } SudoMsg::VerifyNonMembership(msg) => { // TODO: check DA light client is active - + // TODO: assert(processedTime + clientState.fraudPeriod > currentTimestamp()) + let msg = VerifyNonMembershipMsg::try_from(msg)?; let client_cons_state_path = ClientConsensusStatePath::new( From 4d3bf20d9d28053439e58d76369aab48e7ff8e06 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Tue, 2 Apr 2024 12:55:34 +0200 Subject: [PATCH 5/9] bump toolchain version --- .github/workflows/lint.yml | 2 +- .github/workflows/test.yml | 2 +- Cargo.toml | 9 ++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6f11875..38002a3 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -16,7 +16,7 @@ jobs: uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.60.0 + toolchain: 1.71.1 override: true components: rustfmt, clippy diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 11d1571..96c5a80 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.60.0 + toolchain: 1.71.1 target: wasm32-unknown-unknown override: true diff --git a/Cargo.toml b/Cargo.toml index 0fe5d97..74d9959 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,9 +52,9 @@ cosmwasm-std = { version = "1.5.0", features = [ cw-storage-plus = "1.1.0" cw2 = "1.1.1" derive_more = "0.99.17" -ibc-core = { git = "https://github.com/cosmos/ibc-rs", rev = "1410bb03fdba930abd31c0941a5fd7f43d13ec96", default-features = false, features = ["schema"] } # "0.50.0" -ibc-clients = { git = "https://github.com/cosmos/ibc-rs", rev = "1410bb03fdba930abd31c0941a5fd7f43d13ec96", default-features = false, features = ["schema"] } # "0.50.0" -ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs.git", rev = "6cbe4c7ace5a688bc98831fa9c1cc2dabf3b2976", default-features = false } # "0.42.0" +ibc-core = { version = "0.51.0", default-features = false, features = ["schema"] } +ibc-clients = { version = "0.51.0", default-features = false, features = ["schema"] } +ibc-proto = { version = "0.42.2", default-features = false } prost = "0.12.3" schemars = "0.8.15" serde = { version = "1.0", features = ["derive", "rc"] } @@ -62,5 +62,8 @@ tendermint = "0.34.1" tendermint-light-client-verifier = "0.34.1" thiserror = { version = "1.0.49" } +[patch.crates-io] +ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs.git", rev = "6cbe4c7ace5a688bc98831fa9c1cc2dabf3b2976", default-features = false } # "0.42.2" + [dev-dependencies] cw-multi-test = "0.17.0" From 36634778581984e881188aa914ae85ec07ea18e7 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Tue, 2 Apr 2024 16:00:24 +0200 Subject: [PATCH 6/9] tweaking gh flows --- .github/workflows/lint.yml | 10 ---------- .github/workflows/test.yml | 15 +-------------- 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 38002a3..41d636b 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -31,13 +31,3 @@ jobs: with: command: clippy args: -- -D warnings - - - name: Generate Schema - uses: actions-rs/cargo@v1 - with: - command: schema - args: --locked - - - name: Schema Changes - # fails if any changes not committed - run: git diff --exit-code schema diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 96c5a80..05b3f70 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,17 +21,4 @@ jobs: override: true - name: Run unit tests - uses: actions-rs/cargo@v1 - with: - command: test - args: --locked - env: - RUST_BACKTRACE: 1 - - - name: Compile WASM contract - uses: actions-rs/cargo@v1 - with: - command: wasm - args: --locked - env: - RUSTFLAGS: "-C link-arg=-s" + run: make test From 7b23c77fd3de7481d47c296d97ccb4d1063916fb Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Thu, 11 Apr 2024 14:54:19 +0200 Subject: [PATCH 7/9] install cargo nexttest in action --- .github/workflows/test.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 05b3f70..12dd887 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,5 +20,11 @@ jobs: target: wasm32-unknown-unknown override: true + - name: Install cargo-nextest + uses: actions-rs/cargo@v1 + with: + command: install + args: cargo-nextest + - name: Run unit tests run: make test From b0839de19a7aa83cd34b2315312e7e4f00700695 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Thu, 11 Apr 2024 16:45:17 +0200 Subject: [PATCH 8/9] cleaning up ci --- .github/workflows/lint.yml | 33 --------------------------------- .github/workflows/test.yml | 30 ------------------------------ Cargo.toml | 20 +++++--------------- Makefile | 13 +++++-------- 4 files changed, 10 insertions(+), 86 deletions(-) delete mode 100644 .github/workflows/lint.yml delete mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 41d636b..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,33 +0,0 @@ -# Based on https://github.com/actions-rs/example/blob/master/.github/workflows/quickstart.yml - -on: [push, pull_request] - -name: lint - -jobs: - lints: - name: Lints - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v2 - - - name: Install stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: 1.71.1 - override: true - components: rustfmt, clippy - - - name: Run cargo fmt - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check - - - name: Run cargo clippy - uses: actions-rs/cargo@v1 - with: - command: clippy - args: -- -D warnings diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 12dd887..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,30 +0,0 @@ -# Based on https://github.com/actions-rs/example/blob/master/.github/workflows/quickstart.yml - -on: [push, pull_request] - -name: build - -jobs: - test: - name: Test Suite - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v2 - - - name: Install stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: 1.71.1 - target: wasm32-unknown-unknown - override: true - - - name: Install cargo-nextest - uses: actions-rs/cargo@v1 - with: - command: install - args: cargo-nextest - - - name: Run unit tests - run: make test diff --git a/Cargo.toml b/Cargo.toml index 74d9959..18c4aa0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,12 +28,6 @@ panic = 'abort' incremental = false overflow-checks = true -[features] -# for more explicit tests, cargo test --features=backtraces -backtraces = ["cosmwasm-std/backtraces"] -# use library feature to disable all instantiate/execute/query exports -library = [] - [package.metadata.scripts] optimize = """docker run --rm -v "$(pwd)":/code \ --mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \ @@ -43,14 +37,10 @@ optimize = """docker run --rm -v "$(pwd)":/code \ [dependencies] base64 = "0.22.0" -cosmwasm-schema = "1.5.0" -cosmwasm-std = { version = "1.5.0", features = [ - "cosmwasm_1_3", - # Enable this if you only deploy to chains that have CosmWasm 1.4 or higher - # "cosmwasm_1_4", -] } -cw-storage-plus = "1.1.0" -cw2 = "1.1.1" +cosmwasm-schema = "2.0.1" +cosmwasm-std = "2.0.1" +cw-storage-plus = "2.0.0" +cw2 = "2.0.0" derive_more = "0.99.17" ibc-core = { version = "0.51.0", default-features = false, features = ["schema"] } ibc-clients = { version = "0.51.0", default-features = false, features = ["schema"] } @@ -66,4 +56,4 @@ thiserror = { version = "1.0.49" } ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs.git", rev = "6cbe4c7ace5a688bc98831fa9c1cc2dabf3b2976", default-features = false } # "0.42.2" [dev-dependencies] -cw-multi-test = "0.17.0" +cw-multi-test = "2.0.0" diff --git a/Makefile b/Makefile index 70eddb7..43c937d 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,9 @@ help: ## Display this help message @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) +clean: ## Cleans compiled + @cargo clean + install-dev-tools: ## Installs all necessary cargo helpers cargo install wasm-opt @@ -22,9 +25,6 @@ optimize-contracts: ## Optimize WASM files in contracts directory wasm-opt "$$wasm_file" -o "$$optimized_file" -Os; \ done -clean: ## Cleans compiled - @cargo clean - lint: ## cargo check and clippy. Skip clippy on guest code since it's not supported by risc0 ## fmt first, because it's the cheapest cargo +nightly fmt --all --check @@ -42,11 +42,8 @@ find-unused-deps: ## Prints unused dependencies for project. Note: requires nigh check-features: ## Checks that project compiles with all combinations of features. default is not needed because we never check `cfg(default)`, we only use it as an alias. cargo hack check --workspace --feature-powerset --exclude-features default -test-legacy: ## Runs test suite with output from tests printed - @cargo test -- --nocapture -Zunstable-options --report-time - -test: ## Runs test suite using next test - @cargo nextest run --workspace --all-features +test: ## Run tests with all features and without default features. + @cargo test --all-targets --no-default-features docs: ## Generates documentation locally cargo doc --all-features --no-deps --release --open From 2b1cbb5671eb1bc07e5979bff230d0ddc721018a Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Thu, 11 Apr 2024 17:15:55 +0200 Subject: [PATCH 9/9] remove --locked flag --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 43c937d..11012f2 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ help: ## Display this help message clean: ## Cleans compiled @cargo clean - + install-dev-tools: ## Installs all necessary cargo helpers cargo install wasm-opt @@ -14,7 +14,7 @@ build: ## Build the the entire project build-cw: ## Build the WASM file for the rollkit light client @echo "Building the WASM file for the rollkit light client" - @RUSTFLAGS='-C link-arg=-s' cargo build --target wasm32-unknown-unknown --release --lib --locked + @RUSTFLAGS='-C link-arg=-s' cargo build --target wasm32-unknown-unknown --release --lib @mkdir -p contracts @cp target/wasm32-unknown-unknown/release/rollkit_ibc.wasm contracts/