-
Notifications
You must be signed in to change notification settings - Fork 8
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
[STACKED] Command to generate presigned exit message #55
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,36 @@ You can use `eth-staking-smith` as follows to convert your address: | |
|
||
Note that --validator-index and --validator-start-index are two distinct parameter, the former being index of validator on Beacon chain, and the latter is the index of validator private key derived from the seed | ||
|
||
|
||
### Command to send SignedBLSToExecutionChange request to Beacon node | ||
|
||
``` | ||
curl -H "Content-Type: application/json" -d '{ | ||
"message": { | ||
"validator_index": 100, | ||
"from_bls_pubkey": "0x0045b91b2f60b88e7392d49ae1364b55e713d06f30e563f9f99e10994b26221d", | ||
"to_execution_address": "0x71C7656EC7ab88b098defB751B7401B5f6d8976F" | ||
}, | ||
"signature": "0x9220e5badefdfe8abc36cae01af29b981edeb940ff88c438f72c8af876fbd6416138c85f5348c5ace92a081fa15291aa0ffb856141b871dc807f3ec2fe9c8415cac3d76579c61455ab3938bc162e139d060c8aa13fcd670febe46bf0bb579c5a" | ||
}' http://localhost:3500/eth/v1/beacon/pool/bls_to_execution_change | ||
``` | ||
|
||
## Generating pre-signed exit message | ||
|
||
It is possible to create pre-signed voluntary exit message for every validator that | ||
is generated from some known mnemonic, given the minimum epoch for exit to trigger. | ||
|
||
Use `eth-staking-smith` via command line like: | ||
|
||
### Command to generate presigned exit message | ||
|
||
``` | ||
./target/debug/eth-staking-smith presigned-exit-message --chain mainnet --mnemonic "entire habit bottom mention spoil clown finger wheat motion fox axis mechanic country make garment bar blind stadium sugar water scissors canyon often ketchup" --validator_start_index 0 --validator_index 100 --epoch 300000 | ||
``` | ||
|
||
Note that --validator-index and --validator-start-index are two distinct parameter, the former being index of validator on Beacon chain, and the latter is the index of validator private key derived from the seed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm can we not just rename them to make it more explicit? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, renamed in 176cfba, will rename in bls-to-execution-change in nested PR |
||
|
||
|
||
## Exporting CLI standard output into common keystores folder format | ||
|
||
Most validator clients recognize the keystore folder format, | ||
|
@@ -117,18 +147,6 @@ lighthouse account validator import \ | |
--directory validator_keys/ --password-file ./password.txt | ||
``` | ||
|
||
### Command to send SignedBLSToExecutionChange request to Beacon node | ||
|
||
``` | ||
curl -H "Content-Type: application/json" -d '{ | ||
"message": { | ||
"validator_index": 100, | ||
"from_bls_pubkey": "0x0045b91b2f60b88e7392d49ae1364b55e713d06f30e563f9f99e10994b26221d", | ||
"to_execution_address": "0x71C7656EC7ab88b098defB751B7401B5f6d8976F" | ||
}, | ||
"signature": "0x9220e5badefdfe8abc36cae01af29b981edeb940ff88c438f72c8af876fbd6416138c85f5348c5ace92a081fa15291aa0ffb856141b871dc807f3ec2fe9c8415cac3d76579c61455ab3938bc162e139d060c8aa13fcd670febe46bf0bb579c5a" | ||
}' http://localhost:3500/eth/v1/beacon/pool/bls_to_execution_change | ||
``` | ||
|
||
# Implementation Details | ||
To avoid heavy lifting, we're interfacing [Lighthouse account manager](https://github.com/sigp/lighthouse/blob/stable/account_manager), but optimizing it in a way so all operations are done in memory and key material is never written to filesystem during the generation to cater for our use case. | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
pub mod constants; | ||
pub(crate) mod operator; | ||
|
||
use regex::Regex; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod bls_to_execution_change; | ||
pub mod existing_mnemonic; | ||
pub mod new_mnemonic; | ||
pub mod presigned_exit_message; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
use clap::{arg, Parser}; | ||
|
||
use crate::voluntary_exit::operator::SignedVoluntaryExitOperator; | ||
use crate::{chain_spec::validators_root_and_spec, voluntary_exit}; | ||
|
||
#[derive(Clone, Parser)] | ||
pub struct PresignedExitMessageSubcommandOpts { | ||
/// The mnemonic that you used to generate your | ||
/// keys. | ||
/// | ||
/// It is recommended not to use this | ||
/// argument, and wait for the CLI to ask you | ||
/// for your mnemonic as otherwise it will | ||
/// appear in your shell history. | ||
#[arg(long)] | ||
pub mnemonic: String, | ||
|
||
/// The name of Ethereum PoS chain you are targeting. | ||
/// | ||
/// Use "mainnet" if you are | ||
/// depositing ETH | ||
#[arg(value_enum, long)] | ||
pub chain: Option<crate::networks::SupportedNetworks>, | ||
|
||
/// The index of the first validator's keys you wish to generate the address for | ||
/// e.g. if you generated 3 keys before (index #0, index #1, index #2) | ||
/// and you want to generate for the 2nd validator, | ||
/// the validator_start_index would be 1. | ||
/// If no index specified, it will be set to 0. | ||
#[arg(long, visible_alias = "validator_start_index")] | ||
pub validator_start_index: u32, | ||
|
||
/// On-chain beacon index of the validator. | ||
#[arg(long, visible_alias = "validator_index")] | ||
pub validator_index: u32, | ||
|
||
/// Epoch number which must be included in the presigned exit message. | ||
#[arg(long, visible_alias = "execution_address")] | ||
pub epoch: u64, | ||
|
||
/// Path to a custom Eth PoS chain config | ||
#[arg(long, visible_alias = "testnet_config")] | ||
pub testnet_config: Option<String>, | ||
|
||
/// Custom genesis validators root for the custom testnet, passed as hex string. | ||
/// See https://eth2book.info/capella/part3/containers/state/ for value | ||
/// description | ||
#[arg(long, visible_alias = "genesis_validators_root")] | ||
pub genesis_validators_root: Option<String>, | ||
} | ||
|
||
impl PresignedExitMessageSubcommandOpts { | ||
pub fn run(&self) { | ||
let chain = if self.chain.is_some() && self.testnet_config.is_some() { | ||
panic!("should only pass one of testnet_config or chain") | ||
} else if self.testnet_config.is_some() { | ||
// Signalizes custom testnet config will be used | ||
None | ||
} else { | ||
self.chain.clone() | ||
}; | ||
|
||
let (genesis_validators_root, spec) = validators_root_and_spec( | ||
chain.clone(), | ||
if chain.is_some() { | ||
None | ||
} else { | ||
Some(( | ||
self.genesis_validators_root | ||
.clone() | ||
.expect("Genesis validators root parameter must be set"), | ||
self.testnet_config | ||
.clone() | ||
.expect("Testnet config must be set"), | ||
)) | ||
}, | ||
); | ||
|
||
let (voluntary_exit, key_material) = voluntary_exit::voluntary_exit_message_from_mnemonic( | ||
self.mnemonic.as_bytes(), | ||
self.validator_start_index as u64, | ||
self.validator_index as u64, | ||
self.epoch, | ||
); | ||
|
||
let signed_voluntary_exit = | ||
voluntary_exit.sign(&key_material.keypair.sk, genesis_validators_root, &spec); | ||
|
||
signed_voluntary_exit.clone().validate( | ||
&key_material.keypair.pk, | ||
&spec, | ||
&genesis_validators_root, | ||
); | ||
let export = signed_voluntary_exit.export(); | ||
|
||
let presigned_exit_message_json = | ||
serde_json::to_string_pretty(&export).expect("could not parse validator export"); | ||
println!("{}", presigned_exit_message_json); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we showing curl command instead of cli cmd?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The command right now does not support sending output to beacon node; it should be easy to add though given
openssl-sys
is already a dependency. I will do it in #54 as this PR only touches presigned exit message, but bls-to-execution-changeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sending to beacon node was implemented in 64ef067