Skip to content

Commit

Permalink
feat: replace ed25519-dalek with ed25519-consensus (#138)
Browse files Browse the repository at this point in the history
* feat: replaced ed25519-dalek with ed25519-consensus

* fix: keystore version

* fix: clippy

* fix: regen Cargo.lock file

* fix: regenerate lockfile and sp1 elf
  • Loading branch information
sebasti810 authored Oct 14, 2024
1 parent 787bbaf commit e94bc5d
Show file tree
Hide file tree
Showing 16 changed files with 283 additions and 321 deletions.
542 changes: 254 additions & 288 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ dotenvy = "0.15.7"
celestia-rpc = "0.4.0"
celestia-types = "0.4.0"
mockall = "0.12.1"
keystore-rs = "0.1.0"
keystore-rs = "0.1.2"
toml = "0.8.14"
dirs = "5.0.1"
anyhow = "1.0.44"
Expand All @@ -78,7 +78,7 @@ arecibo = { git = "https://github.com/deltadevsde/arecibo" }
sha2 = "0.10.8"
auto_impl = "1.2.0"
bincode = "1.3.3"
ed25519-dalek = "2.1.1"
ed25519-consensus = "2.1.0"
secp256k1 = { version = "0.29.0", features = ["global-context", "rand-std"] }
sp1-zkvm = { version = "1.2.0" }
sp1-sdk = { version = "1.2.0" }
Expand All @@ -96,7 +96,7 @@ rocksdb = { version = "0.21.0", features = ["multi-threaded-cf"] }

[patch.crates-io]
sha2-v0-10-8 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", package = "sha2", branch = "patch-sha2-v0.10.8" }
curve25519-dalek = { git = "https://github.com/sp1-patches/curve25519-dalek", branch = "patch-curve25519-v4.1.3", package = "ed25519-dalek" }
ed25519-consensus = { git = "https://github.com/sp1-patches/ed25519-consensus", branch = "patch-v2.1.0" }
secp256k1 = { git = "https://github.com/sp1-patches/rust-secp256k1", branch = "patch-secp256k1-v0.29.0" }

[workspace.features]
Expand Down
2 changes: 1 addition & 1 deletion crates/bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async-trait = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
redis = { workspace = true }
ed25519-dalek = { workspace = true }
ed25519-consensus = { workspace = true }
base64 = { workspace = true }
tokio = { workspace = true }
bincode = { workspace = true }
Expand Down
6 changes: 2 additions & 4 deletions crates/bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod node_types;

use cfg::{initialize_da_layer, load_config, CommandLineArgs, Commands};
use clap::Parser;
use ed25519_dalek::VerifyingKey as Ed25519VerifyingKey;
use ed25519_consensus::VerificationKey as Ed25519VerifyingKey;
use keystore_rs::{KeyChain, KeyStore, KeyStoreType};
use prism_common::keys::VerifyingKey;

Expand Down Expand Up @@ -41,9 +41,7 @@ async fn main() -> std::io::Result<()> {
let prover_vk = config
.verifying_key
.and_then(|s| s.try_into().ok())
.and_then(|vk: VerifyingKey| {
Ed25519VerifyingKey::from_bytes(vk.as_bytes().try_into().unwrap()).ok()
});
.and_then(|vk: VerifyingKey| Ed25519VerifyingKey::try_from(vk.as_bytes()).ok());

Arc::new(LightClient::new(da, celestia_config, prover_vk))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bin/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async fn test_light_client_prover_talking() -> Result<()> {
let db = setup_db();
let cfg = Config::default();
let signing_key = create_signing_key();
let pubkey = signing_key.verifying_key();
let pubkey = signing_key.verification_key();

let mut test_state = TestTreeState::new();
let _service = test_state.register_service("test_service".to_string());
Expand Down
4 changes: 2 additions & 2 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ sha2.workspace = true
celestia-types.workspace = true
bincode.workspace = true
log.workspace = true
ed25519-dalek.workspace = true
secp256k1.workspace = true
ed25519-consensus.workspace = true
secp256k1.workspace = true
base64.workspace = true
rand.workspace = true

Expand Down
22 changes: 10 additions & 12 deletions crates/common/src/keys.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::{anyhow, Result};
use base64::{engine::general_purpose::STANDARD as engine, Engine as _};
use ed25519_dalek::{
Signature as Ed25519Signature, Signer as Ed25519Signer, SigningKey as Ed25519SigningKey,
VerifyingKey as Ed25519VerifyingKey,
use ed25519_consensus::{
Signature as Ed25519Signature, SigningKey as Ed25519SigningKey,
VerificationKey as Ed25519VerifyingKey,
};
use secp256k1::{
ecdsa::Signature as Secp256k1Signature, Message as Secp256k1Message,
Expand Down Expand Up @@ -37,11 +37,9 @@ impl VerifyingKey {
}
match self {
VerifyingKey::Ed25519(bytes) => {
let vk = Ed25519VerifyingKey::from_bytes(bytes.as_slice().try_into()?)
.map_err(|e| anyhow!(e))?;
let signature = Ed25519Signature::from_bytes(signature.try_into()?);
vk.verify_strict(message, &signature)
.map_err(|e| anyhow!(e))
let vk = Ed25519VerifyingKey::try_from(bytes.as_slice()).map_err(|e| anyhow!(e))?;
let signature = Ed25519Signature::try_from(signature).map_err(|e| anyhow!(e))?;
vk.verify(&signature, message).map_err(|e| anyhow!(e))
}
VerifyingKey::Secp256k1(bytes) => {
let hashed_message = Digest::hash(message).to_bytes();
Expand All @@ -58,7 +56,7 @@ impl VerifyingKey {

impl From<Ed25519SigningKey> for VerifyingKey {
fn from(sk: Ed25519SigningKey) -> Self {
VerifyingKey::Ed25519(sk.verifying_key().to_bytes().to_vec())
VerifyingKey::Ed25519(sk.verification_key().to_bytes().to_vec())
}
}

Expand Down Expand Up @@ -113,7 +111,7 @@ impl TryFrom<String> for VerifyingKey {

#[derive(Clone)]
pub enum SigningKey {
Ed25519(Ed25519SigningKey),
Ed25519(Box<Ed25519SigningKey>),
Secp256k1(Secp256k1SigningKey),
}

Expand All @@ -132,7 +130,7 @@ impl SigningKey {

pub fn verifying_key(&self) -> VerifyingKey {
match self {
SigningKey::Ed25519(sk) => sk.verifying_key().into(),
SigningKey::Ed25519(sk) => sk.verification_key().into(),
SigningKey::Secp256k1(sk) => sk.public_key(SECP256K1).into(),
}
}
Expand All @@ -146,7 +144,7 @@ mod tests {
#[test]
fn test_verifying_key_from_string_ed25519() {
let ed25519_vk =
SigningKey::Ed25519(Ed25519SigningKey::generate(&mut OsRng)).verifying_key();
SigningKey::Ed25519(Box::new(Ed25519SigningKey::new(OsRng))).verifying_key();
let encoded = engine.encode(ed25519_vk.as_bytes());

let result = VerifyingKey::try_from(encoded);
Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
};
use anyhow::{anyhow, Result};
#[cfg(not(feature = "secp256k1"))]
use ed25519_dalek::SigningKey as Ed25519SigningKey;
use ed25519_consensus::SigningKey as Ed25519SigningKey;
use jmt::{mock::MockTreeStore, KeyHash};
use rand::{
rngs::{OsRng, StdRng},
Expand Down Expand Up @@ -200,7 +200,7 @@ pub fn create_random_update(state: &mut TestTreeState, rng: &mut StdRng) -> Upda

#[cfg(not(feature = "secp256k1"))]
pub fn create_mock_signing_key() -> SigningKey {
SigningKey::Ed25519(Ed25519SigningKey::generate(&mut OsRng))
SigningKey::Ed25519(Box::new(Ed25519SigningKey::new(OsRng)))
}

#[cfg(feature = "secp256k1")]
Expand Down
2 changes: 1 addition & 1 deletion crates/da/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ readme.workspace = true
[dependencies]
async-trait = { workspace = true }
serde = { workspace = true }
ed25519-dalek = { workspace = true }
ed25519-consensus = { workspace = true }
tokio = { workspace = true }
bincode = { workspace = true }
hex = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/da/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use async_trait::async_trait;
use ed25519_dalek::{Signature, Signer, SigningKey, VerifyingKey};
use ed25519_consensus::{Signature, SigningKey, VerificationKey as VerifyingKey};
use prism_common::{operation::Operation, tree::Digest};
use serde::{Deserialize, Serialize};
use sp1_sdk::SP1ProofWithPublicValues;
Expand Down Expand Up @@ -56,7 +56,7 @@ impl FinalizedEpoch {
.try_into()
.map_err(|_| anyhow::anyhow!("Invalid signature length"))?;

vk.verify_strict(&message, &signature)
vk.verify(&signature, &message)
.map_err(|e| anyhow::anyhow!("Signature verification failed: {}", e))?;
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/node_types/lightclient/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mock_prover = []
async-trait = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
ed25519-dalek = { workspace = true }
ed25519-consensus = { workspace = true }
base64 = { workspace = true }
tokio = { workspace = true }
bincode = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/node_types/lightclient/src/lightclient.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::{Context, Result};
use ed25519_dalek::VerifyingKey;
use ed25519_consensus::VerificationKey as VerifyingKey;
use prism_common::tree::Digest;
use prism_da::{celestia::CelestiaConfig, DataAvailabilityLayer};
use prism_errors::{DataAvailabilityError, GeneralError};
Expand Down
2 changes: 1 addition & 1 deletion crates/node_types/prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async-trait = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
redis = { workspace = true }
ed25519-dalek = { workspace = true }
ed25519-consensus = { workspace = true }
base64 = { workspace = true }
tokio = { workspace = true }
bincode = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/node_types/prover/src/prover.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::{anyhow, bail, Context, Result};
use ed25519_dalek::SigningKey;
use ed25519_consensus::SigningKey;
use jmt::KeyHash;
use prism_common::tree::{
Batch, Digest, HashchainResponse, HashchainResponse::*, Hasher, KeyDirectoryTree, Proof,
Expand Down
Binary file modified elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ build:

unit-test:
@echo "Running unit tests..."
cargo test --lib --release --features "mock_prover secp256k1" -- --skip test_light_client_prover_talking
cargo test --lib --release --features "mock_prover" -- --skip test_light_client_prover_talking

install-deps:
#!/usr/bin/env bash
Expand Down

0 comments on commit e94bc5d

Please sign in to comment.