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

fix bug with hash tree root in underlying dep #160

Merged
merged 2 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
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
17 changes: 15 additions & 2 deletions Cargo.lock

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

13 changes: 10 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
[workspace]
resolver = "2"
members = ["bin/mev", "mev-boost-rs", "mev-relay-rs", "mev-build-rs", "mev-rs"]
members = [
"bin/mev",
"bin/utils",
"mev-boost-rs",
"mev-relay-rs",
"mev-build-rs",
"mev-rs",
]
default-members = ["bin/mev"]

[workspace.package]
version = "0.3.0"

[workspace.dependencies]
ethereum-consensus = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "c84f44ee7ec04613adf5f2be845df35e05de1efc" }
beacon-api-client = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "c84f44ee7ec04613adf5f2be845df35e05de1efc" }
ethereum-consensus = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "69d1a14585ef190bf32979a972a9794e863ee18d" }
beacon-api-client = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "69d1a14585ef190bf32979a972a9794e863ee18d" }

reth-payload-builder = { git = "https://github.com/paradigmxyz/reth", rev = "5dd5555c5c7d8e43420e273e7005b8af63a847a5" }
reth-primitives = { git = "https://github.com/paradigmxyz/reth", rev = "5dd5555c5c7d8e43420e273e7005b8af63a847a5" }
Expand Down
19 changes: 19 additions & 0 deletions bin/utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "mev-utils"
version.workspace = true
edition = "2021"
license = "MIT OR Apache-2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = { version = "1.0", features = ["full"] }
url = { version = "2.2.2", default-features = false }

mev-rs = { path = "../../mev-rs" }

serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0.92" }

ethereum-consensus = { workspace = true }
beacon-api-client = { workspace = true }
1 change: 1 addition & 0 deletions bin/utils/LICENSE-APACHE
1 change: 1 addition & 0 deletions bin/utils/LICENSE-MIT
28 changes: 28 additions & 0 deletions bin/utils/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use beacon_api_client::{mainnet::Client, BlockId};
use mev_rs::{types::BidRequest, BlindedBlockRelayer, Relay, RelayEndpoint};
use url::Url;

#[tokio::main]
async fn main() {
let endpoint = Url::parse("http://localhost:5052").unwrap();
let beacon_node = Client::new(endpoint);
let id = BlockId::Head;
let signed_block = beacon_node.get_beacon_block(id).await.unwrap();
let slot = signed_block.message().slot() + 1;
let parent_hash =
signed_block.message().body().execution_payload().unwrap().block_hash().clone();

let url = Url::parse("https://0x845bd072b7cd566f02faeb0a4033ce9399e42839ced64e8b2adcfc859ed1e8e1a5a293336a49feac6d9a5edb779be53a@boost-relay-sepolia.flashbots.net/").unwrap();
let relay_endpoint = RelayEndpoint::try_from(url).unwrap();
let relay = Relay::try_from(relay_endpoint).unwrap();
let schedules = relay.get_proposal_schedule().await.unwrap();
for schedule in schedules {
if schedule.slot == slot {
let public_key = schedule.entry.message.public_key;
let bid_request = BidRequest { slot, parent_hash: parent_hash.clone(), public_key };
let signed_bid = relay.fetch_best_bid(&bid_request).await.unwrap();
let signed_bid_str = serde_json::to_string_pretty(&signed_bid).unwrap();
println!("{signed_bid_str}");
}
}
}
59 changes: 59 additions & 0 deletions mev-rs/src/types/builder_bid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,62 @@ impl SignedBuilderBid {
verify_signature(public_key, signing_root.as_ref(), &self.signature)
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::signing::sign_builder_message;
use ethereum_consensus::{crypto::SecretKey, state_transition::Context};
use rand::prelude::*;

const SIGNED_BUILDER_BID_JSON: &str = r#"
{
"message": {
"header": {
"parent_hash": "0xac6e636151a5c90dd7179b5ca62c1e759dd75505ba95d060b9ea2a8e342f88f4",
"fee_recipient": "0x1e2cd78882b12d3954a049fd82ffd691565dc0a5",
"state_root": "0x223c37043a5c9ab328fef7d2a58bc01da7f994252eb552343b97faf6e647d633",
"receipts_root": "0x8b0f90f0a7ad8e3135f9b95d9234c84a4a0440ab8df18327bab6bbc6a5d9efe5",
"logs_bloom": "0x40000008081200020008100002000000042040100420000000000000000000000004000800240000040001000008400010820400004000000801210800648120000100504002042000000008080180020000100000244200080000000004002808100040020008000281008000000810100500000010000000000010000000000080000000a0000020020080404060000001001800800810081000028c50002102084000080000020000030000040018100060000040000000401010240000000400000a0000101000020000008060002008100000a0000002008400000060000096000000200010000000000000980010804508000000080000010200200840",
"prev_randao": "0x5e93d21bf689fd1c293a85dbb93681383867abe057375890a251404bda3417f9",
"block_number": "4522537",
"gas_limit": "30000000",
"gas_used": "4483564",
"timestamp": "1697757948",
"extra_data": "0x496c6c756d696e61746520446d6f63726174697a6520447374726962757465",
"base_fee_per_gas": "9",
"block_hash": "0xf0029e1f18f5bc8944c9ce4453d93f1772e3ac6626470024c8def699271def2e",
"transactions_root": "0xbf12054777b89c3a25b78281604fc99d5e55cb9fedafcce4dc688779f65197ee",
"withdrawals_root": "0xa427d204f34246cdec36b4db9a94f25e08a5be2f7e670ff3072ceb241e8934f6"
},
"value": "2591493712581794",
"pubkey": "0x845bd072b7cd566f02faeb0a4033ce9399e42839ced64e8b2adcfc859ed1e8e1a5a293336a49feac6d9a5edb779be53a"
},
"signature": "0xafb17f2861b808f4728bbc31aeaa36e9b86465ff08fc3a4ccfd302403b48dfe8fc12cfe30349d95822142668187882f0000fc1ea5ae30ea0c6f44d8d3a535f1945d10b7954642a52dec65fbe929e6b09b626c19318e88cea99c38b414589c6f1"
}
"#;

#[test]
fn test_builder_bid_signature() {
let mut rng = thread_rng();
let key = SecretKey::random(&mut rng).unwrap();
let public_key = key.public_key();
let mut builder_bid = BuilderBid {
header: ExecutionPayloadHeader::Deneb(Default::default()),
value: U256::from(234234),
public_key,
};
let context = Context::for_holesky();
let signature = sign_builder_message(&mut builder_bid, &key, &context).unwrap();
let mut signed_builder_bid = SignedBuilderBid { message: builder_bid, signature };
signed_builder_bid.verify_signature(&context).expect("is valid signature");
}

#[test]
fn test_builder_bid_signature_from_relay() {
let mut signed_builder_bid: SignedBuilderBid =
serde_json::from_str(SIGNED_BUILDER_BID_JSON.trim()).unwrap();
let context = Context::for_sepolia();
signed_builder_bid.verify_signature(&context).expect("is valid signature");
}
}
Loading