-
Notifications
You must be signed in to change notification settings - Fork 54
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
Hash arbitrary number of elements in masm
#750
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.
Thank you! Not a full review, but I left a couple of comments inline.
@Overcastan Is it easy to get the note serial number or serial number hash easily? Once it is possible to hash an arbitrary number of elements in masm, and get the serial number, you can use this procedure: #757 If you can only get the hash, that's fine too, you'd just modify this procedure a bit. |
@partylikeits1983 I thought that note serial number is kind of user input, isn't it? So we can add it as an input to the procedure, but in that case versatility of this procedure will decrease. But I don't know the exact use case for it, so if at the moment of this procedure call we always have the note serial number, it should be fine to add it as an input. |
4161d6c
to
12e7cd5
Compare
12e7cd5
to
aa7e423
Compare
Should we add a test for this? |
I was thinking about that, but there is a problem: ideally we want to have something similar to tests in native.rs, but to do so in |
I think once we finalize the procedure here, we should basically copy it (with some minor modifications) to the |
I implemented this function using |
68c78e4
to
55ebae4
Compare
I thought that if we are going to check all 7 top stack elements by hand anyway, we can simplify the |
Using |
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.
Looks good! Thank you. I left a few comments inline.
Before merging this PR, let's make a similar PR in miden-base
to update the rpo module (the PR would need to made against Al's branch). That one is already using a new padding rule - and so, I think, the code should be a bit simpler.
In that PR, let's rename hash_memory
into hash_memory_words
and name the function you wrote in this PR hash_memory
.
80103e5
to
74d3199
Compare
Since |
We won't be able to update |
a2ff613
to
00e05b2
Compare
00e05b2
to
26a010f
Compare
26a010f
to
58eb753
Compare
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.
Looks good! Thank you. I left some more comments inline.
Also, it would be good to test it somehow - even if manually (i.e., we don't need to create a lot of code for this, I just want to make sure similar tests as we did have in miden-vm
work with this too).
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.
Looks good! Thank you! I left a few small comments inline. After these are addressed, we can merge.
miden-lib/asm/miden/note.masm
Outdated
# => [num_inputs/8, num_inputs%8, inputs_ptr] | ||
|
||
# get the end_addr for hash_memory procedure (end address for pairs of words) |
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.
nit: this should say "hash_memory_even" procedure.
let code = " | ||
use.miden::note | ||
|
||
begin | ||
push.1.2.3.4.1000 mem_storew dropw | ||
push.5.6.7.8.1001 mem_storew dropw | ||
push.9.10.11.12.1002 mem_storew dropw | ||
push.13.14.15.16.1003 mem_storew dropw | ||
|
||
push.5.1000 | ||
exec.note::compute_inputs_hash | ||
|
||
push.8.1000 | ||
exec.note::compute_inputs_hash | ||
|
||
push.15.1000 | ||
exec.note::compute_inputs_hash | ||
|
||
push.0.1000 | ||
exec.note::compute_inputs_hash | ||
end | ||
"; |
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 add comments to explain what is being hashed here.
let process = tx_context.execute_code(code).unwrap(); | ||
let expected_stack = [ | ||
Felt::new(0), | ||
Felt::new(0), | ||
Felt::new(0), | ||
Felt::new(0), | ||
Felt::new(10300020282439016154), | ||
Felt::new(3516596904277416676), | ||
Felt::new(11018788508269249672), | ||
Felt::new(7921509648524809116), | ||
Felt::new(13608701685256682132), | ||
Felt::new(16013969809933496273), | ||
Felt::new(15720844923951376941), | ||
Felt::new(15975159621759139720), | ||
Felt::new(12095223039215569196), | ||
Felt::new(16902760742589336416), | ||
Felt::new(12194156716918087419), | ||
Felt::new(2777745863384272413), | ||
]; | ||
assert_eq!(process.get_stack_state()[0..16], expected_stack); |
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.
Is it possible to compute these dynamically? Or at least write comments about how these were computed?
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.
All looks good! Thank you!
This PR implements
compute_inputs_hash
function innote.masm
which allows to compute RPO hash of arbitrary number of Felt elements.TODO:
compute_inputs_hash