Nexus Virtual Machine
The Nexus Virtual Machine (Nexus VM or NVM) is a reduced instruction set computer (RISC) with a byte-addressable random-access memory and a private input tape. This virtual machine abstraction is comparable to others used in the zero-knowledge research space, such as the TinyRAM architecture specification (opens in a new tab). The advantage of using such random-access machines is that they abstract away details of the underlying hardware or operating system and provide a convenient tool for generating claims and proofs about the correctness of a computation.
The NVM architecture has not yet stabilized. The following specification describes the architecture as of the Nexus zkVM 0.2.0 release.
Nexus Virtual Machine Architecture
The Nexus Virtual Machine has a von Neumann architecture, storing instructions and data in the same read-write memory space. The machine has 32 registers and a read-write memory with addresses in the range . The state of the machine is defined as a four-tuple, , where
- denotes the program counter register;
- denotes the memory;
- denotes the state of registers;
- is the private input.
Both and are finite maps. The keys of are addresses in the range . The values of are 8-bit bytes. The keys of are register selectors from the set . The values of are 32-bit words. A word (resp. a halfword) is represented as four (resp. two) consecutive bytes in little endian. By design, updates to register are ignored and the value of is always zero.
The current implementation of the Nexus VM does not yet support providing public inputs at runtime. Also, we remark that during compilation the Nexus VM may be configured to use memory sizes smaller than for efficiency reasons.
At initialization, all the general-purpose registers are set to 0. The program counter is set to . The private input tape contains the byte-encoded private input for the program. Since is initially , the first instruction to be executed will be the one stored at the position of the memory. Since the program code resides in the same area as the data, the initial memory can contain not only the program code but also some initial public input data for the program.
The program counter is always advanced by 4 bytes after the execution of each instruction, unless the instruction itself sets the value of . Moreover, the Nexus VM enforces 4-byte memory alignment for the program counter by checking that is a multiple of 4 when reading an instruction.
Nexus Virtual Machine Instruction Set
The Nexus VM instruction set contains 41 instructions in total, as summarized in table below. Each instruction is specified via an mnemonic and can take some arguments, typically register selectors and an immediate value. The exact format of each instruction is defined as follows:
- is a string name of the instruction;
- is a register selector specifying the destination register;
- is a register selector specifying the first operand;
- is a register selector specifying the second operand; and
- is an immediate value, whose size varies according to instructions.
Table: Summary of the Nexus Virtual Machine Instruction Set, where operations are mod .
Instruction mnemonic | Arguments | Description of functionality |
---|---|---|
sets to | ||
sets to | ||
sets to | ||
sets to | ||
sets to | ||
sets to (signed comparison) | ||
sets to (signed comparison) | ||
sets to (unsigned comparison) | ||
sets to (unsigned comparison) | ||
sets to | ||
sets to | ||
sets to (with zero extension) | ||
sets to (with zero extension) | ||
sets to (with sign extension) | ||
sets to (with sign extension) | ||
sets to the bitwise XOR of and | ||
sets to the bitwise XOR of and | ||
sets to the bitwise AND of and | ||
sets to the bitwise AND of and | ||
sets to the bitwise OR of and | ||
sets to the bitwise OR of and | ||
branches to if | ||
branches to if | ||
branches to if (signed comparison) | ||
branches to if (signed comparison) | ||
branches to if (unsigned comparison) | ||
branches to if (unsigned comparison) | ||
loads the sign extension of the byte at into | ||
loads the sign extension of the half-word at into | ||
loads the word at into | ||
loads the zero extension of the byte at into | ||
loads the zero extension of the half-word at into | ||
stores the least significant byte of at | ||
stores the less significant half-word of at | ||
stores at | ||
jumps to and stores into | ||
jumps to and stores into | ||
No operation | ||
system call | ||
system call | ||
jumps to ; in effect looping forever at the current program counter |
The Nexus VM also enforces 2-byte and 4-byte memory alignments for the instructions operating on half-words and words.
Each instruction is encoded as a 32-bit-long string, ending with 7-bit-long string, preceded by a 5-bit-long register selector in many cases, and other data depending on the operation.
Table: Binary Encoding of Nexus Virtual Machine Instructions, where denotes any binary string of bits, and , , denote respectively the binary representation of the 5-bit-long register selectors , , .
The notation each denote immediate values, interpreted the same way as -immediate values of 32-bit RISC-V architecture. Some immediate values (type B and S) occupy discontiguous positions, so their fragments are written as and . denotes a 5-bit long immediate value.
and contain 20 bits. contains 12 bits. and contain 5 bits. and contain 7 bits.
Instruction mnemonic | Arguments | Binary Encodings (left: most significant bit) |
---|---|---|
The current architecture does not specify an output tape. Nevertheless, one can easily return arbitrary strings as output by encoding that string in some specific region of the memory.
Nexus Virtual Machine Initialization
Initially, the memory is assumed to only contain zero values and all the general-purpose registers are set to 0. The program counter is also set to . The program itself is provided to the Nexus VM via a file in an Executable and Linkable Format (ELF) encoded according to the RV32I Instruction Set in the Volume I, Unprivileged Specification version 20191213 in the The RISC-V Instruction Set Manual (opens in a new tab).
Each instruction in the program is loaded one at a time into the memory starting at address .
Nexus Virtual Machine Extensions
While the universality of the current instruction set allows for executing any program on the Nexus VM, writing a program for the VM may yield inefficient programs due to the limited instruction set of the Nexus VM. As a result, proving the correctness of such computations within the Nexus zkVM may become infeasible for more complex programs. The cost of such an abstraction may be multiplied by more than a factor for functions such as the SHA-256 circuit.
To deal with such scenarios, the Nexus Virtual Machine is being designed with extensibility in mind in order to enable the addition of custom instructions for more complex functions, such as hashing and signature verification.
Currently, the Nexus Virtual Machine uses universal circuits to simulate the whole CPU and this unfortunately increases the complexity of the Nexus Proof System with each additional instruction.
Nevertheless, we will soon be switching to a non-uniform computation model based on recent advances in folding and accumulation techniques (e.g., [KS22], [BC23]), via the concept of zkVM precompiles. In the new model, the cost of proving custom precompile extensions of the NVM instruction set only occurs when that particular precompile is executed by the program.
The main advantage of using precompiles is that it maintains a developer-friendly CPU abstraction while efficiently allowing for the addition of more complex functions.
We intend to eventually support user-defined precompiles that could be provided as extensions of the Nexus zkVM. We expect to first implement these special functions as part of the Nexus VM instruction set.
References
[BBHR19 (opens in a new tab)] Eli Ben-Sasson, Iddo Bentov, Yinon Horesh, and Michael Riabzev. “Scalable zero knowledge with no trusted setup”. In CRYPTO 2019.
[BC23 (opens in a new tab)] Benedikt Bünz and Binyi Chen. “Protostar: Generic efficient accumulation/folding for special sound protocols”. In: Cryptology ePrint Archive (2023)
[BCKL22 (opens in a new tab)] Eli Ben-Sasson, Dan Carmon, Swastik Kopparty, and David Levit. “Scalable and transparent proofs over all large fields, via elliptic curves”. In: Electronic Colloquium on Computational Complexity, Report. Vol. 110. 2022, p. 2022
[CBBZ23 (opens in a new tab)] Binyi Chen, Benedikt Bünz, Dan Boneh, and Zhenfei Zhang. “Hyperplonk: Plonk with linear-time prover and high-degree custom gates”. In EUROCRYPT 2023.
[GGPR13 (opens in a new tab)] Rosario Gennaro, Craig Gentry, Bryan Parno, and Mariana Raykova. “Quadratic span programs and succinct NIZKs without PCPs”. In EUROCRYPT 2013.
[GWC19 (opens in a new tab)] Ariel Gabizon, Zachary J Williamson, and Oana Ciobotaru. “Plonk: Permutations over lagrange-bases for oecumenical noninteractive arguments of knowledge”. In: Cryptology ePrint Archive (2019)
[KS22 (opens in a new tab)] Abhiram Kothapalli and Srinath Setty. “SuperNova: Proving universal machine executions without universal circuits”. In: Cryptology ePrint Archive (2022)
[Sta21 (opens in a new tab)] StarkWare. ethSTARK Documentation. Cryptology ePrint Archive, Paper 2021/582.
[STW23 (opens in a new tab)] Srinath Setty, Justin Thaler, and Riad Wahby. “Customizable constraint systems for succinct arguments”. In: Cryptology ePrint Archive (2023)