Skip to content

Commit 40b3c67

Browse files
committed
fix: filter by deposit signature hash (#14841)
1 parent baf5dcc commit 40b3c67

File tree

1 file changed

+75
-11
lines changed

1 file changed

+75
-11
lines changed

crates/ethereum/evm/src/eip6110.rs

+75-11
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,24 @@ pub fn accumulate_deposits_from_logs<'a>(
4040
logs: impl IntoIterator<Item = &'a Log>,
4141
out: &mut Vec<u8>,
4242
) -> Result<(), BlockValidationError> {
43-
logs.into_iter().filter(|log| log.address == address).try_for_each(|log| {
44-
// We assume that the log is valid because it was emitted by the
45-
// deposit contract.
46-
let decoded_log =
47-
DepositEvent::decode_log(log, false).map_err(|err: alloy_sol_types::Error| {
48-
BlockValidationError::DepositRequestDecode(err.to_string())
49-
})?;
50-
accumulate_deposit_from_log(&decoded_log, out);
51-
Ok(())
52-
})
43+
logs.into_iter()
44+
// filter logs by address
45+
.filter(|log| log.address == address)
46+
// explicitly filter logs by the DepositEvent's signature hash (first topic)
47+
.filter(|log| {
48+
// 0x649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5
49+
log.topics().first() == Some(&DepositEvent::SIGNATURE_HASH)
50+
})
51+
.try_for_each(|log| {
52+
// We assume that the log is valid because it was emitted by the
53+
// deposit contract.
54+
let decoded_log =
55+
DepositEvent::decode_log(log, false).map_err(|err: alloy_sol_types::Error| {
56+
BlockValidationError::DepositRequestDecode(err.to_string())
57+
})?;
58+
accumulate_deposit_from_log(&decoded_log, out);
59+
Ok(())
60+
})
5361
}
5462

5563
/// Accumulate deposits from a receipt. Iterates over the logs in the receipt
@@ -102,10 +110,16 @@ where
102110
#[cfg(test)]
103111
mod tests {
104112
use super::*;
105-
use alloy_primitives::bytes;
113+
use alloy_primitives::{b256, bytes};
106114
use reth_chainspec::MAINNET;
107115
use reth_primitives::TxType;
108116

117+
#[test]
118+
fn check_deposit_sig() {
119+
let expected = b256!("0x649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5");
120+
assert_eq!(expected, DepositEvent::SIGNATURE_HASH);
121+
}
122+
109123
#[test]
110124
fn test_parse_deposit_from_log() {
111125
let receipts = vec![
@@ -143,4 +157,54 @@ mod tests {
143157
)
144158
);
145159
}
160+
161+
#[test]
162+
fn test_parse_deposit_from_log_extra() {
163+
let receipts = vec![
164+
Receipt {
165+
// these don't matter
166+
tx_type: TxType::Legacy,
167+
success: true,
168+
cumulative_gas_used: 0,
169+
// Transfer + Deposit
170+
logs: serde_json::from_str(
171+
r#"[
172+
{
173+
"address": "0x00000000219ab540356cbb839cbe05303d7705fa",
174+
"topics": [
175+
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
176+
"0x0000000000000000000000008b0c2c4c8eb078bc6c01f48523764c8942c0c6c4",
177+
"0x0000000000000000000000000000000000000000000000000000000000000000"
178+
],
179+
"data": "0x0000000000000000000000000000000000000000000000000000000000000001",
180+
"blockNumber": "0x158c89",
181+
"transactionHash": "0xfcd133f57d5bab8cea211bab0361379456b9115a66bd242d62582aab0bb5fe71",
182+
"transactionIndex": "0x0",
183+
"blockHash": "0xe826da725061cdd2ab7638d4c4b5f25a07491f131d05b89628c4613cad07a246",
184+
"logIndex": "0x0",
185+
"removed": false
186+
},
187+
{"address":"0x00000000219ab540356cbb839cbe05303d7705fa","topics":["0x649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"],"data":"0x00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000030998c8086669bf65e24581cda47d8537966e9f5066fc6ffdcba910a1bfb91eae7a4873fcce166a1c4ea217e6b1afd396200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002001000000000000000000000001c340fb72ed14d4eaa71f7633ee9e33b88d4f3900000000000000000000000000000000000000000000000000000000000000080040597307000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006098ddbffd700c1aac324cfdf0492ff289223661eb26718ce3651ba2469b22f480d56efab432ed91af05a006bde0c1ea68134e0acd8cacca0c13ad1f716db874b44abfcc966368019753174753bca3af2ea84bc569c46f76592a91e97f311eddec0000000000000000000000000000000000000000000000000000000000000008e474160000000000000000000000000000000000000000000000000000000000","blockHash":"0x8d1289c5a7e0965b1d1bb75cdc4c3f73dda82d4ebb94ff5b98d1389cebd53b56","blockNumber":"0x12f0d8d","transactionHash":"0xa5239d4c542063d29022545835815b78b09f571f2bf1c8427f4765d6f5abbce9","transactionIndex":"0xc4","logIndex":"0x18f","removed":false}]"#
188+
).unwrap(),
189+
},
190+
// https://etherscan.io/tx/0xd9734d4e3953bcaa939fd1c1d80950ee54aeecc02eef6ae8179f47f5b7103338
191+
Receipt {
192+
// these don't matter
193+
tx_type: TxType::Legacy,
194+
success: true,
195+
cumulative_gas_used: 0,
196+
logs: serde_json::from_str(
197+
r#"[{"address":"0x00000000219ab540356cbb839cbe05303d7705fa","topics":["0x649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"],"data":"0x00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000030a1a2ba870a90e889aa594a0cc1c6feffb94c2d8f65646c937f1f456a315ef649533e25a4614d8f4f66ebdb06481b90af0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200100000000000000000000000a0f04a231efbc29e1db7d086300ff550211c2f6000000000000000000000000000000000000000000000000000000000000000800405973070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060ad416d590e1a7f52baff770a12835b68904efad22cc9f8ba531e50cbbd26f32b9c7373cf6538a0577f501e4d3e3e63e208767bcccaae94e1e3720bfb734a286f9c017d17af46536545ccb7ca94d71f295e71f6d25bf978c09ada6f8d3f7ba0390000000000000000000000000000000000000000000000000000000000000008e374160000000000000000000000000000000000000000000000000000000000","blockHash":"0x8d1289c5a7e0965b1d1bb75cdc4c3f73dda82d4ebb94ff5b98d1389cebd53b56","blockNumber":"0x12f0d8d","transactionHash":"0xd9734d4e3953bcaa939fd1c1d80950ee54aeecc02eef6ae8179f47f5b7103338","transactionIndex":"0x7c","logIndex":"0xe2","removed":false}]"#,
198+
).unwrap(),
199+
},
200+
];
201+
202+
let request_data = parse_deposits_from_receipts(&MAINNET, &receipts).unwrap();
203+
assert_eq!(
204+
request_data,
205+
bytes!(
206+
"998c8086669bf65e24581cda47d8537966e9f5066fc6ffdcba910a1bfb91eae7a4873fcce166a1c4ea217e6b1afd396201000000000000000000000001c340fb72ed14d4eaa71f7633ee9e33b88d4f39004059730700000098ddbffd700c1aac324cfdf0492ff289223661eb26718ce3651ba2469b22f480d56efab432ed91af05a006bde0c1ea68134e0acd8cacca0c13ad1f716db874b44abfcc966368019753174753bca3af2ea84bc569c46f76592a91e97f311eddece474160000000000a1a2ba870a90e889aa594a0cc1c6feffb94c2d8f65646c937f1f456a315ef649533e25a4614d8f4f66ebdb06481b90af0100000000000000000000000a0f04a231efbc29e1db7d086300ff550211c2f60040597307000000ad416d590e1a7f52baff770a12835b68904efad22cc9f8ba531e50cbbd26f32b9c7373cf6538a0577f501e4d3e3e63e208767bcccaae94e1e3720bfb734a286f9c017d17af46536545ccb7ca94d71f295e71f6d25bf978c09ada6f8d3f7ba039e374160000000000"
207+
)
208+
);
209+
}
146210
}

0 commit comments

Comments
 (0)