Skip to content

feat(adkg-cli): rework protocol execution#100

Merged
CluEleSsUK merged 2 commits into
mainfrom
feat/adkg-cli/async-storage
Sep 16, 2025
Merged

feat(adkg-cli): rework protocol execution#100
CluEleSsUK merged 2 commits into
mainfrom
feat/adkg-cli/async-storage

Conversation

@azixus
Copy link
Copy Markdown
Contributor

@azixus azixus commented Sep 11, 2025

Reworks the execution of the ADKG in the cli to fix #96 & fix #97 .

The new execution flow is as follows:

  1. Execute ADKG on G1
    1a. The ADKG has sent an output through the oneshot channel, continue to 2.
    1b. The ADKG has timed out, or returned an error => exit now
  2. Write the priv/pub output to the specified files
  3. Execute the G1 to G2 swap protocol
    3.a. The swap protocol completes, write the priv/pub output to the specified files, continue to 4.
    3.b. The ADKG task has completed its grace period, continue to 4. <-- The swap protocol has timed out.
  4. Wait for the ADKG task to complete its grace period <-- This gives time for both the ADKG & the swap protocol to complete on every node
  5. Write the transcripts to disk

The main fix consists of writing into the priv/pub files as soon as we get the ADKG output.
We also now store both the output on the source group, and the output on the swapped group, resulting in a file with the following format:

adkg_scheme_name = "DXKR23-Bn254G1-Keccak256"
genesis_timestamp = 1756913660
group_pk = "2mHtp5Tfo3LkEO9s1DN4RkhkmpT4cTvs3Uv+ld8UTc8oqB5dZOaAdpGQqimMdJ+yuVbp4sIFMkhjva3NnxSL1Q=="
group_pk_source = "2Nj0GQDtqAQ5liambQul3QgnrmTxFU5UrDlOgRnziaY="

[[node_pks]]
id = 1
pk = "j5nfW8teKjZABd6pO+isTvdlk1IorZ0VGnha+xGTWiMV5DQP6CkCeVoNqSAzGp3lJZuB7wr5Ev9CH/5h0POzbg=="
peer_id = "12D3KooWN21eTopREUZfyfmY8aKjreUjtCeQkWd6hbMENBCQ8njc"
multiaddr = "/ip4/127.0.0.1/tcp/15001"

[[node_pks]]
...

[[node_pks_source]]
id = 1
pk = "qRuY9ZISP9/n5gugqazhYkKV0asV+LrFAhkzeVKgWEU="
peer_id = "12D3KooWN21eTopREUZfyfmY8aKjreUjtCeQkWd6hbMENBCQ8njc"
multiaddr = "/ip4/127.0.0.1/tcp/15001"

[[node_pks_source]]
...

The attributes suffixed with _source shouldn't be used for applications, but they can be helpful for recovery should the swap protocol ever fail, while the ADKG succeeds.

use utils::serialize::fq::{FqDeserialize, FqSerialize};
use utils::serialize::point::{PointDeserializeCompressed, PointSerializeCompressed};

const TOPIC_SWAP_G1_TO_G2: &str = "adkg_dxkr23_swap_g1_to_g2";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not relevant for this PR, but will we need to add a nonce to this in a future world where nodes can be a party to many committees?

// Spawn a task to run the adkg in the background.
let (tx_adkg_out, rx_adkg_out) = oneshot::channel();
let mut adkg_task: tokio::task::JoinHandle<anyhow::Result<()>> = tokio::spawn({
let pks = pks.clone();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ahh, I like this format of

tokio::spawn({
// clones
async move {

It always felt ugly to read doing the clones outside - we should make this an SOP!

@CluEleSsUK CluEleSsUK merged commit 53313b4 into main Sep 16, 2025
6 checks passed
@CluEleSsUK CluEleSsUK deleted the feat/adkg-cli/async-storage branch September 16, 2025 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

adkg-cli: fallback to unswapped output on g1 to g2 public keys swap adkg-cli: Write keys immediately upon creation

2 participants