-
Notifications
You must be signed in to change notification settings - Fork 57
Monero: expose merkle root function #629
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
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,13 @@ use std_shims::vec::Vec; | |
|
||
use crate::primitives::keccak256; | ||
|
||
pub(crate) fn merkle_root(root: [u8; 32], leafs: &[[u8; 32]]) -> [u8; 32] { | ||
/// Calculates the merkel root of the given tree. Equivalent to `tree_hash` in monero-core. | ||
Boog900 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub fn merkle_root(leafs: &[[u8; 32]]) -> [u8; 32] { | ||
match leafs.len() { | ||
0 => root, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We used to handle no leaves being passed. Now no hashes falls through to the n-leaves case. Is that correct? I doubt it as our n-leaf code pads to the nearest power of 2 which is assumed to be 4 as we assumed exceptional handling for 0/1/2. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yeah it will panic, I guess the best thing to do would be to explicitly panic, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would've been so easy for me to check if there was a link to *There wasn't such a link prior, I don't legitimately want to hold this against you. I'd vote we keep the existing explicit argument (potentially renamed from root to first_leaf?) making this unreachable, or return an Option. We can document the panic but I'd consider that a downgrade. Even the Option would be but it isn't such a downgrade I wouldn't agree to it if you believe avoiding these allocations so worthwhile. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll change it to return an option, I don't really like having the first leaf as a separate arg. |
||
1 => keccak256([root, leafs[0]].concat()), | ||
1 => leafs[0], | ||
2 => keccak256([leafs[0], leafs[1]].concat()), | ||
_ => { | ||
let mut hashes = Vec::with_capacity(1 + leafs.len()); | ||
hashes.push(root); | ||
hashes.extend(leafs); | ||
let mut hashes = leafs.to_vec(); | ||
Boog900 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Monero preprocess this so the length is a power of 2 | ||
let mut high_pow_2 = 4; // 4 is the lowest value this can be | ||
|
Uh oh!
There was an error while loading. Please reload this page.