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
63 changes: 63 additions & 0 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ members = [
# runtime
"parachain/runtimes/gargantua",
"parachain/runtimes/nexus",
# for testing pallet-revive
"parachain/runtimes/messier",

# node
"parachain/node",
Expand All @@ -19,6 +21,7 @@ members = [
"modules/pallets/demo",
"modules/pallets/testsuite",
"modules/pallets/call-decompressor",
"modules/pallets/revive-dispatcher",
"modules/pallets/xcm-gateway",
"modules/pallets/token-governor",
"modules/pallets/token-gateway",
Expand Down Expand Up @@ -187,7 +190,7 @@ futures = "0.3.28"
async-trait = "0.1.53"
reqwest-chain = "0.1.0"
reqwest-middleware = "0.2.4"
reqwest = { version="0.11.14", features=["json"]}
reqwest = { version = "0.11.14", features = ["json"] }

# arkworks
ark-ec = { version = "0.4.2", default-features = false }
Expand All @@ -203,6 +206,7 @@ ismp-parachain = { version = "2506.0.0", path = "./modules/ismp/clients/parachai
ismp-parachain-inherent = { version = "2506.0.0", path = "./modules/ismp/clients/parachain/inherent" }
ismp-parachain-runtime-api = { version = "2506.0.0", path = "./modules/ismp/clients/parachain/runtime-api", default-features = false }
pallet-ismp = { version = "2506.0.0", path = "modules/pallets/ismp", default-features = false }
pallet-revive-ismp-dispatcher = { version = "2506.0.0", path = "modules/pallets/revive-dispatcher", default-features = false }
pallet-ismp-rpc = { version = "2506.0.0", path = "modules/pallets/ismp/rpc" }
pallet-ismp-runtime-api = { version = "2506.0.0", path = "modules/pallets/ismp/runtime-api", default-features = false }
pallet-hyperbridge = { version = "2506.0.0", path = "modules/pallets/hyperbridge", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion modules/pallets/call-decompressor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ log = { workspace = true }

# polytope labs
ismp = { workspace = true }
pallet-ismp = { workspace = true, features = ["unsigned"] }
pallet-ismp = { workspace = true }
pallet-ismp-relayer = { workspace = true }

[dependencies.polkadot-sdk]
Expand Down
4 changes: 2 additions & 2 deletions modules/pallets/hyperbridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ where
Preservation::Expendable,
)
.map_err(|err| {
ismp::Error::Custom(format!("Error withdrawing request fees: {err:?}"))
ismp::Error::Custom(format!("Error withdrawing protocol fees: {err:?}"))
})?;
}

Expand Down Expand Up @@ -263,7 +263,7 @@ where
Preservation::Expendable,
)
.map_err(|err| {
ismp::Error::Custom(format!("Error withdrawing request fees: {err:?}"))
ismp::Error::Custom(format!("Error withdrawing protocol fees: {err:?}"))
})?;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/pallets/ismp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ runtime-benchmarks = [
"polkadot-sdk/frame-benchmarking",
]
try-runtime = ["polkadot-sdk/try-runtime"]
unsigned = []

6 changes: 3 additions & 3 deletions modules/pallets/ismp/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ where
fee.fee,
Preservation::Expendable,
)
.map_err(|err| IsmpError::Custom(format!("Error withdrawing request fees: {err:?}")))?;
.map_err(|err| IsmpError::Custom(format!("Error withdrawing relayer fees: {err:?}")))?;
}

let request = match request {
Expand Down Expand Up @@ -140,7 +140,7 @@ where
fee.fee,
Preservation::Expendable,
)
.map_err(|err| IsmpError::Custom(format!("Error withdrawing request fees: {err:?}")))?;
.map_err(|err| IsmpError::Custom(format!("Error withdrawing relayer fees: {err:?}")))?;
}

let req_commitment = hash_request::<Pallet<T>>(&response.request());
Expand Down Expand Up @@ -235,7 +235,7 @@ impl<T: Config> IsmpModule for RefundingModule<T> {
Preservation::Expendable,
)
.map_err(|err| {
IsmpError::Custom(format!("Error withdrawing request fees: {err:?}"))
IsmpError::Custom(format!("Error withdrawing relayer fees: {err:?}"))
})?;
}
}
Expand Down
15 changes: 5 additions & 10 deletions modules/pallets/ismp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ pub mod pallet {
PalletId,
};
use frame_system::pallet_prelude::{BlockNumberFor, *};
#[cfg(feature = "unsigned")]
use ismp::messaging::Message;
use ismp::{
consensus::{
ConsensusClientId, ConsensusStateId, StateCommitment, StateMachineHeight,
Expand All @@ -66,17 +64,16 @@ pub mod pallet {
events::{RequestResponseHandled, TimeoutHandled},
handlers,
host::{IsmpHost, StateMachine},
messaging::CreateConsensusState,
messaging::{CreateConsensusState, Message},
router::IsmpRouter,
};
use sp_core::{storage::ChildInfo, H256};
#[cfg(feature = "unsigned")]
use sp_runtime::transaction_validity::{
InvalidTransaction, TransactionSource, TransactionValidity, TransactionValidityError,
ValidTransaction,
};
use sp_runtime::{
traits::{AccountIdConversion, AtLeast32BitUnsigned},
transaction_validity::{
InvalidTransaction, TransactionSource, TransactionValidity, TransactionValidityError,
ValidTransaction,
},
FixedPointOperand,
};
use sp_std::prelude::*;
Expand Down Expand Up @@ -301,7 +298,6 @@ pub mod pallet {
/// - `messages`: the messages to handle or process.
///
/// Emits different message events based on the Message received if successful.
#[cfg(feature = "unsigned")]
#[pallet::weight(weight())]
#[pallet::call_index(0)]
#[frame_support::transactional]
Expand Down Expand Up @@ -502,7 +498,6 @@ pub mod pallet {
}

/// This allows users execute ISMP datagrams for free. Use with caution.
#[cfg(feature = "unsigned")]
#[pallet::validate_unsigned]
impl<T: Config> ValidateUnsigned for Pallet<T> {
type Call = Call<T>;
Expand Down
67 changes: 67 additions & 0 deletions modules/pallets/revive-dispatcher/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[package]
name = "pallet-revive-ismp-dispatcher"
version = "2506.0.0"
edition = "2021"
description = "IsmpDispatcher precompile implementation for pallet-revive"
authors = ["Polytope Labs <[email protected]>"]
license = "Apache-2.0"
repository = "https://github.com/polytope-labs/hyperbridge"
documentation = "https://docs.rs/pallet-revive-ismp-dispatcher"
keywords = ["pallet-revive", "pallet-ismp", "ismp", "polkadot-sdk", "pallet-ismp", "Risc-v", "evm"]
readme = "./README.md"

[lib]
doctest = false

[dependencies]
alloy-rlp = { workspace = true }
num-traits = { version = "0.2.19", default-features = false }
ruint = { version = "1.15.0", features = ["num-traits"], default-features = false }
scale-info = { workspace = true }
codec = { workspace = true }
log = { workspace = true }
ismp = { workspace = true }
pallet-ismp = { workspace = true }
pallet-hyperbridge = { workspace = true }
hex = { workspace = true }

[dependencies.polkadot-sdk]
workspace = true
features = [
"frame-support",
"frame-system",
"sp-runtime",
"sp-core",
"sp-std",
"sp-io",
"pallet-revive",
]

[dev-dependencies]
anyhow = { workspace = true }
hex-literal = { workspace = true }
polkadot-sdk = { workspace = true, features = [
"std",
"pallet-balances",
"pallet-assets",
"pallet-timestamp",
"pallet-transaction-payment",
"sp-io",
] }
pallet-hyperbridge = { workspace = true, default-features = true }

[features]
default = ["std"]
std = [
"codec/std",
"ruint/std",
"num-traits/std",
"log/std",
"polkadot-sdk/std",
"scale-info/std",
"num-traits/std",
"ismp/std",
"pallet-ismp/std",
"alloy-rlp/std",
]
try-runtime = ["polkadot-sdk/try-runtime"]
41 changes: 41 additions & 0 deletions modules/pallets/revive-dispatcher/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# pallet-revive-ismp-dispatcher

ISMP dispatcher precompile implementation for pallet-revive.

## Overview

The `pallet-revive-ismp-dispatcher` provides a precompile interface for PolkaVM contracts to dispatch ISMP (Interoperable State Machine Protocol) messages. This pallet focuses exclusively on outgoing message dispatch functionality, enabling contracts to:

- Dispatch POST requests to other chains
- Dispatch GET requests for cross-chain state queries
- Dispatch responses to incoming requests
- Fund existing requests and responses with additional fees
- Query configuration parameters like fee tokens and per-byte fees

## Interface

The dispatcher exposes the following core functionality:

### Configuration Queries
- `host()` - Returns the host state machine identifier
- `hyperbridge()` - Returns the connected hyperbridge instance identifier
- `nonce()` - Returns the next available nonce for requests
- `feeToken()` - Returns the configured fee token address
- `perByteFee(bytes dest)` - Returns the per-byte fee for the destination chain

### Message Dispatch
- `dispatch(DispatchPost)` - Dispatches a POST request
- `dispatch(DispatchGet)` - Dispatches a GET request
- `dispatch(DispatchPostResponse)` - Dispatches a response to a POST request

### Fee Management
- `fundRequest(bytes32 commitment, uint256 amount)` - Adds additional fees to a pending request
- `fundResponse(bytes32 commitment, uint256 amount)` - Adds additional fees to a pending response

## Usage

This pallet is designed to be used as a precompile in pallet-revive based runtimes. Contracts can interact with it at the fixed address `0xD27` (3367 in decimal).

## License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.
Loading