diff --git a/bridges/modules/substrate/Cargo.toml b/bridges/modules/substrate/Cargo.toml
index d5ffb159d2..40b7b0b894 100644
--- a/bridges/modules/substrate/Cargo.toml
+++ b/bridges/modules/substrate/Cargo.toml
@@ -24,6 +24,18 @@ tag = 'v2.0.0-rc6'
default-features = false
git = "https://github.com/paritytech/substrate/"
+[dev-dependencies.sp-core]
+version = "2.0.0-rc6"
+tag = 'v2.0.0-rc6'
+default-features = false
+git = "https://github.com/paritytech/substrate/"
+
+[dev-dependencies.sp-state-machine]
+version = "0.8.0-rc6"
+tag = 'v2.0.0-rc6'
+default-features = false
+git = "https://github.com/paritytech/substrate/"
+
[features]
default = ["std"]
std = [
diff --git a/bridges/modules/substrate/src/lib.rs b/bridges/modules/substrate/src/lib.rs
index 84fde5c57d..034c56a8a4 100644
--- a/bridges/modules/substrate/src/lib.rs
+++ b/bridges/modules/substrate/src/lib.rs
@@ -13,3 +13,5 @@
// You should have received a copy of the GNU General Public License
// along with Parity Bridges Common. If not, see .
+
+mod storage_proof;
diff --git a/bridges/modules/substrate/src/storage_proof.rs b/bridges/modules/substrate/src/storage_proof.rs
index dfdc0c5787..40a1399695 100644
--- a/bridges/modules/substrate/src/storage_proof.rs
+++ b/bridges/modules/substrate/src/storage_proof.rs
@@ -14,29 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Parity Bridges Common. If not, see .
-// Copyright 2017-2019 Parity Technologies (UK) Ltd.
-// This file is part of Parity Bridges Common.
+// TODO: remove on actual use
+#![allow(dead_code)]
-// Parity Bridges Common is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Parity Bridges Common is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Parity Bridges Common. If not, see .
-
-//! Logic for checking Parity Bridges Common storage proofs.
+//! Logic for checking Substrate storage proofs.
use hash_db::{HashDB, Hasher, EMPTY_PREFIX};
use sp_runtime::RuntimeDebug;
-use sp_trie::{trie_types::TrieDB, MemoryDB, Trie};
-
-pub(crate) type StorageProof = Vec>;
+use sp_trie::{read_trie_value, Layout, MemoryDB, StorageProof};
/// This struct is used to read storage values from a subset of a Merklized database. The "proof"
/// is a subset of the nodes in the Merkle structure of the database, so that it provides
@@ -57,27 +42,19 @@ where
///
/// This returns an error if the given proof is invalid with respect to the given root.
pub fn new(root: H::Out, proof: StorageProof) -> Result {
- let mut db = MemoryDB::default();
- for item in proof {
- db.insert(EMPTY_PREFIX, &item);
+ let db = proof.into_memory_db();
+ if !db.contains(&root, EMPTY_PREFIX) {
+ return Err(Error::StorageRootMismatch);
}
+
let checker = StorageProofChecker { root, db };
- // Return error if trie would be invalid.
- let _ = checker.trie()?;
Ok(checker)
}
/// Reads a value from the available subset of storage. If the value cannot be read due to an
/// incomplete or otherwise invalid proof, this returns an error.
pub fn read_value(&self, key: &[u8]) -> Result