diff --git a/Cargo.lock b/Cargo.lock index 8b3828d3..e64ea090 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1849,6 +1849,21 @@ dependencies = [ "spki", ] +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "git+https://github.com/sp1-patches/signatures?branch=patch-ecdsa-v0.16.9#de1b108e8140dcb86ecf56f1215ac4b7fab6fcd8" +dependencies = [ + "anyhow", + "cfg-if", + "digest 0.10.7", + "elliptic-curve", + "hex-literal", + "signature", + "sp1-lib", + "spki", +] + [[package]] name = "ed25519" version = "2.2.3" @@ -3450,7 +3465,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6e3919bbaa2945715f0bb6d3934a173d1e9a59ac23767fbaaef277265a7411b" dependencies = [ "cfg-if", - "ecdsa", + "ecdsa 0.16.9 (registry+https://github.com/rust-lang/crates.io-index)", "elliptic-curve", "once_cell", "sha2 0.10.8", @@ -4818,6 +4833,7 @@ dependencies = [ "log", "prism-errors", "rand", + "secp256k1", "serde", "sha2 0.10.8", ] @@ -5814,6 +5830,27 @@ dependencies = [ "zeroize", ] +[[package]] +name = "secp256k1" +version = "0.29.0" +source = "git+https://github.com/sp1-patches/rust-secp256k1?branch=patch-secp256k1-v0.29.0#1da89f39f21f1e4ed4f9f869169a59bbe81edc71" +dependencies = [ + "cfg-if", + "ecdsa 0.16.9 (git+https://github.com/sp1-patches/signatures?branch=patch-ecdsa-v0.16.9)", + "elliptic-curve", + "k256", + "rand", + "secp256k1-sys", +] + +[[package]] +name = "secp256k1-sys" +version = "0.10.0" +source = "git+https://github.com/sp1-patches/rust-secp256k1?branch=patch-secp256k1-v0.29.0#1da89f39f21f1e4ed4f9f869169a59bbe81edc71" +dependencies = [ + "cc", +] + [[package]] name = "security-framework" version = "2.11.1" @@ -8076,8 +8113,3 @@ dependencies = [ "cc", "pkg-config", ] - -[[patch.unused]] -name = "secp256k1" -version = "0.29.0" -source = "git+https://github.com/sp1-patches/rust-secp256k1?branch=patch-secp256k1-v0.29.0#1da89f39f21f1e4ed4f9f869169a59bbe81edc71" diff --git a/Cargo.toml b/Cargo.toml index 720c6e59..3da9bdbd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,7 +75,7 @@ sha2 = "0.10.8" auto_impl = "1.2.0" bincode = "1.3.3" ed25519-dalek = "2.1.1" -secp256k1 = "0.29.0" +secp256k1 = { version = "0.29.0", features = ["global-context", "rand-std"] } sp1-zkvm = { version = "1.2.0" } sp1-sdk = { version = "1.2.0" } prism-common = { path = "crates/common" } @@ -97,6 +97,7 @@ secp256k1 = { git = "https://github.com/sp1-patches/rust-secp256k1", branch = "p default = [] test_utils = [] mock_prover = [] +secp256k1 = [] # [workspace.dev-dependencies] # serial_test = "3.1.1" diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index 8f619b10..c3baae39 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -18,9 +18,11 @@ celestia-types.workspace = true bincode.workspace = true log.workspace = true ed25519-dalek.workspace = true +secp256k1.workspace = true base64.workspace = true rand.workspace = true [features] default = [] test_utils = [] +secp256k1 = ["secp256k1/global-context", "secp256k1/rand-std"] diff --git a/crates/common/src/hashchain.rs b/crates/common/src/hashchain.rs index 71d60f8f..6c40e0cf 100644 --- a/crates/common/src/hashchain.rs +++ b/crates/common/src/hashchain.rs @@ -8,8 +8,8 @@ use std::{ use crate::{ operation::{ - CreateAccountArgs, Operation, PublicKey, RegisterServiceArgs, ServiceChallenge, - ServiceChallengeInput, + CreateAccountArgs, Operation, RegisterServiceArgs, ServiceChallenge, ServiceChallengeInput, + VerifyingKey, }, tree::{Digest, Hasher}, }; @@ -70,7 +70,7 @@ impl Hashchain { pub fn create_account( id: String, - value: PublicKey, + value: VerifyingKey, signature: Vec, service_id: String, challenge: ServiceChallengeInput, @@ -109,7 +109,7 @@ impl Hashchain { return Ok(()); } - let mut valid_keys: HashSet = HashSet::new(); + let mut valid_keys: HashSet = HashSet::new(); for (index, entry) in self.entries.iter().enumerate().take(self.entries.len() - 1) { match &entry.operation { @@ -181,15 +181,15 @@ impl Hashchain { new } - pub fn get_key_at_index(&self, idx: usize) -> Result<&PublicKey> { + pub fn get_key_at_index(&self, idx: usize) -> Result<&VerifyingKey> { self.entries .get(idx) .and_then(|entry| entry.operation.get_public_key()) .ok_or_else(|| anyhow!("No valid public key found at index {}", idx)) } - pub fn get_valid_keys(&self) -> HashSet { - let mut valid_keys: HashSet = HashSet::new(); + pub fn get_valid_keys(&self) -> HashSet { + let mut valid_keys: HashSet = HashSet::new(); for entry in self.entries.clone() { match &entry.operation { @@ -208,7 +208,7 @@ impl Hashchain { valid_keys } - pub fn is_key_revoked(&self, key: PublicKey) -> bool { + pub fn is_key_revoked(&self, key: VerifyingKey) -> bool { self.iter() .rev() .find_map(|entry| match entry.operation.clone() { diff --git a/crates/common/src/operation.rs b/crates/common/src/operation.rs index 854d2e3c..5abffcae 100644 --- a/crates/common/src/operation.rs +++ b/crates/common/src/operation.rs @@ -2,66 +2,115 @@ use anyhow::{anyhow, Context, Result}; use base64::{engine::general_purpose::STANDARD as engine, Engine as _}; use bincode; use celestia_types::Blob; -use ed25519_dalek::{Signature, Signer, SigningKey, VerifyingKey}; +use ed25519_dalek::{ + Signature as Ed25519Signature, Signer as Ed25519Signer, SigningKey as Ed25519SigningKey, + VerifyingKey as Ed25519VerifyingKey, +}; use prism_errors::GeneralError; +use secp256k1::{ + ecdsa::Signature as Secp256k1Signature, Message as Secp256k1Message, + PublicKey as Secp256k1VerifyingKey, SecretKey as Secp256k1SigningKey, SECP256K1, +}; use serde::{Deserialize, Serialize}; use std::{self, fmt::Display}; +use crate::tree::Digest; + #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Hash)] /// Represents a public key supported by the system. -pub enum PublicKey { - // Secp256k1(Vec), // Bitcoin, Ethereum - // Curve25519(Vec), // Signal, Tor - Ed25519(Vec), // Cosmos, OpenSSH, GnuPG +pub enum VerifyingKey { + /// Bitcoin, Ethereum + Secp256k1(Vec), + /// Cosmos, OpenSSH, GnuPG + Ed25519(Vec), } -impl PublicKey { +impl VerifyingKey { + /// Returns the byte representation of the public key. pub fn as_bytes(&self) -> &[u8] { match self { - PublicKey::Ed25519(bytes) => bytes, - // PublicKey::Secp256k1(bytes) => bytes, - // PublicKey::Curve25519(bytes) => bytes, + VerifyingKey::Ed25519(bytes) => bytes, + VerifyingKey::Secp256k1(bytes) => bytes, } } pub fn verify_signature(&self, message: &[u8], signature: &[u8]) -> Result<()> { + if signature.len() != 64 { + return Err(anyhow!("Invalid signature length")); + } match self { - PublicKey::Ed25519(bytes) => { - if signature.len() != 64 { - return Err(anyhow!("Invalid signature length")); - } - - let vk = VerifyingKey::from_bytes(bytes.as_slice().try_into()?) + VerifyingKey::Ed25519(bytes) => { + let vk = Ed25519VerifyingKey::from_bytes(bytes.as_slice().try_into()?) .map_err(|e| anyhow!(e))?; - let signature = Signature::from_bytes(signature.try_into()?); + let signature = Ed25519Signature::from_bytes(signature.try_into()?); vk.verify_strict(message, &signature) .map_err(|e| anyhow!(e)) } + VerifyingKey::Secp256k1(bytes) => { + let hashed_message = Digest::hash(message).to_bytes(); + let vk = Secp256k1VerifyingKey::from_slice(bytes.as_slice())?; + let message = Secp256k1Message::from_digest(hashed_message); + let signature = Secp256k1Signature::from_compact(signature)?; + + vk.verify(SECP256K1, &message, &signature) + .map_err(|e| anyhow!("Failed to verify signature: {}", e)) + } } } } -impl From for PublicKey { - fn from(sk: SigningKey) -> Self { - PublicKey::Ed25519(sk.verifying_key().to_bytes().to_vec()) +impl From for VerifyingKey { + fn from(sk: Ed25519SigningKey) -> Self { + VerifyingKey::Ed25519(sk.verifying_key().to_bytes().to_vec()) } } -impl From for PublicKey { - fn from(vk: VerifyingKey) -> Self { - PublicKey::Ed25519(vk.to_bytes().to_vec()) +impl From for VerifyingKey { + fn from(vk: Ed25519VerifyingKey) -> Self { + VerifyingKey::Ed25519(vk.to_bytes().to_vec()) } } -impl TryFrom for PublicKey { +impl From for VerifyingKey { + fn from(sk: Secp256k1SigningKey) -> Self { + sk.public_key(SECP256K1).into() + } +} + +impl From for VerifyingKey { + fn from(vk: Secp256k1VerifyingKey) -> Self { + VerifyingKey::Secp256k1(vk.serialize().to_vec()) + } +} + +impl TryFrom for VerifyingKey { type Error = anyhow::Error; + /// Attempts to create a `VerifyingKey` from a base64-encoded string. + /// + /// # Arguments + /// + /// * `s` - The base64-encoded string representation of the public key. + /// + /// Depending on the length of the input string, the function will attempt to + /// decode it and create a `VerifyingKey` instance. According to the specifications, + /// the input string should be either [32 bytes (Ed25519)](https://datatracker.ietf.org/doc/html/rfc8032#section-5.1.5) or [33/65 bytes (Secp256k1)](https://www.secg.org/sec1-v2.pdf). + /// The secp256k1 key can be either compressed (33 bytes) or uncompressed (65 bytes). + /// + /// # Returns + /// + /// * `Ok(VerifyingKey)` if the conversion was successful. + /// * `Err` if the input is invalid or the conversion failed. fn try_from(s: String) -> std::result::Result { let bytes = engine .decode(s) .map_err(|e| anyhow!("Failed to decode base64 string: {}", e))?; - Ok(PublicKey::Ed25519(bytes.to_vec())) + match bytes.len() { + 32 => Ok(VerifyingKey::Ed25519(bytes)), + 33 | 65 => Ok(VerifyingKey::Secp256k1(bytes)), + _ => Err(anyhow!("Invalid public key length")), + } } } @@ -69,8 +118,10 @@ impl TryFrom for PublicKey { /// Represents a signature bundle, which includes the index of the key /// in the user's hashchain and the associated signature. pub struct SignatureBundle { - pub key_idx: u64, // Index of the key in the hashchain - pub signature: Vec, // The actual signature + /// Index of the key in the hashchain + pub key_idx: u64, + /// The actual signature + pub signature: Vec, } impl SignatureBundle { @@ -85,57 +136,94 @@ impl SignatureBundle { #[derive(Clone, Serialize, Deserialize, Debug, PartialEq)] /// Input required to complete a challenge for account creation. pub enum ServiceChallengeInput { - Signed(Vec), // Signature bytes + /// Signature bytes + Signed(Vec), } #[derive(Clone, Serialize, Deserialize, Debug, PartialEq)] -// An [`Operation`] represents a state transition in the system. -// In a blockchain analogy, this would be the full set of our transaction types. +/// An [`Operation`] represents a state transition in the system. +/// In a blockchain analogy, this would be the full set of our transaction types. pub enum Operation { - // Creates a new account with the given id and value. + /// Creates a new account with the given id and value. CreateAccount(CreateAccountArgs), - // Adds a value to an existing account. + /// Adds a value to an existing account. AddKey(KeyOperationArgs), - // Revokes a value from an existing account. + /// Revokes a value from an existing account. RevokeKey(KeyOperationArgs), - // Registers a new service with the given id. + /// Registers a new service with the given id. RegisterService(RegisterServiceArgs), } #[derive(Clone, Serialize, Deserialize, Debug, PartialEq)] /// Arguments for creating an account with a service. pub struct CreateAccountArgs { - pub id: String, // Account ID - pub value: PublicKey, // Public Key + /// Account ID + pub id: String, + /// Public key being added + pub value: VerifyingKey, pub signature: Vec, - pub service_id: String, // Associated service ID - pub challenge: ServiceChallengeInput, // Challenge input for verification + /// Associated service ID + pub service_id: String, + /// Challenge input for verification + pub challenge: ServiceChallengeInput, } #[derive(Clone, Serialize, Deserialize, Debug, PartialEq)] /// Arguments for registering a new service. pub struct RegisterServiceArgs { - pub id: String, // Service ID - pub creation_gate: ServiceChallenge, // Challenge gate for access control + /// Service ID + pub id: String, + /// Challenge gate for access control + pub creation_gate: ServiceChallenge, } #[derive(Clone, Serialize, Deserialize, Debug, PartialEq)] pub enum ServiceChallenge { - Signed(PublicKey), + Signed(VerifyingKey), } impl From for ServiceChallenge { fn from(sk: SigningKey) -> Self { - ServiceChallenge::Signed(PublicKey::Ed25519(sk.verifying_key().as_bytes().to_vec())) + ServiceChallenge::Signed(sk.verifying_key()) } } #[derive(Clone, Serialize, Deserialize, Debug, PartialEq)] /// Common structure for operations involving keys (adding or revoking). pub struct KeyOperationArgs { - pub id: String, // Account ID - pub value: PublicKey, // Public key being added or revoked - pub signature: SignatureBundle, // Signature to authorize the action + /// Account ID + pub id: String, + /// Public key being added or revoked + pub value: VerifyingKey, + /// Signature to authorize the action + pub signature: SignatureBundle, +} + +#[derive(Clone)] +pub enum SigningKey { + Ed25519(Ed25519SigningKey), + Secp256k1(Secp256k1SigningKey), +} + +impl SigningKey { + pub fn sign(&self, message: &[u8]) -> Vec { + match self { + SigningKey::Ed25519(sk) => sk.sign(message).to_bytes().to_vec(), + SigningKey::Secp256k1(sk) => { + let hashed_message = Digest::hash(message).to_bytes(); + let message = Secp256k1Message::from_digest(hashed_message); + let signature = SECP256K1.sign_ecdsa(&message, sk); + signature.serialize_compact().to_vec() + } + } + } + + pub fn verifying_key(&self) -> VerifyingKey { + match self { + SigningKey::Ed25519(sk) => sk.verifying_key().into(), + SigningKey::Secp256k1(sk) => sk.public_key(SECP256K1).into(), + } + } } impl Operation { @@ -147,7 +235,7 @@ impl Operation { ) -> Result { let mut op = Operation::CreateAccount(CreateAccountArgs { id: id.to_string(), - value: signing_key.clone().verifying_key().into(), + value: signing_key.clone().verifying_key(), service_id, challenge: ServiceChallengeInput::Signed(Vec::new()), signature: Vec::new(), @@ -161,8 +249,7 @@ impl Operation { match op { Operation::CreateAccount(ref mut args) => { - args.challenge = - ServiceChallengeInput::Signed(service_challenge.to_bytes().to_vec()); + args.challenge = ServiceChallengeInput::Signed(service_challenge); } _ => panic!("Operation should be CreateAccount"), }; @@ -175,7 +262,7 @@ impl Operation { pub fn new_add_key( id: String, - value: PublicKey, + value: VerifyingKey, signing_key: &SigningKey, key_idx: u64, ) -> Result { @@ -200,7 +287,7 @@ impl Operation { pub fn new_revoke_key( id: String, - value: PublicKey, + value: VerifyingKey, signing_key: &SigningKey, key_idx: u64, ) -> Result { @@ -231,7 +318,7 @@ impl Operation { } } - pub fn get_public_key(&self) -> Option<&PublicKey> { + pub fn get_public_key(&self) -> Option<&VerifyingKey> { match self { Operation::RevokeKey(args) | Operation::AddKey(args) => Some(&args.value), Operation::CreateAccount(args) => Some(&args.value), @@ -252,9 +339,9 @@ impl Operation { let signature = signing_key.sign(&serialized); match self { - Operation::CreateAccount(args) => args.signature = signature.to_bytes().to_vec(), + Operation::CreateAccount(args) => args.signature = signature, Operation::AddKey(args) | Operation::RevokeKey(args) => { - args.signature.signature = signature.to_bytes().to_vec() + args.signature.signature = signature } _ => unimplemented!("RegisterService sequencer gating not yet implemented"), } @@ -306,7 +393,7 @@ impl Operation { } } - pub fn verify_user_signature(&self, pubkey: PublicKey) -> Result<()> { + pub fn verify_user_signature(&self, pubkey: VerifyingKey) -> Result<()> { match self { Operation::RegisterService(_) => Ok(()), Operation::CreateAccount(args) => { @@ -381,3 +468,69 @@ impl TryFrom<&Blob> for Operation { .context(format!("Failed to decode blob into Operation: {value:?}")) } } + +#[cfg(test)] +mod tests { + use super::*; + use rand::rngs::OsRng; + + #[test] + fn test_verifying_key_from_string_ed25519() { + let ed25519_vk = + SigningKey::Ed25519(Ed25519SigningKey::generate(&mut OsRng)).verifying_key(); + let encoded = engine.encode(ed25519_vk.as_bytes()); + + let result = VerifyingKey::try_from(encoded); + assert!(result.is_ok()); + + if let Ok(VerifyingKey::Ed25519(key_bytes)) = result { + assert_eq!(key_bytes.len(), 32); + assert_eq!(key_bytes, ed25519_vk.as_bytes()); + } else { + panic!("Expected Ed25519 key"); + } + } + + #[test] + fn test_verifying_key_from_string_secp256k1_compressed() { + let secp256k1_vk = + SigningKey::Secp256k1(Secp256k1SigningKey::new(&mut OsRng)).verifying_key(); + let secp256k1_bytes = secp256k1_vk.as_bytes(); + let encoded = engine.encode(secp256k1_bytes); + + let result = VerifyingKey::try_from(encoded); + assert!(result.is_ok()); + + if let Ok(VerifyingKey::Secp256k1(key_bytes)) = result { + dbg!(key_bytes.len()); + assert_eq!(key_bytes, secp256k1_bytes); + } else { + panic!("Expected Secp256k1 key"); + } + } + + #[test] + fn test_verifying_key_from_string_secp256k1_uncompressed() { + let secp256k1_bytes = [0; 65]; + let encoded = engine.encode(secp256k1_bytes); + + let result = VerifyingKey::try_from(encoded); + assert!(result.is_ok()); + + if let Ok(VerifyingKey::Secp256k1(key_bytes)) = result { + assert_eq!(key_bytes.len(), 65); + assert_eq!(key_bytes, secp256k1_bytes); + } else { + panic!("Expected Secp256k1 key"); + } + } + + #[test] + fn test_verifying_key_from_string_invalid_length() { + let invalid_bytes: [u8; 31] = [1; 31]; + let encoded = engine.encode(invalid_bytes); + + let result = VerifyingKey::try_from(encoded); + assert!(result.is_err()); + } +} diff --git a/crates/common/src/test_utils.rs b/crates/common/src/test_utils.rs index 9fecc5c6..8ad707c6 100644 --- a/crates/common/src/test_utils.rs +++ b/crates/common/src/test_utils.rs @@ -1,12 +1,18 @@ use crate::{ hashchain::Hashchain, - operation::{Operation, PublicKey, ServiceChallenge}, + operation::{Operation, ServiceChallenge, SigningKey, VerifyingKey}, tree::{InsertProof, KeyDirectoryTree, Proof, SnarkableTree, UpdateProof}, }; use anyhow::{anyhow, Result}; -use ed25519_dalek::{SigningKey, VerifyingKey}; +#[cfg(not(feature = "secp256k1"))] +use ed25519_dalek::SigningKey as Ed25519SigningKey; use jmt::{mock::MockTreeStore, KeyHash}; -use rand::{rngs::StdRng, Rng}; +use rand::{ + rngs::{OsRng, StdRng}, + Rng, +}; +#[cfg(feature = "secp256k1")] +use secp256k1::SecretKey as Secp256k1SigningKey; use std::{ collections::{HashMap, HashSet}, sync::Arc, @@ -103,10 +109,10 @@ impl TestTreeState { pub fn add_key_to_account(&mut self, account: &mut TestAccount) -> Result<(), anyhow::Error> { let signing_key_to_add = create_mock_signing_key(); - let pub_key: PublicKey = signing_key_to_add.into(); + let key_to_add = signing_key_to_add.verifying_key(); let op = Operation::new_add_key( account.hashchain.id.clone(), - pub_key.clone(), + key_to_add.clone(), self.signing_keys.get(&account.hashchain.id).unwrap(), 0, )?; @@ -166,9 +172,8 @@ pub fn create_random_update(state: &mut TestTreeState, rng: &mut StdRng) -> Upda .unwrap(); let mut hc = state.tree.get(key).unwrap().unwrap(); - let signing_key = SigningKey::generate(rng); + let signing_key = create_mock_signing_key(); let verifying_key = signing_key.verifying_key(); - let public_key = PublicKey::Ed25519(verifying_key.to_bytes().to_vec()); let signer = state .signing_keys @@ -176,7 +181,8 @@ pub fn create_random_update(state: &mut TestTreeState, rng: &mut StdRng) -> Upda .ok_or_else(|| anyhow::anyhow!("Signing key not found for hashchain")) .unwrap(); - let operation = Operation::new_add_key(hc.id.clone(), public_key.clone(), signer, 0).unwrap(); + let operation = + Operation::new_add_key(hc.id.clone(), verifying_key.clone(), signer, 0).unwrap(); hc.perform_operation(operation) .expect("Adding to hashchain should succeed"); @@ -186,8 +192,14 @@ pub fn create_random_update(state: &mut TestTreeState, rng: &mut StdRng) -> Upda .expect("Update should succeed") } +#[cfg(not(feature = "secp256k1"))] +pub fn create_mock_signing_key() -> SigningKey { + SigningKey::Ed25519(Ed25519SigningKey::generate(&mut OsRng)) +} + +#[cfg(feature = "secp256k1")] pub fn create_mock_signing_key() -> SigningKey { - SigningKey::generate(&mut rand::thread_rng()) + SigningKey::Secp256k1(Secp256k1SigningKey::new(&mut OsRng)) } pub fn create_new_hashchain(id: &str, signing_key: &SigningKey, service: Service) -> Hashchain { diff --git a/crates/common/src/tree.rs b/crates/common/src/tree.rs index 353bf3b1..9a4afc7b 100644 --- a/crates/common/src/tree.rs +++ b/crates/common/src/tree.rs @@ -167,6 +167,10 @@ impl Digest { pub fn to_hex(&self) -> String { hex::encode(self.0) } + + pub fn to_bytes(&self) -> [u8; 32] { + self.0 + } } #[derive(Serialize, Deserialize)] diff --git a/crates/prism/src/main.rs b/crates/prism/src/main.rs index 7b958148..60449d96 100644 --- a/crates/prism/src/main.rs +++ b/crates/prism/src/main.rs @@ -5,9 +5,9 @@ mod webserver; use cfg::{initialize_da_layer, load_config, CommandLineArgs, Commands}; use clap::Parser; -use ed25519_dalek::VerifyingKey; +use ed25519_dalek::VerifyingKey as Ed25519VerifyingKey; use keystore_rs::{KeyChain, KeyStore, KeyStoreType}; -use prism_common::operation::PublicKey; +use prism_common::operation::VerifyingKey; use node_types::{lightclient::LightClient, sequencer::Sequencer, NodeType}; use prism_storage::RedisConnection; @@ -41,8 +41,8 @@ async fn main() -> std::io::Result<()> { let sequencer_vk = config .verifying_key .and_then(|s| s.try_into().ok()) - .and_then(|pk: PublicKey| { - VerifyingKey::from_bytes(pk.as_bytes().try_into().unwrap()).ok() + .and_then(|vk: VerifyingKey| { + Ed25519VerifyingKey::from_bytes(vk.as_bytes().try_into().unwrap()).ok() }); Arc::new(LightClient::new(da, celestia_config, sequencer_vk)) diff --git a/crates/prism/src/node_types/sequencer.rs b/crates/prism/src/node_types/sequencer.rs index c40c2d46..c8a26349 100644 --- a/crates/prism/src/node_types/sequencer.rs +++ b/crates/prism/src/node_types/sequencer.rs @@ -415,7 +415,7 @@ impl Sequencer { mod tests { use super::*; use keystore_rs::create_signing_key; - use prism_common::{operation::PublicKey, test_utils::create_mock_signing_key}; + use prism_common::test_utils::create_mock_signing_key; use prism_da::memory::InMemoryDataAvailabilityLayer; use prism_storage::inmemory::InMemoryDatabase; @@ -459,7 +459,7 @@ mod tests { let sequencer = create_test_sequencer().await; let signing_key = create_mock_signing_key(); - let original_pubkey = signing_key.clone().into(); + let original_pubkey = signing_key.verifying_key(); let service_key = create_mock_signing_key(); let register_service_op = @@ -485,7 +485,7 @@ mod tests { assert!(matches!(proof, Proof::Insert(_))); let new_key = create_mock_signing_key(); - let pubkey = new_key.clone().into(); + let pubkey = new_key.verifying_key(); let add_key_op = Operation::new_add_key("test@example.com".to_string(), pubkey, &signing_key, 0) .unwrap(); @@ -523,7 +523,7 @@ mod tests { // add signing_key_2, so it will be index = 1 Operation::new_add_key( "user1@example.com".to_string(), - signing_key_2.verifying_key().into(), + signing_key_2.verifying_key(), &signing_key_1, 0, ) @@ -531,7 +531,7 @@ mod tests { // try revoking signing_key_2 Operation::new_revoke_key( "user1@example.com".to_string(), - signing_key_2.verifying_key().into(), + signing_key_2.verifying_key(), &signing_key_1, 0, ) @@ -540,7 +540,7 @@ mod tests { // both of these operations are valid individually, but when processed together it will fail. Operation::new_add_key( "user1@example.com".to_string(), - signing_key_3.verifying_key().into(), + signing_key_3.verifying_key(), &signing_key_2, 1, ) @@ -557,7 +557,7 @@ mod tests { let signing_key_1 = create_mock_signing_key(); let signing_key_2 = create_mock_signing_key(); - let new_key = create_mock_signing_key().into(); + let new_key = create_mock_signing_key().verifying_key(); let service_key = create_mock_signing_key(); let operations = vec![ @@ -590,12 +590,7 @@ mod tests { let signing_key_1 = create_mock_signing_key(); let signing_key_2 = create_mock_signing_key(); - let new_key = PublicKey::Ed25519( - create_mock_signing_key() - .verifying_key() - .to_bytes() - .to_vec(), - ); + let new_key = create_mock_signing_key().verifying_key(); let service_key = create_mock_signing_key(); let operations = vec![ diff --git a/crates/prism/tests/integration_tests.rs b/crates/prism/tests/integration_tests.rs index 1b0cc8f9..7640ad7a 100644 --- a/crates/prism/tests/integration_tests.rs +++ b/crates/prism/tests/integration_tests.rs @@ -3,11 +3,13 @@ #[macro_use] extern crate log; use anyhow::Result; -use ed25519_dalek::SigningKey; use keystore_rs::create_signing_key; -use prism_common::operation::{ - CreateAccountArgs, KeyOperationArgs, Operation, PublicKey, ServiceChallengeInput, - SignatureBundle, +use prism_common::{ + operation::{ + CreateAccountArgs, KeyOperationArgs, Operation, ServiceChallengeInput, SignatureBundle, + SigningKey, VerifyingKey, + }, + test_utils::create_mock_signing_key, }; use prism_da::{ celestia::{CelestiaConfig, CelestiaConnection}, @@ -25,7 +27,7 @@ use tokio::{spawn, time::Duration}; fn create_random_user(id: &str, signing_key: SigningKey) -> Operation { let mut op = Operation::CreateAccount(CreateAccountArgs { id: id.to_string(), - value: signing_key.clone().into(), + value: signing_key.verifying_key(), service_id: "test_service".to_string(), signature: Vec::new(), challenge: ServiceChallengeInput::Signed(vec![]), @@ -36,7 +38,7 @@ fn create_random_user(id: &str, signing_key: SigningKey) -> Operation { op } -fn add_key(id: &str, key_idx: u64, new_key: PublicKey, signing_key: SigningKey) -> Operation { +fn add_key(id: &str, key_idx: u64, new_key: VerifyingKey, signing_key: SigningKey) -> Operation { let mut op = Operation::AddKey(KeyOperationArgs { id: id.to_string(), value: new_key.clone(), @@ -113,7 +115,7 @@ async fn test_light_client_sequencer_talking() -> Result<()> { // Create 1 to 3 new accounts let num_new_accounts = rng.gen_range(1..=3); for _ in 0..num_new_accounts { - let new_key = create_signing_key(); + let new_key = create_mock_signing_key(); let new_acc = create_random_user(format!("{}@gmail.com", i).as_str(), new_key.clone()); sequencer @@ -138,7 +140,7 @@ async fn test_light_client_sequencer_talking() -> Result<()> { let signing_key = signing_keys.last().unwrap(); let new_key = create_signing_key(); let new_public_key = - PublicKey::Ed25519(new_key.verifying_key().to_bytes().to_vec()); + VerifyingKey::Ed25519(new_key.verifying_key().to_bytes().to_vec()); let update_op = add_key( account_id, (signing_keys.len() - 1) as u64, diff --git a/elf/riscv32im-succinct-zkvm-elf b/elf/riscv32im-succinct-zkvm-elf index 3e1e39a7..8aaf8598 100755 Binary files a/elf/riscv32im-succinct-zkvm-elf and b/elf/riscv32im-succinct-zkvm-elf differ diff --git a/justfile b/justfile index 708159fa..6d37d68d 100644 --- a/justfile +++ b/justfile @@ -83,7 +83,7 @@ build: unit-test: @echo "Running unit tests..." - cargo test --lib --release --features mock_prover -- --skip test_light_client_sequencer_talking + cargo test --lib --release --features "mock_prover secp256k1" -- --skip test_light_client_sequencer_talking install-deps: #!/usr/bin/env bash