Skip to content

Commit

Permalink
Merge pull request #10 from semiotic-ai/hs2s2-library-impl
Browse files Browse the repository at this point in the history
feat: trait for signature and NCS impl over it
  • Loading branch information
pedrohba1 authored Jan 27, 2025
2 parents 37a2ce8 + 4197fc3 commit fa043c7
Show file tree
Hide file tree
Showing 5 changed files with 465 additions and 74 deletions.
12 changes: 11 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
[workspace]
members = [
"h2s2",
]
]


[workspace.dependencies]
ark-std = {version ="0.5.0", features = ["parallel"]}
ark-ec = {version = "0.5.0", features = ["parallel"]}
ark-ff = { version = "0.5", features = [ "parallel" ] }
blake2 = "0.10.6"
digest = "0.10.7"
rayon = "1.1"
ark-bn254 = "0.5.0"
12 changes: 9 additions & 3 deletions h2s2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ authors = [
"Severiano Sisneros <[email protected]>",
"Alexis Asseman <[email protected]>",
"Tomasz Kornuta <[email protected]>",
"Pedro Bufulin <[email protected]>",
]
license = "Apache-2.0"
description = ""
edition = "2021"
keywords = ["holographic", "homomorphic", "signature-scheme"]
catagories = ["cryptography", "cryptography::cryptocurrencies"]


# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ark-ec = {workspace = true}
ark-std = { workspace = true}
ark-ff = { workspace = true}
ark-bn254 = { workspace = true}
blake2 = {workspace = true}
rayon = { workspace = true}
digest = { workspace = true}
once_cell = "1.20.2"
93 changes: 37 additions & 56 deletions h2s2/src/holographic_homomorphic_signature_scheme.rs
Original file line number Diff line number Diff line change
@@ -1,82 +1,63 @@
//nc1
use crate::ark_std::UniformRand;
use crate::ark_std::Zero;
use crate::Error;
use crate::HomomorphicSignatureScheme;
use ark_ec::pairing::Pairing;
use ark_ec::AffineRepr;
use ark_std::{marker::PhantomData, rand::Rng};
use ark_std::rand::Rng;
use digest::Digest;
use std::ops::MulAssign;

pub struct HolographicHomomorphicSignatureScheme<P: Pairing, D: Digest> {
_pairing: PhantomData<P>,
_hash: PhantomData<D>,
}

#[derive(Clone)]
pub struct H2S2Parameters<P: Pairing> {
pub g1_generators: Vec<P::G1>,
pub g2_generator: P::G2,
}

impl<P: Pairing, D: Digest + Send + Sync> HolographicHomomorphicSignatureScheme for NC1<P, D> {
type Parameters = H2S2Parameters<P>;
type PublicKey = P::G2;
type SecretKey = P::ScalarField;
type Signature = P::G1;
type Message = P::ScalarField;
type Weight = usize;

/// Generate G2 element and `n` G1 elements
fn setup<R: Rng>(rng: &mut R, n: usize) -> Result<Self::Parameters, Error> {}

/// Generate hash aggregate (H_a) with `tag` and `n` lanes
fn precompute(tag: &[u8], n: usize) -> Result<P::G1, Error> {}
use std::error::Error;

pub trait HolographicHomomorphicSignatureScheme<P: Pairing, D: Digest + Send + Sync> {
type Parameters;
type PublicKey;
type SecretKey;
type Signature;
type Message;
type Weight;
type AggregatedSignature;

/// Generate one G2 element and `n` G1 elements
fn setup(n: usize) -> Result<Self::Parameters, Box<dyn Error>>;

/// Generate hash aggregate (H_a) with `tag` and `n` lanes, and a
/// allocation_id as a ScalarField
fn precompute(
pp: &Self::Parameters,
tag: P::ScalarField,
n: usize,
) -> Result<(P::G1, P::ScalarField), Box<dyn Error>>;

/// Generate private and public receipt keys using `pp` parameters from `setup`
fn keygen<R: Rng>(
pp: &Self::Parameters,
rng: &mut R,
) -> Result<(Self::PublicKey, Self::SecretKey), Error> {
}
) -> Result<(Self::PublicKey, Self::SecretKey), Box<dyn Error>>;

/// Sign `message` with `tag` at `index`
fn sign(
pp: &Self::Parameters,
sk: &Self::SecretKey,
tag: &[u8],
index: &[u8],
message: &[Self::Message],
) -> Result<Self::Signature, Error> {
}
tag: P::ScalarField,
index: usize,
message: Self::Message,
) -> Result<Self::Signature, Box<dyn Error>>;

/// Verify a single `signature` matches `message` with `tag` at `index` using `pp` parameter and `pk` public key
/// TODO: index should be restricted to a number from 1 to N (max number of lanes)
fn verify(
pp: &Self::Parameters,
pk: &Self::PublicKey,
tag: &[u8],
index: &[u8],
message: &[Self::Message],
tag: P::ScalarField,
index: usize,
message: &Self::Message,
signature: &Self::Signature,
) -> Result<bool, Error> {
}
) -> Result<bool, Box<dyn Error>>;

/// Verify aggregate `signature` matches `message_aggregate` with `tag` and `hash_aggregate`using `pp` parameter and `pk` public key
/// Verify aggregate `signature` matches `message_aggregate`
/// contained in [`AggregatedSignature`] with `tag` and `hash_aggregate` using `pp` parameter and `pk` public key
fn verify_aggregate(
pp: &Self::Parameters,
pk: &Self::PublicKey,
tag: &[u8],
message_aggregate: &[Self::Message],
hash_aggregate: &P::G1,
signature: &Self::Signature,
) -> Result<bool, Error> {
}
signature: &Self::AggregatedSignature,
) -> Result<bool, Box<dyn Error>>;

/// Aggregate `signatures` with `weights`
fn evaluate(
signatures: &[Self::Signature],
weights: &[Self::Weight],
) -> Result<Self::Signature, Error> {
}
) -> Result<Self::AggregatedSignature, Box<dyn Error>>;
}
16 changes: 2 additions & 14 deletions h2s2/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,2 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
pub mod holographic_homomorphic_signature_scheme;
pub mod ncs;
Loading

0 comments on commit fa043c7

Please sign in to comment.