Skip to content

Commit

Permalink
chore: fix conflicts and rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
merklefruit committed Jun 22, 2024
1 parent d082d06 commit c97e519
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
9 changes: 6 additions & 3 deletions bolt-sidecar/bin/sidecar.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use bolt_sidecar::{
crypto::bls::{from_bls_signature_to_consensus_signature, BLSSigner},
crypto::{
bls::{from_bls_signature_to_consensus_signature, Signer, SignerBLS},
SignableBLS,
},
json_rpc::{api::ApiError, start_server},
primitives::{
BatchedSignedConstraints, ChainHead, CommitmentRequest, ConstraintsMessage,
Expand Down Expand Up @@ -29,7 +32,7 @@ async fn main() -> eyre::Result<()> {

let (api_events, mut api_events_rx) = mpsc::channel(1024);

let signer = BLSSigner::new(config.private_key.clone());
let signer = Signer::new(config.private_key.clone().unwrap());

let state_client = StateClient::new(&config.execution_api, 8);

Expand Down Expand Up @@ -77,7 +80,7 @@ async fn main() -> eyre::Result<()> {
// TODO: get the validator index from somewhere
let message = ConstraintsMessage::build(0, request.slot, request.clone());

let signature = from_bls_signature_to_consensus_signature(signer.sign(&message));
let signature = from_bls_signature_to_consensus_signature(signer.sign(&message.digest())?);
let signed_constraints: BatchedSignedConstraints =
vec![SignedConstraints { message, signature: signature.to_string() }];

Expand Down
9 changes: 4 additions & 5 deletions bolt-sidecar/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ impl TryFrom<Opts> for Config {
config.limits.max_commitments_per_slot = max_commitments;
}

config.commit_boost_url = if let Some(url) = opts.signing.commit_boost_url {
Some(url.trim_end_matches('/').to_string())
} else {
None
};
config.commit_boost_url = opts
.signing
.commit_boost_url
.map(|url| url.trim_end_matches('/').to_string());

config.private_key = if let Some(sk) = opts.signing.private_key {
let sk = SecretKey::from_bytes(&hex::decode(sk)?)
Expand Down
6 changes: 6 additions & 0 deletions bolt-sidecar/src/crypto/bls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,18 @@ pub trait SignerBLSAsync: Send + Sync {
}

/// A BLS signer that can sign any type that implements the `Signable` trait.
#[derive(Debug, Clone)]
pub struct Signer {
key: BlsSecretKey,
}

impl Signer {
/// Create a new signer with the given BLS secret key.
pub fn new(key: BlsSecretKey) -> Self {
Self { key }
}

/// Verify the signature of the object with the given public key.
#[allow(dead_code)]
pub fn verify<T: SignableBLS>(
&self,
Expand All @@ -81,17 +84,20 @@ impl SignerBLSAsync for Signer {
}
}

/// Compatibility between ethereum_consensus and blst
pub fn from_bls_signature_to_consensus_signature(sig_bytes: impl AsRef<[u8]>) -> BlsSignature {
BlsSignature::try_from(sig_bytes.as_ref()).unwrap()
}

/// Generate a random BLS secret key.
pub fn random_bls_secret() -> BlsSecretKey {
let mut rng = rand::thread_rng();
let mut ikm = [0u8; 32];
rng.fill_bytes(&mut ikm);
BlsSecretKey::key_gen(&ikm, &[]).unwrap()
}

/// Sign the given data with the given BLS secret key.
#[inline]
fn sign_with_prefix(key: &BlsSecretKey, data: &[u8]) -> Signature {
key.sign(data, BLS_DST_PREFIX, &[])
Expand Down

0 comments on commit c97e519

Please sign in to comment.