Skip to content

Commit c7bbc8e

Browse files
committed
Remove the public_key field from AggregatedTranscript
And calculate it on the fly if needed.
1 parent f079c81 commit c7bbc8e

5 files changed

Lines changed: 51 additions & 52 deletions

File tree

ferveo/src/api.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl AggregatedTranscript {
290290
let domain =
291291
GeneralEvaluationDomain::<Fr>::new(validators_num as usize)
292292
.expect("Unable to construct an evaluation domain");
293-
let is_valid_optimistic = self.0.aggregate.verify_optimistic();
293+
let is_valid_optimistic = self.0.aggregate().verify_optimistic();
294294
if !is_valid_optimistic {
295295
return Err(Error::InvalidTranscriptAggregate);
296296
}
@@ -307,8 +307,8 @@ impl AggregatedTranscript {
307307
.collect::<Vec<_>>();
308308
// This check also includes `verify_full`. See impl. for details.
309309
do_verify_aggregation(
310-
&self.0.aggregate.coeffs,
311-
&self.0.aggregate.shares,
310+
&self.0.aggregate().coeffs,
311+
&self.0.aggregate().shares,
312312
&validators,
313313
&domain,
314314
&pvss_list,
@@ -342,7 +342,7 @@ impl AggregatedTranscript {
342342
.map(|domain_point| (v.share_index, domain_point))
343343
})
344344
.collect::<HashMap<u32, ferveo_tdec::DomainPoint<E>>>();
345-
self.0.aggregate.create_decryption_share_precomputed(
345+
self.0.aggregate().create_decryption_share_precomputed(
346346
&ciphertext_header.0,
347347
aad,
348348
validator_keypair,
@@ -368,7 +368,7 @@ impl AggregatedTranscript {
368368
Error::DealerNotInValidatorSet(my_public_key.to_string())
369369
})?;
370370

371-
let share = self.0.aggregate.create_decryption_share_simple(
371+
let share = self.0.aggregate().create_decryption_share_simple(
372372
&ciphertext_header.0,
373373
aad,
374374
validator_keypair,
@@ -382,7 +382,7 @@ impl AggregatedTranscript {
382382
}
383383

384384
pub fn public_key(&self) -> DkgPublicKey {
385-
DkgPublicKey(self.0.public_key)
385+
DkgPublicKey(self.0.public_key())
386386
}
387387

388388
pub fn refresh(
@@ -393,7 +393,7 @@ impl AggregatedTranscript {
393393
// TODO: Aggregates structs should be refactored, this is a bit of a mess - #162
394394
let updated_aggregate = self
395395
.0
396-
.aggregate
396+
.aggregate()
397397
.refresh(update_transcripts, validator_keys_map)
398398
.unwrap();
399399
let eeww =
@@ -409,7 +409,7 @@ impl AggregatedTranscript {
409409
) -> Result<Self> {
410410
let new_aggregate = self
411411
.0
412-
.aggregate
412+
.aggregate()
413413
.finalize_handover(&handover_transcript.0, validator_keypair)
414414
.unwrap();
415415
// TODO: Aggregates structs should be refactored, this is a bit of a mess - #162

ferveo/src/dkg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl<E: Pairing> PubliclyVerifiableDkg<E> {
238238
.ok_or(Error::InvalidShareIndex(handover_slot_index))?;
239239

240240
let departing_blinded_share = aggregate
241-
.aggregate
241+
.aggregate()
242242
.get_share_for_validator(departing_validator)?;
243243

244244
Ok(refresh::HandoverTranscript::<E>::new(

ferveo/src/lib.rs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ mod test_dkg_full {
149149
let server_aggregate =
150150
AggregatedTranscript::from_transcripts(transcripts).unwrap();
151151
assert!(server_aggregate
152-
.aggregate
152+
.aggregate()
153153
.verify_aggregation(dkg, transcripts)
154154
.unwrap());
155155

@@ -161,7 +161,7 @@ mod test_dkg_full {
161161
.get_validator(&validator_keypair.public_key())
162162
.unwrap();
163163
server_aggregate
164-
.aggregate
164+
.aggregate()
165165
.create_decryption_share_simple(
166166
ciphertext_header,
167167
aad,
@@ -207,13 +207,13 @@ mod test_dkg_full {
207207
let local_aggregate =
208208
AggregatedTranscript::from_transcripts(&transcripts).unwrap();
209209
assert!(local_aggregate
210-
.aggregate
210+
.aggregate()
211211
.verify_aggregation(&dkg, &transcripts)
212212
.unwrap());
213213
let ciphertext = ferveo_tdec::encrypt::<E>(
214214
SecretBox::new(MSG.into()),
215215
AAD,
216-
&local_aggregate.public_key,
216+
&local_aggregate.public_key(),
217217
rng,
218218
)
219219
.unwrap();
@@ -259,13 +259,13 @@ mod test_dkg_full {
259259
let local_aggregate =
260260
AggregatedTranscript::from_transcripts(&transcripts).unwrap();
261261
assert!(local_aggregate
262-
.aggregate
262+
.aggregate()
263263
.verify_aggregation(&dkg, &transcripts)
264264
.unwrap());
265265
let ciphertext = ferveo_tdec::encrypt::<E>(
266266
SecretBox::new(MSG.into()),
267267
AAD,
268-
&local_aggregate.public_key,
268+
&local_aggregate.public_key(),
269269
rng,
270270
)
271271
.unwrap();
@@ -299,7 +299,7 @@ mod test_dkg_full {
299299
.get_validator(&validator_keypair.public_key())
300300
.unwrap();
301301
local_aggregate
302-
.aggregate
302+
.aggregate()
303303
.create_decryption_share_precomputed(
304304
&ciphertext.header().unwrap(),
305305
AAD,
@@ -344,13 +344,13 @@ mod test_dkg_full {
344344
let local_aggregate =
345345
AggregatedTranscript::from_transcripts(&transcripts).unwrap();
346346
assert!(local_aggregate
347-
.aggregate
347+
.aggregate()
348348
.verify_aggregation(&dkg, &transcripts)
349349
.unwrap());
350350
let ciphertext = ferveo_tdec::encrypt::<E>(
351351
SecretBox::new(MSG.into()),
352352
AAD,
353-
&local_aggregate.public_key,
353+
&local_aggregate.public_key(),
354354
rng,
355355
)
356356
.unwrap();
@@ -365,7 +365,7 @@ mod test_dkg_full {
365365
);
366366

367367
izip!(
368-
&local_aggregate.aggregate.shares,
368+
&local_aggregate.aggregate().shares,
369369
&validator_keypairs,
370370
&decryption_shares,
371371
)
@@ -386,7 +386,7 @@ mod test_dkg_full {
386386
let mut with_bad_decryption_share = decryption_share.clone();
387387
with_bad_decryption_share.decryption_share = TargetField::zero();
388388
assert!(!with_bad_decryption_share.verify(
389-
&local_aggregate.aggregate.shares[0],
389+
&local_aggregate.aggregate().shares[0],
390390
&validator_keypairs[0].public_key().encryption_key,
391391
&ciphertext,
392392
));
@@ -395,7 +395,7 @@ mod test_dkg_full {
395395
let mut with_bad_checksum = decryption_share;
396396
with_bad_checksum.validator_checksum.checksum = G1Affine::zero();
397397
assert!(!with_bad_checksum.verify(
398-
&local_aggregate.aggregate.shares[0],
398+
&local_aggregate.aggregate().shares[0],
399399
&validator_keypairs[0].public_key().encryption_key,
400400
&ciphertext,
401401
));
@@ -427,13 +427,13 @@ mod test_dkg_full {
427427
let local_aggregate =
428428
AggregatedTranscript::from_transcripts(&transcripts).unwrap();
429429
assert!(local_aggregate
430-
.aggregate
430+
.aggregate()
431431
.verify_aggregation(&dkg, &transcripts)
432432
.unwrap());
433433
let ciphertext = ferveo_tdec::encrypt::<E>(
434434
SecretBox::new(MSG.into()),
435435
AAD,
436-
&local_aggregate.public_key,
436+
&local_aggregate.public_key(),
437437
rng,
438438
)
439439
.unwrap();
@@ -535,7 +535,7 @@ mod test_dkg_full {
535535
let decryption_share =
536536
AggregatedTranscript::from_transcripts(&transcripts)
537537
.unwrap()
538-
.aggregate
538+
.aggregate()
539539
.create_decryption_share_simple(
540540
&ciphertext.header().unwrap(),
541541
AAD,
@@ -619,15 +619,15 @@ mod test_dkg_full {
619619
let local_aggregate =
620620
AggregatedTranscript::from_transcripts(&transcripts).unwrap();
621621
assert!(local_aggregate
622-
.aggregate
622+
.aggregate()
623623
.verify_aggregation(&dkg, &transcripts)
624624
.unwrap());
625625

626626
// Ciphertext created from the aggregate public key
627627
let ciphertext = ferveo_tdec::encrypt::<E>(
628628
SecretBox::new(MSG.into()),
629629
AAD,
630-
&local_aggregate.public_key,
630+
&local_aggregate.public_key(),
631631
rng,
632632
)
633633
.unwrap();
@@ -665,12 +665,12 @@ mod test_dkg_full {
665665
// Participants distribute UpdateTranscripts and update their shares
666666
// accordingly. The result is a new, joint AggregatedTranscript.
667667
let new_aggregate = local_aggregate
668-
.aggregate
668+
.aggregate()
669669
.refresh(&update_transcripts, &validator_map)
670670
.unwrap();
671671

672672
// TODO: Assert new aggregate is different than original, including coefficients
673-
assert_ne!(local_aggregate.aggregate, new_aggregate);
673+
assert_ne!(local_aggregate.aggregate(), &new_aggregate);
674674

675675
// TODO: Show that all participants obtain the same new aggregate transcript.
676676

@@ -736,15 +736,15 @@ mod test_dkg_full {
736736
let local_aggregate =
737737
AggregatedTranscript::from_transcripts(&transcripts).unwrap();
738738
assert!(local_aggregate
739-
.aggregate
739+
.aggregate()
740740
.verify_aggregation(&dkg, &transcripts)
741741
.unwrap());
742742

743743
// Ciphertext created from the aggregate public key
744744
let ciphertext = ferveo_tdec::encrypt::<E>(
745745
SecretBox::new(MSG.into()),
746746
AAD,
747-
&local_aggregate.public_key,
747+
&local_aggregate.public_key(),
748748
rng,
749749
)
750750
.unwrap();
@@ -797,7 +797,7 @@ mod test_dkg_full {
797797
// We're doing this for testing purposes, but in practice, this is done
798798
// by the departing participant when using the high-level API.
799799
let share_commitments = get_share_commitments_from_poly_commitments::<E>(
800-
&local_aggregate.aggregate.coeffs,
800+
&local_aggregate.aggregate().coeffs,
801801
&dkg.domain,
802802
);
803803
let share_commitment = ShareCommitment::<E>(
@@ -821,13 +821,13 @@ mod test_dkg_full {
821821
);
822822

823823
let aggregate_after_handover = local_aggregate
824-
.aggregate
824+
.aggregate()
825825
.finalize_handover(&handover_transcript, departing_keypair)
826826
.unwrap();
827827

828828
// If we use a different keypair, we should get an error
829829
let error = local_aggregate
830-
.aggregate
830+
.aggregate()
831831
.finalize_handover(
832832
&handover_transcript,
833833
&incoming_validator_keypair,
@@ -839,22 +839,23 @@ mod test_dkg_full {
839839
);
840840

841841
// New aggregate is different than original...
842-
assert_ne!(local_aggregate.aggregate, aggregate_after_handover);
842+
assert_ne!(local_aggregate.aggregate(), &aggregate_after_handover);
843843

844844
// ...but let's look a bit deeper:
845845
// - Polynomial coefficients are the same, which makes sense since the private shares are not changing
846846
assert_eq!(
847-
local_aggregate.aggregate.coeffs,
847+
local_aggregate.aggregate().coeffs,
848848
aggregate_after_handover.coeffs
849849
);
850850
// - The shares vector is different ...
851851
assert_ne!(
852-
local_aggregate.aggregate.shares,
852+
local_aggregate.aggregate().shares,
853853
aggregate_after_handover.shares
854854
);
855855
// ... but actually they only differ at the handover index
856856
for i in 0..shares_num {
857-
let share_before = local_aggregate.aggregate.shares.get(i as usize);
857+
let share_before =
858+
local_aggregate.aggregate().shares.get(i as usize);
858859
let share_after = aggregate_after_handover.shares.get(i as usize);
859860
if i == handover_slot_index {
860861
assert_ne!(share_before, share_after);

ferveo/src/pvss.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -498,18 +498,13 @@ impl<E: Pairing, T: Aggregate> PubliclyVerifiableSS<E, T> {
498498
}
499499

500500
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
501-
pub struct AggregatedTranscript<E: Pairing> {
501+
pub struct AggregatedTranscript<E: Pairing>(
502502
#[serde(bound(
503503
serialize = "PubliclyVerifiableSS<E, Aggregated>: Serialize",
504504
deserialize = "PubliclyVerifiableSS<E, Aggregated>: DeserializeOwned"
505505
))]
506-
pub aggregate: PubliclyVerifiableSS<E, Aggregated>,
507-
#[serde(bound(
508-
serialize = "ferveo_tdec::DkgPublicKey<E>: Serialize",
509-
deserialize = "ferveo_tdec::DkgPublicKey<E>: DeserializeOwned"
510-
))]
511-
pub public_key: ferveo_tdec::DkgPublicKey<E>,
512-
}
506+
PubliclyVerifiableSS<E, Aggregated>,
507+
);
513508

514509
// TODO: Add tests - #202
515510
impl<E: Pairing> AggregatedTranscript<E> {
@@ -523,11 +518,15 @@ impl<E: Pairing> AggregatedTranscript<E> {
523518
pub fn from_aggregate(
524519
aggregate: PubliclyVerifiableSS<E, Aggregated>,
525520
) -> Result<Self> {
526-
let public_key = ferveo_tdec::DkgPublicKey::<E>(aggregate.coeffs[0]);
527-
Ok(AggregatedTranscript {
528-
aggregate,
529-
public_key,
530-
})
521+
Ok(AggregatedTranscript(aggregate))
522+
}
523+
524+
pub fn aggregate(&self) -> &PubliclyVerifiableSS<E, Aggregated> {
525+
&self.0
526+
}
527+
528+
pub fn public_key(&self) -> ferveo_tdec::DkgPublicKey<E> {
529+
ferveo_tdec::DkgPublicKey::<E>(self.0.coeffs[0])
531530
}
532531
}
533532

ferveo/src/test_serialization.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ const EXPECTED_AGGREGATED_TRANSCRIPT_BINARY_HEX: &str = concat![
5757
"600000000000000098c62bc13cf7570daf7bf84f9bbe3d58b97fbecfeb0ccac0",
5858
"645ea6d19032427a676ef46b7609a4c8026e5552f13f34c910fab79edb261228",
5959
"b79c027f01bc453d0ec7ecb62c78bb31b803efe71bab0b45f6ca65c85e9fe1a6",
60-
"9ced417f4e3ef0253000000000000000b593fb0151e20229edcb564da0628ae7",
61-
"28d6dbbfe58ca45b06e2058dfb684b0c2a6516cb69ff83d51229086d933c5ae4",
60+
"9ced417f4e3ef025",
6261
];
6362
const EXPECTED_DKG_PUBLIC_KEY_BINARY_HEX: &str = concat![
6463
"3000000000000000b593fb0151e20229edcb564da0628ae728d6dbbfe58ca45b",

0 commit comments

Comments
 (0)