GuildOfWeavers / distaff

Zero-knowledge virtual machine written in Rust
MIT License
244 stars 44 forks source link

Introduce high-degree operations #18

Closed bobbinth closed 4 years ago

bobbinth commented 4 years ago

Currently, all instructions are encoded using 5 bit representation. This has several implications:

  1. There can be at most 32 operations
  2. All operations must have degree 3 or less

However, most operations have degree 2 or less with HASHR and CMP being two exceptions.

We can expand the encoding of instructions to 7 bits, such that the upper 2 bits encode high-degree operations, while lower 5 bits encode low-degree operations. This would enable the following:

  1. The number of operations would increase to 34. Out of these:
    1. 2 operations would be of degree 6 or less
    2. 30 operations would be of degree 3 or less
    3. 2 operations: BEGIN and NOOP would span all 7 bits (would be shared between two groups of instructions)
  2. We could move HASHR operation into the high-degree group and increase S-Box degree to 5.
  3. We could move CMP operation to the high-degree group and simplify the constraints so that they don't need to rely on aux stack register.
  4. We would be able to use the 8th bit in all opcodes to enable instruction mirroring in the alt stack.