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

Faheelsattar/add gen bls flag #328

Merged
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
9 changes: 8 additions & 1 deletion crates/rbuilder/src/live_builder/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
base_config::load_config_toml_and_env, payload_events::MevBoostSlotDataGenerator,
},
telemetry,
utils::build_info::Version,
utils::{bls::generate_random_bls_address, build_info::Version},
};

use super::{base_config::BaseConfig, LiveBuilder};
Expand All @@ -34,6 +34,8 @@ enum Cli {
about = "Run system performance benchmarks (CPU, disk, memory)"
)]
SysPerf,
#[clap(name = "gen-bls", about = "Generate a BLS signature")]
GenBls,
}

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -106,6 +108,11 @@ where
println!("{}", format_results(&result, &sysinfo));
return Ok(());
}
Cli::GenBls => {
let address = generate_random_bls_address();
println!("0x{}", address);
return Ok(());
}
};

let config: ConfigType = load_config_toml_and_env(cli.config)?;
Expand Down
22 changes: 22 additions & 0 deletions crates/rbuilder/src/utils/bls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use ethereum_consensus::crypto::SecretKey;
use rand;
use revm_primitives::hex;

pub fn generate_random_bls_address() -> String {
let mut rng = rand::thread_rng();
let sk = SecretKey::random(&mut rng).unwrap();
let pk = sk.public_key();
let raw_bytes = pk.as_ref();
hex::encode(raw_bytes)
}

#[cfg(test)]
mod tests {
use crate::utils::bls::generate_random_bls_address;

#[test]
fn test_generate_random_bls_address() {
let bls_address = generate_random_bls_address();
assert_eq!(bls_address.len(), 96, "BLS address should be of 96 length");
}
}
1 change: 1 addition & 0 deletions crates/rbuilder/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! a2r prefix = alloy to reth conversion
pub mod bls;
pub mod build_info;
pub mod constants;
pub mod error_storage;
Expand Down
Loading