Skip to content

Commit fa043c7

Browse files
authored
Merge pull request #10 from semiotic-ai/hs2s2-library-impl
feat: trait for signature and NCS impl over it
2 parents 37a2ce8 + 4197fc3 commit fa043c7

File tree

5 files changed

+465
-74
lines changed

5 files changed

+465
-74
lines changed

Cargo.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
[workspace]
22
members = [
33
"h2s2",
4-
]
4+
]
5+
6+
7+
[workspace.dependencies]
8+
ark-std = {version ="0.5.0", features = ["parallel"]}
9+
ark-ec = {version = "0.5.0", features = ["parallel"]}
10+
ark-ff = { version = "0.5", features = [ "parallel" ] }
11+
blake2 = "0.10.6"
12+
digest = "0.10.7"
13+
rayon = "1.1"
14+
ark-bn254 = "0.5.0"

h2s2/Cargo.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ authors = [
66
"Severiano Sisneros <severiano@semiotic.ai>",
77
"Alexis Asseman <alexis@semiotic.ai>",
88
"Tomasz Kornuta <tomasz@semiotic.ai>",
9+
"Pedro Bufulin <pedro@semiotic.ai>",
910
]
1011
license = "Apache-2.0"
1112
description = ""
1213
edition = "2021"
1314
keywords = ["holographic", "homomorphic", "signature-scheme"]
1415
catagories = ["cryptography", "cryptography::cryptocurrencies"]
1516

16-
17-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
18-
1917
[dependencies]
18+
ark-ec = {workspace = true}
19+
ark-std = { workspace = true}
20+
ark-ff = { workspace = true}
21+
ark-bn254 = { workspace = true}
22+
blake2 = {workspace = true}
23+
rayon = { workspace = true}
24+
digest = { workspace = true}
25+
once_cell = "1.20.2"
Lines changed: 37 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,63 @@
1-
//nc1
2-
use crate::ark_std::UniformRand;
3-
use crate::ark_std::Zero;
4-
use crate::Error;
5-
use crate::HomomorphicSignatureScheme;
61
use ark_ec::pairing::Pairing;
7-
use ark_ec::AffineRepr;
8-
use ark_std::{marker::PhantomData, rand::Rng};
2+
use ark_std::rand::Rng;
93
use digest::Digest;
10-
use std::ops::MulAssign;
11-
12-
pub struct HolographicHomomorphicSignatureScheme<P: Pairing, D: Digest> {
13-
_pairing: PhantomData<P>,
14-
_hash: PhantomData<D>,
15-
}
16-
17-
#[derive(Clone)]
18-
pub struct H2S2Parameters<P: Pairing> {
19-
pub g1_generators: Vec<P::G1>,
20-
pub g2_generator: P::G2,
21-
}
22-
23-
impl<P: Pairing, D: Digest + Send + Sync> HolographicHomomorphicSignatureScheme for NC1<P, D> {
24-
type Parameters = H2S2Parameters<P>;
25-
type PublicKey = P::G2;
26-
type SecretKey = P::ScalarField;
27-
type Signature = P::G1;
28-
type Message = P::ScalarField;
29-
type Weight = usize;
30-
31-
/// Generate G2 element and `n` G1 elements
32-
fn setup<R: Rng>(rng: &mut R, n: usize) -> Result<Self::Parameters, Error> {}
33-
34-
/// Generate hash aggregate (H_a) with `tag` and `n` lanes
35-
fn precompute(tag: &[u8], n: usize) -> Result<P::G1, Error> {}
4+
use std::error::Error;
5+
6+
pub trait HolographicHomomorphicSignatureScheme<P: Pairing, D: Digest + Send + Sync> {
7+
type Parameters;
8+
type PublicKey;
9+
type SecretKey;
10+
type Signature;
11+
type Message;
12+
type Weight;
13+
type AggregatedSignature;
14+
15+
/// Generate one G2 element and `n` G1 elements
16+
fn setup(n: usize) -> Result<Self::Parameters, Box<dyn Error>>;
17+
18+
/// Generate hash aggregate (H_a) with `tag` and `n` lanes, and a
19+
/// allocation_id as a ScalarField
20+
fn precompute(
21+
pp: &Self::Parameters,
22+
tag: P::ScalarField,
23+
n: usize,
24+
) -> Result<(P::G1, P::ScalarField), Box<dyn Error>>;
3625

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

4432
/// Sign `message` with `tag` at `index`
4533
fn sign(
4634
pp: &Self::Parameters,
47-
sk: &Self::SecretKey,
48-
tag: &[u8],
49-
index: &[u8],
50-
message: &[Self::Message],
51-
) -> Result<Self::Signature, Error> {
52-
}
35+
tag: P::ScalarField,
36+
index: usize,
37+
message: Self::Message,
38+
) -> Result<Self::Signature, Box<dyn Error>>;
5339

5440
/// Verify a single `signature` matches `message` with `tag` at `index` using `pp` parameter and `pk` public key
41+
/// TODO: index should be restricted to a number from 1 to N (max number of lanes)
5542
fn verify(
5643
pp: &Self::Parameters,
57-
pk: &Self::PublicKey,
58-
tag: &[u8],
59-
index: &[u8],
60-
message: &[Self::Message],
44+
tag: P::ScalarField,
45+
index: usize,
46+
message: &Self::Message,
6147
signature: &Self::Signature,
62-
) -> Result<bool, Error> {
63-
}
48+
) -> Result<bool, Box<dyn Error>>;
6449

65-
/// Verify aggregate `signature` matches `message_aggregate` with `tag` and `hash_aggregate`using `pp` parameter and `pk` public key
50+
/// Verify aggregate `signature` matches `message_aggregate`
51+
/// contained in [`AggregatedSignature`] with `tag` and `hash_aggregate` using `pp` parameter and `pk` public key
6652
fn verify_aggregate(
6753
pp: &Self::Parameters,
68-
pk: &Self::PublicKey,
69-
tag: &[u8],
70-
message_aggregate: &[Self::Message],
7154
hash_aggregate: &P::G1,
72-
signature: &Self::Signature,
73-
) -> Result<bool, Error> {
74-
}
55+
signature: &Self::AggregatedSignature,
56+
) -> Result<bool, Box<dyn Error>>;
7557

7658
/// Aggregate `signatures` with `weights`
7759
fn evaluate(
7860
signatures: &[Self::Signature],
7961
weights: &[Self::Weight],
80-
) -> Result<Self::Signature, Error> {
81-
}
62+
) -> Result<Self::AggregatedSignature, Box<dyn Error>>;
8263
}

h2s2/src/lib.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,2 @@
1-
pub fn add(left: usize, right: usize) -> usize {
2-
left + right
3-
}
4-
5-
#[cfg(test)]
6-
mod tests {
7-
use super::*;
8-
9-
#[test]
10-
fn it_works() {
11-
let result = add(2, 2);
12-
assert_eq!(result, 4);
13-
}
14-
}
1+
pub mod holographic_homomorphic_signature_scheme;
2+
pub mod ncs;

0 commit comments

Comments
 (0)