Skip to content

Set indices to be represented as vectors instead of unique #351

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

Merged
merged 10 commits into from
Jul 22, 2022

Conversation

iquerejeta
Copy link
Contributor

@iquerejeta iquerejeta commented Jul 11, 2022

Up until now, a signature could be valid for a single index. This resulted in a practical requirement that the aggregate should have as many signatures as indices, but this is not a requirement by design. Moreover, the current mechanism for signers to find "valid" signatures was by producing the same signature for each index and checking validity. With the changes in this PR we optimise both points. In particular:

  • Signatures contain a vector of the valid indexes
  • Signers produce a single signature and iterate over the indices without having to recompute the signature
  • Signatures are checked once (and not as many times as valid indexes they had)

These changes implements option 3 of #296. In this PR we also implement PartialEq for StmSig and define a canonical display for a VerificationKey and Signature, which closes #336 and closes #337 respectively.

@iquerejeta iquerejeta added breaking-change 🔥 Contains a breaking change P-high Priority: high D-medium Difficulty: medium T-refactor Type: cleanup/refactor labels Jul 11, 2022
@iquerejeta iquerejeta self-assigned this Jul 11, 2022
@github-actions
Copy link

github-actions bot commented Jul 11, 2022

Unit Test Results

233 tests  ±0   233 ✔️ ±0   4m 16s ⏱️ - 3m 3s
  18 suites ±0       0 💤 ±0 
    6 files   ±0       0 ±0 

Results for commit cb6e434. ± Comparison against base commit 50cafcf.

♻️ This comment has been updated with latest results.

@iquerejeta iquerejeta requested a review from Alenar July 21, 2022 10:00
Comment on lines 904 to 923
let mut deduped_sig = sig.clone();
if let Some(indexes) = removal_idx_by_vk.get(sig) {
deduped_sig.indexes = deduped_sig
.indexes
.clone()
.into_iter()
.filter(|i| !indexes.contains(i))
.collect();
}

let size: Result<u64, _> = deduped_sig.indexes.len().try_into();
if let Ok(size) = size {
if dedup_sigs.insert(deduped_sig) {
count += size;
}

if count >= self.params.k {
return Ok(dedup_sigs.into_iter().collect());
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could avoid filtering the deduped_sig.indexes multiple times like this, WDYT?

        for (_, &sig) in sig_by_index.iter() {
            if dedup_sigs.contains(sig) {
                continue;
            }
            let mut deduped_sig = sig.clone();
            if let Some(indexes) = removal_idx_by_vk.get(sig) {
                deduped_sig.indexes = deduped_sig
                    .indexes
                    .clone()
                    .into_iter()
                    .filter(|i| !indexes.contains(i))
                    .collect();
            }

            let size: Result<u64, _> = deduped_sig.indexes.len().try_into();
            if let Ok(size) = size {
                dedup_sigs.insert(deduped_sig);
                count += size;
                if count >= self.params.k {
                    return Ok(dedup_sigs.into_iter().collect());
                }
            }
        }

@@ -250,14 +250,14 @@ pub struct StmSig<D: Clone + Digest + FixedOutput> {

impl<D: Clone + Digest + FixedOutput> Hash for StmSig<D> {
fn hash<H: Hasher>(&self, state: &mut H) {
Hash::hash_slice(&self.to_bytes(), state)
Hash::hash_slice(&self.sigma.to_bytes(), state)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpraynaud , to be able to check that a signature is inside the hashmap before filtering the list of indexes we need to define the hash and the eq functions in a way that does not depend on the set of valid indices. I think it is alright, and I chose the underlying signature for that. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that it was also the case for this part of the code 🤔 (so that a signature number of won lotteries would have been counted multiple times)

if dedup_sigs.insert(deduped_sig) {
    count += size;
}

Using the underlying signature for the hash looks good as there should 't be any need for the same signature with different won lotteries indices after deduplication IMH 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before it was not the case, because we were inserting (and therefore checking if the signature was in the map) after editing the vector of indexes. Therefore, the previous Hash and PartialEq criteria was catching duplicates.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're completely right 👍

@iquerejeta iquerejeta marked this pull request as ready for review July 21, 2022 14:27
Copy link
Member

@jpraynaud jpraynaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@iquerejeta iquerejeta merged commit 03e0edd into main Jul 22, 2022
@iquerejeta iquerejeta deleted the set_indices branch July 22, 2022 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change 🔥 Contains a breaking change D-medium Difficulty: medium P-high Priority: high T-refactor Type: cleanup/refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Think about display of Signatures and VerificationKey for them to be unique Is it possible and necessary to include PartialEq for Path
3 participants