Skip to content

Commit

Permalink
Hyperclient: Fix Wasm (#294)
Browse files Browse the repository at this point in the history
Co-authored-by: David Salami <wizdave97@gmail.com>
  • Loading branch information
seunlanlege and Wizdave97 authored Aug 20, 2024
1 parent 0d7135a commit 07dd5b7
Show file tree
Hide file tree
Showing 20 changed files with 175 additions and 73 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,7 @@ jobs:
hyperclient-tests:
name: Hyperclient Integration Tests
runs-on: ubuntu-latest
# if: github.event.pull_request.draft == false
if: false
if: github.event.pull_request.draft == false
steps:
- name: Get User Permission
id: checkAccess
Expand All @@ -405,7 +404,8 @@ jobs:
username: ${{ github.triggering_actor }}

- name: Check User Permission
if: steps.checkAccess.outputs.require-result == 'false'
# if: steps.checkAccess.outputs.require-result == 'false'
if: false
run: |
echo "${{ github.triggering_actor }} does not have permissions on this repo."
echo "Current permission level is ${{ steps.checkAccess.outputs.user-permission }}"
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,24 @@ jobs:
with:
key: ${{ join(matrix.targets, '-') }}

- name: Install yarn
run: |
curl -fsSL --create-dirs -o $HOME/bin/yarn https://github.com/yarnpkg/yarn/releases/download/v1.22.22/yarn-1.22.22.js
chmod +x $HOME/bin/yarn
echo "$HOME/bin" >> $GITHUB_PATH
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 22
cache-dependency-path: "evm/yarn.lock"
cache: "yarn"

- name: Install npm dependencies
working-directory: evm
run: |
yarn install
- name: Install dependencies
run: |
sudo apt-get update
Expand Down
10 changes: 5 additions & 5 deletions docs/pages/developers/evm/contract-addresses.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The current testnet environment for the Hyperbridge network.
| `IsmpHost` | [`0xF1c7a386325B7D22025D7542b28Ee881Cdf107b3`](https://sepolia.etherscan.io/address/0xF1c7a386325B7D22025D7542b28Ee881Cdf107b3) |
|:------------|:-----|
| `HandlerV1` | [`0xeb1359a98765F7B46FAc4ef56A3f2514891f46Ee`](https://sepolia.etherscan.io/address/0xeb1359a98765F7B46FAc4ef56A3f2514891f46Ee) |
| `PingModule` | [`0x0A7175d240fe71C8AEa0D1D7467bF03C6E217C50`](https://sepolia.etherscan.io/address/0x0A7175d240fe71C8AEa0D1D7467bF03C6E217C50) |
| `PingModule` | [`0x1aD48ADeD62e7C685dF4fb75e6d14d34C8B83081`](https://sepolia.etherscan.io/address/0x1aD48ADeD62e7C685dF4fb75e6d14d34C8B83081) |
| `TokenGateway` | [`0xFb5de9d7908F4407B239129c57B53c67BF645BAa`](https://sepolia.etherscan.io/address/0xFb5de9d7908F4407B239129c57B53c67BF645BAa) |
| `TokenFaucet` | [`0x17d8cc0859fbA942A7af243c3EBB69AbBfe0a320`](https://sepolia.etherscan.io/address/0x17d8cc0859fbA942A7af243c3EBB69AbBfe0a320) |
| `FeeToken (USD.h)` | [`0x146760fDDF18a228BB4dA1c4c63c820Dab171D03`](https://sepolia.etherscan.io/address/0x146760fDDF18a228BB4dA1c4c63c820Dab171D03) |
Expand All @@ -23,7 +23,7 @@ The current testnet environment for the Hyperbridge network.
| `IsmpHost` | [`0x286e1FE1c323EE626bE802b13a5184b588eD14Cb`](https://sepolia.arbiscan.io/address/0x286e1FE1c323EE626bE802b13a5184b588eD14Cb) |
|:------------|:-----|
| `HandlerV1` | [`0x13c4e685DF2Bba9d2006db70F44d93bAE246Ea76`](https://sepolia.arbiscan.io/address/0x13c4e685DF2Bba9d2006db70F44d93bAE246Ea76) |
| `PingModule` | [`0x0A7175d240fe71C8AEa0D1D7467bF03C6E217C50`](https://sepolia.arbiscan.io/address/0x0A7175d240fe71C8AEa0D1D7467bF03C6E217C50) |
| `PingModule` | [`0x1aD48ADeD62e7C685dF4fb75e6d14d34C8B83081`](https://sepolia.arbiscan.io/address/0x1aD48ADeD62e7C685dF4fb75e6d14d34C8B83081) |
| `TokenGateway` | [`0xFb5de9d7908F4407B239129c57B53c67BF645BAa`](https://sepolia.arbiscan.io/address/0xFb5de9d7908F4407B239129c57B53c67BF645BAa) |
| `TokenFaucet` | [`0x17d8cc0859fbA942A7af243c3EBB69AbBfe0a320`](https://sepolia.arbiscan.io/address/0x17d8cc0859fbA942A7af243c3EBB69AbBfe0a320) |
| `FeeToken (USD.h)` | [`0x146760fDDF18a228BB4dA1c4c63c820Dab171D03`](https://sepolia.arbiscan.io/address/0x146760fDDF18a228BB4dA1c4c63c820Dab171D03) |
Expand All @@ -34,7 +34,7 @@ The current testnet environment for the Hyperbridge network.
| `IsmpHost` | [`0x625c531a56DB772CC36313d0A0114956aD8b56c2`](https://sepolia-optimism.etherscan.io/address/0x625c531a56DB772CC36313d0A0114956aD8b56c2) |
|:------------|:-----|
| `HandlerV1` | [`0xd5cB7a7971Ec9455B90F65ee1d941D4e5b5e1ff0`](https://sepolia-optimism.etherscan.io/address/0xd5cB7a7971Ec9455B90F65ee1d941D4e5b5e1ff0) |
| `PingModule` | [`0x0A7175d240fe71C8AEa0D1D7467bF03C6E217C50`](https://sepolia-optimism.etherscan.io/address/0x0A7175d240fe71C8AEa0D1D7467bF03C6E217C50) |
| `PingModule` | [`0x1aD48ADeD62e7C685dF4fb75e6d14d34C8B83081`](https://sepolia-optimism.etherscan.io/address/0x1aD48ADeD62e7C685dF4fb75e6d14d34C8B83081) |
| `TokenGateway` | [`0xFb5de9d7908F4407B239129c57B53c67BF645BAa`](https://sepolia-optimism.etherscan.io/address/0xFb5de9d7908F4407B239129c57B53c67BF645BAa) |
| `TokenFaucet` | [`0x17d8cc0859fbA942A7af243c3EBB69AbBfe0a320`](https://sepolia-optimism.etherscan.io/address/0x17d8cc0859fbA942A7af243c3EBB69AbBfe0a320) |
| `FeeToken (USD.h)` | [`0x146760fDDF18a228BB4dA1c4c63c820Dab171D03`](https://sepolia-optimism.etherscan.io/address/0x146760fDDF18a228BB4dA1c4c63c820Dab171D03) |
Expand All @@ -45,7 +45,7 @@ The current testnet environment for the Hyperbridge network.
| `IsmpHost` | [`0xae9f490EE05588fDD857A078cFC1f5f30ae7185f`](https://sepolia.basescan.org/address/0xae9f490EE05588fDD857A078cFC1f5f30ae7185f) |
|:------------|:-----|
| `HandlerV1` | [`0x2C00a1A42666d42F981E19b633c8d0198149ed36`](https://sepolia.basescan.org/address/0x2C00a1A42666d42F981E19b633c8d0198149ed36) |
| `PingModule` | [`0x0A7175d240fe71C8AEa0D1D7467bF03C6E217C50`](https://sepolia.basescan.org/address/0x0A7175d240fe71C8AEa0D1D7467bF03C6E217C50) |
| `PingModule` | [`0x1aD48ADeD62e7C685dF4fb75e6d14d34C8B83081`](https://sepolia.basescan.org/address/0x1aD48ADeD62e7C685dF4fb75e6d14d34C8B83081) |
| `TokenGateway` | [`0xFb5de9d7908F4407B239129c57B53c67BF645BAa`](https://sepolia.basescan.org/address/0xFb5de9d7908F4407B239129c57B53c67BF645BAa) |
| `TokenFaucet` | [`0x17d8cc0859fbA942A7af243c3EBB69AbBfe0a320`](https://sepolia.basescan.org/address/0x17d8cc0859fbA942A7af243c3EBB69AbBfe0a320) |
| `FeeToken (USD.h)` | [`0x146760fDDF18a228BB4dA1c4c63c820Dab171D03`](https://sepolia.basescan.org/address/0x146760fDDF18a228BB4dA1c4c63c820Dab171D03) |
Expand All @@ -56,7 +56,7 @@ The current testnet environment for the Hyperbridge network.
| `IsmpHost` | [`0xeB8977EDCdA5FaBDcDdEB39861Df25E8821a9e9b`](https://testnet.bscscan.com/address/0xeB8977EDCdA5FaBDcDdEB39861Df25E8821a9e9b) |
|:------------|:-----|
| `HandlerV1` | [`0x5A8B2dA2994dD818c6C3329E2c1d7cc52C863723`](https://testnet.bscscan.com/address/0x5A8B2dA2994dD818c6C3329E2c1d7cc52C863723) |
| `PingModule` | [`0x0A7175d240fe71C8AEa0D1D7467bF03C6E217C50`](https://testnet.bscscan.com/address/0x0A7175d240fe71C8AEa0D1D7467bF03C6E217C50) |
| `PingModule` | [`0x1aD48ADeD62e7C685dF4fb75e6d14d34C8B83081`](https://testnet.bscscan.com/address/0x1aD48ADeD62e7C685dF4fb75e6d14d34C8B83081) |
| `TokenGateway` | [`0xFb5de9d7908F4407B239129c57B53c67BF645BAa`](https://testnet.bscscan.com/address/0xFb5de9d7908F4407B239129c57B53c67BF645BAa) |
| `TokenFaucet` | [`0x17d8cc0859fbA942A7af243c3EBB69AbBfe0a320`](https://testnet.bscscan.com/address/0x17d8cc0859fbA942A7af243c3EBB69AbBfe0a320) |
| `FeeToken (USD.h)` | [`0x146760fDDF18a228BB4dA1c4c63c820Dab171D03`](https://testnet.bscscan.com/address/0x146760fDDF18a228BB4dA1c4c63c820Dab171D03) |
Expand Down
33 changes: 24 additions & 9 deletions evm/abi/src/generated/ping_module.rs

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions evm/examples/PingModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "@polytope-labs/ismp-solidity/StateMachine.sol";
import "@polytope-labs/ismp-solidity/Message.sol";
import "@polytope-labs/ismp-solidity/IDispatcher.sol";
import {IERC20} from "openzeppelin/token/ERC20/IERC20.sol";
import {StorageValue} from "@polytope-labs/solidity-merkle-trees/Types.sol";

struct PingMessage {
bytes dest;
Expand All @@ -24,7 +25,7 @@ contract PingModule is IIsmpModule {
using Message for GetRequest;

event PostResponseReceived();
event GetResponseReceived();
event GetResponseReceived(StorageValue[] message);
event PostRequestTimeoutReceived();
event PostResponseTimeoutReceived();
event GetTimeoutReceived();
Expand Down Expand Up @@ -166,8 +167,8 @@ contract PingModule is IIsmpModule {
emit PostResponseReceived();
}

function onGetResponse(IncomingGetResponse memory) external onlyIsmpHost {
emit GetResponseReceived();
function onGetResponse(IncomingGetResponse memory response) external onlyIsmpHost {
emit GetResponseReceived(response.response.values);
}

function onGetTimeout(GetRequest memory) external onlyIsmpHost {
Expand Down
16 changes: 9 additions & 7 deletions modules/consensus/bsc/prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
mod test;

use anyhow::anyhow;
use bsc_verifier::primitives::{compute_epoch, parse_extra, BscClientUpdate, EPOCH_LENGTH};
use bsc_verifier::primitives::{compute_epoch, parse_extra, BscClientUpdate, Config, EPOCH_LENGTH};
use ethers::{
prelude::Provider,
providers::{Http, Middleware},
Expand All @@ -11,19 +11,21 @@ use ethers::{
use geth_primitives::CodecHeader;
use ismp::messaging::Keccak256;
use sp_core::H256;
use std::{fmt::Debug, sync::Arc};
use std::{fmt::Debug, marker::PhantomData, sync::Arc};
use sync_committee_primitives::constants::BlsPublicKey;
use tracing::{instrument, trace};

#[derive(Clone)]
pub struct BscPosProver {
pub struct BscPosProver<C: Config> {
/// Execution Rpc client
pub client: Arc<Provider<Http>>,
/// Phamtom data
_phantom_data: PhantomData<C>,
}

impl BscPosProver {
impl<C: Config> BscPosProver<C> {
pub fn new(client: Provider<Http>) -> Self {
Self { client: Arc::new(client) }
Self { client: Arc::new(client), _phantom_data: PhantomData }
}

pub async fn fetch_header<T: Into<BlockId> + Send + Sync + Debug + Copy>(
Expand Down Expand Up @@ -58,7 +60,7 @@ impl BscPosProver {
fetch_val_set_change: bool,
) -> Result<Option<BscClientUpdate>, anyhow::Error> {
trace!(target: "bsc-prover", "fetching bsc update for {:?}", attested_header.number);
let parse_extra_data = parse_extra::<I>(&attested_header.extra_data)
let parse_extra_data = parse_extra::<I, C>(&attested_header)
.map_err(|_| anyhow!("Extra data not found in header {:?}", attested_header.number))?;
let source_hash = H256::from_slice(&parse_extra_data.vote_data.source_hash.0);
let target_hash = H256::from_slice(&parse_extra_data.vote_data.target_hash.0);
Expand Down Expand Up @@ -129,7 +131,7 @@ impl BscPosProver {
self.fetch_header(current_epoch_block_number).await?.ok_or_else(|| {
anyhow!("header block could not be fetched {current_epoch_block_number}")
})?;
let current_epoch_extra_data = parse_extra::<I>(&current_epoch_header.extra_data)
let current_epoch_extra_data = parse_extra::<I, C>(&current_epoch_header)
.map_err(|_| anyhow!("Extra data set not found in header"))?;

let current_validators = current_epoch_extra_data
Expand Down
8 changes: 4 additions & 4 deletions modules/consensus/bsc/prover/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bsc_verifier::{
primitives::{compute_epoch, EPOCH_LENGTH},
primitives::{compute_epoch, Testnet, EPOCH_LENGTH},
verify_bsc_header, NextValidators,
};
use ethers::{
Expand All @@ -23,7 +23,7 @@ impl Keccak256 for Host {
}
}

async fn setup_prover() -> BscPosProver {
async fn setup_prover() -> BscPosProver<Testnet> {
dotenv::dotenv().ok();
let consensus_url = std::env::var("BSC_URL").unwrap();
let mut provider = Provider::<Http>::connect(&consensus_url).await;
Expand Down Expand Up @@ -76,7 +76,7 @@ async fn verify_bsc_pos_headers() {
update.attested_header.number.low_u64() % EPOCH_LENGTH >=
(validators.len() as u64 / 2)
{
let result = verify_bsc_header::<Host>(
let result = verify_bsc_header::<Host, Testnet>(
&next_validators.clone().unwrap().validators,
update.clone(),
);
Expand All @@ -88,7 +88,7 @@ async fn verify_bsc_pos_headers() {
continue;
}
}
let result = verify_bsc_header::<Host>(&validators, update.clone()).unwrap();
let result = verify_bsc_header::<Host, Testnet>(&validators, update.clone()).unwrap();
dbg!(&result.hash);
dbg!(result.next_validators.is_some());
if let Some(validators) = result.next_validators {
Expand Down
10 changes: 5 additions & 5 deletions modules/consensus/bsc/verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use alloc::vec::Vec;
use anyhow::anyhow;
use ark_ec::AffineRepr;
use ismp::messaging::Keccak256;
use primitives::{parse_extra, BscClientUpdate, EPOCH_LENGTH, VALIDATOR_BIT_SET_SIZE};
use primitives::{parse_extra, BscClientUpdate, Config, EPOCH_LENGTH, VALIDATOR_BIT_SET_SIZE};
use sp_core::H256;
use sync_committee_verifier::crypto::{pairing, pubkey_to_projective};
pub mod primitives;
Expand Down Expand Up @@ -33,11 +33,11 @@ pub struct NextValidators {
pub rotation_block: u64,
}

pub fn verify_bsc_header<H: Keccak256>(
pub fn verify_bsc_header<H: Keccak256, C: Config>(
current_validators: &Vec<BlsPublicKey>,
update: BscClientUpdate,
) -> Result<VerificationResult, anyhow::Error> {
let extra_data = parse_extra::<H>(&update.attested_header.extra_data)
let extra_data = parse_extra::<H, C>(&update.attested_header)
.map_err(|_| anyhow!("could not parse extra data from header"))?;
let source_hash = H256::from_slice(&extra_data.vote_data.source_hash.0);
let target_hash = H256::from_slice(&extra_data.vote_data.target_hash.0);
Expand Down Expand Up @@ -95,7 +95,7 @@ pub fn verify_bsc_header<H: Keccak256>(
Err(anyhow!("Epoch ancestry submitted is invalid"))?
}
let epoch_header = update.epoch_header_ancestry[0].clone();
let epoch_header_extra_data = parse_extra::<H>(&epoch_header.extra_data)
let epoch_header_extra_data = parse_extra::<H, C>(&epoch_header)
.map_err(|_| anyhow!("could not parse extra data from epoch header"))?;
let validators = epoch_header_extra_data
.validators
Expand All @@ -116,7 +116,7 @@ pub fn verify_bsc_header<H: Keccak256>(
}
// If the source header that was finalized is the epoch header we extract the next validator set
} else if update.source_header.number.low_u64() % EPOCH_LENGTH == 0 {
let epoch_header_extra_data = parse_extra::<H>(&update.source_header.extra_data)
let epoch_header_extra_data = parse_extra::<H, C>(&update.source_header)
.map_err(|_| anyhow!("could not parse extra data from epoch header"))?;
let validators = epoch_header_extra_data
.validators
Expand Down
42 changes: 38 additions & 4 deletions modules/consensus/bsc/verifier/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,30 @@ const BLS_PUBLIC_KEY_LENGTH: usize = 48;
const VALIDATOR_BYTES_LENGTH: usize = 20 + BLS_PUBLIC_KEY_LENGTH;
const VALIDATOR_NUMBER_SIZE: usize = 1; // // Fixed number of extra prefix bytes reserved for validator number after Luban
const ADDRESS_LENGTH: usize = 20;
const TURN_LENGTH_SIZE: usize = 1;
pub const VALIDATOR_BIT_SET_SIZE: usize = 64;

/// This trait should be used to host parameters that could be potentially be different for mainnet
/// and testnet and affect how headers are verified
pub trait Config: Clone + Send + Sync {
/// Timestamp at which the BOHR fork occured
const BOHR_FORK_TIMESTAMP: u64;
}

#[derive(Clone, Default)]
pub struct Testnet;

#[derive(Clone, Default)]
pub struct Mainnet;

impl Config for Testnet {
const BOHR_FORK_TIMESTAMP: u64 = 1724116996;
}

impl Config for Mainnet {
const BOHR_FORK_TIMESTAMP: u64 = u64::MAX;
}

#[derive(Debug, Encode, Decode, Clone)]
pub struct BscClientUpdate {
/// Finalized header
Expand Down Expand Up @@ -68,8 +90,10 @@ pub struct VoteData {
pub target_hash: B256,
}

pub fn parse_extra<H: Keccak256>(extra_data: &[u8]) -> Result<ExtraData, anyhow::Error> {
let data = extra_data;
pub fn parse_extra<H: Keccak256, C: Config>(
header: &CodecHeader,
) -> Result<ExtraData, anyhow::Error> {
let data = header.extra_data.as_slice();

let mut extra = ExtraData {
extra_vanity: Vec::new(),
Expand All @@ -86,7 +110,7 @@ pub fn parse_extra<H: Keccak256>(extra_data: &[u8]) -> Result<ExtraData, anyhow:
vote_address_set: 0,
};

if extra_data.len() < EXTRA_VANITY_LENGTH + EXTRA_SEAL_LENGTH {
if data.len() < EXTRA_VANITY_LENGTH + EXTRA_SEAL_LENGTH {
Err(anyhow!("Invalid extra data"))?;
}

Expand Down Expand Up @@ -126,7 +150,17 @@ pub fn parse_extra<H: Keccak256>(extra_data: &[u8]) -> Result<ExtraData, anyhow:
extra.validators.push(validator_info);
}
extra.validators.sort_by(|a, b| a.address.0.cmp(&b.address.0));
data = &remaining_data[validator_bytes_total_length - VALIDATOR_NUMBER_SIZE..];

// Check for BOHR fork
data = if header.timestamp >= C::BOHR_FORK_TIMESTAMP {
// In Bohr fork there is an extra byte for turn
// https://github.com/bnb-chain/bsc/blob/26a4d4fda656cc78436c1931aaea5dc3ed33eeeb/consensus/parlia/parlia.go#L383
let index = validator_bytes_total_length - VALIDATOR_NUMBER_SIZE + TURN_LENGTH_SIZE;
&remaining_data[index..]
} else {
let index = validator_bytes_total_length - VALIDATOR_NUMBER_SIZE;
&remaining_data[index..]
};
data_length = data.len();
}

Expand Down
16 changes: 11 additions & 5 deletions modules/hyperclient/hyperclient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ interface IGetRequest {
/// `<https://github.com/paritytech/substrate/blob/master/frame/support/src/storage/types/value.rs#L37>`
/// For fetching keys from EVM contracts each key should be 52 bytes
/// This should be a concatenation of contract address and slot hash
keys: string[];
keys: `0x{string}`[];
// Timestamp which this request expires in seconds.
timeoutTimestamp: bigint;
// Height at which this request was emitted on the source
Expand Down Expand Up @@ -276,19 +276,25 @@ export class HyperClient {
* @param {IPostRequest} request
* @returns {Promise<MessageStatusWithMeta>}
*/
query_post_request_status(request: IPostRequest): Promise<MessageStatusWithMeta>;
query_post_request_status(
request: IPostRequest,
): Promise<MessageStatusWithMeta>;
/**
* Queries the status of a request and returns `MessageStatusWithMetadata`
* @param {IGetRequest} request
* @returns {Promise<any>}
*/
query_get_request_status(request: IGetRequest): Promise<MessageStatusWithMeta>;
query_get_request_status(
request: IGetRequest,
): Promise<MessageStatusWithMeta>;
/**
* Accepts a post response and returns a `MessageStatusWithMetadata`
* @param {IPostResponse} response
* @returns {Promise<MessageStatusWithMeta>}
*/
query_post_response_status(response: IPostResponse): Promise<MessageStatusWithMeta>;
query_post_response_status(
response: IPostResponse,
): Promise<MessageStatusWithMeta>;
/**
* Return the status of a post request as a `ReadableStream` that yields
* `MessageStatusWithMeta`
Expand All @@ -306,7 +312,7 @@ export class HyperClient {
* @returns {Promise<ReadableStream<MessageStatusWithMeta>>}
*/
get_request_status_stream(
request: IGetRequest
request: IGetRequest,
): Promise<ReadableStream<MessageStatusWithMeta>>;

/**
Expand Down
2 changes: 1 addition & 1 deletion modules/hyperclient/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@polytope-labs/hyperclient",
"description": "The hyperclient is a library for managing (in-flight) ISMP requests",
"version": "0.6.0",
"version": "0.4.3",
"author": "Polytope Labs (hello@polytope.technology)",
"license": "Apache-2.0",
"bugs": {
Expand Down
11 changes: 9 additions & 2 deletions modules/hyperclient/src/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,17 @@ impl TryFrom<JsClientConfig> for ClientConfig {
fn try_from(value: JsClientConfig) -> Result<Self, Self::Error> {
let to_config = |val: &JsChainConfig| {
if !val.host_address.is_empty() {
let state_machine = if val.state_machine.starts_with("0x") {
let bytes =
from_hex(&val.state_machine).map_err(|err| anyhow!("Hex: {err:?}"))?;
StateMachine::from_str(&String::from_utf8(bytes)?)
.map_err(|e| anyhow!("{e:?}"))?
} else {
StateMachine::from_str(&val.state_machine).map_err(|e| anyhow!("{e:?}"))?
};
let conf = EvmConfig {
rpc_url: val.rpc_url.clone(),
state_machine: StateMachine::from_str(&val.state_machine)
.map_err(|e| anyhow!("{e:?}"))?,
state_machine,
host_address: {
let address = from_hex(&val.host_address)?;
if address.len() != 20 {
Expand Down
Loading

0 comments on commit 07dd5b7

Please sign in to comment.