-
Notifications
You must be signed in to change notification settings - Fork 3
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
Hash as input #137
base: main
Are you sure you want to change the base?
Hash as input #137
Conversation
c7f3f3d
to
d32faa8
Compare
/// Numbers of retries done to find the proof | ||
pub retry_counter: u64, | ||
/// Index of the searched subtree to find the proof | ||
pub search_counter: u64, | ||
/// Sequence of elements from prover's set | ||
pub element_sequence: Vec<Element>, | ||
// Phantom type to link the tree with its hasher | ||
hasher: PhantomData<H>, |
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.
Alternatively, you can remove generics from this type and only introduce generics to the relevant methods.
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 was done similarly to Mithril code base to keep a link between a proof and the underlying hash function.
Of course, in practice this is 0 byte but it keeps the code safe when compiling.
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
pub type Hash = [u8; DIGEST_SIZE]; | ||
|
||
pub(crate) fn truncate(data: &[u8]) -> Hash { | ||
debug_assert!(data.len() >= 16); |
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.
Since we are requiring only 16 bytes, DIGEST_SIZE
above should probably be 16.
@@ -14,18 +14,20 @@ use std::time::Instant; | |||
mod aggregate_signature; | |||
const DATA_LENGTH: usize = 48; | |||
pub(crate) type Element = [u8; DATA_LENGTH]; | |||
use digest::{Digest, FixedOutput}; | |||
use sha2::Sha512; |
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.
why sha256 elsewhere but sha512 here?
/// ``` | ||
pub fn prove(&self, prover_set: &[Element]) -> Option<Proof> { | ||
pub fn prove<H: Digest + FixedOutput>(&self, prover_set: &[Element]) -> Option<Proof<H>> { |
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.
Thinking about this PR again, having domain separation in mind per design document. Two points.
- I think we and the user would benefit from an example showing how to construct and use a hash function that has a domain id inside. Personally, right now I don't understand how easy it is to do.
- The current interfaces would work if the user has a finite number of domain ids since they can be defined directly in the hash function type. However, if we don't know at compile time how many possible domain ids there are, the current interface will not work. The user would need to provide not just the hash function type but also a hash function object.
Content
This PR aims at updating protocols to support different hashes, input by the user.
Pre-submit checklist
Comments
I have kept Blake2bVar when generating data, but changed to Sha256 in tests, benches and examples as it is faster on my machine.
I also fixed some old Clippy warnings.
Issue(s)
Relates to #36