diff --git a/Cargo.lock b/Cargo.lock index ba144daf65..3c2bcb3bea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3925,13 +3925,8 @@ dependencies = [ name = "itp-utils" version = "0.9.0" dependencies = [ - "frame-support", "hex", "parity-scale-codec", - "sgx_tstd", - "sp-core", - "thiserror 1.0.40", - "thiserror 1.0.9", ] [[package]] diff --git a/app-libs/stf/Cargo.toml b/app-libs/stf/Cargo.toml index 61faf98f7d..3bf88299e5 100644 --- a/app-libs/stf/Cargo.toml +++ b/app-libs/stf/Cargo.toml @@ -54,7 +54,6 @@ evm_std = ["evm", "ita-sgx-runtime/evm_std"] sgx = [ "sgx_tstd", "itp-sgx-externalities/sgx", - "itp-utils/sgx", "sp-io/sgx", "itp-node-api/sgx", "itp-node-api-metadata-provider/sgx", @@ -71,7 +70,6 @@ std = [ "itp-stf-interface/std", "itp-storage/std", "itp-types/std", - "itp-utils/std", "itp-node-api/std", "itp-node-api-metadata/std", "itp-node-api-metadata-provider/std", diff --git a/app-libs/stf/src/lib.rs b/app-libs/stf/src/lib.rs index ff5c3c01ae..d938e49d7a 100644 --- a/app-libs/stf/src/lib.rs +++ b/app-libs/stf/src/lib.rs @@ -31,12 +31,14 @@ pub use ita_sgx_runtime::{Balance, Index}; #[cfg(feature = "std")] pub use my_node_runtime::{Balance, Index}; +use alloc::format; use codec::{Decode, Encode}; use derive_more::Display; use itp_node_api_metadata::Error as MetadataError; use itp_node_api_metadata_provider::Error as MetadataProviderError; use itp_stf_primitives::types::AccountId; use itp_types::parentchain::ParentchainError; +use sp_core::bounded::alloc; use std::string::String; pub use getter::*; diff --git a/core-primitives/top-pool-author/Cargo.toml b/core-primitives/top-pool-author/Cargo.toml index 31d862344c..004e164a58 100644 --- a/core-primitives/top-pool-author/Cargo.toml +++ b/core-primitives/top-pool-author/Cargo.toml @@ -54,7 +54,6 @@ std = [ "itp-stf-state-handler/std", "itp-top-pool/std", "itp-types/std", - "itp-utils/std", "jsonrpc-core", "log/std", "thiserror", @@ -67,7 +66,6 @@ sgx = [ "itp-sgx-crypto/sgx", "itp-stf-state-handler/sgx", "itp-top-pool/sgx", - "itp-utils/sgx", "thiserror_sgx", ] test = ["itp-test/sgx", "itp-top-pool/mocks"] diff --git a/core-primitives/types/src/parentchain.rs b/core-primitives/types/src/parentchain.rs index c58ea9819f..f14df4ab43 100644 --- a/core-primitives/types/src/parentchain.rs +++ b/core-primitives/types/src/parentchain.rs @@ -15,14 +15,10 @@ */ -#[cfg(all(not(feature = "std"), feature = "sgx"))] - -#[cfg(feature = "sgx")] -use sgx_tstd as std; - +use alloc::{format, vec::Vec}; use codec::{Decode, Encode}; +use sp_core::bounded::alloc; use sp_runtime::{generic::Header as HeaderG, traits::BlakeTwo256, MultiAddress, MultiSignature}; -use sp_std::vec::Vec; use itp_utils::stringify::account_id_to_string; @@ -109,7 +105,7 @@ pub struct BalanceTransfer { } impl core::fmt::Display for BalanceTransfer { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { let message = format!( "BalanceTransfer :: from: {}, to: {}, amount: {}", account_id_to_string::(&self.from), @@ -128,7 +124,10 @@ impl StaticEvent for BalanceTransfer { pub trait HandleParentchainEvents { const SHIELDING_ACCOUNT: AccountId; fn handle_events(events: impl FilterEvents) -> core::result::Result<(), ParentchainError>; - fn shield_funds(account: &AccountId, amount: Balance) -> core::result::Result<(), ParentchainError>; + fn shield_funds( + account: &AccountId, + amount: Balance, + ) -> core::result::Result<(), ParentchainError>; } #[derive(Debug)] @@ -137,12 +136,12 @@ pub enum ParentchainError { } impl core::fmt::Display for ParentchainError { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - let mut message: &str = ""; + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + let message; match &self { ParentchainError::ShieldFundsFailure => { message = "Parentchain Error: ShieldFundsFailure"; - } + }, } write!(f, "{}", message) } diff --git a/core-primitives/utils/Cargo.toml b/core-primitives/utils/Cargo.toml index bc634cfadb..ad02e01c66 100644 --- a/core-primitives/utils/Cargo.toml +++ b/core-primitives/utils/Cargo.toml @@ -11,28 +11,9 @@ edition = "2021" codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } hex = { version = "0.4.3", default-features = false, features = ["alloc"] } -# substrate -frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } -sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } - -# teaclave -sgx_tstd = { branch = "master", git = "https://github.com/apache/teaclave-sgx-sdk.git", optional = true } - -# sgx enabled external libraries -thiserror_sgx = { package = "thiserror", git = "https://github.com/mesalock-linux/thiserror-sgx", tag = "sgx_1.1.3", optional = true } -# std compatible external libraries (make sure these versions match with the sgx-enabled ones above) -thiserror = { version = "1.0", optional = true } - [features] default = ["std"] std = [ "codec/std", - "frame-support/std", "hex/std", - "sp-core/std", - "thiserror", -] -sgx = [ - "sgx_tstd", - "thiserror_sgx", ] diff --git a/core-primitives/utils/src/buffer.rs b/core-primitives/utils/src/buffer.rs index 304c0ce947..45d5a58d1e 100644 --- a/core-primitives/utils/src/buffer.rs +++ b/core-primitives/utils/src/buffer.rs @@ -17,21 +17,19 @@ //! Buffer utility functions. -use frame_support::ensure; -use std::vec::Vec; - -#[cfg(all(not(feature = "std"), feature = "sgx"))] -use crate::sgx_reexport_prelude::thiserror; +use alloc::vec::Vec; /// Fills a given buffer with data and the left over buffer space with white spaces. pub fn write_slice_and_whitespace_pad( writable: &mut [u8], data: Vec, ) -> Result<(), BufferError> { - ensure!( - data.len() <= writable.len(), - BufferError::InsufficientBufferSize(writable.len(), data.len()) - ); + if data.len() > writable.len() { + return Err(BufferError::InsufficientBufferSize { + actual: writable.len(), + required: data.len(), + }) + } let (left, right) = writable.split_at_mut(data.len()); left.clone_from_slice(&data); // fill the right side with whitespace @@ -39,15 +37,15 @@ pub fn write_slice_and_whitespace_pad( Ok(()) } -#[derive(Debug, thiserror::Error)] +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] pub enum BufferError { - #[error("Insufficient buffer size. Actual: {0}, required: {1}")] - InsufficientBufferSize(usize, usize), + InsufficientBufferSize { actual: usize, required: usize }, } #[cfg(test)] mod tests { use super::*; + use alloc::vec; #[test] fn write_slice_and_whitespace_pad_returns_error_if_buffer_too_small() { diff --git a/core-primitives/utils/src/error.rs b/core-primitives/utils/src/error.rs index 02042b8781..5ca7508d26 100644 --- a/core-primitives/utils/src/error.rs +++ b/core-primitives/utils/src/error.rs @@ -15,19 +15,13 @@ */ -#[cfg(all(not(feature = "std"), feature = "sgx"))] -use crate::sgx_reexport_prelude::*; - -use std::boxed::Box; +use alloc::string::String; pub type Result = core::result::Result; -#[derive(Debug, thiserror::Error)] +#[derive(Debug)] pub enum Error { - #[error("Could not decode from hex data: {0}")] Hex(hex::FromHexError), - #[error("Parity Scale Codec: {0}")] Codec(codec::Error), - #[error(transparent)] - Other(#[from] Box), + Other(String), } diff --git a/core-primitives/utils/src/hex.rs b/core-primitives/utils/src/hex.rs index 8543cba15f..f9d30b5149 100644 --- a/core-primitives/utils/src/hex.rs +++ b/core-primitives/utils/src/hex.rs @@ -17,9 +17,11 @@ //! Hex encoding utility functions. +// Todo: merge with hex_display + use crate::error::{Error, Result}; +use alloc::{string::String, vec::Vec}; use codec::{Decode, Encode}; -use std::{string::String, vec::Vec}; /// Trait to encode a given value to a hex string, prefixed with "0x". pub trait ToHexPrefixed { @@ -70,6 +72,7 @@ pub fn decode_hex>(message: T) -> Result> { #[cfg(test)] mod tests { use super::*; + use alloc::string::ToString; #[test] fn hex_encode_decode_works() { diff --git a/core-primitives/utils/src/hex_display.rs b/core-primitives/utils/src/hex_display.rs new file mode 100644 index 0000000000..f0525b4e2f --- /dev/null +++ b/core-primitives/utils/src/hex_display.rs @@ -0,0 +1,96 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// 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. + +//! Wrapper type for byte collections that outputs hex. +//! +//! Copied from sp-core and made purely no-std. + +/// Simple wrapper to display hex representation of bytes. +pub struct HexDisplay<'a>(&'a [u8]); + +impl<'a> HexDisplay<'a> { + /// Create new instance that will display `d` as a hex string when displayed. + pub fn from(d: &'a R) -> Self { + HexDisplay(d.as_bytes_ref()) + } +} + +impl<'a> core::fmt::Display for HexDisplay<'a> { + fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> { + if self.0.len() < 1027 { + for byte in self.0 { + f.write_fmt(format_args!("{:02x}", byte))?; + } + } else { + for byte in &self.0[0..512] { + f.write_fmt(format_args!("{:02x}", byte))?; + } + f.write_str("...")?; + for byte in &self.0[self.0.len() - 512..] { + f.write_fmt(format_args!("{:02x}", byte))?; + } + } + Ok(()) + } +} + +impl<'a> core::fmt::Debug for HexDisplay<'a> { + fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> { + for byte in self.0 { + f.write_fmt(format_args!("{:02x}", byte))?; + } + Ok(()) + } +} + +/// Simple trait to transform various types to `&[u8]` +pub trait AsBytesRef { + /// Transform `self` into `&[u8]`. + fn as_bytes_ref(&self) -> &[u8]; +} + +impl AsBytesRef for &[u8] { + fn as_bytes_ref(&self) -> &[u8] { + self + } +} + +impl AsBytesRef for [u8] { + fn as_bytes_ref(&self) -> &[u8] { + self + } +} + +impl AsBytesRef for alloc::vec::Vec { + fn as_bytes_ref(&self) -> &[u8] { + self + } +} + +macro_rules! impl_non_endians { + ( $( $t:ty ),* ) => { $( + impl AsBytesRef for $t { + fn as_bytes_ref(&self) -> &[u8] { &self[..] } + } + )* } +} + +impl_non_endians!( + [u8; 1], [u8; 2], [u8; 3], [u8; 4], [u8; 5], [u8; 6], [u8; 7], [u8; 8], [u8; 10], [u8; 12], + [u8; 14], [u8; 16], [u8; 20], [u8; 24], [u8; 28], [u8; 32], [u8; 40], [u8; 48], [u8; 56], + [u8; 64], [u8; 65], [u8; 80], [u8; 96], [u8; 112], [u8; 128] +); diff --git a/core-primitives/utils/src/lib.rs b/core-primitives/utils/src/lib.rs index 03f8f2d263..297ff5090e 100644 --- a/core-primitives/utils/src/lib.rs +++ b/core-primitives/utils/src/lib.rs @@ -17,23 +17,14 @@ //! General utility functions. -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] -#[cfg(all(feature = "std", feature = "sgx"))] -compile_error!("feature \"std\" and feature \"sgx\" cannot be enabled at the same time"); - -#[cfg(all(not(feature = "std"), feature = "sgx"))] -extern crate sgx_tstd as std; - -// re-export module to properly feature gate sgx and regular std environment -#[cfg(all(not(feature = "std"), feature = "sgx"))] -pub mod sgx_reexport_prelude { - pub use thiserror_sgx as thiserror; -} +extern crate alloc; pub mod buffer; pub mod error; pub mod hex; +pub mod hex_display; pub mod stringify; // Public re-exports. @@ -41,4 +32,3 @@ pub use self::{ buffer::write_slice_and_whitespace_pad, hex::{FromHexPrefixed, ToHexPrefixed}, }; -pub use error::Error; diff --git a/core-primitives/utils/src/stringify.rs b/core-primitives/utils/src/stringify.rs index 993c1b15c9..378128891f 100644 --- a/core-primitives/utils/src/stringify.rs +++ b/core-primitives/utils/src/stringify.rs @@ -18,14 +18,13 @@ //! Utility methods to stringify certain types that don't have a working //! `Debug` implementation on `sgx`. +use crate::hex_display::{AsBytesRef, HexDisplay}; +use alloc::{format, string::String}; use codec::Encode; -use sp_core::{crypto::Public, hexdisplay::HexDisplay}; -use std::{format, string::String}; /// Convert a sp_core public type to string. -pub fn public_to_string(t: &T) -> String { - let crypto_pair = t.as_ref(); - format!("{}", HexDisplay::from(&crypto_pair)) +pub fn public_to_string(t: &T) -> String { + format!("{}", HexDisplay::from(t)) } pub fn account_id_to_string(account: &AccountId) -> String { diff --git a/core/direct-rpc-server/Cargo.toml b/core/direct-rpc-server/Cargo.toml index 1eeb0e575f..55efae82fd 100644 --- a/core/direct-rpc-server/Cargo.toml +++ b/core/direct-rpc-server/Cargo.toml @@ -39,7 +39,6 @@ std = [ "sp-runtime/std", # integritee dependencies "itp-types/std", - "itp-utils/std", # local "itc-tls-websocket-server/std", "itp-rpc/std", @@ -50,7 +49,6 @@ std = [ sgx = [ "itc-tls-websocket-server/sgx", "itp-rpc/sgx", - "itp-utils/sgx", "jsonrpc-core_sgx", "sgx_tstd", "sgx_types", diff --git a/core/direct-rpc-server/src/lib.rs b/core/direct-rpc-server/src/lib.rs index be2c4ba7a5..2c0ded9382 100644 --- a/core/direct-rpc-server/src/lib.rs +++ b/core/direct-rpc-server/src/lib.rs @@ -20,6 +20,8 @@ #[cfg(all(feature = "std", feature = "sgx"))] compile_error!("feature \"std\" and feature \"sgx\" cannot be enabled at the same time"); +extern crate alloc; + #[cfg(all(not(feature = "std"), feature = "sgx"))] extern crate sgx_tstd as std; diff --git a/core/direct-rpc-server/src/rpc_responder.rs b/core/direct-rpc-server/src/rpc_responder.rs index d723ebdab5..bc288abf65 100644 --- a/core/direct-rpc-server/src/rpc_responder.rs +++ b/core/direct-rpc-server/src/rpc_responder.rs @@ -19,11 +19,12 @@ use crate::{ response_channel::ResponseChannel, DirectRpcError, DirectRpcResult, RpcConnectionRegistry, RpcHash, SendRpcResponse, }; +use alloc::format; use itp_rpc::{RpcResponse, RpcReturnValue}; use itp_types::{DirectRequestStatus, TrustedOperationStatus}; use itp_utils::{FromHexPrefixed, ToHexPrefixed}; use log::*; -use std::{boxed::Box, sync::Arc, vec::Vec}; +use std::{sync::Arc, vec::Vec}; pub struct RpcResponder where @@ -85,7 +86,7 @@ where let mut new_response = rpc_response.clone(); let mut result = RpcReturnValue::from_hex(&rpc_response.result) - .map_err(|e| DirectRpcError::Other(Box::new(e)))?; + .map_err(|e| DirectRpcError::Other(format!("{:?}", e).into()))?; let do_watch = continue_watching(&status_update); diff --git a/core/direct-rpc-server/src/rpc_watch_extractor.rs b/core/direct-rpc-server/src/rpc_watch_extractor.rs index cad846267d..85654f121c 100644 --- a/core/direct-rpc-server/src/rpc_watch_extractor.rs +++ b/core/direct-rpc-server/src/rpc_watch_extractor.rs @@ -16,11 +16,12 @@ */ use crate::{DetermineWatch, DirectRpcError, DirectRpcResult, RpcHash}; +use alloc::format; use codec::Decode; use itp_rpc::{RpcResponse, RpcReturnValue}; use itp_types::DirectRequestStatus; use itp_utils::FromHexPrefixed; -use std::{boxed::Box, marker::PhantomData}; +use std::marker::PhantomData; pub struct RpcWatchExtractor where @@ -55,7 +56,7 @@ where fn must_be_watched(&self, rpc_response: &RpcResponse) -> DirectRpcResult> { let rpc_return_value = RpcReturnValue::from_hex(&rpc_response.result) - .map_err(|e| DirectRpcError::Other(Box::new(e)))?; + .map_err(|e| DirectRpcError::Other(format!("{:?}", e).into()))?; if !rpc_return_value.do_watch { return Ok(None) diff --git a/core/parentchain/indirect-calls-executor/Cargo.toml b/core/parentchain/indirect-calls-executor/Cargo.toml index 385278e374..bc37518757 100644 --- a/core/parentchain/indirect-calls-executor/Cargo.toml +++ b/core/parentchain/indirect-calls-executor/Cargo.toml @@ -64,7 +64,6 @@ std = [ "itp-api-client-types/std", "itp-types/std", "itp-sgx-runtime-primitives/std", - "itp-utils/std", "log/std", #substrate "binary-merkle-tree/std", diff --git a/core/parentchain/indirect-calls-executor/src/executor.rs b/core/parentchain/indirect-calls-executor/src/executor.rs index 30d7b82657..967bbccccc 100644 --- a/core/parentchain/indirect-calls-executor/src/executor.rs +++ b/core/parentchain/indirect-calls-executor/src/executor.rs @@ -24,15 +24,11 @@ use crate::{ filter_metadata::{EventsFromMetadata, FilterIntoDataFrom}, traits::{ExecuteIndirectCalls, IndirectDispatch, IndirectExecutor}, }; +use alloc::format; use binary_merkle_tree::merkle_root; use codec::Encode; use core::marker::PhantomData; -use ita_stf::{ - TrustedCall, TrustedCallSigned, -}; -use itp_types::parentchain::{ - HandleParentchainEvents, ExtrinsicStatus, FilterEvents, -}; +use ita_stf::{TrustedCall, TrustedCallSigned}; use itp_node_api::metadata::{ pallet_enclave_bridge::EnclaveBridgeCallIndexes, provider::AccessNodeMetadata, NodeMetadataTrait, @@ -41,7 +37,10 @@ use itp_sgx_crypto::{key_repository::AccessKey, ShieldingCryptoDecrypt, Shieldin use itp_stf_executor::traits::StfEnclaveSigning; use itp_stf_primitives::types::AccountId; use itp_top_pool_author::traits::AuthorApi; -use itp_types::{OpaqueCall, ShardIdentifier, H256}; +use itp_types::{ + parentchain::{ExtrinsicStatus, FilterEvents, HandleParentchainEvents}, + OpaqueCall, ShardIdentifier, H256, +}; use log::*; use sp_core::blake2_256; use sp_runtime::traits::{Block as ParentchainBlockTrait, Header, Keccak256}; @@ -148,7 +147,9 @@ impl< })? .ok_or_else(|| Error::Other("Could not create events from metadata".into()))?; - let xt_statuses = events.get_extrinsic_statuses().map_err(|_| Error::Other(format!("Error when shielding for privacy sidechain").into()))?; + let xt_statuses = events.get_extrinsic_statuses().map_err(|_| { + Error::Other(format!("Error when shielding for privacy sidechain").into()) + })?; trace!("xt_statuses:: {:?}", xt_statuses); ParentchainEventHandler::handle_events(events)?; diff --git a/core/parentchain/indirect-calls-executor/src/lib.rs b/core/parentchain/indirect-calls-executor/src/lib.rs index efd240d495..6c29fa6e8e 100644 --- a/core/parentchain/indirect-calls-executor/src/lib.rs +++ b/core/parentchain/indirect-calls-executor/src/lib.rs @@ -27,6 +27,8 @@ #[cfg(all(feature = "std", feature = "sgx"))] compile_error!("feature \"std\" and feature \"sgx\" cannot be enabled at the same time"); +extern crate alloc; + #[cfg(all(not(feature = "std"), feature = "sgx"))] extern crate sgx_tstd as std; diff --git a/core/rpc-client/src/direct_client.rs b/core/rpc-client/src/direct_client.rs index c473a0cdfb..26cc36eee4 100644 --- a/core/rpc-client/src/direct_client.rs +++ b/core/rpc-client/src/direct_client.rs @@ -147,7 +147,7 @@ impl DirectApi for DirectClient { // Decode rpc response. let rpc_response: RpcResponse = serde_json::from_str(&response_str)?; let rpc_return_value = RpcReturnValue::from_hex(&rpc_response.result) - .map_err(|e| Error::Custom(Box::new(e)))?; + .map_err(|e| Error::Custom(format!("{:?}", e).into()))?; // Decode Metadata. let metadata = RuntimeMetadataPrefixed::decode(&mut rpc_return_value.value.as_slice())?; @@ -166,8 +166,9 @@ impl DirectApi for DirectClient { fn decode_from_rpc_response(json_rpc_response: &str) -> Result { let rpc_response: RpcResponse = serde_json::from_str(json_rpc_response)?; - let rpc_return_value = - RpcReturnValue::from_hex(&rpc_response.result).map_err(|e| Error::Custom(Box::new(e)))?; + let rpc_return_value = RpcReturnValue::from_hex(&rpc_response.result) + .map_err(|e| Error::Custom(format!("{:?}", e).into()))?; + let response_message = String::decode(&mut rpc_return_value.value.as_slice())?; match rpc_return_value.status { DirectRequestStatus::Ok => Ok(response_message), diff --git a/enclave-runtime/Cargo.lock b/enclave-runtime/Cargo.lock index ecf30988ec..8c09051e8e 100644 --- a/enclave-runtime/Cargo.lock +++ b/enclave-runtime/Cargo.lock @@ -2401,12 +2401,8 @@ dependencies = [ name = "itp-utils" version = "0.9.0" dependencies = [ - "frame-support", "hex", "parity-scale-codec", - "sgx_tstd", - "sp-core", - "thiserror 1.0.9", ] [[package]] diff --git a/enclave-runtime/Cargo.toml b/enclave-runtime/Cargo.toml index ac380e5fb4..83fcbe4e6f 100644 --- a/enclave-runtime/Cargo.toml +++ b/enclave-runtime/Cargo.toml @@ -127,7 +127,7 @@ itp-time-utils = { path = "../core-primitives/time-utils", default-features = fa itp-top-pool = { path = "../core-primitives/top-pool", default-features = false, features = ["sgx"] } itp-top-pool-author = { path = "../core-primitives/top-pool-author", default-features = false, features = ["sgx"] } itp-types = { path = "../core-primitives/types", default-features = false } -itp-utils = { path = "../core-primitives/utils", default-features = false, features = ["sgx"] } +itp-utils = { path = "../core-primitives/utils", default-features = false } its-block-verification = { path = "../sidechain/block-verification", default-features = false } its-primitives = { path = "../sidechain/primitives", default-features = false } its-sidechain = { path = "../sidechain/sidechain-crate", default-features = false, features = ["sgx"] } diff --git a/enclave-runtime/src/attestation.rs b/enclave-runtime/src/attestation.rs index 857578c431..ecbe3ac9d6 100644 --- a/enclave-runtime/src/attestation.rs +++ b/enclave-runtime/src/attestation.rs @@ -145,7 +145,7 @@ pub unsafe extern "C" fn generate_ias_ra_extrinsic( }; if let Err(e) = write_slice_and_whitespace_pad(extrinsic_slice, extrinsic.encode()) { - return EnclaveError::Other(Box::new(e)).into() + return EnclaveError::BufferError(e).into() }; sgx_status_t::SGX_SUCCESS @@ -180,7 +180,7 @@ pub unsafe extern "C" fn generate_dcap_ra_extrinsic( }; if let Err(e) = write_slice_and_whitespace_pad(extrinsic_slice, extrinsic.encode()) { - return EnclaveError::Other(Box::new(e)).into() + return EnclaveError::BufferError(e).into() }; sgx_status_t::SGX_SUCCESS } @@ -232,7 +232,7 @@ pub unsafe extern "C" fn generate_dcap_ra_quote( let dcap_quote_slice = slice::from_raw_parts_mut(dcap_quote_p, dcap_quote_size as usize); if let Err(e) = write_slice_and_whitespace_pad(dcap_quote_slice, dcap_quote) { - return EnclaveError::Other(Box::new(e)).into() + return EnclaveError::BufferError(e).into() }; sgx_status_t::SGX_SUCCESS @@ -280,7 +280,7 @@ pub unsafe extern "C" fn generate_dcap_ra_extrinsic_from_quote( }; if let Err(e) = write_slice_and_whitespace_pad(extrinsic_slice, extrinsic.encode()) { - return EnclaveError::Other(Box::new(e)).into() + return EnclaveError::BufferError(e).into() }; sgx_status_t::SGX_SUCCESS } @@ -470,7 +470,7 @@ where let extrinsic = extrinsics_factory.create_extrinsics(&[call], None)?[0].clone(); if let Err(e) = write_slice_and_whitespace_pad(extrinsic_slice, extrinsic.encode()) { - return EnclaveError::Other(Box::new(e)).into() + return EnclaveError::BufferError(e).into() }; Ok(()) } diff --git a/enclave-runtime/src/initialization/global_components.rs b/enclave-runtime/src/initialization/global_components.rs index 23f2ac8e23..bb0c960ca0 100644 --- a/enclave-runtime/src/initialization/global_components.rs +++ b/enclave-runtime/src/initialization/global_components.rs @@ -33,7 +33,8 @@ use crate::{ }; use ita_sgx_runtime::Runtime; use ita_stf::{ - privacy_sidechain_inherent::PrivacySidechain, Getter, State as StfState, Stf, TrustedCallSigned, + privacy_sidechain_inherent::ParentchainEventHandler, Getter, State as StfState, Stf, + TrustedCallSigned, }; use itc_direct_rpc_server::{ rpc_connection_registry::ConnectionRegistry, rpc_responder::RpcResponder, @@ -155,7 +156,7 @@ pub type EnclaveIndirectCallsExecutor = IndirectCallsExecut EnclaveNodeMetadataRepository, IndirectCallsFilter, EventCreator, - PrivacySidechain, + ParentchainEventHandler, >; pub type EnclaveValidatorAccessor = ValidatorAccessor< diff --git a/enclave-runtime/src/lib.rs b/enclave-runtime/src/lib.rs index 7c375b8205..111324f0bb 100644 --- a/enclave-runtime/src/lib.rs +++ b/enclave-runtime/src/lib.rs @@ -68,7 +68,6 @@ use once_cell::sync::OnceCell; use sgx_types::sgx_status_t; use sp_runtime::traits::BlakeTwo256; use std::{ - boxed::Box, path::PathBuf, slice, string::{String, ToString}, @@ -189,7 +188,7 @@ pub unsafe extern "C" fn get_rsa_encryption_pubkey( if let Err(e) = write_slice_and_whitespace_pad(pubkey_slice, rsa_pubkey_json.as_bytes().to_vec()) { - return Error::Other(Box::new(e)).into() + return Error::BufferError(e).into() }; sgx_status_t::SGX_SUCCESS @@ -323,7 +322,7 @@ pub unsafe extern "C" fn call_rpc_methods( let response_slice = slice::from_raw_parts_mut(response, response_len as usize); if let Err(e) = write_slice_and_whitespace_pad(response_slice, res.into_bytes()) { - return Error::Other(Box::new(e)).into() + return Error::BufferError(e).into() }; sgx_status_t::SGX_SUCCESS diff --git a/sidechain/block-verification/Cargo.toml b/sidechain/block-verification/Cargo.toml index 376d1267fd..34eed84724 100644 --- a/sidechain/block-verification/Cargo.toml +++ b/sidechain/block-verification/Cargo.toml @@ -34,7 +34,6 @@ std = [ "thiserror", # local "itp-types/std", - "itp-utils/std", "its-primitives/std", # substrate "frame-support/std", @@ -43,7 +42,6 @@ std = [ "sp-runtime/std", ] sgx = [ - "itp-utils/sgx", "sgx_tstd", "thiserror-sgx", ] diff --git a/sidechain/block-verification/src/lib.rs b/sidechain/block-verification/src/lib.rs index 7bcba7e742..b496bcc0be 100644 --- a/sidechain/block-verification/src/lib.rs +++ b/sidechain/block-verification/src/lib.rs @@ -40,6 +40,7 @@ use its_primitives::{ }; use log::*; pub use sp_consensus_slots::Slot; +use sp_core::ByteArray; use sp_runtime::{ app_crypto::Pair, traits::{Block as ParentchainBlockTrait, Header as ParentchainHeaderTrait}, @@ -127,8 +128,8 @@ where expected_author == block.block_data().block_author(), ConsensusError::InvalidAuthority(format!( "Expected author: {}, author found in block: {}", - public_to_string(expected_author), - public_to_string(block.block_data().block_author()) + public_to_string(&expected_author.to_raw_vec()), + public_to_string(&block.block_data().block_author().to_raw_vec()) )) ); diff --git a/sidechain/consensus/aura/Cargo.toml b/sidechain/consensus/aura/Cargo.toml index 5fcd079c4e..f0c527b50f 100644 --- a/sidechain/consensus/aura/Cargo.toml +++ b/sidechain/consensus/aura/Cargo.toml @@ -71,7 +71,6 @@ std = [ "itp-stf-state-handler/std", "itp-time-utils/std", "itp-types/std", - "itp-utils/std", "its-block-composer/std", "its-block-verification/std", "its-consensus-common/std", @@ -90,7 +89,6 @@ sgx = [ "itp-stf-executor/sgx", "itp-stf-state-handler/sgx", "itp-time-utils/sgx", - "itp-utils/sgx", "its-block-composer/sgx", "its-consensus-common/sgx", "its-consensus-slots/sgx", diff --git a/sidechain/rpc-handler/Cargo.toml b/sidechain/rpc-handler/Cargo.toml index bbe5c4e92b..32457c48dd 100644 --- a/sidechain/rpc-handler/Cargo.toml +++ b/sidechain/rpc-handler/Cargo.toml @@ -37,7 +37,6 @@ std = [ "itp-stf-primitives/std", "itp-top-pool-author/std", "itp-types/std", - "itp-utils/std", "its-primitives/std", "jsonrpc-core", "log/std", @@ -47,7 +46,6 @@ sgx = [ "sgx_tstd", "itp-rpc/sgx", "itp-top-pool-author/sgx", - "itp-utils/sgx", "jsonrpc-core_sgx", "rust-base58_sgx", ] diff --git a/sidechain/rpc-handler/src/direct_top_pool_api.rs b/sidechain/rpc-handler/src/direct_top_pool_api.rs index 04a497dadb..729e3cc922 100644 --- a/sidechain/rpc-handler/src/direct_top_pool_api.rs +++ b/sidechain/rpc-handler/src/direct_top_pool_api.rs @@ -131,7 +131,7 @@ where Ok(acc) => acc, Err(msg) => { let error_msg: String = - format!("Could not retrieve pending trusted calls due to: {}", msg); + format!("Could not retrieve pending trusted calls due to: {:?}", msg); return Ok(json!(compute_hex_encoded_return_error(error_msg.as_str()))) }, };