diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 21021ea0..06600144 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -17,17 +17,14 @@ prost = { version = "0.10", default-features = false, features = ["prost-derive" bytes = { version = "1.0.1", default-features = false } hex = { version = "0.4.3", default-features = false, features = [ "alloc" ] } anyhow = { version = "1.0.40", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22", default-features = false } sha2 = { version = "0.9.3", optional = true } sha3 = { version = "0.9.1", optional = true } ripemd160 = { version = "0.9.1", optional = true } -sp-core = { version = "6.0.0", optional = true } [dev-dependencies] sha2 = { version = "0.9.3" } sha3 = { version = "0.9.1" } ripemd160 = { version = "0.9.1" } -sp-core = { version = "6.0.0" } serde = { version = "1.0.125", features = ["derive"] } serde_json = "1.0.64" @@ -38,9 +35,7 @@ std = [ "bytes/std", "hex/std", "anyhow/std", - "sp-std/std", "sha2", "sha3", "ripemd160", - "sp-core", ] diff --git a/rust/src/api.rs b/rust/src/api.rs index 62481f01..4944422e 100644 --- a/rust/src/api.rs +++ b/rust/src/api.rs @@ -1,5 +1,5 @@ -use sp_std::collections::btree_map::BTreeMap; -use sp_std::vec; +use alloc::collections::btree_map::BTreeMap; +use alloc::vec; use crate::compress::{decompress, is_compressed}; use crate::host_functions::HostFunctionsProvider; @@ -233,10 +233,10 @@ mod tests { use super::*; use alloc::string::String; + use alloc::vec::Vec; use anyhow::{bail, ensure}; use prost::Message; use serde::Deserialize; - use sp_std::vec::Vec; #[cfg(feature = "std")] use std::fs::File; #[cfg(feature = "std")] diff --git a/rust/src/compress.rs b/rust/src/compress.rs index a3ef79ee..f18eeb3d 100644 --- a/rust/src/compress.rs +++ b/rust/src/compress.rs @@ -1,7 +1,7 @@ +use alloc::borrow::ToOwned; +use alloc::collections::btree_map::BTreeMap as HashMap; +use alloc::vec::Vec; use prost::Message; -use sp_std::borrow::ToOwned; -use sp_std::collections::btree_map::BTreeMap as HashMap; -use sp_std::vec::Vec; use crate::helpers::Result; use crate::ics23; diff --git a/rust/src/helpers.rs b/rust/src/helpers.rs index d40220c3..36e48188 100644 --- a/rust/src/helpers.rs +++ b/rust/src/helpers.rs @@ -1,2 +1,2 @@ pub type Result = anyhow::Result; -pub type Hash = sp_std::vec::Vec; +pub type Hash = alloc::vec::Vec; diff --git a/rust/src/host_functions.rs b/rust/src/host_functions.rs index 2c52a2b4..d68ba0fa 100644 --- a/rust/src/host_functions.rs +++ b/rust/src/host_functions.rs @@ -22,13 +22,16 @@ pub trait HostFunctionsProvider { pub mod host_functions_impl { use crate::host_functions::HostFunctionsProvider; use ripemd160::Ripemd160; - use sha2::{Digest, Sha512, Sha512Trunc256}; + use sha2::{Digest, Sha256, Sha512, Sha512Trunc256}; use sha3::Sha3_512; pub struct HostFunctionsManager; impl HostFunctionsProvider for HostFunctionsManager { fn sha2_256(message: &[u8]) -> [u8; 32] { - sp_core::hashing::sha2_256(message) + let digest = Sha256::digest(message); + let mut buf = [0u8; 32]; + buf.copy_from_slice(&digest); + buf } fn sha2_512(message: &[u8]) -> [u8; 64] { diff --git a/rust/src/ops.rs b/rust/src/ops.rs index 7574803f..0097d89c 100644 --- a/rust/src/ops.rs +++ b/rust/src/ops.rs @@ -1,5 +1,5 @@ use anyhow::{bail, ensure}; -use sp_std::convert::TryInto; +use core::convert::TryInto; use crate::helpers::{Hash, Result}; use crate::host_functions::HostFunctionsProvider; @@ -80,8 +80,11 @@ fn proto_len(length: usize) -> Result { #[cfg(test)] mod tests { use super::*; + use crate::host_functions::host_functions_impl::HostFunctionsManager; - use sp_std::vec::Vec; + + use alloc::vec; + use alloc::vec::Vec; fn decode(input: &str) -> Vec { hex::decode(input).unwrap() diff --git a/rust/src/verify.rs b/rust/src/verify.rs index 67577ebd..8d84d023 100644 --- a/rust/src/verify.rs +++ b/rust/src/verify.rs @@ -7,7 +7,7 @@ use crate::helpers::Result; use crate::host_functions::HostFunctionsProvider; use crate::ics23; use crate::ops::{apply_inner, apply_leaf}; -use sp_std::vec::Vec; +use alloc::vec::Vec; pub type CommitmentRoot = Vec; @@ -317,12 +317,13 @@ fn right_branches_are_empty(spec: &ics23::InnerSpec, op: &ics23::InnerOp) -> Res #[cfg(test)] mod tests { use super::*; + use crate::api; use crate::host_functions::host_functions_impl::HostFunctionsManager; use crate::ics23::{ExistenceProof, HashOp, InnerOp, InnerSpec, LeafOp, LengthOp, ProofSpec}; - use sp_std::collections::btree_map::BTreeMap as HashMap; - #[cfg(not(feature = "std"))] - use sp_std::prelude::*; + + use alloc::collections::btree_map::BTreeMap as HashMap; + use alloc::vec; #[test] fn calculate_root_from_leaf() {