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

Update mtree_merge doc comments #1260

Merged
merged 1 commit into from
Feb 28, 2024
Merged

Conversation

Fumuran
Copy link
Contributor

@Fumuran Fumuran commented Feb 27, 2024

This small PR changes the doc comments related to mtree_merge instruction.
It removes any comments about returning an error if provided roots are not in the advice provider (since we don't return it).

@@ -158,8 +158,7 @@ pub(super) fn mtree_set(span: &mut SpanBuilder) -> Result<Option<CodeBlock>, Ass
/// follows:
/// - merged root, 4 elements
///
/// This operation will fail if either of the input roots doesn't exist as Merkle tree in the
/// advice provider.
/// It is not expected for provided roots to be in the advice provider.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure that a brief comment is sufficient here, although it is the way I can make it correct without additional explanations.

I also considering this comment, but IMO it is a bit bulky:

/// In case of working with Merkle trees, it is expected that the provided roots exist as Merkle 
/// trees in the advice provider, but this is not checked. In case of working with Merkle Mountain
/// range it is not expected for provided roots to be in the advice provider.

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO it is better to have the bulky comment. Otherwise it takes more time to onboard people.

Question: Why is there a difference in behavior? Can't we align it? It would be best if both structures behaved the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, that was an initial idea of the issue, although it turns out to be quite complicated to make this function work the same for the both structures: #943 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think a more detailed comment is better - but also I don't think we should mention Merkle trees or Merkle mountain ranges here. The instruction behaves the same way in either case, and how downstream code choses to use it is not relevant here, IMO.

/// Returns an error if a Merkle tree for either of the specified roots cannot be found in this
/// advice provider.
/// It is not checked whether a Merkle tree for either of the specified roots can be found in
/// this advice provider.
fn merge_roots(&mut self, lhs: Word, rhs: Word) -> Result<Word, ExecutionError>;
Copy link
Contributor Author

@Fumuran Fumuran Feb 27, 2024

Choose a reason for hiding this comment

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

Working on this issue I noticed that for now we are using this function (and mtree_merge instruction respectively) only in the MMR collection. In that case may be it makes sense to rename internal functions to merge_nodes to avoid inconsistency in merging roots not being roots?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking about it as well - but note sure if merge_nodes is better. Technically, what we are doing here is inserting a new tree into the Merkle store - so, insert_tree would be more appropriate, but that can also be confusing.

So, I'd probably keep it as merge_roots.

Copy link
Contributor

@hackaugusto hackaugusto left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -158,8 +158,7 @@ pub(super) fn mtree_set(span: &mut SpanBuilder) -> Result<Option<CodeBlock>, Ass
/// follows:
/// - merged root, 4 elements
///
/// This operation will fail if either of the input roots doesn't exist as Merkle tree in the
/// advice provider.
/// It is not expected for provided roots to be in the advice provider.
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO it is better to have the bulky comment. Otherwise it takes more time to onboard people.

Question: Why is there a difference in behavior? Can't we align it? It would be best if both structures behaved the same.

@Fumuran Fumuran force-pushed the andrey-update-merge-roots-docs branch from 8cce96e to ee81b80 Compare February 27, 2024 22:30
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you!

Separately from this PR, I noticed that we still have find_lone_leaf function - which I think we don't need any more. Could you check if it is still needed and remove it if not?

/// Returns an error if a Merkle tree for either of the specified roots cannot be found in this
/// advice provider.
/// It is not checked whether a Merkle tree for either of the specified roots can be found in
/// this advice provider.
fn merge_roots(&mut self, lhs: Word, rhs: Word) -> Result<Word, ExecutionError>;
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking about it as well - but note sure if merge_nodes is better. Technically, what we are doing here is inserting a new tree into the Merkle store - so, insert_tree would be more appropriate, but that can also be confusing.

So, I'd probably keep it as merge_roots.

@bobbinth bobbinth merged commit b17befd into next Feb 28, 2024
15 checks passed
@bobbinth bobbinth deleted the andrey-update-merge-roots-docs branch February 28, 2024 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update MemAdviceProvider::merge_roots() implementation to be compliant with specs
3 participants