-
Notifications
You must be signed in to change notification settings - Fork 2
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
Raph@generics #31
Raph@generics #31
Conversation
2ccad0b
to
494c254
Compare
@tolikzinovyev @curiecrypt @djetchev |
37bd66d
to
156cadd
Compare
@rrtoledo there are probably many ways to implement generic data elements. Could you say what other options you considered and why you chose this one? Thanks. |
use blake2::{Blake2s256, Digest}; | ||
|
||
/// Alba's proving algorithm, based on a depth-first search algorithm. | ||
/// Calls up to setup.max_retries times the prove_index function and returns an empty | ||
/// proof if no suitable candidate is found. | ||
pub fn prove(setup: &Setup, prover_set: &[Element]) -> Option<Proof> { | ||
pub fn prove<Element>(setup: &Setup, prover_set: &[Element]) -> Option<Proof<Element>> |
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.
@rrtoledo @tolikzinovyev @curiecrypt : if I think about it, the most general setting occurs when prove()
is parameterized by a generic type and this generic type under the constraint that this type implemetns the traits Eq + Hash. Can we do something like this
fn prove<T: Eq + Hash>(...)
and similarly for any other function.
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.
If you don't want to write <T: Eq + Hash>
in every function signature, you can first define
trait HashableEq: Eq + Hash {}
impl<T: Eq + Hash> HashableEq for T {}
This implements HashableEq
for all types T
that requires implementing both Eq
and Hash
and the second line ensures that any type that implements Eq and Hash automatically satisfies HashableEq
, so you can now write
fn prove<T: HashableEq>(...) {}
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.
@djetchev This looks interesting, we would also need the Copy trait however.
I had a look at the Hash
trait in the past, and I wanted to stay clear from it as it does not seem it was meant for cryptographic purposes (but DoS for hashmaps).
If you look at how it works, you need to use a Hasher
in conjunction to it. However the default hasher is SipHasher13 which is not cryptographically secure but used only to prevent DOS in hashmaps.
I am afraid that by using this trait, we are encourage the use of this default hasher. Perhaps I am being overlycautious, and we can simply provide a different default hash.
// Run prove_index up to max_retries times | ||
(0..setup.max_retries).find_map(|retry_counter| prove_index(setup, prover_set, retry_counter).1) | ||
} | ||
|
||
/// Alba's verification algorithm, returns true if the proof is | ||
/// successfully verified, following the DFS verification, false otherwise. | ||
pub fn verify(setup: &Setup, proof: &Proof) -> bool { | ||
pub fn verify<Element>(setup: &Setup, proof: &Proof<Element>) -> bool |
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.
idem
Closing this PR temporarily to start others of higher priority |
Content
This PR includes...
Pre-submit checklist
Comments
Issue(s)
Relates to #YYY or Closes #YYY