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(sidecar): hex private key #118

Merged
merged 1 commit into from
Jul 5, 2024
Merged
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
7 changes: 6 additions & 1 deletion bolt-sidecar/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ impl TryFrom<Opts> for Config {
.transpose()?;

config.private_key = if let Some(sk) = opts.signing.private_key {
let sk = SecretKey::from_bytes(&hex::decode(sk)?)
// Check if the string starts with "0x" and remove it
let hex_sk = if sk.starts_with("0x") { &sk[2..] } else { &sk };

let sk = SecretKey::from_bytes(&hex::decode(hex_sk)?)
Comment on lines +172 to +175
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve error handling for invalid hex strings.

The current code does not handle cases where the hex string might still be invalid after removing the "0x" prefix. Consider adding additional checks or handling for such cases.

-  let sk = SecretKey::from_bytes(&hex::decode(hex_sk)?)
-    .map_err(|e| eyre::eyre!("Failed decoding BLS secret key: {:?}", e))?;
+  let decoded_hex = hex::decode(hex_sk).map_err(|e| eyre::eyre!("Failed decoding hex string: {:?}", e))?;
+  let sk = SecretKey::from_bytes(&decoded_hex)
+    .map_err(|e| eyre::eyre!("Failed decoding BLS secret key: {:?}", e))?;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Check if the string starts with "0x" and remove it
let hex_sk = if sk.starts_with("0x") { &sk[2..] } else { &sk };
let sk = SecretKey::from_bytes(&hex::decode(hex_sk)?)
// Check if the string starts with "0x" and remove it
let hex_sk = if sk.starts_with("0x") { &sk[2..] } else { &sk };
let decoded_hex = hex::decode(hex_sk).map_err(|e| eyre::eyre!("Failed decoding hex string: {:?}", e))?;
let sk = SecretKey::from_bytes(&decoded_hex)
.map_err(|e| eyre::eyre!("Failed decoding BLS secret key: {:?}", e))?;

.map_err(|e| eyre::eyre!("Failed decoding BLS secret key: {:?}", e))?;
Some(sk)
} else {
Expand Down Expand Up @@ -206,6 +209,8 @@ impl TryFrom<Opts> for Config {
config.beacon_api_url = opts.beacon_api_url.parse()?;
config.mevboost_url = opts.mevboost_url.parse()?;

config.fee_recipient = opts.fee_recipient;

config.validator_indexes = opts.validator_indexes;

config.chain = opts.chain;
Expand Down