Skip to content

Commit

Permalink
Serialization for kzgrs verifier settings
Browse files Browse the repository at this point in the history
  • Loading branch information
bacv committed Aug 30, 2024
1 parent d6d82f5 commit ce3f663
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions nomos-services/data-availability/verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ async-trait = "0.1"
blst = { version = "0.3.11", features = ["serde-secret"] }
bytes = "1.2"
futures = "0.3"
hex = "0.4.3"
kzgrs-backend = { path = "../../../nomos-da/kzgrs-backend" }
nomos-core = { path = "../../../nomos-core" }
nomos-da-storage = { path = "../../../nomos-da/storage" }
Expand Down
21 changes: 18 additions & 3 deletions nomos-services/data-availability/verifier/src/backend/kzgrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,22 @@ impl VerifierBackend for KzgrsDaVerifier {
type Settings = KzgrsDaVerifierSettings;

fn new(settings: Self::Settings) -> Self {
let verifier = NomosKzgrsVerifier::new(settings.sk, &settings.nodes_public_keys);
let bytes = hex::decode(settings.sk).expect("Secret key string should decode to bytes");
let secret_key =
SecretKey::from_bytes(&bytes).expect("Secret key should be reconstructed from bytes");

let nodes_public_keys = settings
.nodes_public_keys
.iter()
.map(|pk_hex| {
let pk_bytes =
hex::decode(pk_hex).expect("Public key string should decode to bytes");
PublicKey::from_bytes(&pk_bytes)
.expect("Public key should be reconstructed from bytes")
})
.collect::<Vec<PublicKey>>();

let verifier = NomosKzgrsVerifier::new(secret_key, &nodes_public_keys);
Self { verifier }
}
}
Expand All @@ -55,6 +70,6 @@ impl DaVerifier for KzgrsDaVerifier {
// TODO: `sk` and `nodes_public_keys` need to be fetched from the params provider service.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct KzgrsDaVerifierSettings {
pub sk: SecretKey,
pub nodes_public_keys: Vec<PublicKey>,
pub sk: String,
pub nodes_public_keys: Vec<String>,
}
2 changes: 2 additions & 0 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2021"
publish = false

[dependencies]
blst = { version = "0.3.11" }
nomos-node = { path = "../nodes/nomos-node", default-features = false }
nomos-network = { path = "../nomos-services/network", features = ["libp2p"] }
cryptarchia-consensus = { path = "../nomos-services/cryptarchia-consensus" }
Expand All @@ -21,6 +22,7 @@ nomos-da-indexer = { path = "../nomos-services/data-availability/indexer" }
nomos-da-verifier = { path = "../nomos-services/data-availability/verifier" }
subnetworks-assignations = { path = "../nomos-da/network/subnetworks-assignations" }
full-replication = { path = "../nomos-da/full-replication" }
hex = "0.4.3"
kzgrs-backend = { path = "../nomos-da/kzgrs-backend" }
rand = "0.8"
once_cell = "1"
Expand Down
16 changes: 13 additions & 3 deletions tests/src/nodes/nomos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::time::Duration;
// internal
use super::{create_tempdir, persist_tempdir, LOGS_PREFIX};
use crate::{adjust_timeout, get_available_port, ConsensusConfig, Node};
use blst::min_sig::SecretKey;
use cryptarchia_consensus::{CryptarchiaInfo, CryptarchiaSettings, TimeConfig};
use cryptarchia_ledger::{Coin, LedgerState};
use kzgrs_backend::dispersal::BlobInfo;
Expand Down Expand Up @@ -33,7 +34,7 @@ use nomos_network::{backends::libp2p::Libp2pConfig, NetworkConfig};
use nomos_node::{api::AxumBackendSettings, Config, Tx};
// crates
use once_cell::sync::Lazy;
use rand::{thread_rng, Rng};
use rand::{thread_rng, Rng, RngCore};
use reqwest::{Client, Url};
use tempfile::NamedTempFile;
use time::OffsetDateTime;
Expand Down Expand Up @@ -360,6 +361,15 @@ fn create_node_config(
#[cfg(feature = "mixnet")] mixnet_config: MixnetConfig,
) -> Config {
let swarm_config: SwarmConfig = Default::default();

let mut rng = rand::thread_rng();
let mut buff = [0u8; 32];
rng.fill_bytes(&mut buff);

let verifier_sk = SecretKey::key_gen(&buff, &[]).unwrap();
let verifier_pk_bytes = verifier_sk.sk_to_pk().to_bytes();
let verifier_sk_bytes = verifier_sk.to_bytes();

let mut config = Config {
network: NetworkConfig {
backend: Libp2pConfig {
Expand Down Expand Up @@ -392,8 +402,8 @@ fn create_node_config(
},
da_verifier: DaVerifierServiceSettings {
verifier_settings: KzgrsDaVerifierSettings {
sk: Default::default(),
nodes_public_keys: Default::default(),
sk: hex::encode(verifier_sk_bytes),
nodes_public_keys: vec![hex::encode(verifier_pk_bytes)],
},
network_adapter_settings: (),
storage_adapter_settings: VerifierStorageAdapterSettings {
Expand Down

0 comments on commit ce3f663

Please sign in to comment.