-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[dkg-cli] add generate-keys and init command #354
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -84,3 +84,4 @@ docs/content/references/framework/** | |
| lcov.info | ||
|
|
||
| **/build/** | ||
| /dkg-state/ | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,26 @@ | ||
| [package] | ||
| name = "dkg-cli" | ||
| version.workspace = true | ||
| authors.workspace = true | ||
| edition.workspace = true | ||
| license.workspace = true | ||
|
|
||
| [dependencies] | ||
| fastcrypto = { workspace = true} | ||
| fastcrypto-tbls = { workspace = true} | ||
| clap.workspace = true | ||
| serde.workspace = true | ||
| serde_json.workspace = true | ||
| bcs.workspace = true | ||
| rand.workspace = true | ||
| hex.workspace = true | ||
| anyhow.workspace = true | ||
| tracing.workspace = true | ||
| sui_types.workspace = true | ||
| sui-sdk-types.workspace = true | ||
| seal-committee = { path = "../seal-committee" } | ||
| tokio = { version = "1.46.1", features = ["rt-multi-thread"] } | ||
|
|
||
| [[bin]] | ||
| name = "dkg-cli" | ||
| path = "src/main.rs" |
This file contains hidden or 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,146 @@ | ||
| # DKG CLI Tool | ||
|
|
||
| ** WARNING: This is WIP. Do not use. ** | ||
|
|
||
| Command-line tool for Distributed Key Generation (DKG) and key rotation protocols. A DKG process involves a coordinator and a set of participating members. Here we describe the processes for both a fresh DKG and a DKG key rotation. | ||
|
|
||
| ### Fresh DKG Process | ||
|
|
||
| #### Coordinator Runbook | ||
|
|
||
| 1. Deploy the `seal_committee` package in the Seal repo. Make sure you are on the right network with wallet with enough gas. Find the package ID in output, set it to env var `COMMITTEE_PKG`. Share this with members later. | ||
|
|
||
| ```bash | ||
| NETWORK=testnet | ||
| sui client switch --env $NETWORK | ||
| cd move/committee | ||
| sui client publish | ||
|
|
||
| COMMITTEE_PKG=0x4563316d2b647263737bbab1afb32495397bd36eefdcd3b1ca42c3c95ebb2fb3 | ||
| ``` | ||
|
|
||
| 2. Gather all members' addresses. | ||
| 3. Initialize the committee onchain. Notify members: | ||
|
|
||
| - Committee package ID (`COMMITTEE_PKG`) | ||
| - Committee object ID (`COMMITTEE_ID`) | ||
|
|
||
| Then announce phase 1. | ||
|
|
||
| ```bash | ||
| THRESHOLD=2 # Replace this with your threshold. | ||
| ADDRESS_0=0x0636157e9d013585ff473b3b378499ac2f1d207ed07d70e2cd815711725bca9d # Replace these with the members' addresses. | ||
| ADDRESS_1=0xe6a37ff5cd968b6a666fb033d85eabc674449f44f9fc2b600e55e27354211ed6 | ||
| ADDRESS_2=0x223762117ab21a439f0f3f3b0577e838b8b26a37d9a1723a4be311243f4461b9 | ||
|
|
||
| sui client call --package $COMMITTEE_PKG --module seal_committee \ | ||
| --function init_committee \ | ||
| --args $THRESHOLD "[\"$ADDRESS_0\", \"$ADDRESS_1\", \"$ADDRESS_2\"]" | ||
|
|
||
| # Find the created committee object in output and share this with members. | ||
| COMMITTEE_ID=0x210f1a2157d76e5c32a5e585ae3733b51105d553dc17f67457132af5e2dae7a5 | ||
| ``` | ||
|
|
||
| 4. Watch the onchain state until all members registered. Check the committee object state members on Explorer containing entries of all members' addresses. | ||
| 5. Notify all members to run phase 2. | ||
| 6. Watch the offchain storage until all members upload their messages. | ||
| 7. Notify all members to run phase 3. | ||
| 8. Monitor the committee onchain object for finalized state when all members approve. | ||
|
|
||
| #### Member Runbook | ||
|
|
||
| 1. Share with the coordinator your address. This is the wallet used for the rest of the onchain commands. | ||
| 2. Receive from coordinator the committee package ID and committee object ID. Verify its parameters (members addresses and threshold) on Sui Explorer. Set environment variables. | ||
|
|
||
| ```bash | ||
| COMMITTEE_PKG=0x4563316d2b647263737bbab1afb32495397bd36eefdcd3b1ca42c3c95ebb2fb3 | ||
| COMMITTEE_ID=0x210f1a2157d76e5c32a5e585ae3733b51105d553dc17f67457132af5e2dae7a5 | ||
| ``` | ||
|
|
||
| 3. Wait for the coordinator to announce phase 1. Run the CLI below to generate keys locally and register the public keys onchain. Make sure you are on the right network with wallet with enough gas. | ||
|
|
||
| ```bash | ||
| # A directory (default to `./dkg-state/`) containing sensitive private keys is created. Keep it secure till DKG is completed. | ||
| cargo run --bin dkg-cli generate-keys | ||
|
|
||
| export DKG_ENC_PK=$(jq -r '.enc_pk' dkg-state/dkg.key) | ||
| export DKG_SIGNING_PK=$(jq -r '.signing_pk' dkg-state/dkg.key) | ||
|
|
||
| # Register onchain. | ||
| sui client switch --env $NETWORK | ||
| YOUR_SERVER_URL="replace your url here" | ||
| MY_ADDRESS=$ADDRESS_0 # Replace your address here. | ||
|
|
||
| sui client switch --address $MY_ADDRESS | ||
| sui client call --package $COMMITTEE_PKG --module seal_committee \ | ||
| --function register \ | ||
| --args $COMMITTEE_ID x"$DKG_ENC_PK" x"$DKG_SIGNING_PK" "$YOUR_SERVER_URL" | ||
| ``` | ||
|
|
||
| 4. Wait for the coordinator to announce phase 2. Initialize the DKG state locally, create your message and upload it to the offchain storage. | ||
joyqvq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ```bash | ||
| cargo run --bin dkg-cli init --my-address $MY_ADDRESS --committee-id $COMMITTEE_ID --network $NETWORK | ||
| ``` | ||
|
|
||
| 5. TODO: Wait for the coordinator to announce phase 3. Process all messages locally and propose the committee onchain. | ||
|
|
||
| ### Key Rotation Process | ||
|
|
||
| A key rotation process is needed when a committee wants to rotate a portion of its members. The contuning members (in both current and next committee) must meet the threshold of the current committee. | ||
|
|
||
| #### Coordinator Runbook | ||
|
|
||
| All steps are the same as the runbook for fresh DKG but step 2. Instead of calling `init_committee`, call `init_rotation`, where `CURRENT_COMMITTEE_ID` is the object ID of the current committee (e.g., `CURRENT_COMMITTEE_ID=0x210f1a2157d76e5c32a5e585ae3733b51105d553dc17f67457132af5e2dae7a5`). | ||
|
|
||
| ```bash | ||
| sui client call --package $COMMITTEE_PKG --module seal_committee \ | ||
| --function init_rotation \ | ||
| --args $CURRENT_COMMITTEE_ID $THRESHOLD "[\"$ADDRESS_1\", \"$ADDRESS_0\", \"$ADDRESS_3\", \"$ADDRESS_4\"]" | ||
| ``` | ||
|
|
||
| #### Member Runbook | ||
|
|
||
| 1. Share with the coordinator your address. This is the wallet used for the rest of the onchain commands. | ||
| 2. Receive from coordinator the next committee ID. Verify its parameters (members addresses, threshold, the current committee ID) on Sui Explorer. Set environment variable. | ||
|
|
||
| ```bash | ||
| # next committee ID | ||
| COMMITTEE_ID=0x210f1a2157d76e5c32a5e585ae3733b51105d553dc17f67457132af5e2dae7a5 | ||
| ``` | ||
|
|
||
| 3. Wait for the coordinator to announce phase 1. Run the CLI below to generate keys locally and register the public keys onchain. Make sure you are on the right network with wallet with enough gas. | ||
|
|
||
| ```bash | ||
| # A directory (default to `./dkg-state/`) containing sensitive private keys is created. Keep it secure till DKG is completed. | ||
| cargo run --bin dkg-cli generate-keys | ||
|
|
||
| export DKG_ENC_PK=$(jq -r '.enc_pk' dkg-state/dkg.key) | ||
| export DKG_SIGNING_PK=$(jq -r '.signing_pk' dkg-state/dkg.key) | ||
|
|
||
| # Register onchain. | ||
| sui client switch --env $NETWORK | ||
| YOUR_SERVER_URL="replace your url here" | ||
| MY_ADDRESS=$ADDRESS_0 # Replace your address here. | ||
|
|
||
| sui client switch --address $MY_ADDRESS | ||
| sui client call --package $COMMITTEE_PKG --module seal_committee \ | ||
| --function register \ | ||
| --args $COMMITTEE_ID x"$DKG_ENC_PK" x"$DKG_SIGNING_PK" "$YOUR_SERVER_URL" | ||
| ``` | ||
|
|
||
| 4. Wait for the coordinator to announce phase 2. | ||
|
|
||
| a. For continuing members, run the CLI below to initialize the local state, create your message and upload it to the offchain storage. Must provide `--old-share` arg. | ||
|
|
||
| ```bash | ||
| cargo run --bin dkg-cli init --my-address $MY_ADDRESS --old-share $DKG_OLD_SHARE --committee-id $COMMITTEE_ID --network $NETWORK | ||
| ``` | ||
|
|
||
| b. For new members, run the CLI below that initialize the local state. Do not provide old share. | ||
|
|
||
| ```bash | ||
| cargo run --bin dkg-cli init --my-address $MY_ADDRESS --committee-id $COMMITTEE_ID --network $NETWORK | ||
| ``` | ||
|
|
||
| 5. TODO: Wait for the coordinator to announce phase 3. Process all messages locally and propose the committee onchain. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.