-
Notifications
You must be signed in to change notification settings - Fork 47
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
feat: add new get_script_hash
kernel procedure
#995
Conversation
Some documentation is still missing but I just wanted to check if my approach was correct. It's a simple procedure but I'm not so experienced in this part of the codebase, so I created this draft first. I used the |
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 have just one comment about the test, but the assembly code for now looks good for me.
use.kernel::prologue | ||
use.kernel::note->note_internal | ||
use.kernel::note | ||
|
||
begin | ||
exec.prologue::prepare_transaction | ||
exec.note_internal::prepare_note | ||
dropw dropw dropw dropw | ||
exec.note::get_note_script_hash | ||
|
||
# truncate the stack | ||
swapw dropw | ||
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.
You said that you used the test for the get_serial_number
as a reference, but it turned out that this test has some flaws in it. Your test (and get_serial_number
one) could be rewritten like so:
use.kernel::prologue
use.miden::note
begin
exec.prologue::prepare_transaction
exec.note::get_note_script_hash
# truncate the stack
swapw dropw
end
So there are three comments:
- As far as I know, we should avoid using procedures from the
kernel
lib directly, so in that case we should use theget_note_script_hash
procedure from themiden
lib, and not from thekernel
. - We don't need to import the same module with different names. Probably at first there were both
miden::note
andkernel::note
modules, that's why we wanted to havekernel::note
as an internal one, but for now it is unnecessary. - We don't need to call
note::prepare_note
procedure — it just moves some data on the stack, without updating any internal variables. We don't use this data, so this execution could be safely removed.
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 for the explanation! I fixed this test and the serial number one.
c4b431e
to
8c94107
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.
LGTM, thank you!
I left just one comment inline.
let script_hash: Word = tx_context.input_notes().get_note(0).note().script().hash().into(); | ||
assert_eq!(process.stack.get_word(0), script_hash); |
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.
I think we can avoid importing the Word
here by calling the .as_elements()
on the RpoDigest
returned from the .hash()
:
let script_hash = tx_context.input_notes().get_note(0).note().script().hash();
assert_eq!(process.stack.get_word(0), script_hash.as_elements());
CHANGELOG.md
Outdated
@@ -10,6 +10,7 @@ | |||
- [BREAKING] Add error messages to errors and implement `core::error::Error` (#974). | |||
- Implemented new `digest_from_hex!` macro (#984). | |||
- Added Format Guidebook to the `miden-lib` crate (#987). | |||
- Added `miden::note::get_script_hash` procedure (#995). |
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.
I think we should note this change as breaking, since it changes the offsets of the kernel procedures.
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!
closes #977
This PR adds a new
get_script_hash
kernel procedure that allows the user to access the note script hash from within the script itself.