Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring-up of state trie hash verification function #3

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
634 changes: 358 additions & 276 deletions Cargo.lock

Large diffs are not rendered by default.

30 changes: 23 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ ruint = { version = "1.7.0", features = ["rlp", "serde"] }
hex = { version = "0.4" }
fixed-hash = { version = "0.8", default-features = false, features = ["rustc-hex"]}
cid = { version = "0.8.3", default-features = false, features = ["serde-codec"] }
primitive-types = { version = "0.12", features = ["rlp", "serde"] }
hash-db = "0.15"
plain_hasher = "0.2"
rlp = { version = "0.5", default-features = false }
sha3 = { version = "0.10", default-features = false }
triehash = "0.8"
hex-literal = "0.3"
derive_more = "0.99"
lazy_static = "1.4.0"
Expand All @@ -35,24 +41,34 @@ serde_json = "1.0"
walkdir = "2.3"
multihash = { version = "0.16.1", default-features = false }

fvm = { version = "3.0.0-alpha.21", default-features = false, features = ["testing"] }
fvm = { version = "3.0.0-rc.1", default-features = false, features = ["testing"] }
fvm_ipld_kamt = { version = "0.2.0" }
fvm_ipld_blockstore = "0.1.1"
fvm_ipld_encoding = "0.3.3"
fvm_shared = { version = "3.0.0-alpha.17", default-features = false }
fvm_integration_tests = { version = "3.0.0-alpha.1" }
fvm_shared = { version = "3.0.0-alpha.20", default-features = false }
fvm_integration_tests = { version = "3.0.0-alpha.3" }

actors-v10 = { package = "fil_builtin_actors_bundle", git = "https://github.com/filecoin-project/builtin-actors", branch = "next", features = ["m2-native"] }
fil_actor_evm = { package = "fil_actor_evm", git = "https://github.com/filecoin-project/builtin-actors", branch = "next" }
fil_actor_eam = { package = "fil_actor_eam", git = "https://github.com/filecoin-project/builtin-actors", branch = "next" }
fil_actors_runtime = { package = "fil_actors_runtime", git = "https://github.com/filecoin-project/builtin-actors", branch = "next", features = ["test_utils"] }
actors-v10 = { package = "fil_builtin_actors_bundle", git = "https://github.com/shamb0/builtin-actors", branch = "shamb0/mirror-next" }
fil_actor_evm = { package = "fil_actor_evm", git = "https://github.com/shamb0/builtin-actors", branch = "shamb0/mirror-next" }
fil_actors_evm_shared = { package = "fil_actors_evm_shared", git = "https://github.com/shamb0/builtin-actors", branch = "shamb0/mirror-next" }
fil_actors_runtime = { package = "fil_actors_runtime", git = "https://github.com/shamb0/builtin-actors", branch = "shamb0/mirror-next", features = ["test_utils"] }

[dev-dependencies]
fil_actor_eam = { package = "fil_actor_eam", git = "https://github.com/shamb0/builtin-actors", branch = "shamb0/mirror-next" }

[dependencies.wasmtime]
version = "2.0.2"
default-features = false
features = ["cranelift", "parallel-compilation"]

[patch.crates-io]
fvm = { path = "../fork02-ref-fvm/ref-fvm/fvm" }
fvm_ipld_kamt = { path = "../fork02-ref-fvm/ref-fvm/ipld/kamt" }
fvm_ipld_blockstore = { path = "../fork02-ref-fvm/ref-fvm/ipld/blockstore" }
fvm_ipld_encoding = { path = "../fork02-ref-fvm/ref-fvm/ipld/encoding" }
fvm_integration_tests = { path = "../fork02-ref-fvm/ref-fvm/testing/integration" }
fvm_shared = { path = "../fork02-ref-fvm/ref-fvm/shared" }

#[patch.crates-io]
#fvm_shared = { git = "https://github.com/filecoin-project/ref-fvm", branch = "master" }
#fvm_sdk = { git = "https://github.com/filecoin-project/ref-fvm", branch = "master" }
Expand Down
21 changes: 8 additions & 13 deletions src/common/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use fvm_ipld_encoding::CborStore;
use fvm_shared::ActorID;
use multihash::Code;

use crate::common::error::Error::{FailedToLoadManifest, FailedToSetActor, FailedToSetState};
use super::error::Error::{FailedToLoadManifest, FailedToSetState};

// Retrieve system, init and accounts actors code CID
pub fn fetch_builtin_code_cid(
Expand Down Expand Up @@ -45,10 +45,8 @@ pub fn set_sys_actor(
balance: Default::default(),
delegated_address: None,
};
state_tree
.set_actor(system_actor::SYSTEM_ACTOR_ID, sys_actor_state)
.map_err(anyhow::Error::from)
.context(FailedToSetActor("system actor".to_owned()))
state_tree.set_actor(system_actor::SYSTEM_ACTOR_ID, sys_actor_state);
Ok(())
}

pub fn set_init_actor(
Expand All @@ -69,10 +67,8 @@ pub fn set_init_actor(
delegated_address: None,
};

state_tree
.set_actor(init_actor::INIT_ACTOR_ID, init_actor_state)
.map_err(anyhow::Error::from)
.context(FailedToSetActor("init actor".to_owned()))
state_tree.set_actor(init_actor::INIT_ACTOR_ID, init_actor_state);
Ok(())
}

pub fn set_eam_actor(state_tree: &mut StateTree<impl Blockstore>, eam_code_cid: Cid) -> Result<()> {
Expand All @@ -91,8 +87,7 @@ pub fn set_eam_actor(state_tree: &mut StateTree<impl Blockstore>, eam_code_cid:
delegated_address: None,
};

state_tree
.set_actor(EAM_ACTOR_ID, eam_actor_state)
.map_err(anyhow::Error::from)
.context(FailedToSetActor("eam actor".to_owned()))
state_tree.set_actor(EAM_ACTOR_ID, eam_actor_state);

Ok(())
}
24 changes: 24 additions & 0 deletions src/common/merkle_trie.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use bytes::Bytes;
use hash_db::Hasher;
use plain_hasher::PlainHasher;
use sha3::{Digest, Keccak256};
pub use triehash::sec_trie_root;

use super::{B256, H160, H256};

pub fn trie_root(acc_data: Vec<(H160, Bytes)>) -> B256 {
B256(sec_trie_root::<KeccakHasher, _, _, _>(acc_data.into_iter()).0)
}

#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct KeccakHasher;

impl Hasher for KeccakHasher {
type Out = H256;
type StdHasher = PlainHasher;
const LENGTH: usize = 32;
fn hash(x: &[u8]) -> Self::Out {
let out = Keccak256::digest(x);
H256::from_slice(out.as_slice())
}
}
2 changes: 2 additions & 0 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod bits;
pub mod builtin;
mod error;
pub mod merkle_trie;
mod skip;
mod system;
pub mod tester;
Expand All @@ -9,6 +10,7 @@ extern crate alloc;

pub use bits::{B160, B256};
pub use error::Error;
pub use primitive_types::{H160, H256};
pub use ruint::aliases::U256;
pub use skip::SKIP_TESTS;
pub use system::system_find_all_json_tests;
Loading