-
Notifications
You must be signed in to change notification settings - Fork 129
feat(kernel): expose tx script root via public kernel procedure #2816
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
Open
partylikeits1983
wants to merge
6
commits into
next
Choose a base branch
from
ajl-kernel-tx-script-root
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3a9cdfc
feat(kernel): expose tx script root via public kernel procedure
partylikeits1983 9933269
docs(changelog): add entry for tx::get_script_root kernel procedure
partylikeits1983 26092e8
Merge remote-tracking branch 'origin/next' into ajl-kernel-tx-script-…
partylikeits1983 433292c
refactor: rename tx script root kernel procedure to retain `tx_script…
partylikeits1983 4b95b31
style: cargo fmt
partylikeits1983 cf6bc0e
Merge branch 'next' into ajl-kernel-tx-script-root
bobbinth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ use miden::protocol::kernel_proc_offsets::TX_PREPARE_FPI_OFFSET | |
| use miden::protocol::kernel_proc_offsets::TX_EXEC_FOREIGN_PROC_OFFSET | ||
| use miden::protocol::kernel_proc_offsets::TX_UPDATE_EXPIRATION_BLOCK_DELTA_OFFSET | ||
| use miden::protocol::kernel_proc_offsets::TX_GET_EXPIRATION_DELTA_OFFSET | ||
| use miden::protocol::kernel_proc_offsets::TX_GET_TX_SCRIPT_ROOT_OFFSET | ||
|
|
||
| #! Returns the block number of the transaction reference block. | ||
| #! | ||
|
|
@@ -319,3 +320,29 @@ pub proc get_expiration_block_delta | |
| swapdw dropw dropw swapw dropw movdn.3 drop drop drop | ||
| # => [expiration_delta] | ||
| end | ||
|
|
||
| #! Returns the transaction script root, or the zero word if no transaction script was executed. | ||
| #! | ||
| #! Inputs: [] | ||
| #! Outputs: [TX_SCRIPT_ROOT] | ||
| #! | ||
| #! Where: | ||
| #! - TX_SCRIPT_ROOT is the root of the transaction script executed in this transaction, or the zero | ||
| #! word if no transaction script was executed. | ||
|
Comment on lines
+324
to
+331
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: We usually call it "empty word" rather than "zero word". |
||
| #! | ||
| #! Invocation: exec | ||
| pub proc get_tx_script_root | ||
| # pad the stack | ||
| padw padw padw push.0.0.0 | ||
| # => [pad(15)] | ||
|
|
||
| push.TX_GET_TX_SCRIPT_ROOT_OFFSET | ||
| # => [offset, pad(15)] | ||
|
|
||
| syscall.exec_kernel_proc | ||
| # => [TX_SCRIPT_ROOT, pad(12)] | ||
|
|
||
| # clean the stack | ||
| swapdw dropw dropw swapw dropw | ||
| # => [TX_SCRIPT_ROOT] | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -752,6 +752,62 @@ async fn test_tx_script_args() -> anyhow::Result<()> { | |||||
| Ok(()) | ||||||
| } | ||||||
|
|
||||||
| /// Tests that `tx::get_tx_script_root` returns the root of the executed transaction script. | ||||||
| #[tokio::test] | ||||||
| async fn test_get_script_root_with_script() -> anyhow::Result<()> { | ||||||
| let tx_script = CodeBuilder::default().compile_tx_script("begin nop end")?; | ||||||
| let expected_root = tx_script.root(); | ||||||
|
|
||||||
| let code = format!( | ||||||
| r#" | ||||||
| use miden::protocol::tx | ||||||
| use $kernel::prologue | ||||||
|
|
||||||
| begin | ||||||
| exec.prologue::prepare_transaction | ||||||
|
|
||||||
| exec.tx::get_tx_script_root | ||||||
| # => [TX_SCRIPT_ROOT] | ||||||
|
|
||||||
| push.{expected_root} assert_eqw.err="tx script root mismatch" | ||||||
| end | ||||||
| "# | ||||||
| ); | ||||||
|
|
||||||
| let tx_context = TransactionContextBuilder::with_existing_mock_account() | ||||||
| .tx_script(tx_script) | ||||||
| .build()?; | ||||||
|
|
||||||
| tx_context.execute_code(&code).await?; | ||||||
|
|
||||||
| Ok(()) | ||||||
| } | ||||||
|
|
||||||
| /// Tests that `tx::get_tx_script_root` returns the zero word when no transaction script is | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| /// executed. | ||||||
| #[tokio::test] | ||||||
| async fn test_get_script_root_without_script() -> anyhow::Result<()> { | ||||||
| let code = r#" | ||||||
| use miden::protocol::tx | ||||||
| use $kernel::prologue | ||||||
|
|
||||||
| begin | ||||||
| exec.prologue::prepare_transaction | ||||||
|
|
||||||
| exec.tx::get_tx_script_root | ||||||
| # => [TX_SCRIPT_ROOT] | ||||||
|
|
||||||
| padw assert_eqw.err="tx script root must be zero when no script is executed" | ||||||
| end | ||||||
| "#; | ||||||
|
|
||||||
| let tx_context = TransactionContextBuilder::with_existing_mock_account().build()?; | ||||||
|
|
||||||
| tx_context.execute_code(code).await?; | ||||||
|
|
||||||
| Ok(()) | ||||||
| } | ||||||
|
|
||||||
| // Tests that advice map from the account code and transaction script gets correctly passed as | ||||||
| // part of the transaction advice inputs | ||||||
| #[tokio::test] | ||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.