Skip to content

Commit

Permalink
Faheelsattar/add gen bls flag (#328)
Browse files Browse the repository at this point in the history
## πŸ“ Summary

Adds `gen-bls` flag to rbuilder for generating BLS address
Closes #307

## βœ… I have completed the following steps:

* [x] Run `make lint`
* [x] Run `make test`
* [x] Added tests (if applicable)
  • Loading branch information
faheelsattar authored Jan 2, 2025
1 parent 821a88c commit 278de7a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
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

0 comments on commit 278de7a

Please sign in to comment.