Skip to content

Commit

Permalink
Migrate to Clap 4.x (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
mksh authored Aug 8, 2024
1 parent e5c8eaf commit 1069258
Show file tree
Hide file tree
Showing 17 changed files with 892 additions and 777 deletions.
433 changes: 214 additions & 219 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ name = "eth_staking_smith"
path = "src/lib.rs"

[dependencies]
clap = "^2.33"
clap = { version = "^4.5", features = ["derive"] }
ethereum_hashing = "0.6.0"
eth2_key_derivation = { git = "https://github.com/ChorusOne/lighthouse", rev = "1be5253610dc8fee3bf4b7a8dc1d01254bc5b57d"}
eth2_keystore = { git = "https://github.com/ChorusOne/lighthouse", rev = "1be5253610dc8fee3bf4b7a8dc1d01254bc5b57d"}
eth2_network_config = { git = "https://github.com/ChorusOne/lighthouse", rev = "1be5253610dc8fee3bf4b7a8dc1d01254bc5b57d" }
ethereum_ssz = "0.5.3"
eth2_wallet = { git = "https://github.com/ChorusOne/lighthouse", rev = "1be5253610dc8fee3bf4b7a8dc1d01254bc5b57d"}
ethereum-types = { version = "0.14.1", optional = true }
env_logger = "^0.11.1"
env_logger = "^0.11"
hex = "0.4"
lazy_static = "1.4"
lazy_static = "1.5"
log = "^0.4"
getrandom = "0.2"
regex = "1.10.3"
serde = "1.0.196"
regex = "1.10.6"
serde = "1.0.204"
serde_derive = "1.0"
serde_json = "1.0"
ssz_rs = { git = "https://github.com/ChorusOne/ssz-rs.git", rev = "1f94d5dfc70c86dab672e91ac46af04a5f96c342" }
Expand All @@ -36,7 +36,7 @@ tiny-bip39 = "1.0.0"
# This must be pinned to a version that lighthouse uses
tree_hash = "0.5.2"
types = { git = "https://github.com/ChorusOne/lighthouse", rev = "1be5253610dc8fee3bf4b7a8dc1d01254bc5b57d"}
uuid = { version = "1.6", features = ["v4"] }
uuid = { version = "1.10", features = ["v4"] }

[dev-dependencies]
test-log = "^0.2"
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2022, 2023 Chorus One AG
Copyright 2022-2024 Chorus One AG

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
212 changes: 195 additions & 17 deletions deny.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
# When outputting inclusion graphs in diagnostics that include features, this
# option can be used to specify the depth at which feature edges will be added.
# This option is included since the graphs can be quite large and the addition
# of features from the crate(s) to all of the graph roots can be far too verbose.
# This option can be overridden via `--feature-depth` on the cmd line
feature-depth = 1

[advisories]

ignore = [
# Only used in CLI, should be fixed by https://github.com/ChorusOne/eth-staking-smith/issues/30
"atty@0.2.14",
# Unmaintained, but only used in CLI
"ansi_term@0.12.1"
]
ignore = []

[licenses]
# The lint level for crates which do not have a detectable license
unlicensed = "allow"
# List of explicitly allowed licenses
# [possible values: any SPDX 3.11 short identifier (+ optional exception)].
allow = [
Expand All @@ -28,9 +13,193 @@ allow = [
"Unicode-DFS-2016",
"BSD-3-Clause",
"BSD-2-Clause",
"Zlib"
"Zlib",
"MPL-2.0",
"OpenSSL"
]

#
# Most of crates above are coming from lighthouse
# where they keep repository license of Apache 2.0
# https://github.com/sigp/lighthouse/blob/291146eeb4fea4bbe0aa3c6aa37eadd566d7e1d4/LICENSE
[[licenses.clarify]]
crate = "merkle_proof"
expression = "Apache-2.0"
license-files = [
{ path = "../../LICENSE", hash = 0x001c7e6c },
]

[[licenses.clarify]]
crate = "bls"
expression = "Apache-2.0"
license-files = [
{ path = "../../LICENSE", hash = 0x001c7e6c },
]


[[licenses.clarify]]
crate = "cached_tree_hash"
expression = "Apache-2.0"
license-files = [
{ path = "../../LICENSE", hash = 0x001c7e6c },
]


[[licenses.clarify]]
crate = "compare_fields"
expression = "Apache-2.0"
license-files = [
{ path = "../../LICENSE", hash = 0x001c7e6c },
]


[[licenses.clarify]]
crate = "compare_fields_derive"
expression = "Apache-2.0"
license-files = [
{ path = "../../LICENSE", hash = 0x001c7e6c },
]


[[licenses.clarify]]
crate = "eth2_config"
expression = "Apache-2.0"
license-files = [
{ path = "../../LICENSE", hash = 0x001c7e6c },
]


[[licenses.clarify]]
crate = "eth2_interop_keypairs"
expression = "Apache-2.0"
license-files = [
{ path = "../../LICENSE", hash = 0x001c7e6c },
]


[[licenses.clarify]]
crate = "eth2_key_derivation"
expression = "Apache-2.0"
license-files = [
{ path = "../../LICENSE", hash = 0x001c7e6c },
]


[[licenses.clarify]]
crate = "eth2_keystore"
expression = "Apache-2.0"
license-files = [
{ path = "../../LICENSE", hash = 0x001c7e6c },
]


[[licenses.clarify]]
crate = "eth2_network_config"
expression = "Apache-2.0"
license-files = [
{ path = "../../LICENSE", hash = 0x001c7e6c },
]


[[licenses.clarify]]
crate = "eth2_wallet"
expression = "Apache-2.0"
license-files = [
{ path = "../../LICENSE", hash = 0x001c7e6c },
]


[[licenses.clarify]]
crate = "int_to_bytes"
expression = "Apache-2.0"
license-files = [
{ path = "../../LICENSE", hash = 0x001c7e6c },
]


[[licenses.clarify]]
crate = "kzg"
expression = "Apache-2.0"
license-files = [
{ path = "../../LICENSE", hash = 0x001c7e6c },
]


[[licenses.clarify]]
crate = "lighthouse_metrics"
expression = "Apache-2.0"
license-files = [
{ path = "../../LICENSE", hash = 0x001c7e6c },
]


[[licenses.clarify]]
crate = "logging"
expression = "Apache-2.0"
license-files = [
{ path = "../../LICENSE", hash = 0x001c7e6c },
]


[[licenses.clarify]]
crate = "pretty_reqwest_error"
expression = "Apache-2.0"
license-files = [
{ path = "../../LICENSE", hash = 0x001c7e6c },
]


[[licenses.clarify]]
crate = "safe_arith"
expression = "Apache-2.0"
license-files = [
{ path = "../../LICENSE", hash = 0x001c7e6c },
]


[[licenses.clarify]]
crate = "sensitive_url"
expression = "Apache-2.0"
license-files = [
{ path = "../../LICENSE", hash = 0x001c7e6c },
]


[[licenses.clarify]]
crate = "swap_or_not_shuffle"
expression = "Apache-2.0"
license-files = [
{ path = "../../LICENSE", hash = 0x001c7e6c },
]


[[licenses.clarify]]
crate = "test_random_derive"
expression = "Apache-2.0"
license-files = [
{ path = "../../LICENSE", hash = 0x001c7e6c },
]


[[licenses.clarify]]
crate = "types"
expression = "Apache-2.0"
license-files = [
{ path = "../../LICENSE", hash = 0x001c7e6c },
]

[[licenses.clarify]]
crate = "ring"
# SPDX considers OpenSSL to encompass both the OpenSSL and SSLeay licenses
# https://spdx.org/licenses/OpenSSL.html
# ISC - Both BoringSSL and ring use this for their new files
# MIT - "Files in third_party/ have their own licenses, as described therein. The MIT
# license, for third_party/fiat, which, unlike other third_party directories, is
# compiled into non-test libraries, is included below."
# OpenSSL - Obviously
expression = "ISC AND MIT AND OpenSSL"
license-files = [{ path = "LICENSE", hash = 0xbd0eed23 }]


#
# Denies versions of Serde derive which contain precompiled binary by default
Expand All @@ -43,3 +212,12 @@ allow = [
deny = [
{ name = "serde_derive", version = ">1.0.171, <1.0.185" }
]


[output]
# When outputting inclusion graphs in diagnostics that include features, this
# option can be used to specify the depth at which feature edges will be added.
# This option is included since the graphs can be quite large and the addition
# of features from the crate(s) to all of the graph roots can be far too verbose.
# This option can be overridden via `--feature-depth` on the cmd line
feature-depth = 1
49 changes: 34 additions & 15 deletions src/bls_to_execution_change.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{key_material, seed::get_eth2_seed, utils::get_withdrawal_credentials};
use crate::{
key_material, networks::SupportedNetworks, seed::get_eth2_seed,
utils::get_withdrawal_credentials,
};
use lazy_static::lazy_static;
use regex::Regex;
use ssz::Encode;
Expand Down Expand Up @@ -37,21 +40,21 @@ lazy_static! {
"4b363db94e286120d76eb905340fdd4e54bfe9f06bf33ff6cf5ad27f511bfe95".as_bytes()[0..32]
.try_into()
.expect("could not wrap genesis validators root");
static ref GENESIS_VALIDATOR_ROOT: HashMap<String, Node> = HashMap::from([
static ref GENESIS_VALIDATOR_ROOT: HashMap<SupportedNetworks, Node> = HashMap::from([
(
"mainnet".to_owned(),
SupportedNetworks::Mainnet,
Node::deserialize(GENESIS_VALIDATORS_ROOT_MAINNET.as_ssz_bytes().as_ref()).unwrap()
),
(
"prater".to_owned(),
SupportedNetworks::Prater,
Node::deserialize(GENESIS_VALIDATORS_ROOT_STUB.as_ssz_bytes().as_ref()).unwrap()
),
(
"goerli".to_owned(),
SupportedNetworks::Goerli,
Node::deserialize(GENESIS_VALIDATORS_ROOT_STUB.as_ssz_bytes().as_ref()).unwrap()
),
(
"holesky".to_owned(),
SupportedNetworks::Holesky,
Node::deserialize(GENESIS_VALIDATORS_ROOT_HOLESKY.as_ssz_bytes().as_ref()).unwrap()
),
]);
Expand Down Expand Up @@ -107,7 +110,7 @@ impl SignedBLSToExecutionChange {
self,
from_bls_withdrawal_credentials: &str,
to_execution_address: &str,
network: &str,
network: SupportedNetworks,
) {
// execution address is same as input
let execution_address = std::str::from_utf8(&self.message.to_execution_address).unwrap();
Expand All @@ -128,8 +131,15 @@ impl SignedBLSToExecutionChange {

// verify signature

let genesis_validator_root = if ["goerli", "prater", "mainnet"].contains(&network) {
let genesis_validator_root = GENESIS_VALIDATOR_ROOT.get(network).unwrap();
let genesis_validator_root = if [
SupportedNetworks::Goerli,
SupportedNetworks::Mainnet,
SupportedNetworks::Holesky,
SupportedNetworks::Prater,
]
.contains(&network)
{
let genesis_validator_root = GENESIS_VALIDATOR_ROOT.get(&network).unwrap();
genesis_validator_root
} else {
panic!("Unknown network name passed");
Expand Down Expand Up @@ -213,7 +223,7 @@ impl BLSToExecutionRequest {
}
}

pub fn sign(self, network: &str) -> SignedBLSToExecutionChange {
pub fn sign(self, network: SupportedNetworks) -> SignedBLSToExecutionChange {
let withdrawal_pubkey = Vector::<u8, BLS_PUBKEY_LEN>::deserialize(
self.bls_keys
.pk
Expand Down Expand Up @@ -242,10 +252,17 @@ impl BLSToExecutionRequest {
fn generate_signed_bls_to_execution_change(
message: BLSToExecutionChange,
secret_key: &[u8],
network: &str,
network: SupportedNetworks,
) -> Result<SignedBLSToExecutionChange, Box<dyn std::error::Error>> {
let genesis_validator_root = if ["goerli", "prater", "mainnet"].contains(&network) {
let genesis_validator_root = GENESIS_VALIDATOR_ROOT.get(network).unwrap();
let genesis_validator_root = if [
SupportedNetworks::Goerli,
SupportedNetworks::Mainnet,
SupportedNetworks::Holesky,
SupportedNetworks::Prater,
]
.contains(&network)
{
let genesis_validator_root = GENESIS_VALIDATOR_ROOT.get(&network).unwrap();
genesis_validator_root
} else {
panic!("Unknown network name passed");
Expand Down Expand Up @@ -317,7 +334,7 @@ mod test {

use types::{Hash256, PublicKey};

use crate::utils;
use crate::{networks::SupportedNetworks, utils};

use super::BLSToExecutionRequest;

Expand All @@ -342,7 +359,9 @@ mod test {

let bls_to_execution_change =
BLSToExecutionRequest::new(PHRASE.as_bytes(), 0, 100, EXECUTION_WITHDRAWAL_ADDRESS);
let signed_bls_to_execution_change = bls_to_execution_change.clone().sign("mainnet");
let signed_bls_to_execution_change = bls_to_execution_change
.clone()
.sign(SupportedNetworks::Mainnet);

// format generated fields for assertion
let to_execution_address =
Expand Down
Loading

0 comments on commit 1069258

Please sign in to comment.