Skip to content
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

Experimental VM-based compilation to VampIR #2241

Closed
wants to merge 29 commits into from
Closed

Experimental VM-based compilation to VampIR #2241

wants to merge 29 commits into from

Conversation

lukaszcz
Copy link
Collaborator

@lukaszcz lukaszcz commented Jul 3, 2023

Implemented

  • Adds a vampir-vm target which compiles to a VM run on top of VampIR (the VM is compiled to a circuit, specialized to the particular Juvix program).
  • Introduces JuvixVM assembly bytecode (Juvix/Compiler/VM) with a parser and an interpreter. Similar to JuvixAsm/JuvixReg, but simpler, more "primitive", and thus easier to write an interpreter for in VampIR.
  • VampIR runtime to execute (interpret) JuvixVM bytecode (runtime/src/vampir/vm.pir).
  • Translation from JuvixVM to VampIR.
  • Partial translation from JuvixReg to JuvixVM. In combination with the JuvixVM -> VampIR translation, this enables a Juvix -> VampIR VM pipeline. Some features are not supported, notably closures.

Not done and not planned

  • Support for closures (requires JuvixVM runtime implementing general closure call with JuvixVM instructions). Clear how to do, but tedious engineering work.
  • Pretty printing of JuvixVM code (useful only for debugging).
  • Division and modulus require Feature request: a non-crashing modulo operation vamp-ir#113, otherwise they're too slow.

Conclusion

The approach is to translate to a VM that is compiled into a circuit. This doesn't seem feasible in practice. The efficiency of this solution is prohibitively poor and it's not clear how to substantially improve it.

It seems that zkVMs typically don't execute on circuits. They consist of an optimized executor which executes the program and generates an execution trace. A separate prover then checks and proves the validity of the execution trace, outputting a witness which can be independently verified. Hence, only the validity of the execution trace is subject to proof/verification. The VM is a conventional VM run natively, except that it generates an appropriate execution trace. Encoding a VM into a circuit seems completely infeasible.

See: Building a zkVM application

Possible future work

The JuvixVM language could potentially be used as a basis for an optimized low-level implementation of a VM generating appropriate execution traces.

@lukaszcz lukaszcz added enhancement New feature or request pipeline:vampir-vm labels Jul 3, 2023
@lukaszcz lukaszcz added this to the 0.4.2 milestone Jul 3, 2023
@lukaszcz lukaszcz self-assigned this Jul 3, 2023
@jonaprieto jonaprieto modified the milestones: 0.4.2, 0.4.3 Jul 24, 2023
@lukaszcz lukaszcz marked this pull request as ready for review July 26, 2023 16:21
@lukaszcz
Copy link
Collaborator Author

lukaszcz commented Jul 27, 2023

Since this doesn't work in practice at present, we defer the PR. See Deferred Pull Requests.

@lukaszcz lukaszcz closed this Jul 27, 2023
@jonaprieto jonaprieto deleted the vampir-vm branch November 28, 2023 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pipeline:vampir-vm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants