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

Raph@generics #31

Closed
wants to merge 4 commits into from
Closed

Raph@generics #31

wants to merge 4 commits into from

Conversation

rrtoledo
Copy link
Collaborator

@rrtoledo rrtoledo commented Oct 8, 2024

Content

This PR includes...

Pre-submit checklist

  • Branch
    • Tests are provided (if possible)
    • Commit sequence broadly makes sense
    • Key commits have useful messages
  • PR
    • No clippy warnings in the CI
    • Self-reviewed the diff
    • Useful pull request description
    • Reviewer requested
  • Documentation
    • Update README file (if relevant)
    • Update documentation website (if relevant)

Comments

Issue(s)

Relates to #YYY or Closes #YYY

@rrtoledo rrtoledo added the enhancement New feature or request label Oct 8, 2024
@rrtoledo rrtoledo self-assigned this Oct 8, 2024
@rrtoledo rrtoledo marked this pull request as draft October 8, 2024 08:52
caledonia/Cargo.toml Outdated Show resolved Hide resolved
@rrtoledo rrtoledo linked an issue Oct 9, 2024 that may be closed by this pull request
@rrtoledo rrtoledo marked this pull request as ready for review November 11, 2024 17:34
@rrtoledo
Copy link
Collaborator Author

rrtoledo commented Nov 11, 2024

@tolikzinovyev @curiecrypt @djetchev
I would put back the functions in an impl Proof to simplify all the fn name<Element>() where Element ....
Should I keep "Element" or use the more common "T"?

@tolikzinovyev
Copy link
Member

@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>>
Copy link
Collaborator

@djetchev djetchev Nov 12, 2024

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.

Copy link
Collaborator

@djetchev djetchev Nov 12, 2024

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>(...) {}

Copy link
Collaborator Author

@rrtoledo rrtoledo Nov 12, 2024

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

idem

@rrtoledo rrtoledo marked this pull request as draft December 3, 2024 10:40
@rrtoledo
Copy link
Collaborator Author

Closing this PR temporarily to start others of higher priority

@rrtoledo rrtoledo closed this Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use generics
3 participants