diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 6f11875..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,43 +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.60.0 - 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 - - - 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 deleted file mode 100644 index 134a404..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,37 +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.60.0 - target: wasm32-unknown-unknown - override: true - - - name: Run unit tests - uses: actions-rs/cargo@v1 - with: - command: unit-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" diff --git a/Cargo.toml b/Cargo.toml index 0fe5d97..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,18 +37,14 @@ 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 = { 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 +52,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" +cw-multi-test = "2.0.0" diff --git a/Makefile b/Makefile index 70eddb7..11012f2 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 @@ -11,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/ @@ -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 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..33cf5d1 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())?; @@ -58,9 +58,14 @@ 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 + // TODO: assert(processedTime + clientState.fraudPeriod > currentTimestamp()) + let msg = VerifyMembershipMsg::try_from(msg)?; let client_cons_state_path = ClientConsensusStatePath::new( @@ -82,6 +87,9 @@ impl<'a, C: ClientType<'a>> Context<'a, C> { ContractResult::success() } 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( @@ -172,6 +180,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 +195,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) } }; 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;