Allow accounts to read and write to memory region in kernel
- 主要語言
- Rust
- 星號
- 132
- 分支
- 167
- 平均合併
- 1 天 23 小時
- 30 天內合併 PR
- 110
描述
## Motivation
Coming out of https://github.com/0xMiden/miden-base/issues/1331#issuecomment-2859942082, it could be useful in a variety of contexts for accounts to have access to a stable memory location. Because the VM does not assign the same memory context across `call`s, an account currently cannot persist anything in memory for the duration of the transaction. The only stable memory context is the kernel itself. So adding a `mem_{storew,loadw}`-like TX kernel API would enable this functionality.
From the above issue, one potential use case could be to keep track of the operations that were invoked on the account. The authentication code could then check if an operation was executed that requires authentication (such as minting assets) and if so, run signature verification. If not (e.g. if assets were burned), then the transaction could pass without requiring a signature verification.
There could be other uses cases for this, such as "cross-note communication" by going through account interfaces.
## Design
For this, we would need:
- A memory region in the kernel of some tbd size, that the native account is allowed to write to and read from arbitrarily.
- Two new kernel APIs, for writing and reading memory with equivalent "signatures" as `mem_{storew,loadw}`.
- `tx_mem_loadw` reads a single felt from the stack (the pointer) and returns the word at that location.
- `tx_mem_storew` reads 5 felts from the stack (the pointer and the word to be stored).
- These validate that the provided pointer points inside the allowed region.
One open question is how large the memory region should be. This depends on the use cases we can come up with for this. A safe bet would be to keep it small initially and increase if the need arises, mainly because increasing is a non-breaking change (API-wise).
貢獻指南
評估
這個 Issue 還沒有評估資料。