Comments (7)
To provide the above interface, one thing that could be done, is to use the same strategy as #701, and have the accounts procedures available to dyncall
.
The user would initialize the memory with the callback addresses in the beginning of the transaction script, and then would exec
the code in miden/account.masm
, which would in turn use a dyncall
to transition to the authenticated account code. Alternatively, the user would not even need to do the initialization himself if we have a flag in memory and perform lazily initialization from the miden lib.
from miden-base.
I think a couple of things may be conflated here. A few comments:
However, for security,
set_account_item
must authenticate the origin of the call, e.g. to prevent a rogue note from changing the account's code. This means the function can not beexec
ed, and it must becall
ed instead.
We need to use syscall
rather than call
to invoke kernel procedures - though, the effect on the stack would be the same in both cases.
Now, because the
call
can return at most 16 elements in the stack, the code above that was suppose to provide a nice API is unusable, because it is pushing 3 elements to the stack which are never cleaned up:
I'm not sure I follow this part. The referenced code should not leave any extra items on the stack (if it does, there is a bug somewhere). The call sequence looks something like this:
- The user runs
exec.account::set_item
in miden/accounts.masm. This is the procedure which has the user-friendly interface (i.e., the user does not need to worry about padding the stack). - Internally,
account::set_item
does the stack padding and makes asyscall
toset_account_item
defined in api.masm. - Then,
set_account_item
performance procedure authentication and executesaccount::set_item
defined in miden/kernels/tx/account.masm.
a. As a side note, putting thekernels
modules into themiden
library was probably not a good decision - they should be in a separate library which is imported by theapi.masm
instead of themiden
library.
Flow between items 2 and 3 has been the source of quite a bit of confusion, and we should probably refactor it (as is described in #685) - but all of this is hidden from the user because exec.account::set_item
from the first step should work like any other function.
from miden-base.
The user runs exec.account::set_item in miden/accounts.masm. This is the procedure which has the user-friendly interface (i.e., the user does not need to worry about padding the stack).
This only works from inside the account context, as in set_item
is not a nice to use function for transaction scripts, for the account code, otherwise the authentication would fail. So there is another call
done by the tx script to the code that does set_item
. This is the one I'm referring to.
from miden-base.
This only works from inside the account context, as in
set_item
is not a nice to use function for transaction scripts, for the account code, otherwise the authentication would fail. So there is anothercall
done by the tx script to the code that doesset_item
. This is the one I'm referring to.
hmmm - account::set_item
should only be available from account context. Trying to execute it from transaction or note script should be an error. We list here which kernel procedure are allowed to be called from which context.
from miden-base.
Or I guess you mean we have a procedure on the account which internally invokes account::set_item
, and this procedure is called from a transaction script via the call
instruction. In this case yes, the caller is responsible for padding the stack and this is also one of the motivations for defining a consistent ABI described in #685.
from miden-base.
hmmm - account::set_item should only be available from account context. Trying to execute it from transaction or note script should be an error. We list here which kernel procedure are allowed to be called from which context.
Yes. We seem to agree on how it works. We don't seem to agree on how useful it is.
Basically what I'm trying to say is this only works as a nice to use function if you're writing the account code. And there is very little use for that. The vast majority of the code will be note scripts or tx scripts. At least in my eyes, the most common case should be the easiest. So that would be making the so-called nice to use functions usable from the tx script.
Account code is more complicated, we can't really hide the padding of the stack, because the function exposed by the account are call
ed, and they have to handle these conventions anyways. If they have to be aware of the convention when exposing the account's API, it doesn't seem that much extra to assume the author can call the kernel using the same convention.
from miden-base.
Basically what I'm trying to say is this only works as a nice to use function if you're writing the account code. And there is very little use for that. The vast majority of the code will be note scripts or tx scripts.
I am not sure about the last point. Writing account procedures which internally call kernel procedures would be fairly common too. I can't say whether it will be more or less common then writing note/tx scripts - but in my mind they are roughly comparable in importance.
I agree that there isn't much we can do with the procedures exposed by the account interface itself because they must be call
-ed. And #685 attempts to define a standard way to call them. But I don't think just because we can't make these procedures as "easy-to-use" as regular procedures, we should make other procedures more complicated.
So, basically, my thinking is:
- Invoking kernel procedures from within account procedures could work the way it does now (where the user does not need to worry about padding the stack).
- Invoking account procedures from note/tx scripts would be more complicated and the user would need to pad the stack, but the methodology for padding should be standardized to have a "uniform ABI".
from miden-base.
Related Issues (20)
- Challenges surrounding sub-second order-book performance on Miden
- Miden Assembly Linter? HOT 3
- Allow user to set the aux field when creating a note HOT 1
- Using hmerge to hash 9 or more stack elements HOT 12
- Add CI job for `doc` + make sure that Miden base passes `make doc` HOT 1
- winter_rand_utils Compiled Under Testing Feature Breaks for WASM Builds HOT 1
- Refactor `apply_delta` for Storage Maps HOT 3
- Allow increasing an account's nonce without changing its state HOT 1
- Add `create_wallet_with_custom_code` wallet helper function in miden-lib HOT 5
- Refactor transaction kernel events and errors
- Make memory setters consistent HOT 1
- Checking that a transaction does not consume two identical notes
- Update names used for input/output notes HOT 4
- Refactor batch/block note tree structure
- Refactor `NoteOrigin` / `NoteInclusionProof` structs
- Allow setting block timestamp and block number when using TransactionContextBuilder HOT 3
- Refactor delta's vault and storage to use maps HOT 1
- feat: add a procedure for basic wallets that creates notes with 0 or more assets
- Refactor account storage to use sequential hash rather than a Merkle tree
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from miden-base.