Skip to content

Commit

Permalink
Merge pull request #17 from 3ierratango/use-eth-salt-values
Browse files Browse the repository at this point in the history
[fix] use eth block values for finalising
  • Loading branch information
naiemk committed Jan 20, 2023
2 parents c0f14c7 + 22a42bd commit bec36a8
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 52 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions alice_node_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
"networks": {
"network_vec": [{
"url": "https://rpc-mumbai.maticvigil.com/",
"ledger_manager": "A8B001Ff4191F5e0D6b5DD15b8D466d8546d214b",
"ledger_manager": "1AC9Fb66D542FEe49728e0da6af230dbECD6d547",
"id": 80001
},
{
"url": "https://data-seed-prebsc-1-s1.binance.org:8545",
"ledger_manager": "A8B001Ff4191F5e0D6b5DD15b8D466d8546d214b",
"url": "https://data-seed-prebsc-2-s3.binance.org:8545",
"ledger_manager": "1AC9Fb66D542FEe49728e0da6af230dbECD6d547",
"id": 97
}],
"pair_vec": [[80001, 97], [97, 80001]],
"signer_public_key": "020a1091341fe5664bfa1782d5e04779689068c916b04cb365ec3153755684d9a1",
"authority_manager_contract_name" : "FERRUM_QUANTUM_PORTAL_AUTHORITY_MGR",
"authority_manager_contract_version" : "000.010",
"authority_manager_contract_address" : "7cD4f4B67A2cB13f46E70b37F79da1942572029E",
"role" : "QP_MINER"
"authority_manager_contract_address" : "6036F77264bbbe1Fd601C773F21a9486313a70ec",
"role" : "QP_FINALIZER"
}
}
10 changes: 5 additions & 5 deletions bob_node_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
"networks": {
"network_vec": [{
"url": "https://rpc-mumbai.maticvigil.com/",
"ledger_manager": "A8B001Ff4191F5e0D6b5DD15b8D466d8546d214b",
"ledger_manager": "1AC9Fb66D542FEe49728e0da6af230dbECD6d547",
"id": 80001
},
{
"url": "https://data-seed-prebsc-1-s1.binance.org:8545",
"ledger_manager": "A8B001Ff4191F5e0D6b5DD15b8D466d8546d214b",
"url": "https://data-seed-prebsc-2-s3.binance.org:8545",
"ledger_manager": "1AC9Fb66D542FEe49728e0da6af230dbECD6d547",
"id": 97
}],
"pair_vec": [[80001, 97], [97, 80001]],
"signer_public_key": "0390084fdbf27d2b79d26a4f13f0ccd982cb755a661969143c37cbc49ef5b91f27",
"authority_manager_contract_name" : "FERRUM_QUANTUM_PORTAL_AUTHORITY_MGR",
"authority_manager_contract_version" : "000.010",
"authority_manager_contract_address" : "7cD4f4B67A2cB13f46E70b37F79da1942572029E",
"role" : "QP_MINER"
"authority_manager_contract_address" : "6036F77264bbbe1Fd601C773F21a9486313a70ec",
"role" : "QP_FINALIZER"
}
}
7 changes: 4 additions & 3 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ name = "ferrum-x-network"

[dependencies]
async-trait = "0.1"
bincode = "1.3.3"
clap = { version = "3.2", features = ["derive"] }
futures = "0.3.24"
libsecp256k1 = { version = "0.7.0", default-features = false, features = ['static-context'] }
log = "0.4.17"
serde = { version = "1.0", features = ["derive"] }
serde_bytes = "0.11"
serde_json = "1.0"
libsecp256k1 = { version = "0.7.0", default-features = false, features = ['static-context'] }
bincode = "1.3.3"

# Parity
codec = { package = "parity-scale-codec", version = "3.2.1", features = ["derive"] }
Expand All @@ -48,6 +48,7 @@ sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/subs
sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" }
sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" }
sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" }
sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30", default-features = false }
sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" }
sp-consensus-aura = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" }
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" }
Expand Down Expand Up @@ -86,9 +87,9 @@ frame-benchmarking = { version = "4.0.0-dev", git = "https://github.com/parityte
frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30", optional = true }

# Local Dependencies
ferrum-primitives = { path = "../primitives" }
ferrum-x-runtime = { path = "../runtime" }
pallet-quantum-portal = { path = "../pallets/quantum-portal" }
ferrum-primitives = { path = "../primitives" }

# CLI-specific dependencies
try-runtime-cli = { version = "0.10.0-dev", optional = true, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" }
Expand Down
11 changes: 4 additions & 7 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ use sc_service::ChainType;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{Pair, Public, H160, U256};
use sp_finality_grandpa::AuthorityId as GrandpaId;
use std::{collections::BTreeMap, path::PathBuf, str::FromStr};
use std::{collections::BTreeMap, str::FromStr};

use crate::{
cli::Cli,
config::{convert, Config, NetworkConfig},
};
use crate::cli::Cli;

// The URL for the telemetry server.
// const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
Expand Down Expand Up @@ -47,7 +44,7 @@ pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
(get_from_seed::<AuraId>(s), get_from_seed::<GrandpaId>(s))
}

pub fn development_config(cli: &Cli) -> Result<ChainSpec, String> {
pub fn development_config(_cli: &Cli) -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;

Ok(ChainSpec::from_genesis(
Expand Down Expand Up @@ -86,7 +83,7 @@ pub fn development_config(cli: &Cli) -> Result<ChainSpec, String> {
))
}

pub fn local_testnet_config(cli: &Cli) -> Result<ChainSpec, String> {
pub fn local_testnet_config(_cli: &Cli) -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;
Ok(ChainSpec::from_genesis(
// Name
Expand Down
2 changes: 1 addition & 1 deletion node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{fs::File, io::BufReader, path::Path};

use serde::{Deserialize, Serialize};

use pallet_quantum_portal::qp_types::{EIP712Config, QpConfig, QpNetworkItem, Role};
use pallet_quantum_portal::qp_types::{EIP712Config, QpConfig, QpNetworkItem};

#[derive(Deserialize, Debug, Clone)]
pub struct Config {
Expand Down
11 changes: 6 additions & 5 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ use sc_executor::NativeElseWasmExecutor;
use sc_keystore::LocalKeystore;
use sc_service::{error::Error as ServiceError, BasePath, Configuration, TaskManager};
use sc_telemetry::{Telemetry, TelemetryWorker};
use sp_core::offchain::OffchainStorage;
use sp_application_crypto::sp_core::offchain::{OffchainStorage, STORAGE_PREFIX};
use sp_core::U256;
// Frontier
use codec::Encode;
use fc_consensus::FrontierBlockImport;
use fc_db::Backend as FrontierBackend;
use fc_mapping_sync::{MappingSyncWorker, SyncStrategy};
use fc_rpc::{EthTask, OverrideHandle};
use fc_rpc_core::types::{FeeHistoryCache, FeeHistoryCacheLimit, FilterPool};
// Runtime
use crate::config::{read_config_from_file, Config};
use ferrum_primitives::{OFFCHAIN_SIGNER_CONFIG_KEY, OFFCHAIN_SIGNER_CONFIG_PREFIX};
use crate::config::read_config_from_file;
use ferrum_primitives::OFFCHAIN_SIGNER_CONFIG_KEY;
use ferrum_x_runtime::{opaque::Block, RuntimeApi};

use crate::cli::Cli;
Expand Down Expand Up @@ -176,9 +177,9 @@ pub fn new_partial(

// Load the configs for the offchain worker to function properly, we read from the file and write to the offchain storage
offchain_storage.set(
OFFCHAIN_SIGNER_CONFIG_PREFIX,
STORAGE_PREFIX,
OFFCHAIN_SIGNER_CONFIG_KEY,
&bincode::serialize(&config.networks).unwrap(),
&crate::config::convert(config.networks).encode(),
);

println!("QP Configs loaded to offchain storage");
Expand Down
4 changes: 2 additions & 2 deletions pallets/quantum-portal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ categories = [
"offchain worker",
]
[dependencies]
array-bytes = "4.1"
log = { version = "0.4.14", default-features = false }
parity-scale-codec = { default-features = false, features = ['derive'], version = '3.1.2' }
parking_lot = "0.11"
scale-info = { default-features = false, features = ['derive'], version = '2.1.2' }
serde = { version = '1.0.130', default-features = false, features = ['derive'] }
serde_json = { version = '1.0.67', default-features = false, features = ['alloc'] }
array-bytes = "4.1"

# Substrate packages
byte-slice-cast = { version = "1.2.1", default-features = false, features = [] }
ethabi-nostd = { path = "../../libraries/ethabi-nostd", default-features = false }
ethereum = { version = "0.12.0", default-features = false }
ferrum-primitives = { default-features = false, path = "../../primitives" }
frame-support = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.30" }
frame-system = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.30" }
hex = { version = "0.4.3", default-features = false }
Expand All @@ -44,7 +45,6 @@ sp-io = { git = 'https://github.com/paritytech/substrate.git', default-features
sp-runtime = { version = "6.0.0", git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.30" }
sp-std = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.30" }
tiny-keccak = { version = "2.0.2", features = ["sha3", "keccak"] }
ferrum-primitives = { default-features = false, path = "../../primitives" }

[features]
default = ['std']
Expand Down
4 changes: 2 additions & 2 deletions pallets/quantum-portal/src/chain_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use numtoa::NumToA;
use sp_std::{prelude::*, str};
use tiny_keccak::{Hasher, Keccak};

#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub enum ChainRequestError {
ErrorGettingJsonRpcResponse,
BadRemoteData,
Expand All @@ -20,7 +20,7 @@ pub enum ChainRequestError {
InvalidHexCharacter,
}

#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub enum TransactionCreationError {
NoSignerFound,
SigningFailed,
Expand Down
6 changes: 4 additions & 2 deletions pallets/quantum-portal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub mod pallet {
fn fmt(&self, fmt: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
match *self {
OffchainErr::FailedSigning => write!(fmt, "Unable to sign transaction"),
OffchainErr::RPCError(ref error) => write!(fmt, "RPC error : {:?}", error),
OffchainErr::RPCError(ref error) => write!(fmt, "RPC error : {error:?}"),
}
}
}
Expand Down Expand Up @@ -199,9 +199,11 @@ pub mod pallet {
{
if let Ok(_guard) = lock.try_lock() {
let network_config = StorageValueRef::persistent(OFFCHAIN_SIGNER_CONFIG_KEY);
//log::info!("Netweork config is {:?}", network_config);
let decoded_config = network_config.get::<QpConfig>();
log::info!("Decoded config is {:?}", decoded_config);

if let Err(e) = decoded_config {
if let Err(_e) = decoded_config {
log::info!("Error reading configuration, exiting offchain worker");
return;
}
Expand Down
1 change: 1 addition & 0 deletions pallets/quantum-portal/src/qp_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub struct EIP712Config {
pub verifying_address: Vec<u8>,
}

#[allow(non_camel_case_types)]
#[derive(
Clone,
Eq,
Expand Down
21 changes: 11 additions & 10 deletions pallets/quantum-portal/src/quantum_portal_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use crate::{
Config,
};
use ethabi_nostd::{decoder::decode, ParamKind, Token};
use frame_support::traits::Randomness;
use frame_support::traits::UnixTime;
use sp_core::{H256, U256};
use sp_std::marker::PhantomData;
use sp_std::prelude::*;
Expand Down Expand Up @@ -275,24 +273,27 @@ impl<T: Config> QuantumPortalClient<T> {
// ) ...
// The last item is a bit complicated, but for now we pass an empty array.
// Support buytes and dynamic arrays in future
let finalizer_list: Vec<Token> = vec![Token::Address(self.signer.from)];
let finalizer_list: Vec<Token> = vec![];

let method_signature = b"finalize(uint256,uint256,bytes32,address[],bytes32,uint64,bytes)";
let (block_details, _) = self.mined_block_by_nonce(remote_chain_id, block_nonce)?;

let method_signature =
b"finalizeSingleSigner(uint256,uint256,bytes32,address[],bytes32,uint64,bytes)";

// generate randomness for salt
let (random_hash, _) = T::PalletRandomness::random_seed();
// let (random_hash, _) = T::PalletRandomness::random_seed();

// let random_hash = ChainUtils::keccack(b"test1");
// log::info!("random_hash {:?}", random_hash);

let salt = Token::FixedBytes(Vec::from(random_hash.as_ref()));
let finalizer_hash = Token::FixedBytes(Vec::from(random_hash.as_ref()));
let salt = Token::FixedBytes(block_details.block_hash.as_ref().to_vec());
let finalizer_hash = Token::FixedBytes(block_details.block_hash.as_ref().to_vec());

let current_timestamp = T::Timestamp::now();
let current_timestamp = block_details.block_metadata.timestamp;
// expirt 1hr from now
let expiry_buffer = core::time::Duration::from_secs(3600u64);
let expiry_time = current_timestamp.saturating_add(expiry_buffer);
let expiry = Token::Uint(U256::from(expiry_time.as_secs()));
let expiry_time = current_timestamp.saturating_add(expiry_buffer.as_secs());
let expiry = Token::Uint(U256::from(expiry_time));

let multi_sig = self.generate_multi_signature(
remote_chain_id,
Expand Down
16 changes: 8 additions & 8 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ version = "0.1.1"
repository = 'https://github.com/ferrumnet/ferrum-x-network'

[package.metadata.docs.rs]
targets = [ "x86_64-unknown-linux-gnu" ]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
blake2-rfc = { version = "0.2.18", optional = true, default-features = false }
hex = { version = "0.4", default-features = false }
impl-serde = { version = "0.3.1", default-features = false }
libsecp256k1 = { version = "0.7", default-features = false, features = [ "hmac" ] }
libsecp256k1 = { version = "0.7", default-features = false, features = ["hmac"] }
log = "0.4"
serde = { version = "1.0.101", optional = true, default-features = false, features = [ "derive" ] }
serde = { version = "1.0.101", optional = true, default-features = false, features = ["derive"] }
sha3 = { version = "0.10", default-features = false }

# Substrate
parity-scale-codec = { version = "3.0.0", default-features = false, features = [ "derive" ] }
scale-info = { version = "2.0", default-features = false, features = [ "derive" ] }
frame-system = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false }
parity-scale-codec = { version = "3.0.0", default-features = false, features = ["derive"] }
scale-info = { version = "2.0", default-features = false, features = ["derive"] }
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false }
sp-runtime-interface = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false }

[dev-dependencies]
hex = "0.4.3"

[features]
default = [ "std" ]
default = ["std"]
std = [
"full_crypto",
"hex/std",
Expand All @@ -45,7 +45,7 @@ std = [
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"frame-system/std"
"frame-system/std",
]

full_crypto = [
Expand Down
2 changes: 1 addition & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ pallet-evm-precompile-sha3fips = { git = 'https://github.com/paritytech/frontier
pallet-evm-precompile-simple = { git = 'https://github.com/paritytech/frontier.git', default-features = false, branch = "polkadot-v0.9.30" }

# Local Dependencies
pallet-quantum-portal = { default-features = false, path = "../pallets/quantum-portal" }
ferrum-primitives = { default-features = false, path = "../primitives" }
pallet-quantum-portal = { default-features = false, path = "../pallets/quantum-portal" }

[build-dependencies]
substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" }
Expand Down
12 changes: 11 additions & 1 deletion scripts/start-local-testnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,20 @@ rm -rf ./chain
./target/release/ferrum-x-network key insert --key-type ofsg --scheme ecdsa --base-path ./chain/alice --chain ferrum-local-testnet.json --suri //Alice

# insert the signing keys for bob
./target/release/ferrum-x-network key insert --key-type ofsg --scheme ecdsa --base-path ./chain/bob --chain ferrum-local-testnet.json --suri //bob
./target/release/ferrum-x-network key insert --key-type ofsg --scheme ecdsa --base-path ./chain/bob --chain ferrum-local-testnet.json --suri //Bob

# start Alice node
./target/release/ferrum-x-network --chain ferrum-local-testnet.json --alice --base-path ./chain/alice --ws-port 9944 --config-file-path ./alice_node_config.json

# start Bob node
# ./target/release/ferrum-x-network --chain ferrum-local-testnet.json --bob --base-path ./chain/bob --ws-port 9945 --config-file-path ./bob_node_config.json


./target/release/ferrum-x-network --alice --base-path ./chain/alice --ws-port 9944 --config-file-path ./alice_node_config.json




rm -rf ./chain
./target/release/ferrum-x-network key insert --key-type ofsg --scheme ecdsa --base-path ./chain/alice --chain ferrum-local-testnet.json --suri //Alice
./target/release/ferrum-x-network key insert --key-type ofsg --scheme ecdsa --base-path ./chain/bob --chain ferrum-local-testnet.json --suri //Bob

0 comments on commit bec36a8

Please sign in to comment.