From 491db8752de99d0543d27446bb32ad872e5aa6e4 Mon Sep 17 00:00:00 2001 From: clearloop Date: Thu, 28 Dec 2023 17:08:00 +0800 Subject: [PATCH] chore(abi): use tiny-keccak instead of sha3 --- Cargo.lock | 21 +-------------------- Cargo.toml | 2 +- abi/Cargo.toml | 4 ++-- abi/src/selector.rs | 8 +++++--- 4 files changed, 9 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c517f46ff..5eb880436 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -879,15 +879,6 @@ dependencies = [ "sha2", ] -[[package]] -name = "keccak" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940" -dependencies = [ - "cpufeatures", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -1566,16 +1557,6 @@ dependencies = [ "digest", ] -[[package]] -name = "sha3" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" -dependencies = [ - "digest", - "keccak", -] - [[package]] name = "sharded-slab" version = "0.1.7" @@ -2216,10 +2197,10 @@ dependencies = [ "hex", "postcard", "serde", - "sha3", "sol-abi", "syn 2.0.42", "thiserror", + "tiny-keccak", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index c7ba3c30c..556e64457 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,10 +40,10 @@ revm = { version = "3.5.0", default-features = false } semver = "1.0.20" serde = { version = "1.0.193", default-features = false } serde_json = "1.0.108" -sha3 = "0.10.8" smallvec = "1.11.2" syn = { version = "2.0.42", features = [ "full" ] } thiserror = "1.0.51" +tiny-keccak = "2.0.2" toml = "0.8.8" tracing = "0.1.40" tracing-subscriber = "0.3.18" diff --git a/abi/Cargo.toml b/abi/Cargo.toml index 37ce2d5a2..93487d1dc 100644 --- a/abi/Cargo.toml +++ b/abi/Cargo.toml @@ -16,14 +16,14 @@ sol-abi.workspace = true hex = { workspace = true, optional = true } postcard = { workspace = true, default-features = false, features = [ "use-std" ], optional = true } serde = { workspace = true, features = [ "derive" ], optional = true } -sha3 = { workspace = true, optional = true } syn = { workspace = true, optional = true } thiserror = { workspace = true, optional = true } +tiny-keccak = { workspace = true, optional = true, features = [ "sha3" ] } # TODO: introduce feature alloc. [features] bytes = [ "postcard", "serde" ] hex = [ "dep:hex", "thiserror", "bytes" ] -selector = [ "sha3" ] +selector = [ "tiny-keccak" ] serde = [ "dep:serde", "sol-abi/serde" ] syn = [ "dep:syn", "sol-abi/syn" ] diff --git a/abi/src/selector.rs b/abi/src/selector.rs index 387d4fc1f..7f5e15f34 100644 --- a/abi/src/selector.rs +++ b/abi/src/selector.rs @@ -2,13 +2,15 @@ #![cfg(feature = "selector")] use crate::Abi; -use sha3::{Digest, Keccak256}; +use tiny_keccak::{Hasher, Sha3}; /// Generate a keccak hash of the input (sha3) pub fn keccak256(input: &[u8]) -> [u8; 32] { - let mut hasher = Keccak256::new(); + let mut hasher = Sha3::v256(); + let mut output = [0; 32]; hasher.update(input); - hasher.finalize().into() + hasher.finalize(&mut output); + output } /// Parse selector from bytes.