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

Mmr packing #841

Merged
merged 1 commit into from
Apr 14, 2023
Merged

Mmr packing #841

merged 1 commit into from
Apr 14, 2023

Conversation

hackaugusto
Copy link
Contributor

@hackaugusto hackaugusto commented Apr 11, 2023

Describe your changes

Review/Merge after #834 #844

This adds the procedure to pack a Mmr.

Checklist before requesting a review

  • Repo forked and branch created from next according to naming convention.
  • Commit messages and codestyle follow conventions.
  • Relevant issues are linked in the PR description.
  • Tests added for new functionality.
  • Documentation/comments updated according to changes.

@hackaugusto hackaugusto mentioned this pull request Apr 11, 2023
@hackaugusto hackaugusto marked this pull request as ready for review April 12, 2023 12:20
padw padw padw
exec.native::hash_even_memory_addresses
exec.native::digest_output
# => [HASH, peaks_end, peaks_end, ...]
Copy link
Contributor Author

@hackaugusto hackaugusto Apr 12, 2023

Choose a reason for hiding this comment

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

I'm modifying the code as follows:

  • [done] Also push this to the advice map, that way pack works better as an inverse operation of unpack.
    • My initial idea was to have another procedure, I guess we can still have it if anyone finds that useful, but from the naming pack/unpack should be the inverse of each other, so one read and the other writes to the advice map
  • [done] I'm going to change the padding to make the length a word
    • My initial idea was to just push padding as necessary to make use of adv.mem, but that would make the format of the input and output different, which can be super confusing. I think it is better to make them consistent. Edit: It would be even more confusing than I thought, I assumed I could just push data to the end, but that is not how adv.mem works, it reads a memory range, so the padding would appear on the position I added in this PR.

Copy link
Contributor Author

@hackaugusto hackaugusto Apr 12, 2023

Choose a reason for hiding this comment

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

humm, adv.mem only accepts immediate parameters, I have to fix that before continuing here.

done: #844

@hackaugusto hackaugusto force-pushed the hacka-mmr-packing branch 2 times, most recently from 8e42ad4 to 4420b91 Compare April 12, 2023 12:46
@hackaugusto
Copy link
Contributor Author

marking this as a draft, first have to fix adv.mem instruction

@hackaugusto hackaugusto marked this pull request as draft April 12, 2023 12:51
@hackaugusto hackaugusto force-pushed the hacka-mmr-packing branch 4 times, most recently from 550b151 to 76da1b8 Compare April 12, 2023 21:08
padw padw padw
exec.native::hash_even_memory_addresses
exec.native::digest_output
# => [HASH, peaks_end, peaks_end, peaks_start, num_leaves, ...]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If adv.mem was defined with start_address and end_address instead of number_of_words, I could reuse peaks_end and maybe save a few cycles.

I haven't changed it because I'm not sure if that would be best in general.

Copy link
Contributor Author

@hackaugusto hackaugusto Apr 13, 2023

Choose a reason for hiding this comment

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

in the end it saved just a single cycle.

note: moving the "control word" with swapw uses the same number of cycles.

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 a few minor comments inline.

stdlib/asm/crypto/hashes/native.masm Outdated Show resolved Hide resolved
@@ -9,7 +26,7 @@
#! Cycles: 4 + 3 * words, where `words` is the `start_addr - end_addr - 1`
#!
#! Where `A` is the capacity word that will be used by the hashing function, and `B'` the hash output.
proc.hash_even_memory_addresses
export.hash_even_memory_addresses
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: the addresses don't have to be even - right? (it's the number of words that needs to be even?) Maybe rename this to something like hash_memory_even?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, that is right. changed the name!

stdlib/asm/collections/mmr.masm Outdated Show resolved Hide resolved
stdlib/asm/collections/mmr.masm Outdated Show resolved Hide resolved
@hackaugusto hackaugusto force-pushed the hacka-mmr-packing branch 4 times, most recently from 16c61cb to fba711a Compare April 14, 2023 16: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.

All looks good! Thank you!

@bobbinth bobbinth merged commit 6e68b69 into next Apr 14, 2023
@bobbinth bobbinth deleted the hacka-mmr-packing branch April 14, 2023 19:19
@bobbinth bobbinth mentioned this pull request Apr 14, 2023
28 tasks
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.

2 participants