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

Relax DKG ceremony constraints #168

Closed
Closed
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.

73 changes: 73 additions & 0 deletions ferveo-python/test/test_ferveo.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,79 @@ def test_precomputed_tdec_doesnt_have_enough_messages():
FerveoVariant.Precomputed, shares_num=4, threshold=4, shares_to_use=3
)

def test_dkg_has_min_shares():
total_shares_num = 5
min_shares_num = 3
threshold = 3

tau = 1
validator_keypairs = [Keypair.random() for _ in range(0, total_shares_num)]
validators = [
Validator(gen_eth_addr(i), keypair.public_key())
for i, keypair in enumerate(validator_keypairs)
]
validators.sort(key=lambda v: v.address)

messages = []
for sender in validators:
dkg = Dkg(
tau=tau,
shares_num=min_shares_num,
security_threshold=threshold,
validators=validators,
me=sender,
)
messages.append(ValidatorMessage(sender, dkg.generate_transcript()))

dkg = Dkg(
tau=tau,
shares_num=min_shares_num,
security_threshold=threshold,
validators=validators,
me=validators[0],
)
pvss_aggregated = dkg.aggregate_transcripts(messages)
assert pvss_aggregated.verify(min_shares_num, messages)

dkg_pk_bytes = bytes(dkg.public_key)
dkg_pk = DkgPublicKey.from_bytes(dkg_pk_bytes)

msg = "abc".encode()
aad = "my-aad".encode()
ciphertext = encrypt(msg, aad, dkg_pk)

decryption_shares = []
for validator, validator_keypair in zip(validators, validator_keypairs):
dkg = Dkg(
tau=tau,
shares_num=total_shares_num,
security_threshold=threshold,
validators=validators,
me=validator,
)
pvss_aggregated = dkg.aggregate_transcripts(messages)
assert pvss_aggregated.verify(total_shares_num, messages)

decryption_share = decryption_share_for_variant(variant, pvss_aggregated)(
dkg, ciphertext.header, aad, validator_keypair
)
decryption_shares.append(decryption_share)

shared_secret = combine_shares_for_variant(variant, decryption_shares)

if variant == FerveoVariant.Simple and len(decryption_shares) < threshold:
with pytest.raises(ThresholdEncryptionError):
decrypt_with_shared_secret(ciphertext, aad, shared_secret)
return

if variant == FerveoVariant.Precomputed and len(decryption_shares) < total_shares_num:
with pytest.raises(ThresholdEncryptionError):
decrypt_with_shared_secret(ciphertext, aad, shared_secret)
return

plaintext = decrypt_with_shared_secret(ciphertext, aad, shared_secret)
assert bytes(plaintext) == msg


PARAMS = [
(1, FerveoVariant.Simple),
Expand Down
27 changes: 14 additions & 13 deletions ferveo-wasm/tests/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use wasm_bindgen_test::*;

type TestSetup = (
u32,
usize,
usize,
u32,
u32,
Vec<Keypair>,
Vec<Validator>,
ValidatorArray,
Expand All @@ -21,11 +21,12 @@ 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 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 +39,8 @@ 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,
security_threshold,
&validators_js,
sender,
)
Expand All @@ -54,8 +55,8 @@ fn setup_dkg() -> TestSetup {

let mut dkg = Dkg::new(
tau,
shares_num as u32,
security_threshold as u32,
shares_num,
security_threshold,
&validators_js,
&validators[0],
)
Expand Down Expand Up @@ -112,8 +113,8 @@ fn tdec_simple() {
.map(|(validator, keypair)| {
let mut dkg = Dkg::new(
tau,
shares_num as u32,
security_threshold as u32,
shares_num,
security_threshold,
&validators_js,
&validator,
)
Expand Down Expand Up @@ -166,8 +167,8 @@ fn tdec_precomputed() {
.map(|(validator, keypair)| {
let mut dkg = Dkg::new(
tau,
shares_num as u32,
security_threshold as u32,
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
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