Unified stdlib procedures call and VM instructions syntax #755
hackaugusto
started this conversation in
Ideas
Replies: 1 comment 2 replies
-
I'd probably hold off on this for now and revisit when/if we ran out of instruction space.
This won't really work because changing procedures in meaningful ways will also change MAST roots and this will result in account interface commitment to be out of sync with assembly code. One thing that we will need to solve at some point is versioning: a |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What is this proposing?
Remove the need for the
exec.
syntax in front of stdlib procedures calls.Why?
This would unify the concept of instructions and stdlib procedures. The idea is to enable the following:
255 VM instructions
This limit exists because the instructions are represented using a single byte, and the space is close to run out.
Once we run out these are the options:
Smart contract pre-compiles
This point is analogous but not the same as smart contract precompiles, it makes more sense to call it pre-compile opcodes.
The VM has a few optimized opcodes already, like u32 arithmetic. However, it is unclear what users will need since there is no user code yet. The idea here is to allow the procedures in the stdlib to be optimized in a backwards compatible manner, this is only useful for on-chain account, which would otherwise need to replace their code to benefit of new optimizations (updating the code will likely not be supported for all accounts, e.g. token faucets).
Modify set of optimized instruction
In a future release it may be the case that we need to replace some internal data structures/algorithm. In that case we most likely will want to preserve the behavior of the existing code, albeit running slower, and add optimized operations for the new data structures. This proposal achieves this by allowing for de-optimizing instructions in a backwards compatible, for example, by replacing a
rpohash
with non-native operations.Downsides
Implementation
exec.
prefix from stdlib calls.u8
instruction representation in favor of astdlib_call
to a procedure. This is what causes the increase in the MASL size.stdlib_call.0x1234
which would be at least one word in length, we would havestdlib_call.<index>
which can be significantly smaller.stdlib_call
would not be content addressable, as in the value of the hashstdlib_call.0x1234
is not the instructions used in the procedure, but the procedure name.prelude prefix
The idea above allows the implementation of a stdlib procedure to change, but never its semantics. To allow for semantic changes there could be a versioned prelude, e.g.
prelude::v1
, deployed code would always refer to the previous prelude with the previous semantics, and new code would be compiled againstprelude::v2
with the new semantics.procedure hash
Because the code is no longer content addressed, this type of upgrade should be limited to the stdlib, user code would not be upgradable like this.
The idea is that the VM and the stdlib are maintained together and already trusted/auditable. So this type of addressing should be okay.
Procedure -> opcode translation
It would be very similar to what is done today in the Assembler, the difference is that the translation would be done in the procedure instead of the instruction level.
This proposal does not affect operation encoding/decoding, the program/MAST hashing, and any of the VM constraints, the proposal is exclusively about how to handle stdlib procedures.
Out of scope
Beta Was this translation helpful? Give feedback.
All reactions