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

Change `sponge_absorb_mem` to be used in combination with `recurse_or_return`? #303

Open Sword-Smith opened 1 week ago

Sword-Smith commented 1 week ago

Cf. #302 instructions that mutate a pointer value should, if possible, read the pointer value from ST[5] or ST[6].

I think it should be possible to replace the loop-condition here if sponge_absorb_mem had five dummy-stack values instead of four and it mutated ST[5] instead of ST[0] as it does now.

            // BEFORE:    _ *remainder 0 0 0 0 *bfe_sequence
            // INVARIANT: _ *remainder a b c d *bfe_sequence'
            // AFTER:     _ *remainder e f g h *remainder
            {hash_all_full_chunks}:
                dup 5 dup 1 eq
                skiz return

                // _ *remainder a b c d *bfe_sequence
                sponge_absorb_mem

                // _ *remainder e f g h *bfe_sequence'
                recurse

With this change the code could be reduced to

            // BEFORE:    _ *remainder *bfe_sequence 0 0 0 0 0
            // INVARIANT: _ *remainder *bfe_sequence' a b c d e
            // AFTER:     _ *remainder *remainder f g h i j
            {hash_all_full_chunks}:
                sponge_absorb_mem
                recurse_or_return