Skip to content

Commit

Permalink
feat(dkg): relax dkg ceremony constraints using new min_shares_num pa…
Browse files Browse the repository at this point in the history
…rameter
  • Loading branch information
piotr-roslaniec committed Jan 10, 2024
1 parent 87c5f34 commit 2511490
Show file tree
Hide file tree
Showing 12 changed files with 262 additions and 93 deletions.
4 changes: 4 additions & 0 deletions ferveo-python/examples/server_api_precomputed.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def gen_eth_addr(i: int) -> str:
shares_num = 4
# In precomputed variant, security threshold must be equal to shares_num
security_threshold = shares_num
min_shares_num = shares_num

validator_keypairs = [Keypair.random() for _ in range(0, shares_num)]
validators = [
Expand All @@ -35,6 +36,7 @@ def gen_eth_addr(i: int) -> str:
dkg = Dkg(
tau=tau,
shares_num=shares_num,
min_shares_num=min_shares_num,
security_threshold=security_threshold,
validators=validators,
me=sender,
Expand All @@ -45,6 +47,7 @@ def gen_eth_addr(i: int) -> str:
dkg = Dkg(
tau=tau,
shares_num=shares_num,
min_shares_num=min_shares_num,
security_threshold=security_threshold,
validators=validators,
me=validators[0],
Expand All @@ -69,6 +72,7 @@ def gen_eth_addr(i: int) -> str:
dkg = Dkg(
tau=tau,
shares_num=shares_num,
min_shares_num=min_shares_num,
security_threshold=security_threshold,
validators=validators,
me=validator,
Expand Down
6 changes: 5 additions & 1 deletion ferveo-python/examples/server_api_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ def gen_eth_addr(i: int) -> str:


tau = 1
security_threshold = 3
shares_num = 4
security_threshold = shares_num - 1
min_shares_num = shares_num
validator_keypairs = [Keypair.random() for _ in range(0, shares_num)]
validators = [
Validator(gen_eth_addr(i), keypair.public_key())
Expand All @@ -33,6 +34,7 @@ def gen_eth_addr(i: int) -> str:
dkg = Dkg(
tau=tau,
shares_num=shares_num,
min_shares_num=min_shares_num,
security_threshold=security_threshold,
validators=validators,
me=sender,
Expand All @@ -45,6 +47,7 @@ def gen_eth_addr(i: int) -> str:
dkg = Dkg(
tau=tau,
shares_num=shares_num,
min_shares_num=min_shares_num,
security_threshold=security_threshold,
validators=validators,
me=me,
Expand Down Expand Up @@ -72,6 +75,7 @@ def gen_eth_addr(i: int) -> str:
dkg = Dkg(
tau=tau,
shares_num=shares_num,
min_shares_num=min_shares_num,
security_threshold=security_threshold,
validators=validators,
me=validator,
Expand Down
12 changes: 8 additions & 4 deletions ferveo-wasm/examples/node/src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function setupTest() {
const tau = 1;
const sharesNum = 4;
const threshold = Math.floor((sharesNum * 2) / 3);
const minSharesNum = sharesNum;

const validatorKeypairs: Keypair[] = [];
const validators: Validator[] = [];
Expand All @@ -40,15 +41,15 @@ function setupTest() {
// validator, including themselves
const messages: ValidatorMessage[] = [];
validators.forEach((sender) => {
const dkg = new Dkg(tau, sharesNum, threshold, validators, sender);
const dkg = new Dkg(tau, sharesNum, minSharesNum, threshold, validators, sender);
const transcript = dkg.generateTranscript();
const message = new ValidatorMessage(sender, transcript);
messages.push(message);
});

// Now that every validator holds a dkg instance and a transcript for every other validator,
// every validator can aggregate the transcripts
const dkg = new Dkg(tau, sharesNum, threshold, validators, validators[0]);
const dkg = new Dkg(tau, sharesNum, minSharesNum, threshold, validators, validators[0]);

const serverAggregate = dkg.aggregateTranscript(messages);
expect(serverAggregate.verify(sharesNum, messages)).toBe(true);
Expand All @@ -65,6 +66,7 @@ function setupTest() {
return {
tau,
sharesNum,
minSharesNum,
threshold,
validatorKeypairs,
validators,
Expand All @@ -82,6 +84,7 @@ describe("ferveo-wasm", () => {
const {
tau,
sharesNum,
minSharesNum,
threshold,
validatorKeypairs,
validators,
Expand All @@ -96,7 +99,7 @@ describe("ferveo-wasm", () => {
zip(validators, validatorKeypairs).forEach(([validator, keypair]) => {
expect(validator.publicKey.equals(keypair.publicKey)).toBe(true);

const dkg = new Dkg(tau, sharesNum, threshold, validators, validator);
const dkg = new Dkg(tau, sharesNum, minSharesNum, threshold, validators, validator);
const aggregate = dkg.aggregateTranscript(messages);
const isValid = aggregate.verify(sharesNum, messages);
expect(isValid).toBe(true);
Expand Down Expand Up @@ -131,6 +134,7 @@ describe("ferveo-wasm", () => {
const {
tau,
sharesNum,
minSharesNum,
threshold,
validatorKeypairs,
validators,
Expand All @@ -143,7 +147,7 @@ describe("ferveo-wasm", () => {
// Having aggregated the transcripts, the validators can now create decryption shares
const decryptionShares: DecryptionSharePrecomputed[] = [];
zip(validators, validatorKeypairs).forEach(([validator, keypair]) => {
const dkg = new Dkg(tau, sharesNum, threshold, validators, validator);
const dkg = new Dkg(tau, sharesNum, minSharesNum, threshold, validators, validator);
const aggregate = dkg.aggregateTranscript(messages);
const isValid = aggregate.verify(sharesNum, messages);
expect(isValid).toBe(true);
Expand Down
36 changes: 23 additions & 13 deletions ferveo-wasm/tests/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use wasm_bindgen_test::*;

type TestSetup = (
u32,
usize,
usize,
u32,
u32,
u32,
Vec<Keypair>,
Vec<Validator>,
ValidatorArray,
Expand All @@ -21,11 +22,13 @@ type TestSetup = (

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

let validator_keypairs =
(0..shares_num).map(gen_keypair).collect::<Vec<Keypair>>();
let validator_keypairs = (0..shares_num as usize)
.map(gen_keypair)
.collect::<Vec<Keypair>>();
let validators = validator_keypairs
.iter()
.enumerate()
Expand All @@ -38,8 +41,9 @@ fn setup_dkg() -> TestSetup {
let messages = validators.iter().map(|sender| {
let dkg = Dkg::new(
tau,
shares_num as u32,
security_threshold as u32,
shares_num,
min_shares_num,
security_threshold,
&validators_js,
sender,
)
Expand All @@ -54,8 +58,9 @@ fn setup_dkg() -> TestSetup {

let mut dkg = Dkg::new(
tau,
shares_num as u32,
security_threshold as u32,
shares_num,
min_shares_num,
security_threshold,
&validators_js,
&validators[0],
)
Expand All @@ -81,6 +86,7 @@ fn setup_dkg() -> TestSetup {
(
tau,
shares_num,
min_shares_num,
security_threshold,
validator_keypairs,
validators,
Expand All @@ -97,6 +103,7 @@ fn tdec_simple() {
let (
tau,
shares_num,
min_shares_num,
security_threshold,
validator_keypairs,
validators,
Expand All @@ -112,8 +119,9 @@ fn tdec_simple() {
.map(|(validator, keypair)| {
let mut dkg = Dkg::new(
tau,
shares_num as u32,
security_threshold as u32,
shares_num,
min_shares_num,
security_threshold,
&validators_js,
&validator,
)
Expand Down Expand Up @@ -151,6 +159,7 @@ fn tdec_precomputed() {
let (
tau,
shares_num,
min_shares_num,
security_threshold,
validator_keypairs,
validators,
Expand All @@ -166,8 +175,9 @@ fn tdec_precomputed() {
.map(|(validator, keypair)| {
let mut dkg = Dkg::new(
tau,
shares_num as u32,
security_threshold as u32,
shares_num,
min_shares_num,
security_threshold,
&validators_js,
&validator,
)
Expand Down
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, 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, shares_num).unwrap(),
&me,
)
.expect("Setup failed")
Expand Down
Loading

0 comments on commit 2511490

Please sign in to comment.