Skip to content

Commit

Permalink
closer to e2e testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny-g committed Dec 15, 2023
1 parent ff368a1 commit ed6ff50
Show file tree
Hide file tree
Showing 18 changed files with 1,211 additions and 556 deletions.
456 changes: 266 additions & 190 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ edition = "2021"
rust-version = "1.70"

[workspace.dependencies]
anyhow = { version = "1.0", default-features = false }
coerce = { version = "0.8", default-features = false}
futures = { version = "0.3", default-features = false }
# futures-channel = { version = "0.3", default-features = false }
Expand All @@ -35,7 +36,7 @@ thiserror = { version = "1.0", default-features = false }
tokio = { version = "1.28", default-features = false }
tracing = { version = "0.1", default-features = false }
tracing-futures = { version = "0.2", default-features = false }
tracing-subscriber = { version = "0.2", default-features = false }
tracing-subscriber = { version = "0.3", default-features = false }

# # wasm
wasmtime = { version = "13.0", default-features = false }
Expand All @@ -53,11 +54,13 @@ wit-bindgen-rust = { version = "0.12", default-features = false }
# crypto, zk
borsh = { version = "1.2", default-features = false }
cid = { version = "0.10", default-features = false }
crypto-bigint = { version = "0.5", default-features = false, features = [] }
digest = { version = "0.10", default-features = false }
ed25519-dalek = { version = "2.1", default-features = false }
# k256 = { git = "https://github.com/risc0/rustcrypto-elliptic-curves", branch = "risc0" }
# pqc_kyber = {version = "0.7.1", default-features = false }
merkle-log = { version = "0.0.9", default-features = false }
rand = { version = "0.8", default-features = false }
sha2 = { version = "0.10", default-features = false }
signature = { version = "2.2", default-features = false }
# veilid-core = { version = "0.2.3", default-features = false, features = [
Expand Down
6 changes: 3 additions & 3 deletions components/persona/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "datalove-persona"
authors.workspace = true
version.workspace = true
edition.workspace = true
authors = { workspace = true }
version = { workspace = true }
edition = { workspace = true }

[dependencies]
datalove-persona-core = { path = "./core", default-features = false, features = [
Expand Down
23 changes: 20 additions & 3 deletions components/persona/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "datalove-persona-core"
authors.workspace = true
version.workspace = true
edition.workspace = true
authors = { workspace = true }
version = { workspace = true }
edition = { workspace = true }

[dependencies]
# general
Expand All @@ -18,12 +18,14 @@ digest = { workspace = true, default-features = false, features = [
] }
ed25519-dalek = { workspace = true, default-features = false, features = [
"digest",
# "fast",
] }
# merkle-log = { workspace = true, default-features = false, features = [
# "borsh",
# "digest",
# ] }
risc0-zkvm = { workspace = true, default-features = false, features = [
"verify",
] }
sha2 = { workspace = true, default-features = false, features = [
] }
Expand All @@ -32,7 +34,21 @@ signature = { workspace = true, default-features = false, features = [
] }

[dev-dependencies]
anyhow = { workspace = true, default-features = false, features = ["std"] }
datalove-persona-core = { path = ".", features = ["std", "test"] }
datalove-persona-risc0 = { path = "../methods" }
ed25519-dalek = { workspace = true, default-features = false, features = [
"rand_core",
"std",
] }
rand = { workspace = true, default-features = false, features = ["std"] }
risc0-zkvm = { workspace = true, default-features = false, features = [
"cuda", # remove
"prove",
"verify",
"std",
] }
tracing-subscriber = { workspace = true, features = ["env-filter"] }

[features]
default = []
Expand All @@ -47,6 +63,7 @@ std = [
"sha2/std",
"signature/std",
]
test = [] # enables test utilities
# serde = [
# "dep:serde",
# "ed25519-dalek/serde",
Expand Down
62 changes: 37 additions & 25 deletions components/persona/core/src/device.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
use std::process::Output;

use crate::{util, Error};
use borsh::{BorshDeserialize, BorshSerialize};
use digest::{typenum::U64, Digest};
use ed25519_dalek::{Signature as Ed25519Signature, VerifyingKey as Ed25519VerifyingKey};
use ed25519_dalek::{
Signature as Ed25519Signature, SigningKey as Ed25519SigningKey,
VerifyingKey as Ed25519VerifyingKey,
};
use sha2::Sha512;
use signature::{DigestSigner, DigestVerifier, Error as SignatureError, Verifier};

///
#[derive(Copy, Clone, Debug, Eq, PartialEq, BorshDeserialize, BorshSerialize)]
pub struct Device {
inner: DeviceInner,
// log: MerkleLog<DeviceLogNode>,
}

impl Device {
pub fn id(&self) -> [u8; 32] {
match self.inner {
DeviceInner::Ed25519(pk) => pk.to_bytes(),
}
}
}

///
#[derive(Copy, Clone, Debug, Eq, PartialEq, BorshDeserialize, BorshSerialize)]
#[borsh(use_discriminant = true)]
#[non_exhaustive]
pub enum Device {
enum DeviceInner {
Ed25519(
#[borsh(
deserialize_with = "util::ed25519::deserialize_key",
Expand All @@ -21,6 +38,8 @@ pub enum Device {
}

#[derive(Copy, Clone, Debug, Eq, PartialEq, BorshDeserialize, BorshSerialize)]
#[borsh(use_discriminant = true)]
#[non_exhaustive]
pub enum DeviceSignature {
Ed25519(
#[borsh(
Expand Down Expand Up @@ -79,7 +98,7 @@ impl Device {
// self.pk.as_bytes() == &NULL_PEER_KEY
// }

pub fn sign<D, Si>(&self, message: &[u8], signer: &Si) -> Result<DeviceSignature, Error>
pub fn sign_message<D, Si>(&self, message: &[u8], signer: &Si) -> Result<DeviceSignature, Error>
where
D: Digest<OutputSize = U64> + Clone,
Si: DigestSigner<D, DeviceSignature>,
Expand All @@ -91,16 +110,12 @@ impl Device {
}

/// assumes we're verifying a protocol message digest
pub(crate) fn verify_digest<D>(
&self,
msg_digest: D,
signature: &DeviceSignature,
) -> Result<(), Error>
fn verify_digest<D>(&self, msg_digest: D, signature: &DeviceSignature) -> Result<(), Error>
where
D: Digest<OutputSize = U64>,
{
match (self, signature) {
(Self::Ed25519(pk), DeviceSignature::Ed25519(sig)) => {
match (self.inner, signature) {
(DeviceInner::Ed25519(pk), DeviceSignature::Ed25519(sig)) => {
Ok(pk.verify_digest(msg_digest, sig)?)
}
}
Expand Down Expand Up @@ -132,19 +147,16 @@ impl Verifier<DeviceSignature> for Device {
}
}

// pub(crate) const NULL_PEER_KEY: [u8; 32] = [
// 59, 106, 39, 188, 206, 182, 164, 45, 98, 163, 168, 208, 42, 111, 13, 115, 101, 50, 21, 119, 29,
// 226, 67, 166, 58, 192, 72, 161, 139, 89, 218, 41,
// ];

// /// A default [`Device`] with a secret key of all zeros.
// impl Default for Device {
// fn default() -> Self {
// let sk = ed25519_dalek::SigningKey::from_bytes(&[0u8; 32]);
// let pk = sk.verifying_key();
// Self::new(pk, &sk).expect("failed to create default peer")
// }
// }
/// A default [`Device`] with a secret key of all zeros.
impl Default for Device {
fn default() -> Self {
let sk = Ed25519SigningKey::from_bytes(&[0u8; 32]);
let pk = sk.verifying_key();
Self {
inner: DeviceInner::Ed25519(pk),
}
}
}

#[cfg(test)]
mod tests {
Expand Down
3 changes: 3 additions & 0 deletions components/persona/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ pub enum Error {
#[cfg_attr(feature = "std", error("Signature error: {0}"))]
SignatureError(#[cfg_attr(feature = "std", from)] signature::Error),

#[cfg_attr(feature = "std", error("Invalid signature error: {0}"))]
InvalidSignatureError(&'static str),

// #[cfg_attr(feature = "std", error("MerkleLog error: {0}"))]
// MerkleLogError(#[cfg_attr(feature = "std", from)] merkle_log::Error),
#[cfg_attr(feature = "std", error("invalid operation: {0}"))]
Expand Down
8 changes: 5 additions & 3 deletions components/persona/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ mod device;
mod error;
mod persona;

pub(crate) mod proof;
pub(crate) mod util;
#[doc(hidden)]
pub mod util;
pub mod zksm;

pub(crate) mod maybestd {
pub use borsh::__private::maybestd::*;
pub use borsh::io;
pub use core::{borrow, cell, cmp, marker, ops};
pub use core::{borrow, cell, cmp, fmt, marker, ops};
}

pub use borsh;
Expand Down
Loading

0 comments on commit ed6ff50

Please sign in to comment.