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

Refactor DKG parameters into a DkgParams #169

Merged
merged 7 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 34 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion ferveo-tdec/benches/tpke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ pub fn bench_create_decryption_share(c: &mut Criterion) {
.map(|ctx| {
// Using create_unchecked here to avoid the cost of verifying the ciphertext
DecryptionShareSimple::create_unchecked(
&ctx.validator_private_key,
&ctx.setup_params.b,
&ctx.private_key_share,
&setup.shared.ciphertext.header().unwrap(),
)
Expand Down
8 changes: 3 additions & 5 deletions ferveo-tdec/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct PublicDecryptionContextSimple<E: Pairing> {

#[derive(Clone, Debug)]
pub struct SetupParams<E: Pairing> {
pub b: E::ScalarField,
pub b: E::ScalarField, // Validator private key
pub b_inv: E::ScalarField,
pub g: E::G1Affine,
pub g_inv: E::G1Prepared,
Expand Down Expand Up @@ -71,8 +71,6 @@ pub struct PrivateDecryptionContextSimple<E: Pairing> {
pub setup_params: SetupParams<E>,
pub private_key_share: PrivateKeyShare<E>,
pub public_decryption_contexts: Vec<PublicDecryptionContextSimple<E>>,
// TODO: Remove/replace with `setup_params.b` after refactoring
pub validator_private_key: E::ScalarField,
}

impl<E: Pairing> PrivateDecryptionContextSimple<E> {
Expand All @@ -82,7 +80,7 @@ impl<E: Pairing> PrivateDecryptionContextSimple<E> {
aad: &[u8],
) -> Result<DecryptionShareSimple<E>> {
DecryptionShareSimple::create(
&self.validator_private_key,
&self.setup_params.b,
&self.private_key_share,
ciphertext_header,
aad,
Expand All @@ -104,7 +102,7 @@ impl<E: Pairing> PrivateDecryptionContextSimple<E> {

DecryptionSharePrecomputed::new(
self.index,
&self.validator_private_key,
&self.setup_params.b,
&self.private_key_share,
ciphertext_header,
aad,
Expand Down
1 change: 0 additions & 1 deletion ferveo-tdec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ pub mod test_common {
h,
},
private_key_share,
validator_private_key: b,
public_decryption_contexts: vec![],
});
public_contexts.push(PublicDecryptionContextSimple::<E> {
Expand Down
24 changes: 8 additions & 16 deletions ferveo-wasm/examples/node/src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ const genEthAddr = (i: number) => {
return EthereumAddress.fromString(ethAddr);
};

function setupTest() {
const tau = 1;
const sharesNum = 4;
const threshold = Math.floor((sharesNum * 2) / 3);

const tau = 1;
function setupTest(sharesNum :number, threshold: number) {
const validatorKeypairs: Keypair[] = [];
const validators: Validator[] = [];
for (let i = 0; i < sharesNum; i++) {
Expand Down Expand Up @@ -63,9 +60,6 @@ function setupTest() {
const ciphertext = ferveoEncrypt(msg, aad, dkg.publicKey());

return {
tau,
sharesNum,
threshold,
validatorKeypairs,
validators,
dkg,
Expand All @@ -79,17 +73,16 @@ function setupTest() {
// This test suite replicates tests from ferveo-wasm/tests/node.rs
describe("ferveo-wasm", () => {
it("simple tdec variant", () => {
const sharesNum = 4;
const threshold = 3;
const {
tau,
sharesNum,
threshold,
validatorKeypairs,
validators,
messages,
msg,
aad,
ciphertext,
} = setupTest();
} = setupTest(sharesNum, threshold);

// Having aggregated the transcripts, the validators can now create decryption shares
const decryptionShares: DecryptionShareSimple[] = [];
Expand Down Expand Up @@ -128,17 +121,16 @@ describe("ferveo-wasm", () => {
});

it("precomputed tdec variant", () => {
const sharesNum = 4;
const threshold = sharesNum; // threshold is equal to sharesNum in precomputed variant
const {
tau,
sharesNum,
threshold,
validatorKeypairs,
validators,
messages,
msg,
aad,
ciphertext,
} = setupTest();
} = setupTest(sharesNum, threshold);

// Having aggregated the transcripts, the validators can now create decryption shares
const decryptionShares: DecryptionSharePrecomputed[] = [];
Expand Down
55 changes: 23 additions & 32 deletions ferveo-wasm/tests/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ use itertools::zip_eq;
use wasm_bindgen_test::*;

type TestSetup = (
u32,
usize,
usize,
Vec<Keypair>,
Vec<Validator>,
ValidatorArray,
Expand All @@ -19,13 +16,12 @@ type TestSetup = (
Ciphertext,
);

fn setup_dkg() -> TestSetup {
let tau = 1;
let shares_num = 16;
let security_threshold = shares_num * 2 / 3;
const TAU: u32 = 0;

let validator_keypairs =
(0..shares_num).map(gen_keypair).collect::<Vec<Keypair>>();
fn setup_dkg(shares_num: u32, security_threshold: u32) -> TestSetup {
let validator_keypairs = (0..shares_num as usize)
.map(gen_keypair)
.collect::<Vec<Keypair>>();
let validators = validator_keypairs
.iter()
.enumerate()
Expand All @@ -37,9 +33,9 @@ fn setup_dkg() -> TestSetup {
// validator, including themselves
let messages = validators.iter().map(|sender| {
let dkg = Dkg::new(
tau,
shares_num as u32,
security_threshold as u32,
TAU,
shares_num,
security_threshold,
&validators_js,
sender,
)
Expand All @@ -53,9 +49,9 @@ fn setup_dkg() -> TestSetup {
// every validator can aggregate the transcripts

let mut dkg = Dkg::new(
tau,
shares_num as u32,
security_threshold as u32,
TAU,
shares_num,
security_threshold,
&validators_js,
&validators[0],
)
Expand All @@ -79,9 +75,6 @@ fn setup_dkg() -> TestSetup {
let ciphertext = ferveo_encrypt(&msg, &aad, &dkg.public_key()).unwrap();

(
tau,
shares_num,
security_threshold,
validator_keypairs,
validators,
validators_js,
Expand All @@ -94,26 +87,25 @@ fn setup_dkg() -> TestSetup {

#[wasm_bindgen_test]
fn tdec_simple() {
let shares_num = 16;
let security_threshold = 10;
let (
tau,
shares_num,
security_threshold,
validator_keypairs,
validators,
validators_js,
messages_js,
msg,
aad,
ciphertext,
) = setup_dkg();
) = setup_dkg(shares_num, security_threshold);

// Having aggregated the transcripts, the validators can now create decryption shares
let decryption_shares = zip_eq(validators, validator_keypairs)
.map(|(validator, keypair)| {
let mut dkg = Dkg::new(
tau,
shares_num as u32,
security_threshold as u32,
TAU,
shares_num,
security_threshold,
&validators_js,
&validator,
)
Expand Down Expand Up @@ -148,26 +140,25 @@ fn tdec_simple() {

#[wasm_bindgen_test]
fn tdec_precomputed() {
let shares_num = 16;
let security_threshold = shares_num; // Must be equal to shares_num in precomputed variant
let (
tau,
shares_num,
security_threshold,
validator_keypairs,
validators,
validators_js,
messages_js,
msg,
aad,
ciphertext,
) = setup_dkg();
) = setup_dkg(shares_num, security_threshold);

// Having aggregated the transcripts, the validators can now create decryption shares
let decryption_shares = zip_eq(validators, validator_keypairs)
.map(|(validator, keypair)| {
let mut dkg = Dkg::new(
tau,
shares_num as u32,
security_threshold as u32,
TAU,
shares_num,
security_threshold,
&validators_js,
&validator,
)
Expand Down
1 change: 1 addition & 0 deletions ferveo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ wasm-bindgen-derive = { version = "0.2.1", optional = true }
criterion = "0.3" # supports pprof, # TODO: Figure out if/how we can update to 0.4
digest = { version = "0.10.0", features = ["alloc"] }
pprof = { version = "0.6", features = ["flamegraph", "criterion"] }
test-case = "3.3.1"

# WASM bindings
console_error_panic_hook = "0.1.7"
Expand Down
2 changes: 2 additions & 0 deletions ferveo/benches/benchmarks/block_proposer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![allow(non_snake_case)]

// TODO: Currently not maintained - see mod.rs

use criterion::{black_box, criterion_group, criterion_main, Criterion};

use ark_bls12_381::*;
Expand Down
3 changes: 2 additions & 1 deletion ferveo/benches/benchmarks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//pub mod block_proposer;
// We disabled the following benchmarks because their outcomes were not relevant to us at the time.
// pub mod block_proposer;
// pub mod pairing;
pub mod eval_domain;
pub mod validity_checks;
6 changes: 1 addition & 5 deletions ferveo/benches/benchmarks/validity_checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ fn setup_dkg(
let me = validators[validator].clone();
PubliclyVerifiableDkg::new(
&validators,
&DkgParams {
tau: 0,
security_threshold: shares_num / 3,
shares_num,
},
&DkgParams::new(0, shares_num / 3, shares_num).unwrap(),
&me,
)
.expect("Setup failed")
Expand Down
6 changes: 1 addition & 5 deletions ferveo/examples/bench_primitives_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ fn setup_dkg(
let me = validators[validator].clone();
PubliclyVerifiableDkg::new(
&validators,
&DkgParams {
tau: 0,
security_threshold,
shares_num,
},
&DkgParams::new(0, security_threshold, shares_num).unwrap(),
&me,
)
.expect("Setup failed")
Expand Down
Loading
Loading