From 2e88cd6c0610ab8c87478ba8d4b417a00a83ed01 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Wed, 4 Sep 2024 20:04:11 +0200 Subject: [PATCH] chore(deps): bump alloy --- Cargo.lock | 40 ++++++++++++++++++++-------------------- Cargo.toml | 16 ++++++---------- src/arguments.rs | 9 +++++---- src/evm.rs | 16 +++++++++------- src/interface_js.rs | 19 +++++++++---------- src/interface_py.rs | 19 +++++++------------ src/selectors.rs | 9 ++++++--- src/state_mutability.rs | 5 +++-- 8 files changed, 65 insertions(+), 68 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6eef958..e75117d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "alloy-dyn-abi" -version = "0.7.7" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413902aa18a97569e60f679c23f46a18db1656d87ab4d4e49d0e1e52042f66df" +checksum = "ba5b68572f5dfa99ede0a491d658c9842626c956b840d0b97d0bbc9637742504" dependencies = [ "alloy-json-abi", "alloy-primitives", @@ -21,9 +21,9 @@ dependencies = [ [[package]] name = "alloy-json-abi" -version = "0.7.7" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc05b04ac331a9f07e3a4036ef7926e49a8bf84a99a1ccfc7e2ab55a5fcbb372" +checksum = "299d2a937b6c60968df3dad2a988b0f0e03277b344639a4f7a31bd68e6285e59" dependencies = [ "alloy-primitives", "alloy-sol-type-parser", @@ -33,9 +33,9 @@ dependencies = [ [[package]] name = "alloy-primitives" -version = "0.7.7" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccb3ead547f4532bc8af961649942f0b9c16ee9226e26caa3f38420651cc0bf4" +checksum = "a767e59c86900dd7c3ce3ecef04f3ace5ac9631ee150beb8b7d22f7fa3bbb2d7" dependencies = [ "alloy-rlp", "bytes", @@ -65,9 +65,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro" -version = "0.7.7" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b40397ddcdcc266f59f959770f601ce1280e699a91fc1862f29cef91707cd09" +checksum = "183bcfc0f3291d9c41a3774172ee582fb2ce6eb6569085471d8f225de7bb86fc" dependencies = [ "alloy-sol-macro-expander", "alloy-sol-macro-input", @@ -79,9 +79,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-expander" -version = "0.7.7" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "867a5469d61480fea08c7333ffeca52d5b621f5ca2e44f271b117ec1fc9a0525" +checksum = "71c4d842beb7a6686d04125603bc57614d5ed78bf95e4753274db3db4ba95214" dependencies = [ "alloy-sol-macro-input", "const-hex", @@ -97,9 +97,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-input" -version = "0.7.7" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e482dc33a32b6fadbc0f599adea520bd3aaa585c141a80b404d0a3e3fa72528" +checksum = "1306e8d3c9e6e6ecf7a39ffaf7291e73a5f655a2defd366ee92c2efebcdf7fee" dependencies = [ "const-hex", "dunce", @@ -112,9 +112,9 @@ dependencies = [ [[package]] name = "alloy-sol-type-parser" -version = "0.7.7" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbcba3ca07cf7975f15d871b721fb18031eec8bce51103907f6dcce00b255d98" +checksum = "f4691da83dce9c9b4c775dd701c87759f173bd3021cbf2e60cde00c5fe6d7241" dependencies = [ "serde", "winnow 0.6.18", @@ -122,10 +122,11 @@ dependencies = [ [[package]] name = "alloy-sol-types" -version = "0.7.7" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91ca40fa20793ae9c3841b83e74569d1cc9af29a2f5237314fd3452d51e38c7" +checksum = "577e262966e92112edbd15b1b2c0947cc434d6e8311df96d3329793fe8047da9" dependencies = [ + "alloy-json-abi", "alloy-primitives", "alloy-sol-macro", "const-hex", @@ -558,9 +559,8 @@ name = "evmole" version = "0.4.1" dependencies = [ "alloy-dyn-abi", - "hex", + "alloy-primitives", "pyo3", - "ruint", "wasm-bindgen", ] @@ -1366,9 +1366,9 @@ dependencies = [ [[package]] name = "syn-solidity" -version = "0.7.7" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c837dc8852cb7074e46b444afb81783140dab12c58867b49fb3898fbafedf7ea" +checksum = "284c41c2919303438fcf8dede4036fd1e82d4fc0fbb2b279bd2a1442c909ca92" dependencies = [ "paste", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index dd43be4..dfae1ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,23 +9,19 @@ readme = "README.md" repository = "https://github.com/cdump/evmole" exclude = ["/javascript", "/python", "/benchmark", "/.github"] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] -ruint = "1.12.3" -hex = { version = "0.4.3", optional = true } +alloy-primitives = "0.8" +alloy-dyn-abi = "0.8" + pyo3 = { version = "0.22.2", features = ["extension-module"], optional = true } wasm-bindgen = { version = "0.2", optional = true } -alloy-dyn-abi = {version = "0.7"} - -[dev-dependencies] -hex = "0.4.3" [features] +python = ["dep:pyo3"] +javascript = ["dep:wasm-bindgen"] + # for dev trace = [] -python = ["dep:hex", "dep:pyo3"] -javascript = ["dep:hex", "dep:wasm-bindgen"] [lib] crate-type = ["cdylib", "lib"] diff --git a/src/arguments.rs b/src/arguments.rs index 66f872a..bc9c246 100644 --- a/src/arguments.rs +++ b/src/arguments.rs @@ -13,10 +13,11 @@ use std::{ cmp::max, collections::{BTreeMap, BTreeSet}, }; +use alloy_primitives::uint; -const VAL_2: U256 = ruint::uint!(2_U256); -const VAL_31_B: [u8; 32] = ruint::uint!(31_U256).to_be_bytes(); -const VAL_131072_B: [u8; 32] = ruint::uint!(131072_U256).to_be_bytes(); +const VAL_2: U256 = uint!(2_U256); +const VAL_31_B: [u8; 32] = uint!(31_U256).to_be_bytes(); +const VAL_131072_B: [u8; 32] = uint!(131072_U256).to_be_bytes(); #[derive(Clone, Debug, PartialEq, Eq, Hash)] struct Val { @@ -681,8 +682,8 @@ pub fn function_arguments(code: &[u8], selector: &Selector, gas_limit: u32) -> S #[cfg(test)] mod test { use crate::function_selectors; - use super::function_arguments; + use alloy_primitives::hex; #[test] fn test_code_offset_buffer() { diff --git a/src/evm.rs b/src/evm.rs index 09fef9d..0079aa4 100644 --- a/src/evm.rs +++ b/src/evm.rs @@ -1,25 +1,27 @@ +use alloy_primitives::uint; + pub mod memory; pub mod op; pub mod stack; pub mod vm; -pub use ruint::aliases::U256; +pub use alloy_primitives::U256; pub const VAL_0_B: [u8; 32] = U256::ZERO.to_be_bytes(); -pub const VAL_1: U256 = ruint::uint!(1_U256); +pub const VAL_1: U256 = uint!(1_U256); pub const VAL_1_B: [u8; 32] = VAL_1.to_be_bytes(); -pub const VAL_4: U256 = ruint::uint!(4_U256); +pub const VAL_4: U256 = uint!(4_U256); -pub const VAL_32: U256 = ruint::uint!(32_U256); +pub const VAL_32: U256 = uint!(32_U256); pub const VAL_32_B: [u8; 32] = VAL_32.to_be_bytes(); -pub const VAL_256: U256 = ruint::uint!(256_U256); +pub const VAL_256: U256 = uint!(256_U256); -pub const VAL_1024: U256 = ruint::uint!(1024_U256); +pub const VAL_1024: U256 = uint!(1024_U256); -pub const VAL_1M: U256 = ruint::uint!(1000000_U256); +pub const VAL_1M: U256 = uint!(1000000_U256); #[derive(Clone)] pub struct Element { diff --git a/src/interface_js.rs b/src/interface_js.rs index 14f5e2b..c9e5a57 100644 --- a/src/interface_js.rs +++ b/src/interface_js.rs @@ -1,18 +1,13 @@ -use hex::FromHex; +use alloy_primitives::hex::{self, FromHex}; use wasm_bindgen::prelude::*; -fn strip_hex_prefix(s: &str) -> &str { - s.strip_prefix("0x").unwrap_or(s) -} - fn decode_hex_code(input: &str) -> Result, JsError> { - hex::decode(strip_hex_prefix(input)) - .map_err(|e| JsError::new(&format!("Failed to decode code hex input: {}", e))) + hex::decode(input).map_err(|e| JsError::new(&format!("Failed to decode code hex input: {e}"))) } fn decode_hex_selector(input: &str) -> Result<[u8; 4], JsError> { - <[u8; 4]>::from_hex(strip_hex_prefix(input)) - .map_err(|e| JsError::new(&format!("Failed to decode selector hex input: {}", e))) + <[u8; 4]>::from_hex(input) + .map_err(|e| JsError::new(&format!("Failed to decode selector hex input: {e}"))) } /// Extracts function selectors from the given bytecode. @@ -50,7 +45,11 @@ pub fn function_arguments(code: &str, selector: &str, gas_limit: u32) -> Result< /// @param {number} gas_limit - Maximum allowed gas usage; set to `0` to use defaults /// @returns {string} `payable` | `nonpayable` | `view` | `pure` #[wasm_bindgen(js_name = functionStateMutability, skip_jsdoc)] -pub fn function_state_mutability(code: &str, selector: &str, gas_limit: u32) -> Result { +pub fn function_state_mutability( + code: &str, + selector: &str, + gas_limit: u32, +) -> Result { let c = decode_hex_code(code)?; let s = decode_hex_selector(selector)?; Ok(crate::state_mutability::function_state_mutability(&c, &s, gas_limit).to_string()) diff --git a/src/interface_py.rs b/src/interface_py.rs index c6a8d4d..da33d6e 100644 --- a/src/interface_py.rs +++ b/src/interface_py.rs @@ -1,8 +1,8 @@ -use std::borrow::Cow; - +use alloy_primitives::hex; use pyo3::exceptions::{PyTypeError, PyValueError}; use pyo3::prelude::*; use pyo3::types::{PyBytes, PyString}; +use std::borrow::Cow; fn input_to_bytes<'a>(code: &'a Bound<'a, PyAny>) -> PyResult> { if let Ok(s) = code.downcast::() { @@ -10,7 +10,7 @@ fn input_to_bytes<'a>(code: &'a Bound<'a, PyAny>) -> PyResult> { .to_str() .map_err(|e| PyValueError::new_err(e.to_string()))?; - let v = hex::decode(strip_hex_prefix(str_slice)) + let v = hex::decode(str_slice) .map_err(|e| PyValueError::new_err(format!("failed to parse hex: {}", e)))?; Ok(Cow::Owned(v)) } else if let Ok(b) = code.downcast::() { @@ -22,10 +22,6 @@ fn input_to_bytes<'a>(code: &'a Bound<'a, PyAny>) -> PyResult> { } } -fn strip_hex_prefix(s: &str) -> &str { - s.strip_prefix("0x").unwrap_or(s) -} - /// Extracts function selectors from the given bytecode. /// /// Args: @@ -101,11 +97,10 @@ fn function_state_mutability( <[u8; 4]>::try_from(selectors_ref).expect("len checked above") }; - Ok(crate::state_mutability::function_state_mutability( - &code_bytes, - &sel, - gas_limit, - ).to_string()) + Ok( + crate::state_mutability::function_state_mutability(&code_bytes, &sel, gas_limit) + .to_string(), + ) } #[pymodule] diff --git a/src/selectors.rs b/src/selectors.rs index ec3ed23..9555265 100644 --- a/src/selectors.rs +++ b/src/selectors.rs @@ -4,7 +4,7 @@ use crate::evm::{ Element, U256, VAL_0_B, VAL_1_B, }; use crate::Selector; - +use alloy_primitives::uint; use std::collections::BTreeSet; #[derive(Clone, Debug, PartialEq, Eq, Hash)] @@ -14,7 +14,7 @@ enum Label { MulSig, } -const VAL_FFFFFFFF_B: [u8; 32] = ruint::uint!(0xffffffff_U256).to_be_bytes(); +const VAL_FFFFFFFF_B: [u8; 32] = uint!(0xffffffff_U256).to_be_bytes(); fn analyze( vm: &mut Vm