diff --git a/Cargo.lock b/Cargo.lock index 28e5041..bd6ec6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -344,6 +344,29 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" +[[package]] +name = "bindgen" +version = "0.68.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "726e4313eb6ec35d2730258ad4e15b547ee75d6afaa1361a922e78e59b7d8078" +dependencies = [ + "bitflags 2.4.0", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 2.0.37", + "which", +] + [[package]] name = "bit-set" version = "0.5.3" @@ -458,6 +481,7 @@ dependencies = [ "serde", "serde_json", "tracing", + "xkcp-rs", ] [[package]] @@ -490,6 +514,15 @@ dependencies = [ "libc", ] +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -523,6 +556,17 @@ dependencies = [ "half", ] +[[package]] +name = "clang-sys" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f" +dependencies = [ + "glob", + "libc", + "libloading", +] + [[package]] name = "clap" version = "4.4.3" @@ -979,6 +1023,12 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "group" version = "0.13.0" @@ -1044,6 +1094,15 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "home" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +dependencies = [ + "windows-sys", +] + [[package]] name = "impl-codec" version = "0.6.0" @@ -1157,12 +1216,28 @@ dependencies = [ "spin", ] +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "libc" version = "0.2.148" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" +[[package]] +name = "libloading" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +dependencies = [ + "cfg-if", + "winapi", +] + [[package]] name = "libm" version = "0.2.7" @@ -1227,6 +1302,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.1" @@ -1271,6 +1352,16 @@ dependencies = [ "libc", ] +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -1470,6 +1561,12 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + [[package]] name = "pest" version = "2.7.3" @@ -1555,6 +1652,16 @@ dependencies = [ "tracing", ] +[[package]] +name = "prettyplease" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" +dependencies = [ + "proc-macro2", + "syn 2.0.37", +] + [[package]] name = "primitive-types" version = "0.12.1" @@ -2088,6 +2195,12 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shlex" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380" + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -2560,6 +2673,18 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + [[package]] name = "winapi" version = "0.3.9" @@ -2675,6 +2800,23 @@ dependencies = [ "tap", ] +[[package]] +name = "xkcp-rs" +version = "0.0.2" +source = "git+https://github.com/DaniPopes/xkcp-rs#08bc699c96eaef22bface9beaba15bebd4701a1b" +dependencies = [ + "xkcp-sys", +] + +[[package]] +name = "xkcp-sys" +version = "0.0.2" +source = "git+https://github.com/DaniPopes/xkcp-rs#08bc699c96eaef22bface9beaba15bebd4701a1b" +dependencies = [ + "bindgen", + "cc", +] + [[package]] name = "zeroize" version = "1.6.0" diff --git a/crates/mipsevm/Cargo.toml b/crates/mipsevm/Cargo.toml index c43b510..8745288 100644 --- a/crates/mipsevm/Cargo.toml +++ b/crates/mipsevm/Cargo.toml @@ -16,6 +16,7 @@ revm = { version = "3.3.0", features = ["no_gas_measuring"] } rustc-hash = "1.1.0" serde = { version = "1.0.188", features = ["derive"] } serde_json = "1.0.107" +xkcp-rs = { git = "https://github.com/DaniPopes/xkcp-rs" } # misc anyhow = "1.0.75" diff --git a/crates/mipsevm/src/page.rs b/crates/mipsevm/src/page.rs index 4e1b2f5..8e4a9d5 100644 --- a/crates/mipsevm/src/page.rs +++ b/crates/mipsevm/src/page.rs @@ -1,7 +1,6 @@ //! This module contains the data structure for a [Page] within the MIPS emulator's [Memory]. -use crate::{utils::keccak_concat_fixed, Address, Gindex, Page}; -use alloy_primitives::keccak256; +use crate::{utils::keccak256, utils::keccak_concat_fixed, Address, Gindex, Page}; use anyhow::Result; use once_cell::sync::Lazy; diff --git a/crates/mipsevm/src/test_utils/mod.rs b/crates/mipsevm/src/test_utils/mod.rs index 8878249..a8f11c2 100644 --- a/crates/mipsevm/src/test_utils/mod.rs +++ b/crates/mipsevm/src/test_utils/mod.rs @@ -1,7 +1,7 @@ //! Testing utilities. -use crate::{utils::concat_fixed, PreimageOracle}; -use alloy_primitives::{hex, keccak256}; +use crate::{utils::concat_fixed, utils::keccak256, PreimageOracle}; +use alloy_primitives::hex; use anyhow::Result; use preimage_oracle::{Hint, Keccak256Key, Key, LocalIndexKey}; use rustc_hash::FxHashMap; diff --git a/crates/mipsevm/src/utils.rs b/crates/mipsevm/src/utils.rs index 1fea74b..8bb78f6 100644 --- a/crates/mipsevm/src/utils.rs +++ b/crates/mipsevm/src/utils.rs @@ -1,6 +1,6 @@ //! This module contains utility and helper functions for this crate. -use alloy_primitives::{keccak256, B256}; +use alloy_primitives::B256; /// Concatenate two fixed sized arrays together into a new array with minimal reallocation. #[inline(always)] @@ -17,10 +17,16 @@ where /// Hash the concatenation of two fixed sized arrays. #[inline(always)] -pub(crate) fn keccak_concat_fixed(a: [T; N], b: [T; M]) -> B256 +pub(crate) fn keccak_concat_fixed(a: [u8; N], b: [u8; M]) -> B256 where - T: Copy + Default, - [T; N + M]: AsRef<[u8]>, + [(); N + M]:, { - keccak256(concat_fixed(a, b)) + keccak256(concat_fixed(a, b).as_slice()) +} + +#[inline(always)] +pub(crate) fn keccak256>(input: T) -> B256 { + let mut out = B256::ZERO; + xkcp_rs::keccak256(input.as_ref(), out.as_mut()); + out } diff --git a/crates/mipsevm/src/witness.rs b/crates/mipsevm/src/witness.rs index 6ac1efa..b010362 100644 --- a/crates/mipsevm/src/witness.rs +++ b/crates/mipsevm/src/witness.rs @@ -1,7 +1,7 @@ //! This module contains the various witness types. -use crate::{State, StateWitness, StateWitnessHasher}; -use alloy_primitives::{keccak256, Bytes, B256, U256}; +use crate::{utils::keccak256, State, StateWitness, StateWitnessHasher}; +use alloy_primitives::{Bytes, B256, U256}; use alloy_sol_types::{sol, SolCall}; use preimage_oracle::KeyType;