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 adding instructions to read memory of the parent context #1025

Open
bobbinth opened this issue Jul 25, 2023 · 3 comments
Open

Consider adding instructions to read memory of the parent context #1025

bobbinth opened this issue Jul 25, 2023 · 3 comments
Labels
enhancement New feature or request instruction set Related to Miden VM instruction set processor Related to Miden VM processor

Comments

@bobbinth
Copy link
Contributor

One of the consequences of #948, is that we would get access to the parent context ID via prnt_ctx column. This means, we would be able to execute operations which read values from (and even write values to) parent memory.

While writing values into parent context may lead to potential security issues, reading values should be OK in most cases, and it could simplify passing large amounts of data from the caller to the callee.

The instructions could be something like pmem_load and pmem_loadw (to mimic mem_load and mem_loadw).

@bobbinth bobbinth added enhancement New feature or request instruction set Related to Miden VM instruction set processor Related to Miden VM processor labels Jul 25, 2023
@hackaugusto
Copy link
Contributor

hackaugusto commented Apr 29, 2024

Question: Could this be extended to all contexts? For example, allowing a note context to pass a pointer and length to the kernel context, for things like assets on a create_note call.

Note: This may be a security vulnerability if a secret is stored in the root context and the note can read it. Maybe it should be limited for a high priority context allowed to read a lower priority context memory? Or maybe a specific memory region should be private and some other area readable (although this makes it harder to write correct code)

@bobbinth
Copy link
Contributor Author

Yes - we could extend it to all contexts - the tricky thing is to get the correct context ID. So, for example, if we want the code executing in root context to read memory from note context, we'd need to pass the following to create_note: note's context ID, pointer, length.

We currently don't have an instruction to get current context ID - though, I don't think there is a reason why we can't add it.

@bitwalker
Copy link
Contributor

Something to note here: this could be done safely using some of my suggestions on the topic of a "Miden component model". Specifically, the ability to switch between arbitrary contexts, and associating "resources" with contexts (see the concept of resources in the Wasm Component Model, documented here). Resources provide a capability-object model that maintains the security of the underlying architecture (Wasm, or in our case, Miden), while also enabling a lot of powerful use cases that would otherwise not be possible.

To provide a bit more detail - resources allow a context to share data with other contexts in the form of a handle, with corresponding ownership semantics (own vs borrow). A resource handle can be used to execute code that operates on its data and only that data. Each resource can have zero or more methods associated with it, and when a method is invoked on a resource, the code associated with it is executed in the context which created the resource, which has full control over it. In effect, the actual memory of the resource isn't shared, but you can do virtually everything of interest as if it was. Typically, resources are associated with capabilities (as part of the resource itself), which determine what the owner of the resource handle can do with the resource - this is the essence of the capability-object model mechanism.

All that to say, I think if we want to start exploring solutions to problems like these, I would strongly recommend that we do so by tackling the fundamental elements we need to implement parts of the component model framework in Miden VM. We'll end up with a much more cohesive set of primitives, which will in turn let us solve not only this problem, but a host of related ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request instruction set Related to Miden VM instruction set processor Related to Miden VM processor
Projects
None yet
Development

No branches or pull requests

3 participants