Files
powdr/test_data
Georg Wiese 1c465e566b Add MemoryWithBootloaderWrite machine to std (#1463)
This PR adds a new memory machine to the standard library that also
supports a `mstore_bootloader` operation: It's like a normal `mstore`,
but the first access to every memory cell *has to* come from this
operation.

As a follow-up, we'll be able to use it in the RISC-V machine (#1462).

I think this is best reviewed by reviewing the diff to the normal memory
machine and comparing it to [the code we have currently inlined in the
RISC-V
machine](abbe26618f/riscv/src/code_gen.rs (L500-L553)):

```diff
3,5c3,7
< // A read/write memory, similar to that of Polygon:
< // https://github.com/0xPolygonHermez/zkevm-proverjs/blob/main/pil/mem.pil
< machine Memory with
---
> /// This machine is a slightly extended version of std::machines::memory::Memory,
> /// where in addition to mstore, there is an mstore_bootloader operation. It behaves
> /// just like mstore, except that the first access to each memory cell must come
> /// from the mstore_bootloader operation.
> machine MemoryWithBootloaderWrite with
7c9
<     operation_id: m_is_write,
---
>     operation_id: operation_id,
13a16
>     operation mstore_bootloader<2> m_addr, m_step, m_value ->;
29a33
>     col witness m_is_bootloader_write;
30a35,36
>     std::utils::force_bool(m_is_bootloader_write);
>     col operation_id = m_is_write + 2 * m_is_bootloader_write;
35a42
>     (1 - is_mem_op) * m_is_bootloader_write = 0;
37,39c44,45
<     // If the next line is a not a write and we have an address change,
<     // then the value is zero.
<     (1 - m_is_write') * m_change * m_value' = 0;
---
>     // The first operation of a new address has to be a bootloader write
>     m_change * (1 - m_is_bootloader_write') = 0;
41,42c47,52
<     // change has to be 1 in the last row, so that a first read on row zero is constrained to return 0
<     (1 - m_change) * LAST = 0;
---
>     // m_change has to be 1 in the last row, so that the above constraint is triggered.
>     // An exception to this when the last address is -1, which is only possible if there is
>     // no memory operation in the entire chunk (because addresses are 32 bit unsigned).
>     // This exception is necessary so that there can be valid assignment in this case.
>     pol m_change_or_no_memory_operations = (1 - m_change) * (m_addr + 1);
>     LAST * m_change_or_no_memory_operations = 0;
46c56
<     (1 - m_is_write') * (1 - m_change) * (m_value' - m_value) = 0;
---
>     (1 - m_is_write' - m_is_bootloader_write') * (1 - m_change) * (m_value' - m_value) = 0;
➜  powdr git:(memory-with-bootloader-write) ✗ 
```
2024-06-24 21:02:07 +00:00
..