Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce SoneiumHost #372

Merged
merged 5 commits into from
Jan 28, 2025
Merged
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
6 changes: 3 additions & 3 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,13 @@ geth-primitives = { path = "./modules/consensus/geth-primitives", default-featur
sync-committee-primitives = { path = "./modules/consensus/sync-committee/primitives", default-features = false }
sync-committee-prover = { path = "./modules/consensus/sync-committee/prover" }
sync-committee-verifier = { path = "./modules/consensus/sync-committee/verifier", default-features = false }
grandpa-verifier-primitives = { version = "0.1.1", path = "./modules/consensus/grandpa/primitives", default-features = false }
grandpa-verifier = { version = "0.1.1", path = "./modules/consensus/grandpa/verifier", default-features = false }
grandpa-verifier-primitives = { version = "0.1.2", path = "./modules/consensus/grandpa/primitives", default-features = false }
grandpa-verifier = { version = "0.1.2", path = "./modules/consensus/grandpa/verifier", default-features = false }
grandpa-prover = { path = "./modules/consensus/grandpa/prover" }

# consensus clients
ismp-bsc = { path = "./modules/ismp/clients/bsc", default-features = false }
ismp-grandpa = { version = "15.0.0", path = "./modules/ismp/clients/grandpa", default-features = false }
ismp-grandpa = { version = "15.0.1", path = "./modules/ismp/clients/grandpa", default-features = false }
ismp-parachain = { version = "15.0.1", path = "./modules/ismp/clients/parachain/client", default-features = false }
ismp-parachain-inherent = { version = "15.0.0", path = "./modules/ismp/clients/parachain/inherent" }
ismp-parachain-runtime-api = { version = "15.0.0", path = "./modules/ismp/clients/parachain/runtime-api", default-features = false }
Expand Down
14 changes: 14 additions & 0 deletions docs/pages/developers/evm/contracts/mainnet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,17 @@ The ISMP solidity contracts are deployed on the following networks:
| `UniswapV2 (Mocked)` | [`0xB2e26652e4BAd1e56055A051f922E06760cA0BFE`](https://gnosisscan.io/address/0xB2e26652e4BAd1e56055A051f922E06760cA0BFE) |
| `Inscriptions` | [`0x9251C6B5f4e2CEE34269400CBB43AD5C813606F6`](https://gnosisscan.io/address/0x9251C6B5f4e2CEE34269400CBB43AD5C813606F6) |
| `TokenGateway` | [`0xFd413e3AFe560182C4471F4d143A96d3e259B6dE`](https://gnosisscan.io/address/0xFd413e3AFe560182C4471F4d143A96d3e259B6dE) |


## Soneium


| `IsmpHost` | [`0xc6b03c129a30241Ea6a572284Ff1e9fD5c534Cb3`](https://soneium.blockscout.com/address/0xc6b03c129a30241Ea6a572284Ff1e9fD5c534Cb3) |
|:------------|:-----|
| `HandlerV1` | [`0x7DDBfE2bC9216f830d241f7AfDd52747826A8a74`](https://soneium.blockscout.com/address/0x7DDBfE2bC9216f830d241f7AfDd52747826A8a74) |
| `ConsensusClient` | [`0x1BE0224FA90cAc24Fc57066b4C87EeDF78Ca79fF`](https://soneium.blockscout.com/address/0x1BE0224FA90cAc24Fc57066b4C87EeDF78Ca79fF) |
| `HostManager` | [`0x8e88e8BEc14aAf69090c226320FeF36C8eF2F85f`](https://soneium.blockscout.com/address/0x8e88e8BEc14aAf69090c226320FeF36C8eF2F85f) |
| `FeeToken (USDC.e)` | [`0xbA9986D2381edf1DA03B0B9c1f8b00dc4AacC369`](https://soneium.blockscout.com/address/0xbA9986D2381edf1DA03B0B9c1f8b00dc4AacC369) |
| `UniswapV2` | `0x0000000000000000000000000000000000000000` |
| `Inscriptions` | [`0x9251C6B5f4e2CEE34269400CBB43AD5C813606F6`](https://soneium.blockscout.com/address/0x9251C6B5f4e2CEE34269400CBB43AD5C813606F6) |
| `TokenGateway` | [`0xFd413e3AFe560182C4471F4d143A96d3e259B6dE`](https://soneium.blockscout.com/address/0xFd413e3AFe560182C4471F4d143A96d3e259B6dE) |
2 changes: 2 additions & 0 deletions evm/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ arbitrum = "${ARBITRUM_RPC_URL}"
base = "${BASE_RPC_URL}"
bsc = "${BSC_RPC_URL}"
gnosis = "${GNOSIS_RPC_URL}"
soneium = "${SONEIUM_RPC_URL}"

[etherscan]
# testnet
Expand All @@ -41,3 +42,4 @@ optimism = { key = "${OPTIMISM_ETHERSCAN_API_KEY}", chain = 10, url = "https://a
base = { key = "${BASE_ETHERSCAN_API_KEY}", chain = 8453, url = "https://api.basescan.org/api" }
bsc = { key = "${BSC_ETHERSCAN_API_KEY}", chain = 56, url = "https://api.bscscan.com/api" }
gnosis = { key = "${GNOSIS_ETHERSCAN_API_KEY}", chain = 100, url = "https://api.gnosisscan.io/api" }
soneium = { key = "${SONEIUM_BLOCKSCOUT_API_KEY}", chain = 1868, url = "https://soneium.blockscout.com/api" }
1 change: 1 addition & 0 deletions evm/script/BaseScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ abstract contract BaseScript is Script {
address payable internal BASE_HOST = payable(vm.envAddress("BASE_HOST"));
address payable internal BNB_HOST = payable(vm.envAddress("BNB_HOST"));
address payable internal GNOSIS_HOST = payable(vm.envAddress("GNOSIS_HOST"));
address payable internal SONEIUM_HOST = payable(vm.envAddress("SONEIUM_HOST"));

bytes32 internal privateKey = vm.envBytes32("PRIVATE_KEY");
string internal host = vm.envString("HOST");
Expand Down
4 changes: 4 additions & 0 deletions evm/script/DeployGateway.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ contract DeployScript is BaseScript {
vm.startBroadcast(uint256(privateKey));
deployInscription(GNOSIS_HOST, admin);
deployGateway(GNOSIS_HOST, admin, callDispatcher);
} else if (host.toSlice().startsWith("soneium".toSlice())) {
vm.startBroadcast(uint256(privateKey));
deployInscription(SONEIUM_HOST, admin);
deployGateway(SONEIUM_HOST, admin, callDispatcher);
}
}

Expand Down
16 changes: 11 additions & 5 deletions evm/script/DeployIsmp.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import "../src/hosts/Arbitrum.sol";
import "../src/hosts/Optimism.sol";
import "../src/hosts/Base.sol";
import "../src/hosts/Gnosis.sol";
import "../src/hosts/Soneium.sol";

import {ERC6160Ext20} from "@polytope-labs/erc6160/tokens/ERC6160Ext20.sol";
import {TokenGateway, Asset, TokenGatewayParamsExt, TokenGatewayParams, AssetMetadata} from "../src/modules/TokenGateway.sol";
Expand All @@ -30,6 +31,7 @@ import {StateMachine} from "@polytope-labs/ismp-solidity/StateMachine.sol";
import {FeeToken} from "../test/FeeToken.sol";
import {CallDispatcher} from "../src/modules/CallDispatcher.sol";
import {BaseScript} from "./BaseScript.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";

bytes32 constant MINTER_ROLE = keccak256("MINTER ROLE");
bytes32 constant BURNER_ROLE = keccak256("BURNER ROLE");
Expand All @@ -44,7 +46,7 @@ contract DeployScript is BaseScript {
vm.startBroadcast(uint256(privateKey));

// consensus client
SP1Verifier verifier = new SP1Verifier();
SP1Verifier verifier = new SP1Verifier{salt: salt}();
SP1Beefy consensusClient = new SP1Beefy{salt: salt}(verifier);

// handler
Expand All @@ -56,7 +58,8 @@ contract DeployScript is BaseScript {
stateMachines[0] = paraId;

address uniswapV2 = vm.envAddress(string.concat(host, "_UNISWAP_V2"));
address feeToken = vm.envAddress(string.concat(host, "_DAI"));
address feeToken = vm.envAddress(string.concat(host, "_FEE_TOKEN"));
uint256 decimals = IERC20Metadata(feeToken).decimals();

// EvmHost
PerByteFee[] memory perByteFees = new PerByteFee[](0);
Expand All @@ -66,12 +69,12 @@ contract DeployScript is BaseScript {
admin: admin,
hostManager: address(manager),
handler: address(handler),
defaultTimeout: 60 * 60,
defaultTimeout: 2 * 60 * 60,
unStakingPeriod: 21 * (60 * 60 * 24),
challengePeriod: 0,
consensusClient: address(consensusClient),
defaultPerByteFee: 3 * 1e15, // $0.003/byte
stateCommitmentFee: 10 * 1e18, // $10
defaultPerByteFee: 3 * (10 ** (decimals - 2)), // $0.003/byte
stateCommitmentFee: 10 * (10 ** decimals), // $10
hyperbridge: StateMachine.polkadot(paraId),
feeToken: feeToken,
stateMachines: stateMachines
Expand Down Expand Up @@ -106,6 +109,9 @@ contract DeployScript is BaseScript {
} else if (host.toSlice().startsWith("gnosis".toSlice())) {
GnosisHost h = new GnosisHost{salt: salt}(params);
return address(h);
} else if (host.toSlice().startsWith("soneium".toSlice())) {
SoneiumHost h = new SoneiumHost{salt: salt}(params);
return address(h);
}

revert("Unknown host");
Expand Down
35 changes: 35 additions & 0 deletions evm/src/hosts/Soneium.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (C) Polytope Labs Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
pragma solidity ^0.8.17;

import {EvmHost, HostParams} from "./EvmHost.sol";

/**
* @title The SoneiumHost
* @author Polytope Labs (hello@polytope.technology)
*
* @notice The IsmpHost and IsmpDispatcher implementation for the Soneium state machine.
* Refer to the official ISMP specification. https://docs.hyperbridge.network/protocol/ismp
*/
contract SoneiumHost is EvmHost {
constructor(HostParams memory params) EvmHost(params) {}

/// chainId for the Soneium mainnet
uint256 public constant CHAIN_ID = 1868;

function chainId() public pure override returns (uint256) {
return CHAIN_ID;
}
}
23 changes: 0 additions & 23 deletions evm/test/SP1BeefyTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,6 @@ contract SP1BeefyTest is Test {
sp1 = new SP1Verifier();
}

function testAbiDecode() public {
bytes
memory encoded = hex"000000000000000000000000000000000000000000000000000000000160c36c00000000000000000000000000000000000000000000000000000000000005d60000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000160c36b97834c42788ee64ebc661ca927adb2df9e7964a91c61ccd54f542022ad27952100000000000000000000000000000000000000000000000000000000000005d70000000000000000000000000000000000000000000000000000000000000190a2f65237d65bf11eaf9883b0c994bc18a95ab47b43b572d7aff843b432973c9b7e2a5acf19da2d1c1f1e90c951fd996299699edf011464d0976a0b613b00411200000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000340000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000d270000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000012bacef909d9f380defaf3b43b063bbcca5894af6a9aeecf2f4f40954da066ca7b76ad993003005b4528466a4054871fcdaf62d951478b3c9fadfa7e9a1d176dc65455357251ca64fad2022f40c2bbf8f757595fa2f7f795417649d978e008b79ee6fac9942100661757261201b9d970800000000045250535290729cb4381d686b46b93fe119aa9fa0523498e73530fae930da8ec417e066d362a20d83050449534d5001010000000000000000000000000000000000000000000000000000000000000000bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a05617572610101cac07fddba00a5cfcdb310f1612f7b10f01517f66aa9d74491eff3984ddd6f576f5cfee93c5cffe3f8b872ecae278dd7791624a439214f66620ea3d2a19852820000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000104090690900a331610accb89fe31c04e9d4e0af42b9a99c946330fa6955af1254eb86aa8d3156ad94ef914c0f0901e9226264c7ebbd95145ec8e4a49dca2d348300d1fff3f19cd79389cd6fa52de5d8b0dfe2d60e5d53f7c706c0568c46dfc19c7bb232a951b01fc65f1360369a2ac0c50bbb41163127840d1dedc2e3f6ee98338bd59c7b81e8ea4f720ca1a2b9f7207e27ccb833c4965503a47e4fa62ea5e419555bfdd6421af119e05ad9e13adc643de98945d29f6a6b8d2a470a218e4a2abc9092b693618e7ecf7e780dbe7580bccfe2d5be334035c7ac5361d435cbc760c7896290f7b2b109a2dbe6c47e8401ab119a2da052fb3c0933f3e1669a59437bd8bc8dc157b00000000000000000000000000000000000000000000000000000000";

BeefyConsensusState memory state = BeefyConsensusState({
latestHeight: 0,
beefyActivationBlock: 0,
currentAuthoritySet: AuthoritySetCommitment({
id: 1494,
len: 400,
root: bytes32(0xa2f65237d65bf11eaf9883b0c994bc18a95ab47b43b572d7aff843b432973c9b)
}),
nextAuthoritySet: AuthoritySetCommitment({
id: 1495,
len: 400,
root: bytes32(0xa2f65237d65bf11eaf9883b0c994bc18a95ab47b43b572d7aff843b432973c9b)
})
});

SP1Beefy sp1Beefy = new SP1Beefy(sp1);
sp1Beefy.verifyConsensus(abi.encode(state), encoded);
}

function testPolkadotVerifier() public view {
bytes
memory proof = hex"11b6a09d0602783a739ff23a34879d0f31c9742293407605ad35b2ab9f2112445436251c2929a1f895ee9c0a7185734a57da30feaa42de756ef44ac2383ad0146f525ed41ea56e5485fe3d329cec126256c2c19918560e93fea6e69d6c1287aba55359e020f8368e1be185cabcaf87407e6e700be708bb4f0e3d800fea43e7e06f95d8a7141f29d97bbdec0ead4c051dc1a8ff931bf470e7f48bf8edba580d1a1e7f93bf2c7fc4b3124ccbbcaa0cb0243a3be77001d71fc4eb020bfce79d88ce520a9cf611b8032714b5f7429e0bd89c76474f67e0b8f02c0a1cc9fd3cbc8fdf6039a89904236d309f7153c388b5c66d5e5bdc484f4272b71aa246b121bbac05fd50bbe5";
Expand Down
2 changes: 1 addition & 1 deletion modules/consensus/grandpa/primitives/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grandpa-verifier-primitives"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
authors = ["Polytope Labs <hello@polytope.technology>"]
license = "Apache-2.0"
Expand Down
14 changes: 2 additions & 12 deletions modules/consensus/grandpa/primitives/src/justification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ use sp_consensus_grandpa::{
AuthorityId, AuthorityList, AuthoritySignature, ConsensusLog, Equivocation, RoundNumber,
ScheduledChange, SetId, GRANDPA_ENGINE_ID,
};
use sp_core::ed25519;
use sp_runtime::{generic::OpaqueDigestItemId, traits::Header as HeaderT};
use sp_runtime::{generic::OpaqueDigestItemId, traits::Header as HeaderT, RuntimeAppPublic};
use sp_std::prelude::*;

/// A GRANDPA justification for block finality, it includes a commit message and
Expand Down Expand Up @@ -243,18 +242,9 @@ where
H: Encode,
N: Encode,
{
log::trace!(target: "pallet_grandpa", "Justification Message {:?}", (round, set_id));
let buf = (message, round, set_id).encode();

let signature_bytes: &[u8] = signature.as_ref();
let sp_finality_signature: ed25519::Signature =
signature_bytes.try_into().map_err(|_| anyhow!("Could not fetch signature"))?;

let id_bytes: &[u8] = id.as_ref();
let pub_key: ed25519::Public =
id_bytes.try_into().map_err(|_| anyhow!("Could not fetch public key"))?;

if sp_io::crypto::ed25519_verify(&sp_finality_signature, &buf, &pub_key) {
if !id.verify(&buf, signature) {
Err(anyhow!("invalid signature for precommit in grandpa justification"))?
}

Expand Down
2 changes: 1 addition & 1 deletion modules/consensus/grandpa/prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ where

Ok(ConsensusState {
current_authorities,
current_set_id: current_set_id + 1,
current_set_id,
latest_height,
latest_hash: hash.into(),
slot_duration,
Expand Down
4 changes: 2 additions & 2 deletions modules/consensus/grandpa/verifier/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grandpa-verifier"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
authors = ["Polytope Labs <hello@polytope.technology>"]
license = "Apache-2.0"
Expand All @@ -14,7 +14,7 @@ keywords = ["substrate", "polkadot-sdk", "ISMP", "interoperability", "GRANDPA"]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { workspace = true, features = ["derive"]}
codec = { workspace = true, features = ["derive"] }
anyhow = { workspace = true, default-features = false }
finality-grandpa = { version = "0.16.0", features = ["derive-codec"], default-features = false }
serde = { workspace = true, features = ["derive"] }
Expand Down
4 changes: 2 additions & 2 deletions modules/consensus/grandpa/verifier/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async fn follow_grandpa_justifications() {
let relay_ws_url = std::env::var("RELAY_HOST")
.unwrap_or_else(|_| "wss://hyperbridge-paseo-relay.blockops.network:443".to_string());

let para_ids = vec![2000];
let para_ids = vec![1000];

println!("Connecting to relay chain {relay_ws_url}");
let prover = GrandpaProver::<subxt_utils::BlakeSubstrateChain>::new(ProverOptions {
Expand Down Expand Up @@ -85,7 +85,7 @@ async fn follow_grandpa_justifications() {

// slot duration in milliseconds for parachains
let slot_duration = 6000;
let hash = prover.client.rpc().block_hash(Some(10u64.into())).await.unwrap().unwrap();
let hash = prover.client.rpc().finalized_head().await.unwrap();
let mut consensus_state = prover.initialize_consensus_state(slot_duration, hash).await.unwrap();
println!("Grandpa proofs are now available");
while let Some(Ok(_)) = subscription.next().await {
Expand Down
14 changes: 11 additions & 3 deletions modules/ismp/clients/grandpa/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ismp-grandpa"
version = "15.0.0"
version = "15.0.1"
edition = "2021"
authors = ["Polytope Labs <hello@polytope.technology>"]
license = "Apache-2.0"
Expand All @@ -15,9 +15,7 @@ readme = "./README.md"
anyhow = { workspace = true }
codec = { workspace = true, features = ["derive"] }
primitive-types = { workspace = true }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
merkle-mountain-range = { workspace = true }
finality-grandpa = { version = "0.16.0", features = ["derive-codec"], default-features = false }
frame-benchmarking = { workspace = true, optional = true }
sp-std = { workspace = true }

Expand All @@ -39,6 +37,16 @@ sp-core = { workspace = true }
# cumulus
substrate-state-machine = { workspace = true }

[dependencies.scale-info]
version = "2.1.1"
default-features = false
features = ["derive"]

[dependencies.finality-grandpa]
version = "0.16.0"
features = ["derive-codec"]
default-features = false

[features]
default = ["std"]
std = [
Expand Down
8 changes: 6 additions & 2 deletions modules/ismp/clients/grandpa/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ where
consensus_state,
headers_with_finality_proof,
)
.map_err(|_| Error::Custom("Error verifying parachain headers".into()))?;
.map_err(|err| {
Error::Custom(format!("Error verifying parachain headers: {err:#?}"))
})?;

let parachain_headers = parachain_headers
.into_iter()
Expand Down Expand Up @@ -171,7 +173,9 @@ where
consensus_state,
standalone_chain_message.finality_proof,
)
.map_err(|_| Error::Custom("Error verifying grandpa header".parse().unwrap()))?;
.map_err(|err| {
Error::Custom(format!("Error verifying grandpa header: {err:#?}"))
})?;
let digest_result = fetch_overlay_root_and_timestamp(
header.digest(),
consensus_state.slot_duration,
Expand Down
2 changes: 1 addition & 1 deletion parachain/runtimes/gargantua/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("gargantua"),
impl_name: create_runtime_str!("gargantua"),
authoring_version: 1,
spec_version: 1_600,
spec_version: 1_800,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
2 changes: 1 addition & 1 deletion parachain/runtimes/nexus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("nexus"),
impl_name: create_runtime_str!("nexus"),
authoring_version: 1,
spec_version: 2_000,
spec_version: 2_200,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
Loading