Skip to content
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

feat: test all available curves #186

Merged
merged 34 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
141ebdd
feat: test all curves
smuu Dec 19, 2024
9aa437b
feat: config checks
smuu Dec 19, 2024
9c63742
feat: build
smuu Dec 19, 2024
a9f608d
fix: remove debug message
smuu Dec 19, 2024
9e31143
fix: intentation
smuu Dec 19, 2024
bacc54e
fix: test output as before
smuu Dec 19, 2024
ef9b950
Merge branch 'main' into smuu/20241213-test-all-curves
smuu Dec 19, 2024
8223b70
fix: wrong usage of function
smuu Dec 19, 2024
db1b9e8
feat: apply coderabbit review 1st round
smuu Dec 19, 2024
efb146c
fix: errors
smuu Dec 19, 2024
c2740af
feat: apply coderabbit review 2nd round
smuu Dec 19, 2024
06c3c14
feat: apply review from jns-ps
smuu Dec 19, 2024
4f1fce2
Merge branch 'main' into smuu/20241213-test-all-curves
smuu Dec 19, 2024
313ff7e
feat: build
smuu Dec 19, 2024
fec1480
feat: apply clippy changes
smuu Dec 19, 2024
a02f267
fix: unit tests
smuu Dec 19, 2024
706bb76
feat: apply coderabbit review 3rd round
smuu Dec 19, 2024
4fca18a
fix: funding
smuu Dec 19, 2024
51a4efd
refactor(keys): algorithm as enum
jns-ps Dec 19, 2024
7fbf5c5
chore: Incorporate changes in zkvm elf
jns-ps Dec 19, 2024
15fc919
fix: fund all in sequence
smuu Dec 19, 2024
64e68f3
feat: integration test all curves
smuu Dec 19, 2024
58a0978
fix: clippy
smuu Dec 19, 2024
a37a8fb
fix: remove unused dep
smuu Dec 19, 2024
0403811
Merge branch 'crypto-alg-as-enum' into smuu/20241213-test-all-curves
smuu Dec 29, 2024
bf06889
feat: apply coderabbit review 4th round
smuu Dec 29, 2024
3608504
Merge branch 'main' into smuu/20241213-test-all-curves
smuu Jan 8, 2025
0a36317
feat: applied review
smuu Jan 8, 2025
90c6b60
feat: apply review
smuu Jan 9, 2025
81c5ed8
revert unused dep
smuu Jan 9, 2025
cae20ba
fix: apply review
smuu Jan 9, 2025
a381432
fix: remove debugging message
smuu Jan 9, 2025
0c529b4
feat: add rust comment
smuu Jan 9, 2025
68c9579
fix: remove logging key
smuu Jan 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ jmt = { git = "https://github.com/deltadevsde/jmt", branch = "rehashing-circuit"
sha2 = "0.10.8"
tempfile = "3.14.0"
auto_impl = "1.2.0"
paste = "1.0.15"
smuu marked this conversation as resolved.
Show resolved Hide resolved

# prism
prism-common = { path = "crates/common" }
Expand Down
14 changes: 10 additions & 4 deletions ci/run-validator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ provision_light_nodes() {
"$NODE_NAME" \
"$light_address" \
"$BRIDGE_COINS" \
--fees 21000utia
--fees 21000utia \
--broadcast-mode block
done

echo "Provisioning finished."
Expand Down Expand Up @@ -160,12 +161,18 @@ provision_bridge_nodes() {
"$NODE_NAME" \
"$bridge_address" \
"$BRIDGE_COINS" \
--fees 21000utia
--fees 21000utia \
--broadcast-mode block
done

echo "Provisioning finished."
}

provision() {
provision_bridge_nodes
provision_light_nodes
}

# Set up the validator for a private alone network.
# Based on
# https://github.com/celestiaorg/celestia-app/blob/main/scripts/single-node.sh
Expand Down Expand Up @@ -202,8 +209,7 @@ setup_private_validator() {
main() {
# Configure stuff
setup_private_validator
provision_bridge_nodes &
provision_light_nodes &
provision &
# Start the celestia-app
echo "Configuration finished. Running a validator node..."
celestia-appd start --api.enable --grpc.enable --force-no-bbr
Expand Down
11 changes: 11 additions & 0 deletions crates/cli/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ pub struct CommandArgs {
#[arg(long)]
verifying_key: Option<String>,

/// The algorithm used for the verifying key.
///
/// Can be one of: `ed25519`, `secp256k1`, `secp256r1`.
#[arg(long, default_value = "ed25519")]
verifying_key_algorithm: Option<String>,

#[arg(long)]
config_path: Option<String>,

Expand Down Expand Up @@ -97,6 +103,7 @@ pub struct Config {
pub da_layer: DALayerOption,
pub redis_config: Option<RedisConfig>,
pub verifying_key: Option<String>,
pub verifying_key_algorithm: String,
}

impl Default for Config {
Expand All @@ -107,6 +114,7 @@ impl Default for Config {
da_layer: DALayerOption::default(),
redis_config: Some(RedisConfig::default()),
verifying_key: None,
verifying_key_algorithm: "ed25519".to_string(),
}
}
}
Expand Down Expand Up @@ -201,6 +209,9 @@ fn apply_command_line_args(config: Config, args: CommandArgs) -> Config {
}),
da_layer: config.da_layer,
verifying_key: args.verifying_key.or(config.verifying_key),
verifying_key_algorithm: args
.verifying_key_algorithm
.unwrap_or(config.verifying_key_algorithm),
}
}

Expand Down
129 changes: 72 additions & 57 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ mod node_types;
use cfg::{initialize_da_layer, load_config, Cli, Commands};
use clap::Parser;
use keystore_rs::{KeyChain, KeyStore, KeyStoreType};
use prism_keys::VerifyingKey;
use prism_keys::{CryptoAlgorithm, SigningKey, VerifyingKey};
use std::io::{Error, ErrorKind};

use node_types::NodeType;
use prism_lightclient::LightClient;
use prism_prover::Prover;
use prism_storage::RedisConnection;
use std::sync::Arc;

use std::{str::FromStr, sync::Arc};
#[macro_use]
extern crate log;

Expand All @@ -24,105 +24,120 @@ async fn main() -> std::io::Result<()> {
let node: Arc<dyn NodeType> = match cli.command {
Commands::LightClient(args) => {
let config = load_config(args.clone())
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?;

let da = initialize_da_layer(&config)
.await
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?;

let celestia_config = config.celestia_config.ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::NotFound,
"celestia configuration not found",
)
Error::new(ErrorKind::NotFound, "celestia configuration not found")
})?;

let prover_vk = config.verifying_key.and_then(|s| s.try_into().ok()).and_then(
|vk: VerifyingKey| match vk {
VerifyingKey::Ed25519(key) => Some(key),
_ => None,
},
);
let verifying_key_algorithm =
CryptoAlgorithm::from_str(&config.verifying_key_algorithm).map_err(|_| {
Error::new(
ErrorKind::InvalidInput,
"invalid verifying key algorithm format",
)
})?;
smuu marked this conversation as resolved.
Show resolved Hide resolved
let prover_vk = VerifyingKey::from_algorithm_and_bytes(
verifying_key_algorithm,
config.verifying_key.unwrap().as_bytes(),
smuu marked this conversation as resolved.
Show resolved Hide resolved
)
.map_err(|e| Error::new(ErrorKind::InvalidInput, e.to_string()))?;
smuu marked this conversation as resolved.
Show resolved Hide resolved

Arc::new(LightClient::new(da, celestia_config, prover_vk))
Arc::new(LightClient::new(da, celestia_config, Some(prover_vk)))
}
Commands::Prover(args) => {
let config = load_config(args.clone())
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?;

let da = initialize_da_layer(&config)
.await
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?;

let redis_config = config.clone().redis_config.ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::NotFound,
"redis configuration not found",
)
})?;
let redis_config = config
.clone()
.redis_config
.ok_or_else(|| Error::new(ErrorKind::NotFound, "redis configuration not found"))?;
let redis_connections = RedisConnection::new(&redis_config)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?;

let signing_key = KeyStoreType::KeyChain(KeyChain)
let signing_key_chain = KeyStoreType::KeyChain(KeyChain)
.get_signing_key()
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?;

let verifying_key_algorithm =
CryptoAlgorithm::from_str(&config.verifying_key_algorithm).map_err(|_| {
Error::new(
ErrorKind::InvalidInput,
"invalid verifying key algorithm format",
)
})?;
let signing_key = SigningKey::from_algorithm_and_bytes(
verifying_key_algorithm,
signing_key_chain.as_bytes(),
)
.map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid signing key: {}", e)))?;
let verifying_key = signing_key.verifying_key();

let prover_cfg = prism_prover::Config {
prover: true,
batcher: true,
webserver: config.webserver.unwrap_or_default(),
signing_key: signing_key.clone(),
verifying_key: signing_key.verification_key(),
verifying_key: verifying_key.clone(),
start_height: config.celestia_config.unwrap_or_default().start_height,
};

info!(
"prover verifying key: {}",
VerifyingKey::from(prover_cfg.verifying_key)
);

Arc::new(
Prover::new(Arc::new(Box::new(redis_connections)), da, &prover_cfg).map_err(
|e| {
error!("error initializing prover: {}", e);
std::io::Error::new(std::io::ErrorKind::Other, e.to_string())
Error::new(ErrorKind::Other, e.to_string())
},
)?,
)
}
Commands::FullNode(args) => {
let config = load_config(args.clone())
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?;

let da = initialize_da_layer(&config)
.await
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?;

let redis_config = config.clone().redis_config.ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::NotFound,
"redis configuration not found",
)
})?;
let redis_config = config
.clone()
.redis_config
.ok_or_else(|| Error::new(ErrorKind::NotFound, "redis configuration not found"))?;
let redis_connections = RedisConnection::new(&redis_config)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?;

let signing_key = KeyStoreType::KeyChain(KeyChain)
let signing_key_chain = KeyStoreType::KeyChain(KeyChain)
.get_signing_key()
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?;

let verifying_key_algorithm =
CryptoAlgorithm::from_str(&config.verifying_key_algorithm).map_err(|_| {
Error::new(
ErrorKind::InvalidInput,
"invalid verifying key algorithm format",
)
})?;
let signing_key = SigningKey::from_algorithm_and_bytes(
verifying_key_algorithm,
signing_key_chain.as_bytes(),
)
.map_err(|e| Error::new(ErrorKind::InvalidInput, format!("Invalid signing key: {}", e)))?;

let prover_vk = config
.verifying_key
.and_then(|s| s.try_into().ok())
.and_then(|vk: VerifyingKey| match vk {
VerifyingKey::Ed25519(key) => Some(key),
_ => None,
})
.ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::NotFound,
"prover verifying key not found",
)
.ok_or_else(|| Error::new(ErrorKind::NotFound, "prover verifying key not found"))
.and_then(|vk| {
VerifyingKey::from_algorithm_and_bytes(verifying_key_algorithm, vk.as_bytes())
.map_err(|e| Error::new(ErrorKind::InvalidInput, e.to_string()))
})?;

let prover_cfg = prism_prover::Config {
Expand All @@ -138,12 +153,12 @@ async fn main() -> std::io::Result<()> {
Prover::new(Arc::new(Box::new(redis_connections)), da, &prover_cfg).map_err(
|e| {
error!("error initializing prover: {}", e);
std::io::Error::new(std::io::ErrorKind::Other, e.to_string())
Error::new(ErrorKind::Other, e.to_string())
},
)?,
)
}
};

node.start().await.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))
node.start().await.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
}
Loading
Loading