Skip to content

Commit

Permalink
Merge branch 'seun/beefy-sync' into seun/messenger
Browse files Browse the repository at this point in the history
  • Loading branch information
seunlanlege committed Oct 30, 2023
2 parents c3b6529 + 95e10a9 commit 748638b
Show file tree
Hide file tree
Showing 28 changed files with 1,035 additions and 1,421 deletions.
23 changes: 2 additions & 21 deletions Cargo.lock

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

37 changes: 1 addition & 36 deletions evm/forge/Cargo.lock

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

4 changes: 2 additions & 2 deletions evm/forge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ ethers = { git = "https://github.com/gakonst/ethers-rs", features = ["ethers-sol
# polytope-labs
merkle-mountain-range-labs = { package = "ckb-merkle-mountain-range", git = "https://github.com/polytope-labs/merkle-mountain-range", branch = "seun/simplified-mmr" }
rs_merkle = { git = "https://github.com/polytope-labs/rs-merkle", branch = "seun/2d-merkle-proofs" }
ismp = { path = "../../parachain/modules/ismp/core" }
ismp = { git = "https://github.com/polytope-labs/ismp-rs", branch = "main" }
beefy-prover = { git = "ssh://[email protected]/polytope-labs/tesseract.git", branch = "main" }
beefy-verifier-primitives = { git = "ssh://[email protected]/polytope-labs/tesseract.git", branch = "main" }

## substrate
beefy-primitives = { package = "sp-consensus-beefy", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.2.0" }
beefy-primitives = { package = "sp-consensus-beefy", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
16 changes: 8 additions & 8 deletions evm/forge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod tests;

pub use crate::forge::{execute, runner};
pub use ethers::{abi::Token, types::U256, utils::keccak256};
use ismp::mmr::{DataOrHash, MmrHasher};
// use ismp::mmr::{DataOrHash, MmrHasher};
use merkle_mountain_range::{util::MemMMR, Error, Merge};
use rs_merkle::Hasher;

Expand Down Expand Up @@ -54,13 +54,13 @@ impl From<u32> for NumberHash {
}
}

pub fn unwrap_hash(item: &DataOrHash) -> [u8; 32] {
match item {
DataOrHash::Hash(h) => (*h).into(),
_ => panic!("not a hash"),
}
}
// pub fn unwrap_hash(item: &DataOrHash) -> [u8; 32] {
// match item {
// DataOrHash::Hash(h) => (*h).into(),
// _ => panic!("not a hash"),
// }
// }

use primitive_types::H256;

pub type Mmr = MemMMR<DataOrHash, MmrHasher<Keccak256>>;
// pub type Mmr = MemMMR<DataOrHash, MmrHasher<Keccak256>>;
10 changes: 5 additions & 5 deletions evm/forge/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod beefy_v1;
mod get_response;
mod get_timeout;
mod post_request;
mod post_response;
mod post_timeout;
// mod get_response;
// mod get_timeout;
// mod post_request;
// mod post_response;
// mod post_timeout;
9 changes: 4 additions & 5 deletions evm/forge/src/tests/beefy_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ struct Config {
}

#[tokio::test(flavor = "multi_thread")]
#[ignore]
async fn beefy_consensus_client_test() {
let mut runner = runner();
let config = envy::from_env::<Config>().unwrap();
Expand Down Expand Up @@ -126,6 +125,7 @@ async fn beefy_consensus_client_test() {
let VersionedFinalityProof::V1(signed_commitment) =
VersionedFinalityProof::<u32, Signature>::decode(&mut &*commitment).unwrap();


match signed_commitment.commitment.validator_set_id {
id if id < consensus_state.current_authority_set.id.as_u64() => {
// If validator set id of signed commitment is less than current validator set id we
Expand All @@ -140,15 +140,16 @@ async fn beefy_consensus_client_test() {
};

let consensus_proof: abi::BeefyConsensusProof =
prover.consensus_proof(signed_commitment).await.unwrap().into();
prover.consensus_proof(signed_commitment.clone()).await.unwrap().into();

if consensus_proof.relay.signed_commitment.commitment.block_number ==
consensus_state.latest_height
{
continue
}

dbg!(&consensus_proof.relay.signed_commitment.commitment);
dbg!(&signed_commitment.commitment);


let (new_state, intermediates) = execute::<_, (bytes::Bytes, abi::IntermediateState)>(
&mut runner,
Expand All @@ -167,8 +168,6 @@ async fn beefy_consensus_client_test() {
{
let debug_consensus_state: ConsensusState = consensus_state.clone().into();
dbg!(&debug_consensus_state);
let intermediate: local::IntermediateState = intermediates.into();
dbg!(&intermediate);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion evm/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ arbitrum-goerli = "${ARBITRUM_GOERLI_RPC_URL}"
base-goerli = "${BASE_GOERLI_RPC_URL}"

[etherscan]
goerli = { key = "${GOERLI_ETHERSCAN_API_KEY}" }
goerli = { key = "${GOERLI_ETHERSCAN_API_KEY}", chain = 5, url = " https://api-goerli.etherscan.io/api" }
optimism-goerli = { key = "${OPTIMISM_ETHERSCAN_API_KEY}", chain = 420, url = "https://api-goerli-optimistic.etherscan.io/api" }
arbitrum-goerli = { key = "${ARBITRUM_ETHERSCAN_API_KEY}", chain = 421613, url = "https://api-goerli.arbiscan.io/api" }
base-goerli = { key = "${BASE_ETHERSCAN_API_KEY}", chain = 84531, url = "https://api-goerli.basescan.org/api" }
34 changes: 23 additions & 11 deletions evm/script/DeployGateway.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import "multi-chain-tokens/tokens/ERC20.sol";

import "../src/modules/TokenGateway.sol";
import "../src/modules/TokenFaucet.sol";
import "../test/PingModule.sol";
import "../test/CrossChainMessenger.sol";

contract DeployScript is Script {
bytes32 public salt = keccak256(bytes("gargantuan_v0"));
bytes32 public salt = keccak256(bytes("gargantua-v0.0.5"));

address public GOERLI_HOST = 0x4a23BF364332dC8d8Dd81552466c7d267D20e988;
address public ARB_GOERLI_HOST = 0xb58F8D53c8e55345d3A620094670B0C3892a097b;
address public OP_GOERLI_HOST = 0x4e74812F70A40328F3703740F03cE8d6208f0CEC;
address public BASE_GOERLI_HOST = 0x9ff290c1650423EF5BA96eE066604Ca4c457C79C;
address public GOERLI_HOST = 0xDaC0797eb874d7a4A53521DD16250fbEb85797f0;
address public ARB_GOERLI_HOST = 0xa8070743D9e2B4aa3dEF52ed04A8e045F16C3252;
address public OP_GOERLI_HOST = 0xB8D705737d63Ce49ec8c491b968D29F497D431f1;
address public BASE_GOERLI_HOST =
0x5Cd82e710385e7e14c5fa97B9Ceae31150Be8dFd;

bytes32 public constant MINTER_ROLE = keccak256("MINTER ROLE");
bytes32 public constant BURNER_ROLE = keccak256("BURNER ROLE");
Expand All @@ -24,29 +27,38 @@ contract DeployScript is Script {

vm.createSelectFork("goerli");
vm.startBroadcast(uint256(privateKey));
deployGateway(GOERLI_HOST, admin);
deployMessenger(GOERLI_HOST, admin);
vm.stopBroadcast();

vm.createSelectFork("arbitrum-goerli");
vm.startBroadcast(uint256(privateKey));
deployGateway(ARB_GOERLI_HOST, admin);
deployMessenger(ARB_GOERLI_HOST, admin);
vm.stopBroadcast();

vm.createSelectFork("optimism-goerli");
vm.startBroadcast(uint256(privateKey));
deployGateway(OP_GOERLI_HOST, admin);
deployMessenger(OP_GOERLI_HOST, admin);
vm.stopBroadcast();

vm.createSelectFork("base-goerli");
vm.startBroadcast(uint256(privateKey));
deployGateway(BASE_GOERLI_HOST, admin);
deployMessenger(BASE_GOERLI_HOST, admin);
vm.stopBroadcast();
}

function deployMessenger(address host, address admin) public {
CrossChainMessenger c = new CrossChainMessenger{ salt: salt }(admin);
c.setIsmpHost(host);
}

function deployGateway(address host, address admin) public {
MultiChainNativeERC20 t = new MultiChainNativeERC20{ salt: salt }(admin, "Hyperbridge Test Token", "CORE");
MultiChainNativeERC20 t = new MultiChainNativeERC20{salt: salt}(
admin,
"Hyperbridge Test Token",
"CORE"
);

TokenGateway gateway = new TokenGateway{ salt: salt }(admin);
TokenGateway gateway = new TokenGateway{salt: salt}(admin);
gateway.setIsmpHost(host);
t.grantRole(MINTER_ROLE, address(gateway));
t.grantRole(BURNER_ROLE, address(gateway));
Expand Down
5 changes: 3 additions & 2 deletions evm/script/DeployIsmp.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import "../src/hosts/Ethereum.sol";
import "../src/hosts/Arbitrum.sol";
import "../src/hosts/Optimism.sol";
import "../src/hosts/Base.sol";
import "../test/PingModule.sol";

contract DeployScript is Script {
bytes32 public salt = keccak256(bytes("gargantuan_v0"));
bytes32 public salt = keccak256(bytes("gargantua-v0.0.1"));

function run() external {
address admin = vm.envAddress("ADMIN");
Expand Down Expand Up @@ -56,7 +57,7 @@ contract DeployScript is Script {
// set the ismphost on the cross-chain governor
governor.setIsmpHost(hostAddress);
// deploy the ping module as well
// PingModule m = new PingModule{salt: salt}(hostAddress);
PingModule m = new PingModule{salt: salt}(hostAddress);
vm.stopBroadcast();
}

Expand Down
4 changes: 2 additions & 2 deletions evm/script/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ if [ "$1" = "local" ]; then
# load local .env
source .env
# deploy
HOST="ethereum" forge script script/DeployIsmp.s.sol:DeployScript --rpc-url "$GOERLI_RPC_URL" --broadcast -vvvv --sender="$ADMIN"
HOST="ethereum" forge script script/DeployIsmp.s.sol:DeployScript --rpc-url "$GOERLI_RPC_URL" --broadcast --verify -vvvv --sender="$ADMIN"
else
echo "Deploying to $1"
# load prod .env
Expand All @@ -12,4 +12,4 @@ else
HOST=$1 forge script script/DeployIsmp.s.sol:DeployScript --rpc-url "$1" --broadcast -vvvv --sender="$ADMIN"
# verify
HOST=$1 forge script script/DeployIsmp.s.sol:DeployScript --rpc-url "$1" --resume --verify -vvvv --sender="$ADMIN"
fi
fi
12 changes: 8 additions & 4 deletions evm/src/EvmHost.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ pragma solidity 0.8.17;
import "openzeppelin/utils/Context.sol";
import "openzeppelin/utils/math/Math.sol";

import "ismp/interfaces/IIsmpModule.sol";
import "ismp/interfaces/IIsmpHost.sol";
import "ismp/interfaces/IHandler.sol";
import "ismp/IIsmpModule.sol";
import "ismp/IIsmpHost.sol";
import "ismp/IHandler.sol";

struct HostParams {
// default timeout in seconds for requests.
Expand Down Expand Up @@ -312,8 +312,12 @@ abstract contract EvmHost is IIsmpHost, Context {
*/
function dispatchIncoming(PostRequest memory request) external onlyHandler {
address destination = _bytesToAddress(request.to);
IIsmpModule(destination).onAccept(request);

// Ideally this would prevent failing requests from poisoning the batch,
// doesn't work, sigh solidity
try IIsmpModule(destination).onAccept(request) {} catch {}

// doesn't matter if it failed, if it failed once, it'll fail again
bytes32 commitment = Message.hash(request);
_requestReceipts[commitment] = true;
}
Expand Down
6 changes: 3 additions & 3 deletions evm/src/HandlerV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import "solidity-merkle-trees/MerkleMountainRange.sol";
import "solidity-merkle-trees/MerklePatricia.sol";
import "openzeppelin/utils/Context.sol";

import "ismp/interfaces/IConsensusClient.sol";
import "ismp/interfaces/IHandler.sol";
import "ismp/interfaces/IIsmpHost.sol";
import "ismp/IConsensusClient.sol";
import "ismp/IHandler.sol";
import "ismp/IIsmpHost.sol";

contract HandlerV1 is IHandler, Context {
using Bytes for bytes;
Expand Down
4 changes: 2 additions & 2 deletions evm/src/beefy/BeefyV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
pragma solidity 0.8.17;

import "./Codec.sol";
import "ismp/interfaces/StateMachine.sol";
import "ismp/interfaces/IConsensusClient.sol";
import "ismp/StateMachine.sol";
import "ismp/IConsensusClient.sol";

import "solidity-merkle-trees/MerkleMultiProof.sol";
import "solidity-merkle-trees/MerkleMountainRange.sol";
Expand Down
4 changes: 2 additions & 2 deletions evm/src/hosts/Arbitrum.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;

import "ismp/EvmHost.sol";
import "ismp/interfaces/StateMachine.sol";
import "../EvmHost.sol";
import "ismp/StateMachine.sol";

contract ArbitrumHost is EvmHost {
constructor(HostParams memory params) EvmHost(params) {}
Expand Down
Loading

0 comments on commit 748638b

Please sign in to comment.