Skip to content

Commit 921807b

Browse files
committed
yapper optionally read enc_key from contract
1 parent 2488c60 commit 921807b

File tree

6 files changed

+61
-14
lines changed

6 files changed

+61
-14
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

justfile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,16 @@ test-dyn-comm: build_release_until build-test-utils
218218
-u http://localhost:8545 \
219219
-k 0x2bbf15bc655c4cc157b769cfcb1ea9924b9e1a35 \
220220
-c test-configs/c1/committee.toml" \
221-
--run "8:sleep 5" \
222-
--spawn "9:target/release/yapper --keyset-file test-configs/c1/committee.toml" \
221+
--run "8:sleep 8" \
222+
--run "9:target/release/register \
223+
-u http://localhost:8545 \
224+
-k 0x2bbf15bc655c4cc157b769cfcb1ea9924b9e1a35 \
225+
-c test-configs/c0/committee.toml \
226+
-a threshold-enc-key" \
227+
--spawn "10:target/release/yapper \
228+
--keyset-file test-configs/c1/committee.toml \
229+
--parent-url http://localhost:8545 \
230+
--key-manager-contract 0x2bbf15bc655c4cc157b769cfcb1ea9924b9e1a35" \
223231
target/release/run-committee -- --configs test-configs/c1/ \
224232
--committee 1 \
225233
--timeboost target/release/timeboost \

yapper/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ cliquenet = { path = "../cliquenet" }
1414
futures = { workspace = true }
1515
reqwest = { workspace = true }
1616
timeboost = { path = "../timeboost" }
17+
timeboost-contract = { path = "../timeboost-contract" }
1718
timeboost-utils = { path = "../timeboost-utils" }
1819
tokio = { workspace = true }
1920
tracing = { workspace = true }

yapper/src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use bon::Builder;
22
use cliquenet::Address;
33
use reqwest::Url;
4+
use timeboost::crypto::prelude::ThresholdEncKey;
45

56
#[derive(Debug, Clone, Builder)]
67
pub(crate) struct YapperConfig {
@@ -12,4 +13,6 @@ pub(crate) struct YapperConfig {
1213
pub(crate) nitro_url: Option<Url>,
1314
/// Chain id for l2 chain
1415
pub(crate) chain_id: u64,
16+
/// Use a given threshold encryption key, instead of fetching from nodes
17+
pub(crate) threshold_enc_key: Option<ThresholdEncKey>,
1518
}

yapper/src/main.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
77
use std::path::PathBuf;
88

9+
use alloy::{primitives::Address, providers::ProviderBuilder};
910
use anyhow::{Context, Result};
1011

1112
use clap::Parser;
1213
use reqwest::Url;
13-
use timeboost::config::CommitteeConfig;
14+
use timeboost::{config::CommitteeConfig, crypto::prelude::ThresholdEncKey};
15+
use timeboost_contract::KeyManager;
1416
use timeboost_utils::types::logging::init_logging;
1517
use timeboost_utils::wait_for_live_peer;
1618
use tokio::signal::{
@@ -45,6 +47,14 @@ struct Cli {
4547
/// Nitro node url.
4648
#[clap(long)]
4749
nitro_url: Option<Url>,
50+
51+
/// Parent chain where KeyManager is deployed
52+
#[clap(long)]
53+
parent_url: Option<Url>,
54+
55+
/// KeyManager contract address on the parent chain
56+
#[clap(long)]
57+
key_manager_contract: Option<Address>,
4858
}
4959

5060
#[tokio::main]
@@ -66,10 +76,25 @@ async fn main() -> Result<()> {
6676
addresses.push(node.http_api);
6777
}
6878

79+
let threshold_enc_key = if let Some(rpc) = cli.parent_url {
80+
let km_addr = cli
81+
.key_manager_contract
82+
.expect("provide both parent chain and key manager contract");
83+
let provider = ProviderBuilder::new().connect_http(rpc);
84+
let contract = KeyManager::new(km_addr, provider);
85+
86+
Some(ThresholdEncKey::from_bytes(
87+
&contract.thresholdEncryptionKey().call().await?.0,
88+
)?)
89+
} else {
90+
None
91+
};
92+
6993
let config = YapperConfig::builder()
7094
.addresses(addresses)
7195
.tps(cli.tps)
7296
.maybe_nitro_url(cli.nitro_url)
97+
.maybe_threshold_enc_key(threshold_enc_key)
7398
.chain_id(cli.chain_id)
7499
.build();
75100
let yapper = Yapper::new(config).await?;

yapper/src/yapper.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use alloy::{
1010
use anyhow::{Context, Result};
1111
use futures::future::join_all;
1212
use reqwest::{Client, Url};
13-
use timeboost::types::BundleVariant;
13+
use timeboost::{crypto::prelude::ThresholdEncKey, types::BundleVariant};
1414
use timeboost_utils::enc_key::ThresholdEncKeyCellAccumulator;
1515
use timeboost_utils::load_generation::{TxInfo, make_bundle, make_dev_acct_bundle, tps_to_millis};
1616
use tokio::time::interval;
@@ -42,6 +42,7 @@ pub(crate) struct Yapper {
4242
interval: Duration,
4343
chain_id: u64,
4444
provider: Option<RootProvider>,
45+
enc_key: Option<ThresholdEncKey>,
4546
}
4647

4748
impl Yapper {
@@ -68,12 +69,14 @@ impl Yapper {
6869
} else {
6970
None
7071
};
72+
7173
Ok(Self {
7274
urls,
7375
interval: Duration::from_millis(tps_to_millis(cfg.tps)),
7476
client,
7577
provider,
7678
chain_id: cfg.chain_id,
79+
enc_key: cfg.threshold_enc_key,
7780
})
7881
}
7982

@@ -93,25 +96,31 @@ impl Yapper {
9396
warn!("failed to prepare txn");
9497
continue;
9598
};
96-
let enc_key = match acc.enc_key().await {
99+
let enc_key = match self.enc_key.as_ref() {
97100
Some(key) => key,
98-
None => {
99-
warn!("encryption key not available yet");
100-
continue;
101-
}
101+
None => match acc.enc_key().await {
102+
Some(key) => key,
103+
None => {
104+
warn!("encryption key not available yet");
105+
continue;
106+
}
107+
},
102108
};
103109
let Ok(b) = make_dev_acct_bundle(enc_key, txn) else {
104110
warn!("failed to generate dev account bundle");
105111
continue;
106112
};
107113
b
108114
} else {
109-
let enc_key = match acc.enc_key().await {
115+
let enc_key = match self.enc_key.as_ref() {
110116
Some(key) => key,
111-
None => {
112-
warn!("encryption key not available yet");
113-
continue;
114-
}
117+
None => match acc.enc_key().await {
118+
Some(key) => key,
119+
None => {
120+
warn!("encryption key not available yet");
121+
continue;
122+
}
123+
},
115124
};
116125
let Ok(b) = make_bundle(enc_key) else {
117126
warn!("failed to generate bundle");

0 commit comments

Comments
 (0)