TritonVM / triton-vm

Triton is a virtual machine that comes with Algebraic Execution Tables (AET) and Arithmetic Intermediate Representations (AIR) for use in combination with a STARK proof system.
https://triton-vm.org
Apache License 2.0
223 stars 35 forks source link

Instruction Maybe-Wishlist for Recursion and Consensus #259

Open aszepieniec opened 3 months ago

aszepieniec commented 3 months ago

This is a tracking issue. We add imagined instructions that could make recursion (or consensus programs) faster.

read_mem_forward

dot_step

merkle_step

get_colinear_y

recurse_or_return

absorb_from_mem

Sword-Smith commented 3 months ago

It turns out the the opstack table height is the bottle-neck in the verifier, not the clock cycle count (which is recorded by the processor table). So counting number of clock cycles that a new instruction would shave off might not be the relevant metric.

I was considering a recurse instruction that acted as the current recurse if the top to stack elements are different and acts as return if the two top stack elements are the same. That would probably shave off a good amount of both opstack table rows since the start of almost all our loops looks like this:

loop_label:
    dup <m>
    dup <n>
    eq
    skiz return

    <loop body>
    recurse

This new recurse instruction would save 4 opstack table rows and 4 clock cycles for each loop iteration.

Sword-Smith commented 1 month ago

I guess my view has changed a bit.

The recurse_or_return I think would work best is one that returns if ST[5] == 1. Otherwise it recurses. That could be used in combination with merkle_step to reduce the loop body to 2 instructions.

A loop that walks up a Merkle tree would then be:

auth_path_loop:
    merkle_step
    recurse_or_return

I understand that this creates a problem for Merkle trees of height 0, with only one node. But I think that's not a practical problem.

edit: but let's see where we stand after having added the dot_steps and the merkle_step.