Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bundle hash on ethsendbundle #1308

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion crates/rpc-types-mev/src/eth_calls.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{u256_numeric_string, Privacy, Validity};

use alloy_eips::BlockNumberOrTag;
use alloy_primitives::{Address, Bytes, B256, U256};
use alloy_primitives::{keccak256, Address, Bytes, Keccak256, B256, U256};
use serde::{Deserialize, Serialize};

/// Bundle of transactions for `eth_callBundle`
Expand Down Expand Up @@ -138,6 +138,37 @@ pub struct EthSendBundle {
pub replacement_uuid: Option<String>,
}

impl EthSendBundle {
/// Returns the bundle hash.
///
/// This is the keccak256 hash of the transaction hashes of the
/// transactions in the bundle.
///
/// ## Note
///
/// Logic for calculating the bundle hash is as follows:
/// - Calculate the hash of each transaction in the bundle
/// - Concatenate the hashes, in bundle order
/// - Calculate the keccak256 hash of the concatenated hashes
///
/// See the [flashbots impl].
///
/// This function will not verify transaction correctness. If the bundle
/// `txs` contains invalid transactions, the bundle hash will still be
/// calculated.
///
/// [flashbots impl]: https://github.com/flashbots/mev-geth/blob/fddf97beec5877483f879a77b7dea2e58a58d653/internal/ethapi/api.go#L2067
pub fn bundle_hash(&self) -> B256 {
let mut hasher = Keccak256::default();
for tx in &self.txs {
// NB: the txs must contain envelopes, so the tx_hash is just the
// keccak256 hash of the envelope. no need to deserialize the tx
hasher.update(keccak256(tx));
}
hasher.finalize()
}
}

/// Response from the matchmaker after sending a bundle.
#[derive(Deserialize, Debug, Serialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
Expand Down