0xPolygonMiden / miden-vm

STARK-based virtual machine
MIT License
621 stars 158 forks source link

Add procedures to read and verify data from the advice stack #1312

Open hackaugusto opened 5 months ago

hackaugusto commented 5 months ago

We often have to write code that does the following:

I think steps 1 through 3 should have a procedure, and step the another one for steps 1 through 4.

hackaugusto commented 5 months ago

Well, I just realized we have some of this functionality already:

https://github.com/0xPolygonMiden/miden-vm/blob/a20cb5f87e8bb21bbad6e1d884a5a7950ef9a52b/stdlib/asm/mem.masm#L157-L164

But we never use it because that is less efficient, because the counter goes to the stack, and we usually write code with a hardcoded constants. I guess we have a few alternatives:

export.pipe_to_memory_even(count)
  repead.@count
    adv_pipe hperm
  end
end

Where the @count would be replaced by the assembler, similar to a preprocessor.

hackaugusto commented 5 months ago

The idea of using constant seems to have an issue of its own: https://github.com/0xPolygonMiden/miden-vm/issues/297

bobbinth commented 4 months ago
  • Extend the assembly syntax to allow for constant arguments to procedures, something like:
export.pipe_to_memory_even(count)
  repead.@count
    adv_pipe hperm
  end
end

This is a bit tricky because for every value of @count, we'd have a different MAST root. This means that we won't be able to compile this function to MAST without knowing the calling context. The way the assembler is structured now, I believe something like that won't be possible, and also it won't be possible once we transition to MAST-based libraries. But overall, I agree, this would be a nice way to avoid some code duplication.