-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat(smt): add smt
crate
#41
feat(smt): add smt
crate
#41
Conversation
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.
tACK
Thanks @waddaboo
Nice you added docstring and a README.
I
- checked tests locally
- checked the function signatures and overall code to see if it matches the original TS implementation
I suggested some improvements but they aren't blocking merging this PR imo
Let's wait for someone else review too cc @curryrasul
Don't forget to format the code in order to have the ci check pass
crates/smt/examples/smt.rs
Outdated
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.
do you think this should be included in the published crates?
If not we need to add an exclude
or include
field to the crate's manifest
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.
Thanks for the review!
I saw some other libraries included examples and some did not, so I'm not sure either. Since the README Usage
section is the same as in examples
, I think it's ok to remove it?
pub enum Node { | ||
Str(String), | ||
BigInt(BigInt), | ||
} |
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.
I like adding the flexibility of working with String or BigInt.
What do you (and other reviewers) think of using generics instead?
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.
Yes, it might make sense to avoid doing these checks at runtime, but 90% of things can be represented by String and BigInt. I don't know if the game is worth the candle. Anyone has any additional comments here?
/// # Returns | ||
/// | ||
/// A new instance of the SMT. | ||
pub fn new(hash: HashFunction, big_numbers: bool) -> Self { |
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.
see previous comment, wouldn't it be nicer to rely on generics instead of making a runtime check on big_numbers
?
I am thinking about something like:
pub struct SMT<T>
where
T: Clone + PartialEq + Eq + Hash + Display + FromStr {}
pub enum Node<T>
where
T: Clone + PartialEq + Eq + Hash + Display + FromStr,
{
Value(T),
}
impl<T> SMT<T> {}
let smt_string = SMT::<String>::new(hash_function);
let smt_bigint = SMT::<BigInt>::new(hash_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.
let's not block that PR based on my previous comment. My comment on generics probably apply to the TS implementation too.
And this PR should mirror the TS implementation, which is does 👌
Co-authored-by: sripwoud <[email protected]>
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.
@0xjei Thanks for the review! As for the comment on using generics, do I implement it now or wait for further comments? |
No need to implement it now. Let's merge. @cedoor we need your approval too. Thanks @waddaboo |
@sripwoud thanks. Ready to be merged 👍🏽 |
Description
Added the Sparse Merkle Tree (SMT) implementation in Rust.
Related Issue(s)
Closes: #8
Other information
Checklist
yarn format
andyarn compile
without getting any errorsAdditional Questions