-
Notifications
You must be signed in to change notification settings - Fork 44
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
Conversation
mithril-core/src/stm.rs
Outdated
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()); | ||
} | ||
} |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 👍
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're completely right 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I blame the GH browser editor...
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:
These changes implements option 3 of #296. In this PR we also implement
PartialEq
forStmSig
and define a canonical display for aVerificationKey
andSignature
, which closes #336 and closes #337 respectively.