Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fnv/core verifier #939

Merged
merged 77 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
f6e8390
Full node signer and signature
curiecrypt May 24, 2023
7899d44
full node verifier struct
curiecrypt May 24, 2023
aba7649
impl full node verifier
curiecrypt May 25, 2023
05ac546
stm_signer_avk inherits stm_signer
curiecrypt May 25, 2023
6f0883a
full node verifier added
curiecrypt May 25, 2023
fd60980
log updated
curiecrypt May 26, 2023
1a0822b
review changes v0
curiecrypt May 29, 2023
79e0cdb
review changes v1 - verifier
curiecrypt May 29, 2023
f60f258
review changes v2 - naming
curiecrypt May 29, 2023
71dee10
Update mithril-stm/src/stm.rs
curiecrypt May 29, 2023
b6961d4
review changes v3 - documentation
curiecrypt May 29, 2023
253e752
test setup functions
curiecrypt May 30, 2023
0c6a89a
test_full_node_verifier failing
curiecrypt May 30, 2023
84a2801
test_full_node_verifier failing clippy warning resolved
curiecrypt May 30, 2023
4d16974
fmt error
curiecrypt May 30, 2023
7d073ab
rev 02 naming stm signer core
curiecrypt Jun 5, 2023
02c0fa7
rev 02 documentation for SignerCore and StmSigner
curiecrypt Jun 5, 2023
dd60e59
rev 02 do not consume closed_reg
curiecrypt Jun 5, 2023
bf802d1
Apply suggestions from code review
curiecrypt Jun 5, 2023
4b056fb
rev 02 mismatched types
curiecrypt Jun 5, 2023
da81706
rev 02 documentation preliminery_verify
curiecrypt Jun 5, 2023
99cb9b1
new signer core
curiecrypt Jun 6, 2023
25ae123
assign index for signer core removed
curiecrypt Jun 6, 2023
0017065
dedup sigs for full node verification
curiecrypt Jun 6, 2023
d5db714
new impl for full node verifier
curiecrypt Jun 7, 2023
fda42a3
fmt and clippy
curiecrypt Jun 7, 2023
f4ab93f
clerk aggr dedup used from FNV
curiecrypt Jun 7, 2023
1738e4f
StmAggrSig impl depend on FNV and StmSigRegParty
curiecrypt Jun 7, 2023
ec99cf1
errors updated
curiecrypt Jun 8, 2023
aeb21c9
test functions updated
curiecrypt Jun 8, 2023
dce0a81
FullNodeVerifier to CoreVerifier
curiecrypt Jun 8, 2023
d99d739
Core verification error enum
curiecrypt Jun 8, 2023
f6e7ea8
core verifier test fails only for NoQuorum
curiecrypt Jun 8, 2023
c418202
full node verifier passes test for phi_f 0.6
curiecrypt Jun 12, 2023
257a5f2
errors for StmAggrSig updated
curiecrypt Jun 13, 2023
f8af3c3
core verifier test problem debugged
curiecrypt Jun 14, 2023
d36d0fa
core verifier prop test passes
curiecrypt Jun 14, 2023
a10bcf8
unnecessary casting removed
curiecrypt Jun 14, 2023
45c7174
NoQourum has 1 param
curiecrypt Jun 14, 2023
6afcb54
closed_reg as option for StmSigner
curiecrypt Jun 15, 2023
227ba4d
core signer removed and tests updated
curiecrypt Jun 15, 2023
9ac31be
Apply suggestions from code review
curiecrypt Jun 23, 2023
a9d08d1
round 1 review updates
curiecrypt Jun 24, 2023
b7e0375
round 2 review updates
curiecrypt Jun 24, 2023
c4e5edf
round 3 review updates
curiecrypt Jun 24, 2023
9561757
core verifier protocol test
curiecrypt Jun 26, 2023
0541267
update loops test core verifier
curiecrypt Jun 26, 2023
37b7529
remove helper setup_core_signer
curiecrypt Jun 26, 2023
75ab9a1
rename test stm core
curiecrypt Jun 26, 2023
098499d
Unused functions of StmSigner are removed
curiecrypt Jun 26, 2023
e3eca90
serde for StmSigRegParty corrected
curiecrypt Jun 26, 2023
d945d32
documentation updated
curiecrypt Jun 26, 2023
606b0e7
documentation updated v2
curiecrypt Jun 26, 2023
37626eb
documentation updated v3
curiecrypt Jun 26, 2023
e28f411
dedup_sigs for clerk removed and dedup test updated
curiecrypt Jul 3, 2023
9c298a6
bench core verifier
curiecrypt Jul 4, 2023
6b26e78
Update doc and README
curiecrypt Jul 5, 2023
086b4a5
size_benches for core verification
curiecrypt Jul 5, 2023
993965a
Apply suggestions from code review
curiecrypt Jul 7, 2023
9d3ebed
code review correction - size_benches
curiecrypt Jul 7, 2023
ca8fb75
code review correction - size_benches, benches
curiecrypt Jul 7, 2023
0b646af
code review correction - errors.rs
curiecrypt Jul 10, 2023
15de48a
code review correction - tests/stm_core, tests/stm_protocol
curiecrypt Jul 10, 2023
b304246
code review correction - tests/stm_core v2
curiecrypt Jul 10, 2023
3bd2cf9
code review correction - stm.rs and related files
curiecrypt Jul 10, 2023
1ef4d2a
code review correction - general
curiecrypt Jul 11, 2023
9b2a6fa
resolving map sig regparty v0
curiecrypt Jul 26, 2023
7d16e41
resolving map sig regparty v1
curiecrypt Jul 27, 2023
0d1c8b5
remove debug test
curiecrypt Jul 27, 2023
ce9e587
clippy warning resolved, doc updated
curiecrypt Jul 27, 2023
a5fa5f8
gh code scanning warning
curiecrypt Jul 27, 2023
0242339
rebase leftovers corrected
curiecrypt Jul 28, 2023
851d013
update doc new_core_signer
curiecrypt Aug 1, 2023
4cac0ab
PhantomData corrected
curiecrypt Aug 10, 2023
6a78518
leftover removed
curiecrypt Aug 10, 2023
6824cbe
changelog update
curiecrypt Aug 10, 2023
22972f7
resolve hash conflict
curiecrypt Aug 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ mithril-infra/.terraform*
mithril-infra/terraform.tfstate*
mithril-infra/*.tfvars
justfile

2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion mithril-stm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.3.0 (10-08-2023)
### Added
- Added `Coreverifier` struct and its functionalities to cover signature procedure for a full node.
- Adapted existing functionality to inherit from a more generic structure `Coreverifier`.
- Added tests for core verification.

## 0.2.5 (15-03-2023)
### Added
- Included helper functions for unsafe code
Expand All @@ -14,7 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## 0.2.0 (16-12-2022)
### Changed
- Addapted the `Signature` struct, so that it does not contain the verification key and
- Adapted the `Signature` struct, so that it does not contain the verification key and
the stake, as these values are not required.

## 0.1.0 (05-12-2022)
Expand Down
2 changes: 1 addition & 1 deletion mithril-stm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-stm"
version = "0.2.20"
version = "0.3.0"
edition = { workspace = true }
authors = { workspace = true }
documentation = { workspace = true }
Expand Down
9 changes: 7 additions & 2 deletions mithril-stm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
* We implemented the concatenation proof system as batch proofs:
* Individual signatures do not contain the Merkle path to prove membership of the avk. Instead, it is the role of the aggregator to generate such proofs. This allows for a more efficient implementation of batched membership proofs (or batched Merkle paths).
* Protocol documentation is given in [Mithril Protocol in depth](https://mithril.network/doc/mithril/mithril-protocol/protocol/).
* The API also includes *core verification*. This functionality allows a full node verifier (`CoreVerifier`) that is
able to verify the signatures that are generated without the registration information, i.e., `avk`. A
`CoreVerifier` is assumed to know identities of the signers, so, it does not need to check the registration.


* This library provides:
* The implementation of the Stake-based Threshold Multisignatures
* The implementation of `CoreVerifier`
* Key registration procedure for STM signatures
* The tests for the library functions and STM scheme
* The tests for the library functions, STM scheme, and `CoreVerifier`
* Benchmark tests

## Pre-requisites
Expand Down Expand Up @@ -117,7 +121,8 @@ fn main() {

// Check all parties can verify every sig
for (s, p) in sigs.iter().zip(ps.iter()) {
assert!(s.verify(&params, &p.verification_key(), &p.get_stake(), &avk, &msg).is_ok(), "Verification failed");
assert!(s.verify(&params, &p.verification_key(), &p.get_stake(), &avk, &msg).is_ok(), "Verification
failed");
}

// Aggregate with random parties
Expand Down
79 changes: 78 additions & 1 deletion mithril-stm/benches/size_benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use blake2::{
Blake2b, Digest,
};
use mithril_stm::key_reg::KeyReg;
use mithril_stm::stm::{StmClerk, StmInitializer, StmParameters, StmSig, StmSigner};
use mithril_stm::stm::{
CoreVerifier, Stake, StmClerk, StmInitializer, StmParameters, StmSig, StmSigRegParty,
StmSigner, StmVerificationKey,
};
use rand_chacha::ChaCha20Rng;
use rand_core::{RngCore, SeedableRng};
use rayon::iter::ParallelIterator;
Expand Down Expand Up @@ -60,6 +63,70 @@ where
);
}

fn core_size<H>(k: u64, m: u64, nparties: usize)
where
H: Digest + Clone + Sync + Send + Default + FixedOutput,
{
let mut rng = ChaCha20Rng::from_seed([0u8; 32]);
let mut msg = [0u8; 16];
rng.fill_bytes(&mut msg);

let mut public_signers: Vec<(StmVerificationKey, Stake)> = Vec::with_capacity(nparties);
let mut initializers: Vec<StmInitializer> = Vec::with_capacity(nparties);

let parties = (0..nparties)
.map(|_| 1 + (rng.next_u64() % 9999))
.collect::<Vec<_>>();

let params = StmParameters { k, m, phi_f: 0.2 };

for stake in parties {
let initializer = StmInitializer::setup(params, stake, &mut rng);
initializers.push(initializer.clone());
public_signers.push((initializer.verification_key().vk, initializer.stake));
}

let core_verifier = CoreVerifier::setup(&public_signers);

let signers: Vec<StmSigner<H>> = initializers
.into_iter()
.filter_map(|s| s.new_core_signer(&core_verifier.eligible_parties))
.collect();

let mut signatures: Vec<StmSig> = Vec::with_capacity(nparties);
for s in signers {
if let Some(sig) = s.core_sign(&msg, core_verifier.total_stake) {
signatures.push(sig);
}
}
curiecrypt marked this conversation as resolved.
Show resolved Hide resolved

let sig_reg_list = signatures
.iter()
.map(|sig| StmSigRegParty {
sig: sig.clone(),
reg_party: core_verifier.eligible_parties[sig.signer_index as usize],
})
.collect::<Vec<StmSigRegParty>>();

let dedup_sigs = CoreVerifier::dedup_sigs_for_indices(
&core_verifier.total_stake,
&params,
&msg,
&sig_reg_list,
)
.unwrap();

let mut size_sigs: usize = 0;
for sig in dedup_sigs {
size_sigs += sig.to_bytes().len();
}

println!(
"k = {} | m = {} | nr parties = {}; {} bytes",
k, m, nparties, size_sigs,
);
}

fn main() {
println!("+-------------------+");
println!("| Size of proofs |");
Expand All @@ -72,4 +139,14 @@ fn main() {
size::<Blake2b<U64>>(k, m, nparties, "Blake2b 512");
size::<Blake2b<U32>>(k, m, nparties, "Blake2b 256");
}

println!("\n+-------------------------+");
println!("| Size of core signatures |");
println!("+-------------------------+");
println!("+-------------------------+");

for (k, m, nparties) in params {
core_size::<Blake2b<U64>>(k, m, nparties);
}
println!("+-------------------------+");
}
81 changes: 80 additions & 1 deletion mithril-stm/benches/stm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use blake2::digest::{Digest, FixedOutput};
use blake2::{digest::consts::U32, Blake2b};
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use mithril_stm::key_reg::KeyReg;
use mithril_stm::stm::{StmAggrSig, StmClerk, StmInitializer, StmParameters, StmSigner};
use mithril_stm::stm::{
CoreVerifier, Stake, StmAggrSig, StmClerk, StmInitializer, StmParameters, StmSigner,
StmVerificationKey,
};
use rand_chacha::ChaCha20Rng;
use rand_core::{RngCore, SeedableRng};
use rayon::prelude::*;
Expand Down Expand Up @@ -144,6 +147,56 @@ fn batch_benches<H>(
}
}

fn core_verifier_benches<H>(c: &mut Criterion, nr_parties: usize, params: StmParameters)
where
H: Clone + Debug + Digest + Send + Sync + FixedOutput + Default,
{
let mut group = c.benchmark_group("Core verifier");
let mut rng = ChaCha20Rng::from_seed([0u8; 32]);
let mut msg = [0u8; 16];
rng.fill_bytes(&mut msg);

let mut public_signers: Vec<(StmVerificationKey, Stake)> = Vec::with_capacity(nr_parties);
let mut initializers: Vec<StmInitializer> = Vec::with_capacity(nr_parties);

let param_string = format!(
"k: {}, m: {}, nr_parties: {}",
params.k, params.m, nr_parties
);

let stakes = (0..nr_parties)
.map(|_| 1 + (rng.next_u64() % 9999))
.collect::<Vec<_>>();

for stake in stakes {
let initializer = StmInitializer::setup(params, stake, &mut rng);
initializers.push(initializer.clone());
public_signers.push((initializer.verification_key().vk, initializer.stake));
}

let core_verifier = CoreVerifier::setup(&public_signers);

let signers: Vec<StmSigner<H>> = initializers
.into_iter()
.filter_map(|s| s.new_core_signer(&core_verifier.eligible_parties))
.collect();

group.bench_function(BenchmarkId::new("Play all lotteries", &param_string), |b| {
b.iter(|| {
signers[0].core_sign(&msg, core_verifier.total_stake);
})
});

let signatures = signers
.par_iter()
.filter_map(|p| p.core_sign(&msg, core_verifier.total_stake))
.collect::<Vec<_>>();

group.bench_function(BenchmarkId::new("Core verification", &param_string), |b| {
b.iter(|| core_verifier.verify(&signatures, &params, &msg))
});
}

fn batch_stm_benches_blake_300(c: &mut Criterion) {
batch_benches::<Blake2b<U32>>(
c,
Expand Down Expand Up @@ -171,6 +224,18 @@ fn stm_benches_blake_300(c: &mut Criterion) {
);
}

fn core_verifier_benches_blake_300(c: &mut Criterion) {
core_verifier_benches::<Blake2b<U32>>(
c,
300,
StmParameters {
m: 150,
k: 25,
phi_f: 0.2,
},
);
}

fn batch_stm_benches_blake_2000(c: &mut Criterion) {
batch_benches::<Blake2b<U32>>(
c,
Expand Down Expand Up @@ -198,9 +263,23 @@ fn stm_benches_blake_2000(c: &mut Criterion) {
);
}

fn core_verifier_benches_blake_2000(c: &mut Criterion) {
core_verifier_benches::<Blake2b<U32>>(
c,
2000,
StmParameters {
m: 1523,
k: 250,
phi_f: 0.2,
},
);
}

criterion_group!(name = benches;
config = Criterion::default().nresamples(1000);
targets =
core_verifier_benches_blake_300,
core_verifier_benches_blake_2000,
stm_benches_blake_300,
stm_benches_blake_2000,
batch_stm_benches_blake_300,
Expand Down
Loading
Loading