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

Consider refactoring the semantics of DYN operation #1091

Closed
bobbinth opened this issue Oct 4, 2023 · 2 comments
Closed

Consider refactoring the semantics of DYN operation #1091

bobbinth opened this issue Oct 4, 2023 · 2 comments
Assignees
Labels
air Related to Miden AIR and constraints assembly Related to Miden assembly instruction set Related to Miden VM instruction set processor Related to Miden VM processor
Milestone

Comments

@bobbinth
Copy link
Contributor

bobbinth commented Oct 4, 2023

Support for dynamic procedure invocation was added in #1055. Currently, this works as follows: to invoke a dynamic procedure we get the MAST root of the procedure from the top of the stack. However, as discussed in #1078 (comment), this results in an inconvenience: we can't drop the entire procedure root from the stack at the time DYN operation is executed, and thus, we keep the full procedure root on the stack. This means that the called procedure is responsible for dropping the root from the stack. And in turn, this means that semantics for dynamic and static invocations are different.

One potential solution is described in #1078 (comment). Basically, we change the semantics of the DYN operation to work as follows:

Inputs:  [proc_ptr, ...]
Outputs: [...]

Basically, when DYN operation is executed, we'd read the procedure hash from memory locations specified by proc_ptr (instead of getting it from the top of the stack), and then drop the pointer from the stack. Thus, by the time we start executing procedure code, the stack would be "clean" from the procedure's standpoint. This would make invocation semantics between static and dynamic calls the same.

Or, at least almost the same. There is one thing that will remain different: the number of stack slots which can be used for parameters for call instructions. Specifically, for regular call instruction, we would still be able to pass 16 field elements to the callee. However, for dyncall, we'd only be able to pass 15 as 1 element would be taken up by the procedure pointer.

@bobbinth bobbinth added assembly Related to Miden assembly instruction set Related to Miden VM instruction set processor Related to Miden VM processor air Related to Miden AIR and constraints labels Oct 4, 2023
@bobbinth bobbinth added this to the v0.12.0 milestone Sep 26, 2024
@Fumuran
Copy link
Contributor

Fumuran commented Sep 26, 2024

The same problem occurred during the implementation of foreign procedure invocation (0xPolygonMiden/miden-base#847): foreign procedures should be invoked using dyncall which require to handle the procedure hash on the top of the stack.

@bobbinth
Copy link
Contributor Author

Closed by #1535.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
air Related to Miden AIR and constraints assembly Related to Miden assembly instruction set Related to Miden VM instruction set processor Related to Miden VM processor
Projects
Status: Done
Development

No branches or pull requests

3 participants