Skip to content

Commit 9ac30c9

Browse files
committed
chore(signer)!: reformat & clean up
1 parent ad6d373 commit 9ac30c9

File tree

7 files changed

+35
-313
lines changed

7 files changed

+35
-313
lines changed

config.example.toml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# The main configuration file for the Commit-Boost sidecar.
1+
# The main configuration file for the Commit-Boost sidecar.
22
# Some fields are optional and can be omitted, in which case the default value, if present, will be used.
33

44
# Chain spec id. Supported values: Mainnet, Holesky, Helder
@@ -18,7 +18,7 @@ port = 18550
1818
# Whether to forward `status` calls to relays or skip and return 200
1919
# OPTIONAL, DEFAULT: true
2020
relay_check = true
21-
# Timeout in milliseconds for the `get_header` call to relays. Note that the CL has also a timeout (e.g. 1 second) so
21+
# Timeout in milliseconds for the `get_header` call to relays. Note that the CL has also a timeout (e.g. 1 second) so
2222
# this should be lower than that, leaving some margin for overhead
2323
# OPTIONAL, DEFAULT: 950
2424
timeout_get_header_ms = 950
@@ -34,10 +34,11 @@ skip_sigverify = false
3434
# Minimum bid in ETH that will be accepted from `get_header`
3535
# OPTIONAL, DEFAULT: 0.0
3636
min_bid_eth = 0.0
37+
# How late in milliseconds in the slot is "late". This impacts the `get_header` requests, by shortening timeouts for `get_header` calls to
3738
# List of URLs of relay monitors to send registrations to
3839
# OPTIONAL
3940
relay_monitors = []
40-
# How late in milliseconds in the slot is "late". This impacts the `get_header` requests, by shortening timeouts for `get_header` calls to
41+
# How late in milliseconds in the slot is "late". This impacts the `get_header` requests, by shortening timeouts for `get_header` calls to
4142
# relays and make sure a header is returned within this deadline. If the request from the CL comes later in the slot, then fetching headers is skipped
4243
# to force local building and miniminzing the risk of missed slots. See also the timing games section below
4344
# OPTIONAL, DEFAULT: 2000
@@ -55,12 +56,12 @@ url = "http://0xa1cec75a3f0661e99299274182938151e8433c61a19222347ea1313d839229cb
5556
headers = { X-MyCustomHeader = "MyCustomValue" }
5657
# Whether to enable timing games, as tuned by `target_first_request_ms` and `frequency_get_header_ms`.
5758
# These values should be carefully chosen for each relay, as each relay has different latency and timing games setups.
58-
# They should only be used by advanced users, and if mis-configured can result in unforeseen effects, e.g. fetching a lower header value,
59+
# They should only be used by advanced users, and if mis-configured can result in unforeseen effects, e.g. fetching a lower header value,
5960
# or getting a temporary IP ban.
60-
#
61+
#
6162
# EXAMPLES
6263
# Assuming: timeout_get_header_ms = 950, frequency_get_header_ms = 300, target_first_request_ms = 200, late_in_slot_time_ms = 2000
63-
#
64+
#
6465
# 1) CL request comes at 100ms in the slot (max timeout 1050ms in the slot), then:
6566
# - sleep for 100ms
6667
# - send request at 200ms with 850ms timeout
@@ -112,13 +113,13 @@ id = "DA_COMMIT"
112113
type = "commit"
113114
# Docker image of the module
114115
docker_image = "test_da_commit"
115-
# Additional config needed by the business logic of the module should also be set here.
116+
# Additional config needed by the business logic of the module should also be set here.
116117
# See also `examples/da_commit/src/main.rs` for more information
117118
sleep_secs = 5
118119

119120
# Configuration for how metrics should be collected and scraped
120121
[metrics]
121-
# Path to a `prometheus.yml` file to use in Prometheus. If using a custom config file, be sure to add a
122+
# Path to a `prometheus.yml` file to use in Prometheus. If using a custom config file, be sure to add a
122123
# file discovery section as follows:
123124
# ```yml
124125
# file_sd_configs:

crates/common/src/signer/mod.rs

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use std::{
2-
fmt::{self, LowerHex},
3-
};
1+
use std::fmt::{self, LowerHex};
42

53
use alloy::rpc::types::beacon::BlsPublicKey;
64
use eyre::Context;
@@ -12,38 +10,11 @@ pub mod schemes;
1210
#[allow(clippy::module_inception)]
1311
mod signer;
1412

15-
pub use schemes::{bls::BlsSecretKey, ecdsa::EcdsaSecretKey, ecdsa::EcdsaPublicKey, ecdsa::EcdsaSignature};
16-
pub use signer::{ConsensusSigner, BlsSigner, EcdsaSigner};
17-
18-
// pub type Pubkey<T> = <T as SecretKey>::PublicKey;
19-
20-
// pub trait SecretKey {
21-
// type PublicKey: AsRef<[u8]> + Clone + Verifier<Self>;
22-
// type Signature: AsRef<[u8]> + Clone;
23-
24-
// fn new_random() -> Self;
25-
// fn new_from_bytes(bytes: &[u8]) -> eyre::Result<Self>
26-
// where
27-
// Self: Sized;
28-
// fn pubkey(&self) -> Self::PublicKey;
29-
// fn sign(&self, msg: &[u8]) -> Self::Signature;
30-
// fn sign_msg(&self, msg: &impl TreeHash) -> Self::Signature {
31-
// self.sign(&msg.tree_hash_root().0)
32-
// }
33-
// }
34-
35-
// pub trait Verifier<T: SecretKey>
36-
// where
37-
// T: ?Sized,
38-
// {
39-
// type VerificationError: Error;
40-
41-
// fn verify_signature(
42-
// &self,
43-
// msg: &[u8],
44-
// signature: &T::Signature,
45-
// ) -> Result<(), Self::VerificationError>;
46-
// }
13+
pub use schemes::{
14+
bls::BlsSecretKey,
15+
ecdsa::{EcdsaPublicKey, EcdsaSecretKey, EcdsaSignature},
16+
};
17+
pub use signer::{BlsSigner, ConsensusSigner, EcdsaSigner};
4718

4819
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Encode, Decode)]
4920
#[serde(untagged)]

crates/common/src/signer/schemes/bls.rs

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use blst::BLST_ERROR;
33
use tree_hash::TreeHash;
44

55
use crate::{
6-
error::BlstErrorWrapper, signature::sign_builder_root, signer::GenericPubkey, types::Chain, utils::blst_pubkey_to_alloy
6+
error::BlstErrorWrapper, signature::sign_builder_root, signer::GenericPubkey, types::Chain,
7+
utils::blst_pubkey_to_alloy,
78
};
89

910
pub type BlsSecretKey = blst::min_pk::SecretKey;
@@ -54,39 +55,11 @@ fn random_secret() -> BlsSecretKey {
5455
}
5556
}
5657

57-
// impl SecretKey for BlsSecretKey {
58-
// // type PublicKey = BlsPublicKey;
59-
// // type Signature = BlsSignature;
60-
61-
// // fn new_random() -> Self {
62-
// // use rand::RngCore;
63-
64-
// // let mut rng = rand::thread_rng();
65-
// // let mut ikm = [0u8; 32];
66-
// // rng.fill_bytes(&mut ikm);
67-
68-
// // match BlsSecretKey::key_gen(&ikm, &[]) {
69-
// // Ok(key) => key,
70-
// // // Key material is always valid (32 `u8`s), so `key_gen` can't return Err.
71-
// // Err(_) => unreachable!(),
72-
// // }
73-
// // }
74-
75-
// fn new_from_bytes(bytes: &[u8]) -> eyre::Result<Self> {
76-
// Ok(BlsSecretKey::from_bytes(bytes).map_err(BlstErrorWrapper::from)?)
77-
// }
78-
79-
// fn pubkey(&self) -> Self::PublicKey {
80-
// blst_pubkey_to_alloy(&self.sk_to_pk())
81-
// }
82-
83-
// fn sign(&self, msg: &[u8]) -> Self::Signature {
84-
// let signature = self.sign(msg, BLS_DST_SIG, &[]).to_bytes();
85-
// BlsSignature::from_slice(&signature)
86-
// }
87-
// }
88-
89-
pub fn verify_bls_signature(pubkey: &BlsPublicKey, msg: &[u8], signature: &BlsSignature) -> Result<(), BlstErrorWrapper> {
58+
pub fn verify_bls_signature(
59+
pubkey: &BlsPublicKey,
60+
msg: &[u8],
61+
signature: &BlsSignature,
62+
) -> Result<(), BlstErrorWrapper> {
9063
use crate::utils::{alloy_pubkey_to_blst, alloy_sig_to_blst};
9164

9265
let pubkey = alloy_pubkey_to_blst(pubkey)?;
@@ -100,28 +73,6 @@ pub fn verify_bls_signature(pubkey: &BlsPublicKey, msg: &[u8], signature: &BlsSi
10073
}
10174
}
10275

103-
// impl Verifier<BlsSecretKey> for Pubkey<BlsSecretKey> {
104-
// type VerificationError = BlstErrorWrapper;
105-
106-
// fn verify_signature(
107-
// &self,
108-
// msg: &[u8],
109-
// signature: &<BlsSecretKey as SecretKey>::Signature,
110-
// ) -> Result<(), Self::VerificationError> {
111-
// use crate::utils::{alloy_pubkey_to_blst, alloy_sig_to_blst};
112-
113-
// let pubkey = alloy_pubkey_to_blst(self)?;
114-
// let signature = alloy_sig_to_blst(signature)?;
115-
116-
// let res = signature.verify(true, msg, BLS_DST_SIG, &[], &pubkey, true);
117-
// if res == BLST_ERROR::BLST_SUCCESS {
118-
// Ok(())
119-
// } else {
120-
// Err(res.into())
121-
// }
122-
// }
123-
// }
124-
12576
impl From<BlsPublicKey> for GenericPubkey {
12677
fn from(value: BlsPublicKey) -> Self {
12778
GenericPubkey::Bls(value)

crates/common/src/signer/schemes/ecdsa.rs

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,7 @@ impl EcdsaSigner {
192192

193193
pub async fn sign(&self, chain: Chain, object_root: [u8; 32]) -> EcdsaSignature {
194194
match self {
195-
EcdsaSigner::Local(sk) =>
196-
/* sign_builder_root(chain, sk, object_root), */
197-
{
195+
EcdsaSigner::Local(sk) => {
198196
let domain = chain.builder_domain();
199197
let signing_root = compute_signing_root(object_root, domain);
200198
k256::ecdsa::signature::Signer::<EcdsaSignatureInner>::sign(sk, &signing_root)
@@ -208,6 +206,7 @@ impl EcdsaSigner {
208206
}
209207
}
210208

209+
// TODO(David): Add tests for this verification, most probably not properly working yet
211210
pub fn verify_ecdsa_signature(
212211
pubkey: &EcdsaPublicKey,
213212
msg: &[u8],
@@ -219,43 +218,6 @@ pub fn verify_ecdsa_signature(
219218
ecdsa_pubkey.verify(msg, &ecdsa_sig)
220219
}
221220

222-
// impl SecretKey for EcdsaSecretKey {
223-
// type PublicKey = EcdsaPublicKey;
224-
225-
// type Signature = EcdsaSignature;
226-
227-
// fn new_random() -> Self {
228-
// EcdsaSecretKey::random(&mut rand::thread_rng())
229-
// }
230-
231-
// fn new_from_bytes(bytes: &[u8]) -> Result<Self> {
232-
// Ok(EcdsaSecretKey::from_slice(bytes)?)
233-
// }
234-
235-
// fn pubkey(&self) -> Self::PublicKey {
236-
// EcdsaPublicKeyInner::from(self).into()
237-
// }
238-
239-
// fn sign(&self, msg: &[u8]) -> Self::Signature {
240-
// k256::ecdsa::signature::Signer::<EcdsaSignatureInner>::sign(self, msg).into()
241-
// }
242-
// }
243-
244-
// impl Verifier<EcdsaSecretKey> for Pubkey<EcdsaSecretKey> {
245-
// type VerificationError = k256::ecdsa::Error;
246-
247-
// fn verify_signature(
248-
// &self,
249-
// msg: &[u8],
250-
// signature: &<EcdsaSecretKey as SecretKey>::Signature,
251-
// ) -> Result<(), Self::VerificationError> {
252-
// use k256::ecdsa::signature::Verifier;
253-
// let ecdsa_pubkey = EcdsaPublicKeyInner::from_sec1_bytes(&self.encoded)?;
254-
// let ecdsa_sig = EcdsaSignatureInner::from_bytes(signature)?;
255-
// ecdsa_pubkey.verify(msg, &ecdsa_sig)
256-
// }
257-
// }
258-
259221
impl From<EcdsaPublicKey> for GenericPubkey {
260222
fn from(value: EcdsaPublicKey) -> Self {
261223
GenericPubkey::Ecdsa(value)

crates/common/src/signer/signer.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,4 @@
1+
// TODO(David): Remove module
12
pub use super::schemes::bls::BlsSigner;
23
pub type ConsensusSigner = BlsSigner;
34
pub type EcdsaSigner = super::schemes::ecdsa::EcdsaSigner;
4-
5-
// #[derive(Clone)]
6-
// pub enum Signer<T: SecretKey> {
7-
// Local(T),
8-
// }
9-
10-
// impl<T: SecretKey> Signer<T> {
11-
// pub fn new_random() -> Self {
12-
// Signer::Local(T::new_random())
13-
// }
14-
15-
// pub fn new_from_bytes(bytes: &[u8]) -> Result<Self> {
16-
// T::new_from_bytes(bytes).map(Self::Local)
17-
// }
18-
19-
// pub fn pubkey(&self) -> T::PublicKey {
20-
// match self {
21-
// Signer::Local(secret) => secret.pubkey(),
22-
// }
23-
// }
24-
25-
// pub async fn sign(&self, chain: Chain, object_root: [u8; 32]) -> T::Signature {
26-
// match self {
27-
// Signer::Local(sk) => sign_builder_root(chain, sk, object_root),
28-
// }
29-
// }
30-
31-
// pub async fn sign_msg(&self, chain: Chain, msg: &impl TreeHash) -> T::Signature {
32-
// self.sign(chain, msg.tree_hash_root().0).await
33-
// }
34-
// }

0 commit comments

Comments
 (0)