triton-vm icon indicating copy to clipboard operation
triton-vm copied to clipboard

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

Open Sword-Smith opened this issue 8 months ago • 0 comments

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

Sword-Smith avatar Jun 17 '24 14:06 Sword-Smith