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

MastForest maximum node length invariant #1394

Merged
merged 4 commits into from
Jul 19, 2024

Conversation

sergerad
Copy link
Contributor

@sergerad sergerad commented Jul 15, 2024

Closes #1392

  • Enforce invariant that MastForest node length is < 2^30
  • Return errors from add_node() and enforce_node()
  • Map errors to AssemblyError

@sergerad
Copy link
Contributor Author

@plafer LMK if this makes sense.

And are we happy panicking in add_node()? Or do we want to return error and refactor usage?

@sergerad sergerad marked this pull request as ready for review July 15, 2024 08:06
@plafer
Copy link
Contributor

plafer commented Jul 15, 2024

@sergerad Thank you for taking this on, it is super appreciated!

The current implementation looks great; however, could you rebase it on the plafer-mast-forest-serialization branch? We can then wait for that PR to be merged before we merge this one. When I created #1392, I assumed the PR would be merged by the time anyone started working on it 😅.

Hence, the current implementation can stay the same, and the new MastNodeId::from_u32_safe() could be modified to use the new TryFrom that you implemented.

And are we happy panicking in add_node()? Or do we want to return error and refactor usage?

If you are willing to do the work, returning an error would be much better as it's definitely the direction we want to go in. This would also require a similar change to MastForestBuilder::ensure_node().

@plafer
Copy link
Contributor

plafer commented Jul 15, 2024

Actually, thinking about it a bit more, I think it makes more sense for MastForest to know about the $2^{30}$ limit on number of nodes as opposed to the MastNodeId (a constraint that ultimately comes from the MastForest serialization format). So:

  • MastNodeId::from_u32_safe() remains unchanged
  • MastForest::add_node() contains the $2^{30}$ node limit check, and returns an error instead of panicking

@sergerad
Copy link
Contributor Author

Thanks very much for that guidance @plafer. I will make those changes including the removal of the panic.

@sergerad sergerad force-pushed the serge-mast-node-id-invariant branch from 489e93f to c235257 Compare July 16, 2024 08:02
@sergerad sergerad changed the title add MastNodeId::TryFrom<u32> MastForest maximum node length invariant Jul 16, 2024
@sergerad sergerad changed the base branch from next to plafer-mast-forest-serialization July 16, 2024 08:06
@sergerad
Copy link
Contributor Author

@plafer I have added the node count invariant logic to MastForest and updated the relevant fns to return errors.

Most of the diffs are due to adding unwrap() in test files. All other files should be handling the new errors, not unwrapping.

I have done my best to handle those errors appropriately and map to AssemblyError. Let me know if and how to change the approach I have there with MastForestError.

@sergerad sergerad force-pushed the serge-mast-node-id-invariant branch from c235257 to 4b02340 Compare July 16, 2024 09:36
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 for tackling this! I left a few small comments inline.

core/src/mast/mod.rs Outdated Show resolved Hide resolved
core/src/mast/mod.rs Outdated Show resolved Hide resolved
core/src/mast/serialization/mod.rs Outdated Show resolved Hide resolved
assembly/src/assembler/mod.rs Show resolved Hide resolved
assembly/src/assembler/instruction/procedures.rs Outdated Show resolved Hide resolved
assembly/src/assembler/basic_block_builder.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@plafer plafer 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! Just left a few minor comments

assembly/src/assembler/basic_block_builder.rs Outdated Show resolved Hide resolved
assembly/src/assembler/instruction/procedures.rs Outdated Show resolved Hide resolved
assembly/src/assembler/instruction/procedures.rs Outdated Show resolved Hide resolved
assembly/src/assembler/instruction/procedures.rs Outdated Show resolved Hide resolved
core/src/mast/serialization/mod.rs Outdated Show resolved Hide resolved
@sergerad
Copy link
Contributor Author

Think I have covered all the current comments. Thanks!

@sergerad sergerad requested review from plafer and bobbinth July 17, 2024 04:19
Copy link
Contributor

@plafer plafer left a comment

Choose a reason for hiding this comment

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

LGTM! (let's fix clippy and wait for #1370 to be merged so that we can merge this into next)

@plafer plafer deleted the branch 0xPolygonMiden:next July 17, 2024 14:30
@plafer plafer closed this Jul 17, 2024
@plafer plafer reopened this Jul 17, 2024
@plafer plafer changed the base branch from plafer-mast-forest-serialization to next July 17, 2024 14:32
@plafer
Copy link
Contributor

plafer commented Jul 17, 2024

Merged #1370, and changed the target branch to next

@sergerad sergerad force-pushed the serge-mast-node-id-invariant branch from a06971c to bcb4963 Compare July 17, 2024 18:09
@sergerad
Copy link
Contributor Author

Fixed clippy and changelog 👍

@sergerad sergerad requested a review from plafer July 17, 2024 18:11
Copy link
Contributor

@plafer plafer left a comment

Choose a reason for hiding this comment

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

🙏

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! I left one small comment inline.

core/Cargo.toml Outdated Show resolved Hide resolved
@sergerad sergerad requested a review from bobbinth July 19, 2024 04:33
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.

All looks good! Thank you!

@bobbinth bobbinth merged commit 14995b4 into 0xPolygonMiden:next Jul 19, 2024
9 checks passed
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.

3 participants