forked from ethereum/staking-deposit-cli
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to sign a withdrawal credentials update message using a v…
…alidator keystore (#88) * Adding command to create keystore signature for validator PoO * Fixing withdrawal address prompt for bls keystore command * Updating bls keystore domain as 0x0B is used by consolidation * Updating readme to include reference to UCWM github
- Loading branch information
1 parent
7708681
commit e15b4e5
Showing
16 changed files
with
702 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
bls_to_execution_changes | ||
bls_to_execution_changes_keystore | ||
exit_transactions | ||
partial_deposits | ||
validator_keys | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# generate-bls-to-execution-change-keystore | ||
|
||
<div class="warning"> | ||
This command is associated with the a proposed solution to update withdrawal credentials for those who are missing their mnemonic. At this point this has not been approved or implemented and there is no guarantee credentials will be modified in the future. | ||
|
||
The project is located [here](https://github.com/eth-educators/update-credentials-without-mnemonic) if you would like to learn more. | ||
</div> | ||
|
||
## Description | ||
Signs a withdrawal credential update message using the provided keystore. This signature is one of the required proofs of ownership for validators who have lost or are missing their mnemonic and are unable to perform the BLS change needed to update their withdrawal credentials. | ||
|
||
## Optional Arguments | ||
|
||
- **`--chain`**: The chain to use for generating the deposit data. Options are: 'mainnet', 'holesky', etc. | ||
|
||
- **`--keystore`**: The keystore file associating with the validator you wish to sign with. This keystore file should match the provided validator index. | ||
|
||
- **`--keystore_password`**: The password that is used to encrypt the provided keystore. Note: It's not your mnemonic password. <span class="warning"></span> | ||
|
||
- **`--validator_index`**: The validator index corresponding to the provided keystore. | ||
|
||
- **`--withdrawal_address`**: Ethereum execution address in hexadecimal encoded form that you wish to set as your withdrawal credentials. | ||
|
||
- **`--output_folder`**: The folder path for the `bls_to_execution_change_keystore_signature-*` JSON file. | ||
|
||
- **`--devnet_chain_setting`**: The custom chain setting of a devnet or testnet. Note that it will override your `--chain` choice. | ||
|
||
## Example Usage | ||
|
||
```sh | ||
./deposit generate-bls-to-execution-change | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import json | ||
import os | ||
from typing import Any, Dict | ||
from eth_typing import HexAddress | ||
from eth_utils import to_canonical_address | ||
from py_ecc.bls import G2ProofOfPossession as bls | ||
|
||
from ethstaker_deposit.exceptions import ValidationError | ||
from ethstaker_deposit.settings import BaseChainSetting | ||
from ethstaker_deposit.utils.ssz import ( | ||
BLSToExecutionChangeKeystore, | ||
SignedBLSToExecutionChangeKeystore, | ||
compute_signing_root, | ||
compute_bls_to_execution_change_keystore_domain, | ||
) | ||
|
||
|
||
def bls_to_execution_change_keystore_generation( | ||
chain_settings: BaseChainSetting, | ||
signing_key: int, | ||
execution_address: HexAddress, | ||
validator_index: int) -> SignedBLSToExecutionChangeKeystore: | ||
if execution_address is None: | ||
raise ValueError("The execution address should NOT be empty.") | ||
if chain_settings.GENESIS_VALIDATORS_ROOT is None: | ||
raise ValidationError("The genesis validators root should NOT be empty " | ||
"for this chain to obtain the BLS to execution change.") | ||
|
||
message = BLSToExecutionChangeKeystore( # type: ignore[no-untyped-call] | ||
validator_index=validator_index, | ||
to_execution_address=to_canonical_address(execution_address), | ||
) | ||
domain = compute_bls_to_execution_change_keystore_domain( | ||
fork_version=chain_settings.GENESIS_FORK_VERSION, | ||
genesis_validators_root=chain_settings.GENESIS_VALIDATORS_ROOT, | ||
) | ||
signing_root = compute_signing_root(message, domain) | ||
signature = bls.Sign(signing_key, signing_root) | ||
|
||
return SignedBLSToExecutionChangeKeystore( # type: ignore[no-untyped-call] | ||
message=message, | ||
signature=signature, | ||
) | ||
|
||
|
||
def export_bls_to_execution_change_keystore_json(folder: str, | ||
signed_execution_change: SignedBLSToExecutionChangeKeystore, | ||
timestamp: float) -> str: | ||
signed_bls_to_execution_change_keystore_json: Dict[str, Any] = {} | ||
|
||
address = '0x' + signed_execution_change.message.to_execution_address.hex() # type: ignore[attr-defined] | ||
index = signed_execution_change.message.validator_index # type: ignore[attr-defined] | ||
signature = '0x' + signed_execution_change.signature.hex() # type: ignore[attr-defined] | ||
|
||
message = { | ||
'to_execution_address': address, | ||
'validator_index': index, | ||
} | ||
signed_bls_to_execution_change_keystore_json.update({'message': message}) | ||
signed_bls_to_execution_change_keystore_json.update({'signature': signature}) | ||
|
||
filefolder = os.path.join( | ||
folder, | ||
'bls_to_execution_change_keystore_signature-%s-%i.json' % (index, timestamp) | ||
) | ||
|
||
with open(filefolder, 'w') as f: | ||
json.dump(signed_bls_to_execution_change_keystore_json, f) | ||
if os.name == 'posix': | ||
os.chmod(filefolder, int('440', 8)) # Read for owner & group | ||
return filefolder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.