Communicating with the host #764
Replies: 2 comments
-
I think we can stack this problem like the following:
Each option has stronger features for VM -> Host communication. DirectionMiden definitely needs a way for the host to inject data into the VM, and this is solved with the Advice provider. However, it is unclear if the other direction from the VM to the host is also required. In this scenario the VM can not provide data to the host program. The VM execution would represent a state transition function of the host program. The VM's inputs would be something like the hash of the previous state and next, and the VM execution would validate that the protocol invariants are held through the transition. The assumption is that the host program has already executed its progam code, and it only needs to provide to the VM the data it needs to prove the execution was valid w.r.t. its protocol. ProsThe advantage of not supporting pushing data form the VM to the host is simplicity. In this case there is no need to add instructions to the VM and APIs to the Miden code base for the host to read data. With this approach even though the VM is capable of running arbitrary computation, the user code would not be structured for that. IOW, the host program would be fully fledged, and run the complete program, and the VM would only run a model that proves the host program was executed correctly. This means the code executed in the VM would be simpler, take fewer cycles and maybe result in better proving performance. ConsThis effectively means the VM is intended to run a small model of the full program, which means there is a need for two implementations, one in Miden and one in the host program. StructureIn this scenario Miden would be more than a prover, instead the VM execution would be part of the host program architecture and the host program needs to read data from the VM. For this the VM needs to expose APIs to read data, but the interpretation of the data is left to the host program, i.e. the host program can read bytes This is scenario is akin to memory mapping some of the VM's memory on the host. ProsThe advantage of not having knowledge of the structure in the VM, is that we don't need to add complex APIs to represent this in the VM. We just have to document the APIs to read the VM's memory and leave for the API's user to:
ConsThis will likely be harder to debug Validity of the dataIn this scenario, not only the Miden program is part of the host architecture, but there are APIs allowing the host to integrate with the VM and validate the data produced during the VM execution. The host program would not need to deserialize data and instead would implement some interface to be plugged in the VM, at the end of the execution the data structures would be available to the host program. ProsPerhaps this would be the best programming model if VM -> Host communication is allowed. Assuming debugging would be easier because the Host data structure implementation would validate the data, and the execution would fail on the instruction that produced invalid data ConsThis is way more complex, and would probably require a lot of work |
Beta Was this translation helpful? Give feedback.
-
this has been implemented with events |
Beta Was this translation helpful? Give feedback.
-
The Miden VM can perform arbitrary computation, that means the user program may create arbitrarily complicated data structures, and it may be useful to communicate the data produced by the Miden execution back to the host.
Here is an small example that builds a Merkle tree and supports an odd number of elements (not properly tested):
Code to build a Merkle tree
Assuming a program like this:
At the end of the execution we will have in memory a tree like this:
This discussion is on how to extract that data from the VM's memory into the host program.
Beta Was this translation helpful? Give feedback.
All reactions