Skip to content

Commit 3ba01ec

Browse files
committed
all: Replace tiny-keccak with alloy::primitives::keccak256
tiny-keccak 2.0 dropped the top-level keccak256 function and changed Keccak's streaming API, breaking every call site. Route all keccak hashing through alloy::primitives::keccak256, which is already used elsewhere in the codebase, and drop the tiny-keccak dependency.
1 parent 64023bc commit 3ba01ec

12 files changed

Lines changed: 16 additions & 35 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chain/ethereum/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ serde = { workspace = true }
1212
prost = { workspace = true }
1313
prost-types = { workspace = true }
1414
anyhow = "1.0"
15-
tiny-keccak = "1.5.0"
1615
hex = "0.4.3"
1716
semver = { workspace = true }
1817
thiserror = { workspace = true }

chain/ethereum/src/adapter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use graph::data_source::common::ContractCall;
99
use graph::firehose::CallToFilter;
1010
use graph::firehose::CombinedFilter;
1111
use graph::firehose::LogFilter;
12+
use graph::prelude::alloy::primitives::keccak256;
1213
use graph::prelude::alloy::primitives::{Address, B256};
1314
use graph::prelude::alloy::rpc::types::Log;
1415
use graph::prelude::alloy::transports::{RpcError, TransportErrorKind};
@@ -19,7 +20,6 @@ use std::cmp;
1920
use std::collections::{HashMap, HashSet};
2021
use std::fmt;
2122
use thiserror::Error;
22-
use tiny_keccak::keccak256;
2323

2424
use graph::prelude::*;
2525
use graph::{

chain/ethereum/src/call_helper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn is_rpc_revert_message(message: &str) -> bool {
7272

7373
/// Decode a Solidity revert(reason) payload, returning the reason string when possible.
7474
fn as_solidity_revert_reason(bytes: &[u8]) -> Option<String> {
75-
let selector = &tiny_keccak::keccak256(b"Error(string)")[..4];
75+
let selector = &graph::prelude::alloy::primitives::keccak256(b"Error(string)")[..4];
7676
if bytes.len() >= 4 && &bytes[..4] == selector {
7777
abi::DynSolType::String
7878
.abi_decode(&bytes[4..])

chain/ethereum/src/data_source.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use graph::env::ENV_VARS;
2121
use graph::futures03::TryStreamExt;
2222
use graph::futures03::future::try_join;
2323
use graph::futures03::stream::FuturesOrdered;
24+
use graph::prelude::alloy::primitives::keccak256;
2425
use graph::prelude::alloy::{
2526
consensus::{TxEnvelope, TxLegacy},
2627
network::TransactionResponse,
@@ -37,7 +38,6 @@ use std::num::NonZeroU32;
3738
use std::str::FromStr;
3839
use std::sync::Arc;
3940
use std::time::{Duration, Instant};
40-
use tiny_keccak::{Keccak, keccak256};
4141

4242
use graph::{
4343
blockchain::{self, Blockchain},
@@ -1589,13 +1589,7 @@ impl MappingEventHandler {
15891589

15901590
/// Hashes a string to a B256 hash.
15911591
fn string_to_b256(s: &str) -> B256 {
1592-
let mut result = [0u8; 32];
1593-
let data = s.replace(' ', "").into_bytes();
1594-
let mut sponge = Keccak::new_keccak256();
1595-
sponge.update(&data);
1596-
sponge.finalize(&mut result);
1597-
1598-
B256::from_slice(&result)
1592+
keccak256(s.replace(' ', "").as_bytes())
15991593
}
16001594

16011595
#[derive(Clone, Debug, Default, Hash, Eq, PartialEq, Deserialize)]

core/src/subgraph/context/instance/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ where
104104
};
105105

106106
let mapping_request_sender = {
107-
let module_hash = tiny_keccak::keccak256(module_bytes.as_ref());
107+
let module_hash = alloy::primitives::keccak256(module_bytes.as_ref()).0;
108108
if let Some(sender) = self.module_cache.get(&module_hash) {
109109
sender.clone()
110110
} else {

graph/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ slog-async = "2.5.0"
6262
slog-envlogger = "2.1.0"
6363
slog-term = "2.7.0"
6464
petgraph = "0.8.3"
65-
tiny-keccak = "1.5.0"
6665
tokio = { workspace = true}
6766
tokio-stream = { workspace = true }
6867
tokio-retry = { workspace = true }

graph/src/components/subgraph/proof_of_indexing/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ mod tests {
134134
// return the same result.
135135
check_for_child_errors(&case.data).expect("Found child errors");
136136

137-
let offline_fast = tiny_keccak::keccak256(&fast_stable_hash(&case.data).to_le_bytes());
137+
let offline_fast =
138+
alloy::primitives::keccak256(fast_stable_hash(&case.data).to_le_bytes()).0;
138139
let offline_legacy = stable_hash_legacy::<SetHasher, _>(&case.data);
139140

140141
for (version, offline, hardcoded) in [

graph/src/components/subgraph/proof_of_indexing/online.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ impl ProofOfIndexingFinisher {
324324

325325
match self.state {
326326
Hashers::Legacy(legacy) => legacy.finish(),
327-
Hashers::Fast(fast) => tiny_keccak::keccak256(&fast.finish().to_le_bytes()),
327+
Hashers::Fast(fast) => alloy::primitives::keccak256(fast.finish().to_le_bytes()).0,
328328
}
329329
}
330330
}

graph/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ pub mod prelude {
100100
pub use std::sync::Arc;
101101
pub use std::time::Duration;
102102
pub use thiserror;
103-
pub use tiny_keccak;
104103
pub use tokio;
105104
pub use toml;
106105
pub use tonic;

0 commit comments

Comments
 (0)