-
Notifications
You must be signed in to change notification settings - Fork 161
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
Support ability to specify advice data via MASM #1547
Comments
This change is beneficial to #1544 since I was thinking of a way to convey the notion that The MASM-facing part (syntax, parsing, etc.) of the implementation would take me quite a lot of time since I'm not familiar with the code, but the VM-facing part I believe I can do in a reasonable amount of time. If @bitwalker is ok with it, I can take a stab at it.
I've taken a look and here are my findings on what needs to be done to implement this:
Yes, I think it should be an error. From
If the user code treats the advice provider as a some sort of dictionary, that's a valid use case. I'm not sure if it should be an error. |
Yes, I think merging would work fine here. If there is a conflict (two entries with the same key by different data), we'd error out here as well.
Yeah - I think once we have this support for advice map entries in |
I'll wrap-up my current work ( |
The parser already knows how to parse various sizes of constants, including single words, or even arbitrarily large data (the size of the data itself indicates which type it is).
These would be effectively globally visible symbols, and while unlikely, you can have conflicting keys, so I think any attempt to make it seem like these can be scoped should be avoided.
I'm not sure how we handle this during execution today actually, presumably we just clobber the data if two things are loaded with the same key into the advice map? During assembly I think it has to be an error. It might be possible to skip the error if the data is the same, I think it's still an open question whether or not you would want to know about the conflicting key regardless. I'm questioning a bit whether it makes sense to define this stuff in Miden Assembly;
Setting that aside for a moment:
|
We'll need to catch conflicting keys (different values for the same key, but fine if the keys overlap with the same value), but a straight merge of the two maps should be fine otherwise.
Once we can write our rodata to the @greenhat For now, I would focus purely on the implementation around the |
In some situations it maybe desirable to specify some data which a given program assumes to be available in the advice provider. One example of this is read-only data output by the compiler, but there could be may other examples. Currently, such data needs to be loaded separately into the VM which introduces extra complexities.
One way around this is to allow users to define data which is to be loaded into the advice provider before a given program starts executing. The syntax for this in MASM could look like so:
Here,
advent
specifies that we want to add an entry to the advice map. The key for the entry would be the word defined by0x9dfb1fc9f2d5625a...
value. The data of the entry would be the list of field elements defined by the hex encoded string. We also provide a way to specify a labelFOO
by which they key can be referred to from the code. For example:Would push the key
0x9dfb1fc9f2d5625a...
onto the stack.Upon assembly, this data would be added to the
MastForest
. For this, we'd need to add a singleAdviceMap
property to theMastForest
struct - e.g., something like this:Then, when the VM starts executing a given MAST forest, it'll copy the contents of the advice map into its advice provider (we can also use a slightly more sophisticated strategy to make sure that the map is copied only once).
Open questions
While the above approach should work, there are a few things we need to clarify before implementing it:
FOO
refers to a full word. All our constants currently refer to single elements. Ideally, we should be able to tell by looking at the constant name whether it is for a full word or a single element. So, maybe we should come up with some simple scheme here to differentiate them?FOO
be accessible outside of the module it was defined in? It seems like it would be a good idea, but then we need to be able to apply some kind of visibility modifiers toadvent
.The text was updated successfully, but these errors were encountered: