From 884659ef8f23d08464ddfa870924cc937e372155 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Fri, 25 Oct 2024 09:42:34 +0200 Subject: [PATCH 1/9] adjust guess fee to decimals --- Cargo.lock | 10 ++ Cargo.toml | 1 + app-libs/stf/Cargo.toml | 2 + app-libs/stf/src/getter.rs | 6 +- app-libs/stf/src/guess_the_number.rs | 23 ++++- app-libs/stf/src/helpers.rs | 16 +++- app-libs/stf/src/lib.rs | 2 +- enclave-runtime/Cargo.lock | 134 +++++++++++++++------------ 8 files changed, 125 insertions(+), 69 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 30cb6c717..3fa260b4e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2794,6 +2794,15 @@ dependencies = [ "substrate-api-client", ] +[[package]] +name = "ita-parentchain-specs" +version = "0.1.0" +dependencies = [ + "hex", + "itp-types", + "log 0.4.20", +] + [[package]] name = "ita-sgx-runtime" version = "0.9.0" @@ -2826,6 +2835,7 @@ dependencies = [ "base58", "frame-support", "frame-system", + "ita-parentchain-specs", "ita-sgx-runtime", "itp-hashing", "itp-node-api", diff --git a/Cargo.toml b/Cargo.toml index 53bd4f0bd..dbf8554cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ resolver = "2" members = [ "app-libs/oracle", "app-libs/parentchain-interface", + "app-libs/parentchain-specs", "app-libs/sgx-runtime", "app-libs/sgx-runtime/pallets/parentchain", "app-libs/sgx-runtime/pallets/guess-the-number", diff --git a/app-libs/stf/Cargo.toml b/app-libs/stf/Cargo.toml index 418e2602e..a1c042668 100644 --- a/app-libs/stf/Cargo.toml +++ b/app-libs/stf/Cargo.toml @@ -16,6 +16,7 @@ sgx_tstd = { branch = "master", features = ["untrusted_fs", "net", "backtrace"], # local crates ita-sgx-runtime = { default-features = false, path = "../sgx-runtime" } +ita-parentchain-specs = { default-features = false, path = "../parentchain-specs" } itp-hashing = { default-features = false, path = "../../core-primitives/hashing" } itp-node-api = { default-features = false, path = "../../core-primitives/node-api" } itp-node-api-metadata = { default-features = false, path = "../../core-primitives/node-api/metadata" } @@ -61,6 +62,7 @@ std = [ "rlp/std", # local "ita-sgx-runtime/std", + "ita-parentchain-specs/std", "itp-hashing/std", "itp-sgx-externalities/std", "itp-stf-interface/std", diff --git a/app-libs/stf/src/getter.rs b/app-libs/stf/src/getter.rs index a478067b5..c65516f59 100644 --- a/app-libs/stf/src/getter.rs +++ b/app-libs/stf/src/getter.rs @@ -38,7 +38,7 @@ use crate::evm_helpers::{get_evm_account, get_evm_account_codes, get_evm_account use crate::{ guess_the_number::{GuessTheNumberPublicGetter, GuessTheNumberTrustedGetter}, - helpers::{shard_vault, wrap_bytes}, + helpers::{shielding_target, wrap_bytes}, }; use itp_sgx_runtime_primitives::types::Moment; use itp_stf_primitives::traits::PoolTransactionValidation; @@ -272,9 +272,7 @@ impl ExecuteGetter for PublicGetter { integritee, target_a, target_b, - shielding_target: shard_vault() - .map(|v| v.1) - .unwrap_or(ParentchainId::Integritee), + shielding_target: shielding_target(), }; Some(parentchains_info.encode()) }, diff --git a/app-libs/stf/src/guess_the_number.rs b/app-libs/stf/src/guess_the_number.rs index 44fcb7d24..14067ace7 100644 --- a/app-libs/stf/src/guess_the_number.rs +++ b/app-libs/stf/src/guess_the_number.rs @@ -1,15 +1,22 @@ -use crate::helpers::enclave_signer_account; +use crate::helpers::{enclave_signer_account, shielding_target, shielding_target_genesis_hash}; #[cfg(not(feature = "std"))] use alloc::format; use codec::{Decode, Encode}; use frame_support::dispatch::UnfilteredDispatchable; -use ita_sgx_runtime::{GuessTheNumber, GuessType, Runtime, System}; +use ita_parentchain_specs::MinimalChainSpec; +use ita_sgx_runtime::{ + GuessTheNumber, GuessType, ParentchainIntegritee, ParentchainTargetA, ParentchainTargetB, + Runtime, System, +}; use itp_node_api::metadata::provider::AccessNodeMetadata; use itp_node_api_metadata::NodeMetadataTrait; use itp_sgx_runtime_primitives::types::{Balance, Moment}; use itp_stf_interface::{ExecuteCall, ExecuteGetter}; use itp_stf_primitives::error::StfError; -use itp_types::{parentchain::ParentchainCall, AccountId}; +use itp_types::{ + parentchain::{ParentchainCall, ParentchainId}, + AccountId, +}; use itp_utils::stringify::account_id_to_string; use log::{debug, info, trace}; use sp_runtime::MultiAddress; @@ -66,6 +73,7 @@ where _calls: &mut Vec, _node_metadata_repo: Arc, ) -> Result<(), Self::Error> { + let fee = get_fee_for(&self); match self { Self::set_winnings(sender, winnings) => { // authorization happens in pallet itself, we just pass authentication @@ -101,7 +109,6 @@ where // endow fee to enclave (self) let fee_recipient: itp_stf_primitives::types::AccountId = enclave_signer_account(); // fixme: apply fees through standard frame process and tune it - let fee = crate::STF_GUESS_FEE; info!("guess fee {}", fee); ita_sgx_runtime::BalancesCall::::transfer { dest: MultiAddress::Id(fee_recipient), @@ -129,6 +136,14 @@ where } } +fn get_fee_for(tc: &GuessTheNumberTrustedCall) -> Balance { + let one = MinimalChainSpec::one_unit(shielding_target_genesis_hash().unwrap_or_default()); + match tc { + GuessTheNumberTrustedCall::guess(..) => one / crate::STF_GUESS_FEE_DIVIDER, + _ => Balance::from(0u32), + } +} + #[derive(Encode, Decode, Clone, Debug, PartialEq, Eq)] #[allow(non_camel_case_types)] pub enum GuessTheNumberPublicGetter { diff --git a/app-libs/stf/src/helpers.rs b/app-libs/stf/src/helpers.rs index fafb0e147..650d2e217 100644 --- a/app-libs/stf/src/helpers.rs +++ b/app-libs/stf/src/helpers.rs @@ -23,7 +23,7 @@ use itp_stf_primitives::{ types::AccountId, }; use itp_storage::{storage_double_map_key, storage_map_key, storage_value_key, StorageHasher}; -use itp_types::parentchain::ParentchainId; +use itp_types::parentchain::{Hash, ParentchainId}; use itp_utils::stringify::account_id_to_string; use log::*; use std::prelude::v1::*; @@ -116,6 +116,20 @@ pub fn shard_vault() -> Option<(AccountId, ParentchainId)> { get_shard_vaults().into_iter().next() } +/// get shielding target from parentchain pallets +pub fn shielding_target() -> ParentchainId { + shard_vault().map(|v| v.1).unwrap_or(ParentchainId::Integritee) +} + +/// get genesis hash of shielding target parentchain, if available +pub fn shielding_target_genesis_hash() -> Option { + match shielding_target() { + ParentchainId::Integritee => ParentchainIntegritee::parentchain_genesis_hash(), + ParentchainId::TargetA => ParentchainTargetA::parentchain_genesis_hash(), + ParentchainId::TargetB => ParentchainTargetB::parentchain_genesis_hash(), + } +} + /// We assume it has been ensured elsewhere that there can't be multiple shard vaults on multiple parentchains pub fn get_shard_vaults() -> Vec<(AccountId, ParentchainId)> { [ diff --git a/app-libs/stf/src/lib.rs b/app-libs/stf/src/lib.rs index 322bb8250..847fdb42f 100644 --- a/app-libs/stf/src/lib.rs +++ b/app-libs/stf/src/lib.rs @@ -51,4 +51,4 @@ pub(crate) const ENCLAVE_ACCOUNT_KEY: &str = "Enclave_Account_Key"; // fixme: this if a temporary hack only. double-check decimals for target chain // as long as it is hard-coded, needs to be reasonable for 10 (Paseo) and 12 decimals pub const STF_TX_FEE: Balance = 100_000_000; -pub const STF_GUESS_FEE: Balance = 10_000_000_000; +pub const STF_GUESS_FEE_DIVIDER: Balance = 10; diff --git a/enclave-runtime/Cargo.lock b/enclave-runtime/Cargo.lock index 473c0fb6e..db005fde6 100644 --- a/enclave-runtime/Cargo.lock +++ b/enclave-runtime/Cargo.lock @@ -18,7 +18,7 @@ version = "0.4.2" source = "git+https://github.com/encointer/substrate-api-client.git?branch=v0.9.42-tag-v0.14.0-retracted-check-metadata-hash#eddca35c73b5e2e3d0371fa923a0ba605c2f0d61" dependencies = [ "ac-primitives", - "log", + "log 0.4.17", "maybe-async", ] @@ -33,7 +33,7 @@ dependencies = [ "either", "frame-metadata", "hex", - "log", + "log 0.4.17", "parity-scale-codec", "scale-bits", "scale-decode", @@ -380,7 +380,7 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb5b05133427c07c4776906f673ccf36c21b102c9829c641a5b56bd151d44fd6" dependencies = [ - "log", + "log 0.4.17", "parity-scale-codec", "scale-info", ] @@ -759,7 +759,7 @@ version = "0.1.0" source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.13.0-polkadot-v0.9.42#abf29acd41a0fca9cd7025b297b6a9fa272a122f" dependencies = [ "common-primitives", - "log", + "log 0.4.17", "parity-scale-codec", "scale-info", "serde 1.0.192", @@ -827,7 +827,7 @@ dependencies = [ "its-sidechain", "jsonrpc-core", "lazy_static", - "log", + "log 0.4.17", "multibase", "once_cell 1.4.0", "parity-scale-codec", @@ -858,7 +858,7 @@ version = "0.9.0" source = "git+https://github.com/integritee-network/env_logger-sgx#55745829b2ae8a77f0915af3671ec8a9a00cace9" dependencies = [ "humantime", - "log", + "log 0.4.17", "regex 1.3.1", "sgx_tstd", "termcolor", @@ -940,7 +940,7 @@ dependencies = [ "evm-core", "evm-gasometer", "evm-runtime", - "log", + "log 0.4.17", "parity-scale-codec", "primitive-types", "rlp", @@ -1064,7 +1064,7 @@ source = "git+https://github.com/integritee-network/frontier.git?branch=bar/polk dependencies = [ "hex", "libsecp256k1", - "log", + "log 0.4.17", "parity-scale-codec", "scale-info", "sp-core", @@ -1126,7 +1126,7 @@ dependencies = [ "frame-support-procedural", "impl-trait-for-tuples", "k256", - "log", + "log 0.4.17", "parity-scale-codec", "paste", "scale-info", @@ -1189,7 +1189,7 @@ version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", - "log", + "log 0.4.17", "parity-scale-codec", "scale-info", "sp-core", @@ -1516,7 +1516,7 @@ name = "http_req" version = "0.8.1" source = "git+https://github.com/integritee-network/http_req#3723e88235f2b29bc1a31835853b072ffd0455fd" dependencies = [ - "log", + "log 0.4.17", "rustls 0.19.0 (git+https://github.com/mesalock-linux/rustls?branch=mesalock_sgx)", "sgx_tstd", "unicase", @@ -1653,7 +1653,7 @@ dependencies = [ "itp-enclave-metrics", "itp-ocall-api", "lazy_static", - "log", + "log 0.4.17", "parity-scale-codec", "serde 1.0.192", "sgx_tstd", @@ -1676,13 +1676,22 @@ dependencies = [ "itp-stf-primitives", "itp-types", "itp-utils", - "log", + "log 0.4.17", "parity-scale-codec", "sgx_tstd", "sp-core", "sp-runtime", ] +[[package]] +name = "ita-parentchain-specs" +version = "0.1.0" +dependencies = [ + "hex", + "itp-types", + "log 0.4.22", +] + [[package]] name = "ita-sgx-runtime" version = "0.9.0" @@ -1714,6 +1723,7 @@ version = "0.9.0" dependencies = [ "frame-support", "frame-system", + "ita-parentchain-specs", "ita-sgx-runtime", "itp-hashing", "itp-node-api", @@ -1725,7 +1735,7 @@ dependencies = [ "itp-storage", "itp-types", "itp-utils", - "log", + "log 0.4.17", "pallet-balances", "pallet-parentchain", "pallet-sudo", @@ -1749,7 +1759,7 @@ dependencies = [ "itp-types", "itp-utils", "jsonrpc-core", - "log", + "log 0.4.17", "parity-scale-codec", "serde_json 1.0.108", "sgx_tstd", @@ -1769,7 +1779,7 @@ dependencies = [ "itp-stf-state-handler", "itp-top-pool-author", "itp-types", - "log", + "log 0.4.17", "parity-scale-codec", "sgx_tstd", "sp-runtime", @@ -1795,7 +1805,7 @@ version = "0.9.0" dependencies = [ "itc-parentchain-block-importer", "itp-import-queue", - "log", + "log 0.4.17", "sgx_tstd", "sgx_types", "thiserror", @@ -1812,7 +1822,7 @@ dependencies = [ "itp-stf-executor", "itp-stf-interface", "itp-types", - "log", + "log 0.4.17", "parity-scale-codec", "sgx_tstd", "sgx_types", @@ -1836,7 +1846,7 @@ dependencies = [ "itp-test", "itp-top-pool-author", "itp-types", - "log", + "log 0.4.17", "parity-scale-codec", "sgx_tstd", "sgx_types", @@ -1857,7 +1867,7 @@ dependencies = [ "itp-storage", "itp-test", "itp-types", - "log", + "log 0.4.17", "parity-scale-codec", "sgx_tstd", "sgx_types", @@ -1881,7 +1891,7 @@ dependencies = [ "base64 0.13.1", "http", "http_req", - "log", + "log 0.4.17", "serde 1.0.192", "serde_json 1.0.108", "sgx_tstd", @@ -1895,7 +1905,7 @@ version = "0.9.0" dependencies = [ "bit-vec", "chrono 0.4.26", - "log", + "log 0.4.17", "mio", "mio-extras", "rcgen", @@ -1965,7 +1975,7 @@ dependencies = [ "itp-sgx-crypto", "itp-sgx-io", "itp-time-utils", - "log", + "log 0.4.17", "num-bigint", "parity-scale-codec", "rustls 0.19.0 (git+https://github.com/mesalock-linux/rustls?rev=sgx_1.1.3)", @@ -2131,7 +2141,7 @@ dependencies = [ "derive_more", "itp-sgx-io", "itp-sgx-temp-dir", - "log", + "log 0.4.17", "ofb", "parity-scale-codec", "serde_json 1.0.60 (git+https://github.com/mesalock-linux/serde-json-sgx?tag=sgx_1.1.3)", @@ -2149,7 +2159,7 @@ dependencies = [ "derive_more", "environmental 1.1.3", "itp-hashing", - "log", + "log 0.4.17", "parity-scale-codec", "postcard", "serde 1.0.192", @@ -2202,7 +2212,7 @@ dependencies = [ "itp-time-utils", "itp-top-pool-author", "itp-types", - "log", + "log 0.4.17", "parity-scale-codec", "sgx_tstd", "sgx_types", @@ -2248,7 +2258,7 @@ dependencies = [ "itp-stf-state-observer", "itp-time-utils", "itp-types", - "log", + "log 0.4.17", "parity-scale-codec", "rust-base58", "sgx_tstd", @@ -2262,7 +2272,7 @@ name = "itp-stf-state-observer" version = "0.9.0" dependencies = [ "itp-types", - "log", + "log 0.4.17", "sgx_tstd", "thiserror", ] @@ -2302,7 +2312,7 @@ dependencies = [ "itp-time-utils", "itp-types", "jsonrpc-core", - "log", + "log 0.4.17", "parity-scale-codec", "sgx_crypto_helper", "sgx_tstd", @@ -2332,7 +2342,7 @@ dependencies = [ "its-primitives", "jsonrpc-core", "linked-hash-map", - "log", + "log 0.4.17", "parity-scale-codec", "serde 1.0.192", "sgx_tstd", @@ -2355,7 +2365,7 @@ dependencies = [ "itp-top-pool", "itp-types", "jsonrpc-core", - "log", + "log 0.4.17", "parity-scale-codec", "sgx_tstd", "sp-core", @@ -2407,7 +2417,7 @@ dependencies = [ "itp-types", "its-primitives", "its-state", - "log", + "log 0.4.17", "parity-scale-codec", "sgx_tstd", "sgx_types", @@ -2424,7 +2434,7 @@ dependencies = [ "itp-types", "itp-utils", "its-primitives", - "log", + "log 0.4.17", "sgx_tstd", "sp-consensus-slots", "sp-core", @@ -2458,7 +2468,7 @@ dependencies = [ "its-primitives", "its-state", "its-validateer-fetch", - "log", + "log 0.4.17", "parity-scale-codec", "sgx_tstd", "sp-core", @@ -2484,7 +2494,7 @@ dependencies = [ "its-block-verification", "its-primitives", "its-state", - "log", + "log 0.4.17", "parity-scale-codec", "sgx_tstd", "sgx_types", @@ -2504,7 +2514,7 @@ dependencies = [ "its-consensus-common", "its-primitives", "lazy_static", - "log", + "log 0.4.17", "parity-scale-codec", "sgx_tstd", "sp-consensus-slots", @@ -2538,7 +2548,7 @@ dependencies = [ "itp-utils", "its-primitives", "jsonrpc-core", - "log", + "log 0.4.17", "parity-scale-codec", "rust-base58", "sgx_tstd", @@ -2567,7 +2577,7 @@ dependencies = [ "itp-sgx-externalities", "itp-storage", "its-primitives", - "log", + "log 0.4.17", "parity-scale-codec", "sgx_tstd", "sp-core", @@ -2584,7 +2594,7 @@ dependencies = [ "itp-pallet-storage", "itp-types", "its-primitives", - "log", + "log 0.4.17", "parity-scale-codec", "sp-core", "sp-runtime", @@ -2597,7 +2607,7 @@ version = "18.0.0" source = "git+https://github.com/scs/jsonrpc?branch=no_std_v18#0faf53c491c3222b96242a973d902dd06e9b6674" dependencies = [ "futures 0.3.8", - "log", + "log 0.4.17", "serde 1.0.118", "serde_derive 1.0.118", "serde_json 1.0.60 (git+https://github.com/mesalock-linux/serde-json-sgx)", @@ -2707,6 +2717,12 @@ dependencies = [ "sgx_tstd", ] +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + [[package]] name = "matches" version = "0.1.8" @@ -2766,7 +2782,7 @@ version = "0.6.21" source = "git+https://github.com/mesalock-linux/mio-sgx?tag=sgx_1.1.3#5b0e56a3066231c7a8d1876c7be3a19b08ffdfd5" dependencies = [ "iovec", - "log", + "log 0.4.17", "net2", "sgx_libc", "sgx_trts", @@ -2780,7 +2796,7 @@ version = "2.0.6" source = "git+https://github.com/integritee-network/mio-extras-sgx?rev=963234b#963234bf55e44f9efff921938255126c48deef3a" dependencies = [ "lazycell", - "log", + "log 0.4.17", "mio", "sgx_tstd", "sgx_types", @@ -2947,7 +2963,7 @@ source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.4 dependencies = [ "frame-support", "frame-system", - "log", + "log 0.4.17", "parity-scale-codec", "scale-info", "sp-runtime", @@ -2966,7 +2982,7 @@ dependencies = [ "frame-system", "hex", "impl-trait-for-tuples", - "log", + "log 0.4.17", "parity-scale-codec", "rlp", "scale-info", @@ -2983,7 +2999,7 @@ dependencies = [ "frame-support", "frame-system", "itp-randomness", - "log", + "log 0.4.17", "pallet-balances", "pallet-timestamp", "parity-scale-codec", @@ -3000,7 +3016,7 @@ version = "0.11.0" dependencies = [ "frame-support", "frame-system", - "log", + "log 0.4.17", "pallet-balances", "parity-scale-codec", "scale-info", @@ -3031,7 +3047,7 @@ source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.4 dependencies = [ "frame-support", "frame-system", - "log", + "log 0.4.17", "parity-scale-codec", "scale-info", "sp-inherents", @@ -3457,7 +3473,7 @@ version = "0.19.0" source = "git+https://github.com/mesalock-linux/rustls?tag=sgx_1.1.3#95b5e79dc24b02f3ce424437eb9698509d0baf58" dependencies = [ "base64 0.13.0 (git+https://github.com/mesalock-linux/rust-base64-sgx)", - "log", + "log 0.4.17", "ring", "sct", "sgx_tstd", @@ -3470,7 +3486,7 @@ version = "0.19.0" source = "git+https://github.com/mesalock-linux/rustls?branch=mesalock_sgx#95b5e79dc24b02f3ce424437eb9698509d0baf58" dependencies = [ "base64 0.13.0 (git+https://github.com/mesalock-linux/rust-base64-sgx)", - "log", + "log 0.4.17", "ring", "sct", "sgx_tstd", @@ -3483,7 +3499,7 @@ version = "0.19.0" source = "git+https://github.com/mesalock-linux/rustls?rev=sgx_1.1.3#95b5e79dc24b02f3ce424437eb9698509d0baf58" dependencies = [ "base64 0.13.0 (git+https://github.com/mesalock-linux/rust-base64-sgx)", - "log", + "log 0.4.17", "ring", "sct", "sgx_tstd", @@ -4053,7 +4069,7 @@ name = "sp-api" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ - "log", + "log 0.4.17", "parity-scale-codec", "scale-info", "sp-api-proc-macro", @@ -4109,7 +4125,7 @@ version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "finality-grandpa", - "log", + "log 0.4.17", "parity-scale-codec", "scale-info", "sp-api", @@ -4143,7 +4159,7 @@ dependencies = [ "hash-db 0.16.0", "hash256-std-hasher", "libsecp256k1", - "log", + "log 0.4.17", "merlin", "parity-scale-codec", "paste", @@ -4225,7 +4241,7 @@ version = "7.0.0" dependencies = [ "itp-sgx-externalities", "libsecp256k1", - "log", + "log 0.4.17", "parity-scale-codec", "sgx_tstd", "sp-core", @@ -4250,7 +4266,7 @@ dependencies = [ "either", "hash256-std-hasher", "impl-trait-for-tuples", - "log", + "log 0.4.17", "parity-scale-codec", "paste", "scale-info", @@ -4449,7 +4465,7 @@ dependencies = [ "derive_more", "frame-metadata", "hex", - "log", + "log 0.4.17", "maybe-async", "parity-scale-codec", "serde 1.0.192", @@ -4540,7 +4556,7 @@ source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.13 dependencies = [ "common-primitives", "derive_more", - "log", + "log 0.4.17", "parity-scale-codec", "scale-info", "serde 1.0.192", @@ -4636,7 +4652,7 @@ checksum = "767abe6ffed88a1889671a102c2861ae742726f52e0a5a425b92c9fbfa7e9c85" dependencies = [ "hash-db 0.16.0", "hashbrown 0.13.2", - "log", + "log 0.4.17", "smallvec 1.11.0", ] @@ -4675,7 +4691,7 @@ dependencies = [ "bytes 1.0.1", "http", "httparse", - "log", + "log 0.4.17", "rand 0.7.3", "rustls 0.19.0 (git+https://github.com/mesalock-linux/rustls?tag=sgx_1.1.3)", "sgx_tstd", From 1004fb1fc2acdb09d85919f8be4557ab0fdf0728 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Fri, 25 Oct 2024 10:27:26 +0200 Subject: [PATCH 2/9] charge all stf fees properly, with respect to decimals --- app-libs/stf/src/guess_the_number.rs | 52 +++++++++---------- app-libs/stf/src/lib.rs | 8 ++- app-libs/stf/src/trusted_call.rs | 70 +++++++++++++------------- cli/src/benchmark/mod.rs | 9 ++-- enclave-runtime/src/test/tests_main.rs | 4 +- 5 files changed, 71 insertions(+), 72 deletions(-) diff --git a/app-libs/stf/src/guess_the_number.rs b/app-libs/stf/src/guess_the_number.rs index 14067ace7..bf9aa4dd1 100644 --- a/app-libs/stf/src/guess_the_number.rs +++ b/app-libs/stf/src/guess_the_number.rs @@ -1,25 +1,37 @@ -use crate::helpers::{enclave_signer_account, shielding_target, shielding_target_genesis_hash}; +/* + Copyright 2021 Integritee AG and Supercomputing Systems AG + + 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. + +*/ + +// TrustedCalls and Getters for the Guess-The-Number game + +use crate::helpers::shielding_target_genesis_hash; #[cfg(not(feature = "std"))] use alloc::format; use codec::{Decode, Encode}; use frame_support::dispatch::UnfilteredDispatchable; use ita_parentchain_specs::MinimalChainSpec; -use ita_sgx_runtime::{ - GuessTheNumber, GuessType, ParentchainIntegritee, ParentchainTargetA, ParentchainTargetB, - Runtime, System, -}; +use ita_sgx_runtime::{GuessTheNumber, GuessType, Runtime, System}; use itp_node_api::metadata::provider::AccessNodeMetadata; use itp_node_api_metadata::NodeMetadataTrait; use itp_sgx_runtime_primitives::types::{Balance, Moment}; use itp_stf_interface::{ExecuteCall, ExecuteGetter}; use itp_stf_primitives::error::StfError; -use itp_types::{ - parentchain::{ParentchainCall, ParentchainId}, - AccountId, -}; +use itp_types::{parentchain::ParentchainCall, AccountId}; use itp_utils::stringify::account_id_to_string; -use log::{debug, info, trace}; -use sp_runtime::MultiAddress; +use log::*; use sp_std::{sync::Arc, vec::Vec}; /// General public information about the status of the guess-the-number game @@ -73,7 +85,6 @@ where _calls: &mut Vec, _node_metadata_repo: Arc, ) -> Result<(), Self::Error> { - let fee = get_fee_for(&self); match self { Self::set_winnings(sender, winnings) => { // authorization happens in pallet itself, we just pass authentication @@ -106,19 +117,6 @@ where Self::guess(sender, guess) => { let origin = ita_sgx_runtime::RuntimeOrigin::signed(sender); std::println!("⣿STF⣿ guess-the-number: someone is attempting a guess"); - // endow fee to enclave (self) - let fee_recipient: itp_stf_primitives::types::AccountId = enclave_signer_account(); - // fixme: apply fees through standard frame process and tune it - info!("guess fee {}", fee); - ita_sgx_runtime::BalancesCall::::transfer { - dest: MultiAddress::Id(fee_recipient), - value: fee, - } - .dispatch_bypass_filter(origin.clone()) - .map_err(|e| { - Self::Error::Dispatch(format!("GuessTheNumber fee error: {:?}", e.error)) - })?; - ita_sgx_runtime::GuessTheNumberCall::::guess { guess } .dispatch_bypass_filter(origin) .map_err(|e| { @@ -136,10 +134,10 @@ where } } -fn get_fee_for(tc: &GuessTheNumberTrustedCall) -> Balance { +pub fn get_fee_for(tc: &GuessTheNumberTrustedCall) -> Balance { let one = MinimalChainSpec::one_unit(shielding_target_genesis_hash().unwrap_or_default()); match tc { - GuessTheNumberTrustedCall::guess(..) => one / crate::STF_GUESS_FEE_DIVIDER, + GuessTheNumberTrustedCall::guess(..) => one / crate::STF_GUESS_FEE_UNIT_DIVIDER, _ => Balance::from(0u32), } } diff --git a/app-libs/stf/src/lib.rs b/app-libs/stf/src/lib.rs index 847fdb42f..74405d07a 100644 --- a/app-libs/stf/src/lib.rs +++ b/app-libs/stf/src/lib.rs @@ -47,8 +47,6 @@ pub mod test_genesis; pub mod trusted_call; pub(crate) const ENCLAVE_ACCOUNT_KEY: &str = "Enclave_Account_Key"; - -// fixme: this if a temporary hack only. double-check decimals for target chain -// as long as it is hard-coded, needs to be reasonable for 10 (Paseo) and 12 decimals -pub const STF_TX_FEE: Balance = 100_000_000; -pub const STF_GUESS_FEE_DIVIDER: Balance = 10; +pub const STF_SHIELDING_FEE_AMOUNT_DIVIDER: Balance = 571; // approx 0.175% +pub const STF_TX_FEE_UNIT_DIVIDER: Balance = 100; // 0.01 tokens +pub const STF_GUESS_FEE_UNIT_DIVIDER: Balance = 10; // 0.1 tokens diff --git a/app-libs/stf/src/trusted_call.rs b/app-libs/stf/src/trusted_call.rs index f6c58f394..6cf15d804 100644 --- a/app-libs/stf/src/trusted_call.rs +++ b/app-libs/stf/src/trusted_call.rs @@ -25,11 +25,15 @@ use std::vec::Vec; use crate::evm_helpers::{create_code_hash, evm_create2_address, evm_create_address}; use crate::{ guess_the_number::GuessTheNumberTrustedCall, - helpers::{enclave_signer_account, ensure_enclave_signer_account, shard_vault, wrap_bytes}, - Getter, + helpers::{ + enclave_signer_account, ensure_enclave_signer_account, shard_vault, + shielding_target_genesis_hash, wrap_bytes, + }, + Getter, STF_SHIELDING_FEE_AMOUNT_DIVIDER, }; use codec::{Compact, Decode, Encode}; use frame_support::{ensure, traits::UnfilteredDispatchable}; +use ita_parentchain_specs::MinimalChainSpec; #[cfg(feature = "evm")] use ita_sgx_runtime::{AddressMapping, HashedAddressMapping}; pub use ita_sgx_runtime::{Balance, Index}; @@ -244,6 +248,10 @@ where let system_nonce = System::account_nonce(&sender); ensure!(self.nonce == system_nonce, Self::Error::InvalidNonce(self.nonce, system_nonce)); + // try to charge fee first and fail early + let fee = get_fee_for(&self); + charge_fee(fee, &sender)?; + // increment the nonce, no matter if the call succeeds or fails. // The call must have entered the transaction pool already, // so it should be considered as valid @@ -283,25 +291,6 @@ where TrustedCall::balance_transfer(from, to, value) => { let origin = ita_sgx_runtime::RuntimeOrigin::signed(from.clone()); std::println!("⣿STF⣿ 🔄 balance_transfer from ⣿⣿⣿ to ⣿⣿⣿ amount ⣿⣿⣿"); - // endow fee to enclave (self) - let fee_recipient: AccountId = enclave_signer_account(); - // fixme: apply fees through standard frame process and tune it - let fee = crate::STF_TX_FEE; - info!( - "from {}, to {}, amount {}, fee {}", - account_id_to_string(&from), - account_id_to_string(&to), - value, - fee - ); - ita_sgx_runtime::BalancesCall::::transfer { - dest: MultiAddress::Id(fee_recipient), - value: fee, - } - .dispatch_bypass_filter(origin.clone()) - .map_err(|e| { - Self::Error::Dispatch(format!("Balance Transfer error: {:?}", e.error)) - })?; ita_sgx_runtime::BalancesCall::::transfer { dest: MultiAddress::Id(to), value, @@ -318,11 +307,6 @@ where account_id_to_string(&beneficiary), value ); - // endow fee to enclave (self) - let fee_recipient: AccountId = enclave_signer_account(); - // fixme: apply fees through standard frame process and tune it. has to be at least two L1 transfer's fees - let fee = crate::STF_TX_FEE * 3; - info!( "balance_unshield(from (L2): {}, to (L1): {}, amount {} (+fee: {}), shard {})", account_id_to_string(&account_incognito), @@ -332,15 +316,6 @@ where shard ); - let origin = ita_sgx_runtime::RuntimeOrigin::signed(account_incognito.clone()); - ita_sgx_runtime::BalancesCall::::transfer { - dest: MultiAddress::Id(fee_recipient), - value: fee, - } - .dispatch_bypass_filter(origin) - .map_err(|e| { - Self::Error::Dispatch(format!("Balance Unshielding error: {:?}", e.error)) - })?; burn_funds(account_incognito, value)?; let (vault, parentchain_id) = shard_vault().ok_or_else(|| { @@ -593,6 +568,29 @@ where } } +fn get_fee_for(tc: &TrustedCallSigned) -> Balance { + let one = MinimalChainSpec::one_unit(shielding_target_genesis_hash().unwrap_or_default()); + match &tc.call { + TrustedCall::balance_transfer(..) => one / crate::STF_TX_FEE_UNIT_DIVIDER, + TrustedCall::balance_unshield(..) => one / crate::STF_TX_FEE_UNIT_DIVIDER * 3, + TrustedCall::guess_the_number(call) => crate::guess_the_number::get_fee_for(&call), + _ => Balance::from(0u32), + } +} + +fn charge_fee(fee: Balance, payer: &AccountId) -> Result<(), StfError> { + debug!("attempting to charge fee for TrustedCall"); + let fee_recipient: AccountId = enclave_signer_account(); + let origin = ita_sgx_runtime::RuntimeOrigin::signed(payer.clone()); + ita_sgx_runtime::BalancesCall::::transfer { + dest: MultiAddress::Id(fee_recipient), + value: fee, + } + .dispatch_bypass_filter(origin) + .map_err(|e| StfError::Dispatch(format!("Fee Payment Error: {:?}", e.error)))?; + Ok(()) +} + fn burn_funds(account: AccountId, amount: u128) -> Result<(), StfError> { let account_info = System::account(&account); if account_info.data.free < amount { @@ -610,7 +608,7 @@ fn burn_funds(account: AccountId, amount: u128) -> Result<(), StfError> { fn shield_funds(account: AccountId, amount: u128) -> Result<(), StfError> { //fixme: make fee configurable and send fee to vault account on L2 - let fee = amount / 571; // approx 0.175% + let fee = amount / STF_SHIELDING_FEE_AMOUNT_DIVIDER; // endow fee to enclave (self) let fee_recipient: AccountId = enclave_signer_account(); diff --git a/cli/src/benchmark/mod.rs b/cli/src/benchmark/mod.rs index 550bc18cc..d514f35a6 100644 --- a/cli/src/benchmark/mod.rs +++ b/cli/src/benchmark/mod.rs @@ -25,7 +25,9 @@ use crate::{ }; use codec::Decode; use hdrhistogram::Histogram; -use ita_stf::{Getter, Index, TrustedCall, TrustedCallSigned, TrustedGetter, STF_TX_FEE}; +use ita_stf::{ + Getter, Index, TrustedCall, TrustedCallSigned, TrustedGetter, STF_TX_FEE_UNIT_DIVIDER, +}; use itc_rpc_client::direct_client::{DirectApi, DirectClient}; use itp_stf_primitives::{ traits::TrustedCallSigning, @@ -136,7 +138,8 @@ impl BenchmarkCommand { println!("Nonce for account {}: {}", self.funding_account, nonce_start); let mut accounts = Vec::new(); - let initial_balance = (self.number_iterations + 1) * (STF_TX_FEE + EXISTENTIAL_DEPOSIT); + let initial_balance = (self.number_iterations + 1) + * (1_000_000_000_000 / STF_TX_FEE_UNIT_DIVIDER + EXISTENTIAL_DEPOSIT); // Setup new accounts and initialize them with money from Alice. for i in 0..self.number_clients { let nonce = i + nonce_start; @@ -230,7 +233,7 @@ impl BenchmarkCommand { output.push(result); // FIXME: We probably should re-fund the account in this case. - if client.current_balance <= EXISTENTIAL_DEPOSIT + STF_TX_FEE { + if client.current_balance <= 1_000_000_000_000 / STF_TX_FEE_UNIT_DIVIDER + EXISTENTIAL_DEPOSIT { error!("Account {:?} does not have enough balance anymore. Finishing benchmark early", client.account.public()); break; } diff --git a/enclave-runtime/src/test/tests_main.rs b/enclave-runtime/src/test/tests_main.rs index 6e737d8c5..dc3047ce1 100644 --- a/enclave-runtime/src/test/tests_main.rs +++ b/enclave-runtime/src/test/tests_main.rs @@ -428,7 +428,9 @@ fn test_create_state_diff() { assert_eq!(receiver_acc_info.data.free, TX_AMOUNT); assert_eq!( sender_acc_info.data.free, - ita_stf::test_genesis::ENDOWED_ACC_FUNDS - TX_AMOUNT - ita_stf::STF_TX_FEE + ita_stf::test_genesis::ENDOWED_ACC_FUNDS + - TX_AMOUNT + - 1_000_000_000_000 / ita_stf::STF_TX_FEE_UNIT_DIVIDER ); } From e5680ce0d5db60ccffe77b8b9639bb954cb29c2b Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Fri, 25 Oct 2024 10:31:11 +0200 Subject: [PATCH 3/9] clippy&taplo --- app-libs/stf/Cargo.toml | 2 +- app-libs/stf/src/trusted_call.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app-libs/stf/Cargo.toml b/app-libs/stf/Cargo.toml index a1c042668..d6e1ef08f 100644 --- a/app-libs/stf/Cargo.toml +++ b/app-libs/stf/Cargo.toml @@ -15,8 +15,8 @@ sha3 = { version = "0.10", default-features = false } sgx_tstd = { branch = "master", features = ["untrusted_fs", "net", "backtrace"], git = "https://github.com/apache/teaclave-sgx-sdk.git", optional = true } # local crates -ita-sgx-runtime = { default-features = false, path = "../sgx-runtime" } ita-parentchain-specs = { default-features = false, path = "../parentchain-specs" } +ita-sgx-runtime = { default-features = false, path = "../sgx-runtime" } itp-hashing = { default-features = false, path = "../../core-primitives/hashing" } itp-node-api = { default-features = false, path = "../../core-primitives/node-api" } itp-node-api-metadata = { default-features = false, path = "../../core-primitives/node-api/metadata" } diff --git a/app-libs/stf/src/trusted_call.rs b/app-libs/stf/src/trusted_call.rs index 6cf15d804..542fac2f4 100644 --- a/app-libs/stf/src/trusted_call.rs +++ b/app-libs/stf/src/trusted_call.rs @@ -289,7 +289,7 @@ where Ok::<(), Self::Error>(()) }, TrustedCall::balance_transfer(from, to, value) => { - let origin = ita_sgx_runtime::RuntimeOrigin::signed(from.clone()); + let origin = ita_sgx_runtime::RuntimeOrigin::signed(from); std::println!("⣿STF⣿ 🔄 balance_transfer from ⣿⣿⣿ to ⣿⣿⣿ amount ⣿⣿⣿"); ita_sgx_runtime::BalancesCall::::transfer { dest: MultiAddress::Id(to), @@ -573,7 +573,7 @@ fn get_fee_for(tc: &TrustedCallSigned) -> Balance { match &tc.call { TrustedCall::balance_transfer(..) => one / crate::STF_TX_FEE_UNIT_DIVIDER, TrustedCall::balance_unshield(..) => one / crate::STF_TX_FEE_UNIT_DIVIDER * 3, - TrustedCall::guess_the_number(call) => crate::guess_the_number::get_fee_for(&call), + TrustedCall::guess_the_number(call) => crate::guess_the_number::get_fee_for(call), _ => Balance::from(0u32), } } From 770567650742fe1816844ead595b03559f1069ae Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Fri, 25 Oct 2024 10:58:48 +0200 Subject: [PATCH 4/9] add missing new lib --- app-libs/parentchain-specs/Cargo.toml | 17 ++++++++ app-libs/parentchain-specs/src/lib.rs | 56 +++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 app-libs/parentchain-specs/Cargo.toml create mode 100644 app-libs/parentchain-specs/src/lib.rs diff --git a/app-libs/parentchain-specs/Cargo.toml b/app-libs/parentchain-specs/Cargo.toml new file mode 100644 index 000000000..bd12ae9fc --- /dev/null +++ b/app-libs/parentchain-specs/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "ita-parentchain-specs" +version = "0.1.0" +authors = ["Integritee AG "] +edition = "2021" + +[dependencies] +hex = { version = "0.4.3", default-features = false, features = ["alloc"] } +itp-types = { path = "../../core-primitives/types", default-features = false } +log = { version = "0.4", default-features = false } + +[features] +default = ["std"] +std = [ + "hex/std", + "log/std", +] diff --git a/app-libs/parentchain-specs/src/lib.rs b/app-libs/parentchain-specs/src/lib.rs new file mode 100644 index 000000000..a5bc04e85 --- /dev/null +++ b/app-libs/parentchain-specs/src/lib.rs @@ -0,0 +1,56 @@ +/* + Copyright 2021 Integritee AG + + 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. + +*/ +// chain specs which can't be derived from chain state trustlessly by the light client +// we hardcode them here so they can't be changed by an adversarial enclave operator + +#![cfg_attr(all(not(target_env = "sgx"), not(feature = "std")), no_std)] +#![cfg_attr(target_env = "sgx", feature(rustc_private))] +use itp_types::parentchain::{Balance, Hash}; +use log::warn; + +const PASEO_RELAY_GENESIS_HASH_HEX: &str = + "77afd6190f1554ad45fd0d31aee62aacc33c6db0ea801129acb813f913e0764f"; +const INTEGRITEE_PASEO_GENESIS_HASH_HEX: &str = + "1b69c462cd7dfea0e855c2008b66490cc8bbe90bc80b297ec0896a1c0941ce15"; +const INTEGRITEE_KUSAMA_GENESIS_HASH_HEX: &str = + "cdedc8eadbfa209d3f207bba541e57c3c58a667b05a2e1d1e86353c9000758da"; + +/// modify this for testing if necessary +const LOCAL_TEST_GENESIS_HASH_HEX: &str = + "6ca6d29ad6c4a200c4af356f74f03d6467dbc8a6e9ef225a2e672a990e1c7ead"; +pub struct MinimalChainSpec {} + +impl MinimalChainSpec { + pub fn decimals(genesis_hash: Hash) -> u8 { + let genesis_hash_hex = hex::encode(genesis_hash); + match genesis_hash_hex.as_ref() { + PASEO_RELAY_GENESIS_HASH_HEX => 10, + INTEGRITEE_PASEO_GENESIS_HASH_HEX | INTEGRITEE_KUSAMA_GENESIS_HASH_HEX => 12, + LOCAL_TEST_GENESIS_HASH_HEX => 10, + _ => { + warn!( + "parentchain spec for genesis {} unknown. defaulting to 12 decimals", + genesis_hash_hex + ); + 12 + }, + } + } + pub fn one_unit(genesis_hash: Hash) -> Balance { + 10u128.pow(Self::decimals(genesis_hash) as u32) + } +} From 1f6013f15d73f8a73e8e9e77001699360367866d Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Fri, 25 Oct 2024 11:03:16 +0200 Subject: [PATCH 5/9] fmt --- enclave-runtime/src/test/tests_main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/enclave-runtime/src/test/tests_main.rs b/enclave-runtime/src/test/tests_main.rs index dc3047ce1..c1e2c9af1 100644 --- a/enclave-runtime/src/test/tests_main.rs +++ b/enclave-runtime/src/test/tests_main.rs @@ -429,8 +429,7 @@ fn test_create_state_diff() { assert_eq!( sender_acc_info.data.free, ita_stf::test_genesis::ENDOWED_ACC_FUNDS - - TX_AMOUNT - - 1_000_000_000_000 / ita_stf::STF_TX_FEE_UNIT_DIVIDER + - TX_AMOUNT - 1_000_000_000_000 / ita_stf::STF_TX_FEE_UNIT_DIVIDER ); } From 7955de6fba18844508debbddaf819b447d45c1fb Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Fri, 25 Oct 2024 12:28:00 +0200 Subject: [PATCH 6/9] double fee tolerance because fees went up --- cli/demo_shielding_unshielding.sh | 2 +- cli/demo_shielding_unshielding_using_shard_vault.sh | 2 +- cli/demo_shielding_unshielding_using_shard_vault_on_target_a.sh | 2 +- cli/demo_sidechain.sh | 2 +- cli/test_auto_shielding_with_transfer_bob.sh | 2 +- cli/test_shield_on_target_nodes_with_transfer_to_alice.sh | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/demo_shielding_unshielding.sh b/cli/demo_shielding_unshielding.sh index 97c945a52..be353d565 100755 --- a/cli/demo_shielding_unshielding.sh +++ b/cli/demo_shielding_unshielding.sh @@ -67,7 +67,7 @@ echo "" # the parentchain token is 12 decimal UNIT=$(( 10 ** 12 )) -FEE_TOLERANCE=$((10 ** 11)) +FEE_TOLERANCE=$((2 * 10 ** 11)) # make these amounts greater than ED AMOUNT_SHIELD=$(( 6 * UNIT )) diff --git a/cli/demo_shielding_unshielding_using_shard_vault.sh b/cli/demo_shielding_unshielding_using_shard_vault.sh index b5997f0ed..699ca902b 100755 --- a/cli/demo_shielding_unshielding_using_shard_vault.sh +++ b/cli/demo_shielding_unshielding_using_shard_vault.sh @@ -67,7 +67,7 @@ echo "" # the parentchain token is 12 decimal UNIT=$(( 10 ** 12 )) -FEE_TOLERANCE=$((10 ** 11)) +FEE_TOLERANCE=$((2 * 10 ** 11)) # make these amounts greater than ED AMOUNT_SHIELD=$(( 6 * UNIT )) diff --git a/cli/demo_shielding_unshielding_using_shard_vault_on_target_a.sh b/cli/demo_shielding_unshielding_using_shard_vault_on_target_a.sh index 9d3555837..0e5c39463 100755 --- a/cli/demo_shielding_unshielding_using_shard_vault_on_target_a.sh +++ b/cli/demo_shielding_unshielding_using_shard_vault_on_target_a.sh @@ -77,7 +77,7 @@ echo "" # the parentchain token is 12 decimal UNIT=$(( 10 ** 12 )) -FEE_TOLERANCE=$((10 ** 11)) +FEE_TOLERANCE=$((2 * 10 ** 11)) # make these amounts greater than ED AMOUNT_SHIELD=$(( 6 * UNIT )) diff --git a/cli/demo_sidechain.sh b/cli/demo_sidechain.sh index 4f7d7f4ce..771110a23 100755 --- a/cli/demo_sidechain.sh +++ b/cli/demo_sidechain.sh @@ -74,7 +74,7 @@ echo "Using trusted-worker 2 uri ${WORKER_2_URL}:${WORKER_2_PORT}" # the parentchain token is 12 decimal UNIT=$(( 10 ** 12 )) -FEE_TOLERANCE=$((10 ** 11)) +FEE_TOLERANCE=$((2 * 10 ** 11)) INITIALFUNDS=$((5 * UNIT)) AMOUNTTRANSFER=$((2 * UNIT)) diff --git a/cli/test_auto_shielding_with_transfer_bob.sh b/cli/test_auto_shielding_with_transfer_bob.sh index 8659670f6..d58340ed9 100644 --- a/cli/test_auto_shielding_with_transfer_bob.sh +++ b/cli/test_auto_shielding_with_transfer_bob.sh @@ -53,7 +53,7 @@ echo "" # the parentchain token is 12 decimal UNIT=$(( 10 ** 12 )) -FEE_TOLERANCE=$((10 ** 11)) +FEE_TOLERANCE=$((2 * 10 ** 11)) # make these amounts greater than ED AMOUNT_SHIELD=$(( 6 * UNIT )) diff --git a/cli/test_shield_on_target_nodes_with_transfer_to_alice.sh b/cli/test_shield_on_target_nodes_with_transfer_to_alice.sh index 9a3d10dfa..3e62d56d1 100755 --- a/cli/test_shield_on_target_nodes_with_transfer_to_alice.sh +++ b/cli/test_shield_on_target_nodes_with_transfer_to_alice.sh @@ -64,7 +64,7 @@ echo "" # the parentchain token is 12 decimal UNIT=$(( 10 ** 12 )) -FEE_TOLERANCE=$((10 ** 11)) +FEE_TOLERANCE=$((2 * 10 ** 11)) # make these amounts greater than ED AMOUNT_SHIELD=$(( 6 * UNIT )) From 21d79892b83e5bc3cb0f541fec14420ad2828c45 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Sat, 26 Oct 2024 08:41:27 +0200 Subject: [PATCH 7/9] fix dirct call test by increasing amounts --- cli/demo_direct_call.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/demo_direct_call.sh b/cli/demo_direct_call.sh index 29357ac81..8eda4a027 100755 --- a/cli/demo_direct_call.sh +++ b/cli/demo_direct_call.sh @@ -63,8 +63,8 @@ echo "Using trusted-worker uri ${WORKER_1_URL}:${WORKER_1_PORT}" echo "" -AMOUNTSHIELD=50000000000 -AMOUNTTRANSFER=40000000000 +AMOUNTSHIELD=5000000000000 +AMOUNTTRANSFER=4000000000000 CLIENT="${CLIENT_BIN} -p ${INTEGRITEE_RPC_PORT} -P ${WORKER_1_PORT} -u ${INTEGRITEE_RPC_URL} -U ${WORKER_1_URL}" # we simply believe the enclave here without verifying the teerex RA @@ -116,7 +116,7 @@ echo "" # They only work if you're running from fresh genesis. case $TEST in first) - if [ "40000000000" = "$RESULT" ]; then + if [ "4000000000000" = "$RESULT" ]; then echo "test passed (1st time)" echo "" exit 0 @@ -126,7 +126,7 @@ case $TEST in fi ;; second) - if [ "80000000000" = "$RESULT" ]; then + if [ "8000000000000" = "$RESULT" ]; then echo "test passed (2nd time)" echo "" exit 0 From a966627e13d9e13800341e3f1272a56d684af40a Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Sat, 26 Oct 2024 08:47:11 +0200 Subject: [PATCH 8/9] iprovements of direct call test --- cli/demo_direct_call.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/demo_direct_call.sh b/cli/demo_direct_call.sh index 8eda4a027..818ed025f 100755 --- a/cli/demo_direct_call.sh +++ b/cli/demo_direct_call.sh @@ -116,7 +116,7 @@ echo "" # They only work if you're running from fresh genesis. case $TEST in first) - if [ "4000000000000" = "$RESULT" ]; then + if [ "$AMOUNTTRANSFER" = "$RESULT" ]; then echo "test passed (1st time)" echo "" exit 0 @@ -126,7 +126,7 @@ case $TEST in fi ;; second) - if [ "8000000000000" = "$RESULT" ]; then + if [ $((2 * AMOUNTTRANSFER)) -eq "$RESULT" ]; then echo "test passed (2nd time)" echo "" exit 0 From fdb118962233c85cc66754eaa33e5b81e5d6e0d1 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Sat, 26 Oct 2024 08:55:09 +0200 Subject: [PATCH 9/9] fix doeble dep on log --- enclave-runtime/Cargo.lock | 126 ++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 66 deletions(-) diff --git a/enclave-runtime/Cargo.lock b/enclave-runtime/Cargo.lock index db005fde6..2a849912f 100644 --- a/enclave-runtime/Cargo.lock +++ b/enclave-runtime/Cargo.lock @@ -18,7 +18,7 @@ version = "0.4.2" source = "git+https://github.com/encointer/substrate-api-client.git?branch=v0.9.42-tag-v0.14.0-retracted-check-metadata-hash#eddca35c73b5e2e3d0371fa923a0ba605c2f0d61" dependencies = [ "ac-primitives", - "log 0.4.17", + "log", "maybe-async", ] @@ -33,7 +33,7 @@ dependencies = [ "either", "frame-metadata", "hex", - "log 0.4.17", + "log", "parity-scale-codec", "scale-bits", "scale-decode", @@ -380,7 +380,7 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb5b05133427c07c4776906f673ccf36c21b102c9829c641a5b56bd151d44fd6" dependencies = [ - "log 0.4.17", + "log", "parity-scale-codec", "scale-info", ] @@ -759,7 +759,7 @@ version = "0.1.0" source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.13.0-polkadot-v0.9.42#abf29acd41a0fca9cd7025b297b6a9fa272a122f" dependencies = [ "common-primitives", - "log 0.4.17", + "log", "parity-scale-codec", "scale-info", "serde 1.0.192", @@ -827,7 +827,7 @@ dependencies = [ "its-sidechain", "jsonrpc-core", "lazy_static", - "log 0.4.17", + "log", "multibase", "once_cell 1.4.0", "parity-scale-codec", @@ -858,7 +858,7 @@ version = "0.9.0" source = "git+https://github.com/integritee-network/env_logger-sgx#55745829b2ae8a77f0915af3671ec8a9a00cace9" dependencies = [ "humantime", - "log 0.4.17", + "log", "regex 1.3.1", "sgx_tstd", "termcolor", @@ -940,7 +940,7 @@ dependencies = [ "evm-core", "evm-gasometer", "evm-runtime", - "log 0.4.17", + "log", "parity-scale-codec", "primitive-types", "rlp", @@ -1064,7 +1064,7 @@ source = "git+https://github.com/integritee-network/frontier.git?branch=bar/polk dependencies = [ "hex", "libsecp256k1", - "log 0.4.17", + "log", "parity-scale-codec", "scale-info", "sp-core", @@ -1126,7 +1126,7 @@ dependencies = [ "frame-support-procedural", "impl-trait-for-tuples", "k256", - "log 0.4.17", + "log", "parity-scale-codec", "paste", "scale-info", @@ -1189,7 +1189,7 @@ version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "frame-support", - "log 0.4.17", + "log", "parity-scale-codec", "scale-info", "sp-core", @@ -1516,7 +1516,7 @@ name = "http_req" version = "0.8.1" source = "git+https://github.com/integritee-network/http_req#3723e88235f2b29bc1a31835853b072ffd0455fd" dependencies = [ - "log 0.4.17", + "log", "rustls 0.19.0 (git+https://github.com/mesalock-linux/rustls?branch=mesalock_sgx)", "sgx_tstd", "unicase", @@ -1653,7 +1653,7 @@ dependencies = [ "itp-enclave-metrics", "itp-ocall-api", "lazy_static", - "log 0.4.17", + "log", "parity-scale-codec", "serde 1.0.192", "sgx_tstd", @@ -1676,7 +1676,7 @@ dependencies = [ "itp-stf-primitives", "itp-types", "itp-utils", - "log 0.4.17", + "log", "parity-scale-codec", "sgx_tstd", "sp-core", @@ -1689,7 +1689,7 @@ version = "0.1.0" dependencies = [ "hex", "itp-types", - "log 0.4.22", + "log", ] [[package]] @@ -1735,7 +1735,7 @@ dependencies = [ "itp-storage", "itp-types", "itp-utils", - "log 0.4.17", + "log", "pallet-balances", "pallet-parentchain", "pallet-sudo", @@ -1759,7 +1759,7 @@ dependencies = [ "itp-types", "itp-utils", "jsonrpc-core", - "log 0.4.17", + "log", "parity-scale-codec", "serde_json 1.0.108", "sgx_tstd", @@ -1779,7 +1779,7 @@ dependencies = [ "itp-stf-state-handler", "itp-top-pool-author", "itp-types", - "log 0.4.17", + "log", "parity-scale-codec", "sgx_tstd", "sp-runtime", @@ -1805,7 +1805,7 @@ version = "0.9.0" dependencies = [ "itc-parentchain-block-importer", "itp-import-queue", - "log 0.4.17", + "log", "sgx_tstd", "sgx_types", "thiserror", @@ -1822,7 +1822,7 @@ dependencies = [ "itp-stf-executor", "itp-stf-interface", "itp-types", - "log 0.4.17", + "log", "parity-scale-codec", "sgx_tstd", "sgx_types", @@ -1846,7 +1846,7 @@ dependencies = [ "itp-test", "itp-top-pool-author", "itp-types", - "log 0.4.17", + "log", "parity-scale-codec", "sgx_tstd", "sgx_types", @@ -1867,7 +1867,7 @@ dependencies = [ "itp-storage", "itp-test", "itp-types", - "log 0.4.17", + "log", "parity-scale-codec", "sgx_tstd", "sgx_types", @@ -1891,7 +1891,7 @@ dependencies = [ "base64 0.13.1", "http", "http_req", - "log 0.4.17", + "log", "serde 1.0.192", "serde_json 1.0.108", "sgx_tstd", @@ -1905,7 +1905,7 @@ version = "0.9.0" dependencies = [ "bit-vec", "chrono 0.4.26", - "log 0.4.17", + "log", "mio", "mio-extras", "rcgen", @@ -1975,7 +1975,7 @@ dependencies = [ "itp-sgx-crypto", "itp-sgx-io", "itp-time-utils", - "log 0.4.17", + "log", "num-bigint", "parity-scale-codec", "rustls 0.19.0 (git+https://github.com/mesalock-linux/rustls?rev=sgx_1.1.3)", @@ -2141,7 +2141,7 @@ dependencies = [ "derive_more", "itp-sgx-io", "itp-sgx-temp-dir", - "log 0.4.17", + "log", "ofb", "parity-scale-codec", "serde_json 1.0.60 (git+https://github.com/mesalock-linux/serde-json-sgx?tag=sgx_1.1.3)", @@ -2159,7 +2159,7 @@ dependencies = [ "derive_more", "environmental 1.1.3", "itp-hashing", - "log 0.4.17", + "log", "parity-scale-codec", "postcard", "serde 1.0.192", @@ -2212,7 +2212,7 @@ dependencies = [ "itp-time-utils", "itp-top-pool-author", "itp-types", - "log 0.4.17", + "log", "parity-scale-codec", "sgx_tstd", "sgx_types", @@ -2258,7 +2258,7 @@ dependencies = [ "itp-stf-state-observer", "itp-time-utils", "itp-types", - "log 0.4.17", + "log", "parity-scale-codec", "rust-base58", "sgx_tstd", @@ -2272,7 +2272,7 @@ name = "itp-stf-state-observer" version = "0.9.0" dependencies = [ "itp-types", - "log 0.4.17", + "log", "sgx_tstd", "thiserror", ] @@ -2312,7 +2312,7 @@ dependencies = [ "itp-time-utils", "itp-types", "jsonrpc-core", - "log 0.4.17", + "log", "parity-scale-codec", "sgx_crypto_helper", "sgx_tstd", @@ -2342,7 +2342,7 @@ dependencies = [ "its-primitives", "jsonrpc-core", "linked-hash-map", - "log 0.4.17", + "log", "parity-scale-codec", "serde 1.0.192", "sgx_tstd", @@ -2365,7 +2365,7 @@ dependencies = [ "itp-top-pool", "itp-types", "jsonrpc-core", - "log 0.4.17", + "log", "parity-scale-codec", "sgx_tstd", "sp-core", @@ -2417,7 +2417,7 @@ dependencies = [ "itp-types", "its-primitives", "its-state", - "log 0.4.17", + "log", "parity-scale-codec", "sgx_tstd", "sgx_types", @@ -2434,7 +2434,7 @@ dependencies = [ "itp-types", "itp-utils", "its-primitives", - "log 0.4.17", + "log", "sgx_tstd", "sp-consensus-slots", "sp-core", @@ -2468,7 +2468,7 @@ dependencies = [ "its-primitives", "its-state", "its-validateer-fetch", - "log 0.4.17", + "log", "parity-scale-codec", "sgx_tstd", "sp-core", @@ -2494,7 +2494,7 @@ dependencies = [ "its-block-verification", "its-primitives", "its-state", - "log 0.4.17", + "log", "parity-scale-codec", "sgx_tstd", "sgx_types", @@ -2514,7 +2514,7 @@ dependencies = [ "its-consensus-common", "its-primitives", "lazy_static", - "log 0.4.17", + "log", "parity-scale-codec", "sgx_tstd", "sp-consensus-slots", @@ -2548,7 +2548,7 @@ dependencies = [ "itp-utils", "its-primitives", "jsonrpc-core", - "log 0.4.17", + "log", "parity-scale-codec", "rust-base58", "sgx_tstd", @@ -2577,7 +2577,7 @@ dependencies = [ "itp-sgx-externalities", "itp-storage", "its-primitives", - "log 0.4.17", + "log", "parity-scale-codec", "sgx_tstd", "sp-core", @@ -2594,7 +2594,7 @@ dependencies = [ "itp-pallet-storage", "itp-types", "its-primitives", - "log 0.4.17", + "log", "parity-scale-codec", "sp-core", "sp-runtime", @@ -2607,7 +2607,7 @@ version = "18.0.0" source = "git+https://github.com/scs/jsonrpc?branch=no_std_v18#0faf53c491c3222b96242a973d902dd06e9b6674" dependencies = [ "futures 0.3.8", - "log 0.4.17", + "log", "serde 1.0.118", "serde_derive 1.0.118", "serde_json 1.0.60 (git+https://github.com/mesalock-linux/serde-json-sgx)", @@ -2717,12 +2717,6 @@ dependencies = [ "sgx_tstd", ] -[[package]] -name = "log" -version = "0.4.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" - [[package]] name = "matches" version = "0.1.8" @@ -2782,7 +2776,7 @@ version = "0.6.21" source = "git+https://github.com/mesalock-linux/mio-sgx?tag=sgx_1.1.3#5b0e56a3066231c7a8d1876c7be3a19b08ffdfd5" dependencies = [ "iovec", - "log 0.4.17", + "log", "net2", "sgx_libc", "sgx_trts", @@ -2796,7 +2790,7 @@ version = "2.0.6" source = "git+https://github.com/integritee-network/mio-extras-sgx?rev=963234b#963234bf55e44f9efff921938255126c48deef3a" dependencies = [ "lazycell", - "log 0.4.17", + "log", "mio", "sgx_tstd", "sgx_types", @@ -2963,7 +2957,7 @@ source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.4 dependencies = [ "frame-support", "frame-system", - "log 0.4.17", + "log", "parity-scale-codec", "scale-info", "sp-runtime", @@ -2982,7 +2976,7 @@ dependencies = [ "frame-system", "hex", "impl-trait-for-tuples", - "log 0.4.17", + "log", "parity-scale-codec", "rlp", "scale-info", @@ -2999,7 +2993,7 @@ dependencies = [ "frame-support", "frame-system", "itp-randomness", - "log 0.4.17", + "log", "pallet-balances", "pallet-timestamp", "parity-scale-codec", @@ -3016,7 +3010,7 @@ version = "0.11.0" dependencies = [ "frame-support", "frame-system", - "log 0.4.17", + "log", "pallet-balances", "parity-scale-codec", "scale-info", @@ -3047,7 +3041,7 @@ source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.4 dependencies = [ "frame-support", "frame-system", - "log 0.4.17", + "log", "parity-scale-codec", "scale-info", "sp-inherents", @@ -3473,7 +3467,7 @@ version = "0.19.0" source = "git+https://github.com/mesalock-linux/rustls?tag=sgx_1.1.3#95b5e79dc24b02f3ce424437eb9698509d0baf58" dependencies = [ "base64 0.13.0 (git+https://github.com/mesalock-linux/rust-base64-sgx)", - "log 0.4.17", + "log", "ring", "sct", "sgx_tstd", @@ -3486,7 +3480,7 @@ version = "0.19.0" source = "git+https://github.com/mesalock-linux/rustls?branch=mesalock_sgx#95b5e79dc24b02f3ce424437eb9698509d0baf58" dependencies = [ "base64 0.13.0 (git+https://github.com/mesalock-linux/rust-base64-sgx)", - "log 0.4.17", + "log", "ring", "sct", "sgx_tstd", @@ -3499,7 +3493,7 @@ version = "0.19.0" source = "git+https://github.com/mesalock-linux/rustls?rev=sgx_1.1.3#95b5e79dc24b02f3ce424437eb9698509d0baf58" dependencies = [ "base64 0.13.0 (git+https://github.com/mesalock-linux/rust-base64-sgx)", - "log 0.4.17", + "log", "ring", "sct", "sgx_tstd", @@ -4069,7 +4063,7 @@ name = "sp-api" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ - "log 0.4.17", + "log", "parity-scale-codec", "scale-info", "sp-api-proc-macro", @@ -4125,7 +4119,7 @@ version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "finality-grandpa", - "log 0.4.17", + "log", "parity-scale-codec", "scale-info", "sp-api", @@ -4159,7 +4153,7 @@ dependencies = [ "hash-db 0.16.0", "hash256-std-hasher", "libsecp256k1", - "log 0.4.17", + "log", "merlin", "parity-scale-codec", "paste", @@ -4241,7 +4235,7 @@ version = "7.0.0" dependencies = [ "itp-sgx-externalities", "libsecp256k1", - "log 0.4.17", + "log", "parity-scale-codec", "sgx_tstd", "sp-core", @@ -4266,7 +4260,7 @@ dependencies = [ "either", "hash256-std-hasher", "impl-trait-for-tuples", - "log 0.4.17", + "log", "parity-scale-codec", "paste", "scale-info", @@ -4465,7 +4459,7 @@ dependencies = [ "derive_more", "frame-metadata", "hex", - "log 0.4.17", + "log", "maybe-async", "parity-scale-codec", "serde 1.0.192", @@ -4556,7 +4550,7 @@ source = "git+https://github.com/integritee-network/pallets.git?branch=sdk-v0.13 dependencies = [ "common-primitives", "derive_more", - "log 0.4.17", + "log", "parity-scale-codec", "scale-info", "serde 1.0.192", @@ -4652,7 +4646,7 @@ checksum = "767abe6ffed88a1889671a102c2861ae742726f52e0a5a425b92c9fbfa7e9c85" dependencies = [ "hash-db 0.16.0", "hashbrown 0.13.2", - "log 0.4.17", + "log", "smallvec 1.11.0", ] @@ -4691,7 +4685,7 @@ dependencies = [ "bytes 1.0.1", "http", "httparse", - "log 0.4.17", + "log", "rand 0.7.3", "rustls 0.19.0 (git+https://github.com/mesalock-linux/rustls?tag=sgx_1.1.3)", "sgx_tstd",