Skip to content

Commit

Permalink
chore(abi): use tiny-keccak instead of sha3
Browse files Browse the repository at this point in the history
  • Loading branch information
clearloop committed Dec 28, 2023
1 parent dc08a95 commit 491db87
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 26 deletions.
21 changes: 1 addition & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
8 changes: 5 additions & 3 deletions abi/src/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 491db87

Please sign in to comment.