Skip to content

Commit

Permalink
Enable Wasmtime and Remove secp256k1 (#593)
Browse files Browse the repository at this point in the history
Co-authored-by: Hernando Castano <castano.ha@gmail.com>
  • Loading branch information
2 people authored and bkchr committed Apr 10, 2024
1 parent 5e4358a commit 595481f
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 31 deletions.
2 changes: 1 addition & 1 deletion bridges/bin/millau/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pallet-message-lane-rpc = { path = "../../../modules/message-lane/rpc" }
frame-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sc-basic-authorship = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sc-cli = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sc-cli = { git = "https://github.com/paritytech/substrate.git", branch = "master", features = ["wasmtime"] }
sc-client-api = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sc-consensus = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sc-consensus-aura = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
Expand Down
2 changes: 1 addition & 1 deletion bridges/bin/rialto/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ rialto-runtime = { path = "../runtime" }
frame-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sc-basic-authorship = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sc-cli = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sc-cli = { git = "https://github.com/paritytech/substrate.git", branch = "master", features = ["wasmtime"] }
sc-client-api = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sc-consensus = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sc-consensus-aura = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
Expand Down
8 changes: 4 additions & 4 deletions bridges/relays/ethereum-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ edition = "2018"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[dependencies]
bp-eth-poa = { path = "../../primitives/ethereum-poa" }
codec = { package = "parity-scale-codec", version = "1.3.4" }
ethereum-tx-sign = "3.0"
headers-relay = { path = "../headers-relay" }
hex = "0.4"
hex-literal = "0.3"
jsonrpsee = { git = "https://github.com/svyatonik/jsonrpsee.git", branch = "shared-client-in-rpc-api", default-features = false, features = ["http"] }
libsecp256k1 = { version = "0.3.4", default-features = false, features = ["hmac"] }
log = "0.4.11"
parity-crypto = { version = "0.6", features = ["publickey"] }
relay-utils = { path = "../utils" }
web3 = "0.13"
web3 = { version = "0.14", default-features = false }
22 changes: 11 additions & 11 deletions bridges/relays/ethereum-client/src/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@

use crate::types::{Address, CallRequest, U256};
use crate::{Client, Result};

use parity_crypto::publickey::KeyPair;
use bp_eth_poa::signatures::{secret_to_address, SignTransaction};
use hex_literal::hex;
use secp256k1::SecretKey;

/// Ethereum signing params.
#[derive(Clone, Debug)]
pub struct SigningParams {
/// Ethereum chain id.
pub chain_id: u64,
/// Ethereum transactions signer.
pub signer: KeyPair,
pub signer: SecretKey,
/// Gas price we agree to pay.
pub gas_price: U256,
}
Expand All @@ -37,10 +38,9 @@ impl Default for SigningParams {
// account that has a lot of ether when we run instant seal engine
// address: 0x00a329c0648769a73afac7f9381e08fb43dbea72
// secret: 0x4d5db4107d237df6a3d58ee5f70ae63d73d7658d4026f2eefd2f204c81682cb7
signer: KeyPair::from_secret_slice(
&hex::decode("4d5db4107d237df6a3d58ee5f70ae63d73d7658d4026f2eefd2f204c81682cb7")
.expect("secret is hardcoded, thus valid; qed"),
)
signer: SecretKey::parse(&hex!(
"4d5db4107d237df6a3d58ee5f70ae63d73d7658d4026f2eefd2f204c81682cb7"
))
.expect("secret is hardcoded, thus valid; qed"),
gas_price: 8_000_000_000u64.into(), // 8 Gwei
}
Expand All @@ -59,7 +59,7 @@ pub async fn sign_and_submit_transaction(
let nonce = if let Some(n) = nonce {
n
} else {
let address: Address = params.signer.address().as_fixed_bytes().into();
let address: Address = secret_to_address(&params.signer);
client.account_nonce(address).await?
};

Expand All @@ -70,15 +70,15 @@ pub async fn sign_and_submit_transaction(
};
let gas = client.estimate_gas(call_request).await?;

let raw_transaction = ethereum_tx_sign::RawTransaction {
let raw_transaction = bp_eth_poa::UnsignedTransaction {
nonce,
to: contract_address,
value: U256::zero(),
gas: if double_gas { gas.saturating_mul(2.into()) } else { gas },
gas_price: params.gas_price,
data: encoded_call,
payload: encoded_call,
}
.sign(&params.signer.secret().as_fixed_bytes().into(), &params.chain_id);
.sign_by(&params.signer, Some(params.chain_id));

let _ = client.submit_transaction(raw_transaction).await?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion bridges/relays/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ ethabi-derive = "12.0"
futures = "0.3.8"
hex = "0.4"
hex-literal = "0.3"
libsecp256k1 = { version = "0.3.4", default-features = false, features = ["hmac"] }
log = "0.4.11"
num-traits = "0.2"
parity-crypto = { version = "0.6", features = ["publickey"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.60"
time = "0.2"
Expand Down
3 changes: 2 additions & 1 deletion bridges/relays/ethereum/src/ethereum_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::rpc_errors::RpcError;
use crate::substrate_sync_loop::QueuedRialtoHeader;

use async_trait::async_trait;
use bp_eth_poa::signatures::secret_to_address;
use codec::{Decode, Encode};
use ethabi::FunctionOutputDecoder;
use headers_relay::sync_types::SubmittedHeaders;
Expand Down Expand Up @@ -134,7 +135,7 @@ impl EthereumHighLevelRpc for EthereumClient {
headers: Vec<QueuedRialtoHeader>,
) -> SubmittedHeaders<RialtoHeaderId, RpcError> {
// read nonce of signer
let address: Address = params.signer.address().as_fixed_bytes().into();
let address: Address = secret_to_address(&params.signer);
let nonce = match self.account_nonce(address).await {
Ok(nonce) => nonce,
Err(error) => {
Expand Down
12 changes: 5 additions & 7 deletions bridges/relays/ethereum/src/ethereum_exchange_submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! Submitting Ethereum -> Substrate exchange transactions.

use bp_eth_poa::{
signatures::{SecretKey, SignTransaction},
signatures::{secret_to_address, SignTransaction},
UnsignedTransaction,
};
use relay_ethereum_client::{
Expand Down Expand Up @@ -56,7 +56,7 @@ pub fn run(params: EthereumExchangeSubmitParams) {
let result: Result<_, String> = local_pool.run_until(async move {
let eth_client = EthereumClient::new(eth_params);

let eth_signer_address = eth_sign.signer.address();
let eth_signer_address = secret_to_address(&eth_sign.signer);
let sub_recipient_encoded = sub_recipient;
let nonce = match eth_nonce {
Some(eth_nonce) => eth_nonce,
Expand All @@ -83,11 +83,9 @@ pub fn run(params: EthereumExchangeSubmitParams) {
value: eth_amount,
payload: sub_recipient_encoded.to_vec(),
};
let eth_tx_signed = eth_tx_unsigned.clone().sign_by(
&SecretKey::parse(eth_sign.signer.secret().as_fixed_bytes())
.expect("key is accepted by secp256k1::KeyPair and thus is valid; qed"),
Some(eth_sign.chain_id),
);
let eth_tx_signed = eth_tx_unsigned
.clone()
.sign_by(&eth_sign.signer, Some(eth_sign.chain_id));
eth_client
.submit_transaction(eth_tx_signed)
.await
Expand Down
9 changes: 4 additions & 5 deletions bridges/relays/ethereum/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ use ethereum_sync_loop::EthereumSyncParams;
use headers_relay::sync::TargetTransactionMode;
use hex_literal::hex;
use instances::{BridgeInstance, Kovan, RialtoPoA};
use parity_crypto::publickey::{KeyPair, Secret};
use relay_utils::{initialize::initialize_relay, metrics::MetricsParams};
use secp256k1::SecretKey;
use sp_core::crypto::Pair;
use substrate_sync_loop::SubstrateSyncParams;

Expand Down Expand Up @@ -134,10 +134,9 @@ fn ethereum_connection_params(matches: &clap::ArgMatches) -> Result<EthereumConn
fn ethereum_signing_params(matches: &clap::ArgMatches) -> Result<EthereumSigningParams, String> {
let mut params = EthereumSigningParams::default();
if let Some(eth_signer) = matches.value_of("eth-signer") {
params.signer = eth_signer
.parse::<Secret>()
.map_err(|e| format!("Failed to parse eth-signer: {}", e))
.and_then(|secret| KeyPair::from_secret(secret).map_err(|e| format!("Invalid eth-signer: {}", e)))?;
params.signer =
SecretKey::parse_slice(&hex::decode(eth_signer).map_err(|e| format!("Failed to parse eth-signer: {}", e))?)
.map_err(|e| format!("Invalid eth-signer: {}", e))?;
}
if let Some(eth_chain_id) = matches.value_of("eth-chain-id") {
params.chain_id = eth_chain_id
Expand Down

0 comments on commit 595481f

Please sign in to comment.