Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce instruction merkle_step_mem #304

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions specification/src/arithmetization-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
| [CascadeTable](cascade-table.md) | 6 | 2 | 12 |
| [LookupTable](lookup-table.md) | 4 | 2 | 10 |
| [U32Table](u32-table.md) | 10 | 1 | 13 |
| DegreeLowering (-/8/4) | 0/111/203 | 0/14/36 | 0/153/311 |
| DegreeLowering (-/8/4) | 0/113/226 | 0/14/38 | 0/155/340 |
| Randomizers | 0 | 1 | 3 |
| **TOTAL** | **149/260/352** | **50/64/86** | **299/452/610** |
| **TOTAL** | **149/262/375** | **50/64/88** | **299/454/639** |
<!-- auto-gen info stop table_overview -->

## Constraints
Expand All @@ -44,14 +44,14 @@ Before automatic degree lowering:
| [U32Table](u32-table.md) | 1 | 15 | 22 | 2 | 12 |
| [Grand Cross-Table Argument](table-linking.md) | 0 | 0 | 0 | 14 | 1 |
| **TOTAL** | **79** | **76** | **150** | **23** | **19** |
| (# nodes) | (534) | (624) | (6077) | (213) | |
| (# nodes) | (534) | (624) | (6176) | (213) | |

After lowering degree to 8:

| table name | #initial | #consistency | #transition | #terminal |
|:-----------------------------------------------|---------:|-------------:|------------:|----------:|
| [ProgramTable](program-table.md) | 6 | 4 | 10 | 2 |
| [ProcessorTable](processor-table.md) | 29 | 10 | 158 | 1 |
| [ProcessorTable](processor-table.md) | 29 | 10 | 160 | 1 |
| [OpStackTable](operational-stack-table.md) | 3 | 0 | 5 | 0 |
| [RamTable](random-access-memory-table.md) | 7 | 0 | 12 | 1 |
| [JumpStackTable](jump-stack-table.md) | 6 | 0 | 6 | 0 |
Expand All @@ -60,15 +60,15 @@ After lowering degree to 8:
| [LookupTable](lookup-table.md) | 3 | 1 | 4 | 1 |
| [U32Table](u32-table.md) | 1 | 18 | 24 | 2 |
| [Grand Cross-Table Argument](table-linking.md) | 0 | 0 | 0 | 14 |
| **TOTAL** | **79** | **80** | **271** | **23** |
| (# nodes) | (534) | (635) | (6335) | (213) |
| **TOTAL** | **79** | **80** | **273** | **23** |
| (# nodes) | (534) | (635) | (6438) | (213) |

After lowering degree to 4:

| table name | #initial | #consistency | #transition | #terminal |
|:-----------------------------------------------|---------:|-------------:|------------:|----------:|
| [ProgramTable](program-table.md) | 6 | 4 | 10 | 2 |
| [ProcessorTable](processor-table.md) | 31 | 10 | 209 | 1 |
| [ProcessorTable](processor-table.md) | 31 | 10 | 234 | 1 |
| [OpStackTable](operational-stack-table.md) | 3 | 0 | 5 | 0 |
| [RamTable](random-access-memory-table.md) | 7 | 0 | 13 | 1 |
| [JumpStackTable](jump-stack-table.md) | 6 | 0 | 7 | 0 |
Expand All @@ -77,8 +77,8 @@ After lowering degree to 4:
| [LookupTable](lookup-table.md) | 3 | 1 | 4 | 1 |
| [U32Table](u32-table.md) | 1 | 26 | 34 | 2 |
| [Grand Cross-Table Argument](table-linking.md) | 0 | 0 | 0 | 14 |
| **TOTAL** | **81** | **94** | **369** | **23** |
| (# nodes) | (538) | (676) | (6557) | (213) |
| **TOTAL** | **81** | **94** | **394** | **23** |
| (# nodes) | (538) | (676) | (6731) | (213) |
<!-- auto-gen info stop constraints_overview -->


Expand All @@ -90,8 +90,8 @@ In order to gauge the runtime cost for this step, the following table provides e
<!-- auto-gen info start tasm_air_evaluation_cost -->
| Type | Processor | Op Stack | RAM |
|:-------------|----------:|---------:|------:|
| static | 34609 | 64237 | 22716 |
| dynamic | 45793 | 71697 | 26444 |
| static | 35381 | 65645 | 23226 |
| dynamic | 46805 | 73265 | 27034 |
<!-- auto-gen info stop tasm_air_evaluation_cost -->

## Opcode Pressure
Expand All @@ -107,7 +107,7 @@ The table below helps answer this question at a glance.
| n | n | y | 8 |
| n | y | n | 11 |
| n | y | y | 3 |
| y | n | n | 5 |
| y | n | n | 6 |
| y | n | y | 0 |
| y | y | n | 4 |
| y | y | y | 0 |
Expand Down
1 change: 1 addition & 0 deletions specification/src/instruction-groups.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ A summary of all instructions and which groups they are part of is given in the
| `read_io` + `n` | x | x | | x | | | x | | x | | | | | | |
| `write_io` + `n` | x | x | | x | | | x | | | | | | | | x |
| `merkle_step` | | | x | x | | x | | | | | 6 | | | | |
| `merkle_step_mem` | | | x | | | x | | | | | 8 | | | | |
| `xx_dot_step` | | | x | | | | | | | x | 5 | | | | |
| `xb_dot_step` | | | x | | | | | | | x | 5 | | | | x |

Expand Down
19 changes: 19 additions & 0 deletions specification/src/instruction-specific-transition-constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,25 @@ The two [Evaluation Arguments also used for instruction hash](processor-table.md
1. `hv0` through `hv4` hold the sibling digest of the node indicated by `st5`, as read from the interface for non-deterministic input.
1. `hv5` holds the result of `st5 % 2`, the Merkle tree node index's least significant bit, indicating whether it is a left or right node.

## Instruction `merkle_step_mem`

In addition to its [instruction groups](instruction-groups.md), this instruction has the following constraints.
The two [Evaluation Arguments also used for instruction hash](processor-table.md#transition-constraints) guarantee correct transition of the top of the stack.
See also [`merkle_step`](#instruction-merkle_step).

### Description

1. Stack element `st6` does not change.
1. Stack element `st7` is incremented by 5.
1. Helper variable `hv5` is either 0 or 1.
1. `st5` is shifted by 1 bit to the right. In other words, twice `st5` in the next row plus `hv5` equals `st5` in the current row.
1. The running product with the RAM Table accumulates `hv0` through `hv4` using the (appropriately adjusted) RAM pointer held in `st7`.

### Helper variable definitions for `merkle_step_mem`

1. `hv0` through `hv4` hold the sibling digest of the node indicated by `st5`, as read from RAM at the address held in `st7`.
1. `hv5` holds the result of `st5 % 2`, the Merkle tree node index's least significant bit, indicating whether it is a left or right node.

## Instruction `xx_dot_step`

In addition to its [instruction groups](instruction-groups.md), this instruction has the following constraints.
Expand Down
25 changes: 18 additions & 7 deletions specification/src/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Should the jump stack be empty, executing any of these instruction causes Triton
Instruction `recurse_or_return` behaves – surprise! – either like instruction `recurse` or like instruction `return`.
The (deterministic) decision which behavior to exhibit is made at runtime and depends on stack elements `st5` and `st6`.
If `st5 != st6`, then `recurse_or_return` acts like instruction `recurse`, else like `return`.
The instruction is designed to facilitate loops using pointer equality as termination condition and to play nicely with instruction `merkle_step`.
The instruction is designed to facilitate loops using pointer equality as termination condition and to play nicely with instructions [`merkle_step`](#many-in-one) and [`merkle_step_mem`](#many-in-one).

## Memory Access

Expand Down Expand Up @@ -148,11 +148,12 @@ Triton VM cannot know the number of elements that will be absorbed.

## Many-In-One

| Instruction | Opcode | old op stack | new op stack | Description |
|:--------------|:-------|:----------------|:-----------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `merkle_step` | 36 | `_ i edcba` | `_ (i div 2) zyxwv` | Helps traversing a Merkle tree during authentication path verification. Crashes the VM if `i` is not u32. See extended description below. |
| `xx_dot_step` | 80 | `_ z y x *b *a` | `_ z+p2 y+p1 x+p0 *b+3 *a+3` | Reads two extension field elements from RAM located at the addresses corresponding to the two top stack elements, multiplies the extension field elements, and adds the product `(p0, p1, p2)` to an accumulator located on stack immediately below the two pointers. Also, increase the pointers by the number of words read. |
| `xb_dot_step` | 88 | `_ z y x *b *a` | `_ z+p2 y+p1 x+p0 *b+3 *a+1` | Reads one base field element from RAM located at the addresses corresponding to the top of the stack, one extension field element from RAM located at the address of the second stack element, multiplies the field elements, and adds the product `(p0, p1, p2)` to an accumulator located on stack immediately below the two pointers. Also, increase the pointers by the number of words read. |
| Instruction | Opcode | old op stack | new op stack | Description |
|:------------------|:-------|:----------------|:-----------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `merkle_step` | 36 | `_ i edcba` | `_ (i div 2) zyxwv` | Helps traversing a Merkle tree during authentication path verification. Crashes the VM if `i` is not u32. See extended description below. |
| `merkle_step_mem` | 44 | `_ p f i edcba` | `_ p+5 f (i div 2) zyxwv` | Helps traversing a Merkle tree during authentication path verification with the authentication path being supplied in RAM. Crashes the VM if `i` is not u32. See extended description below. |
| `xx_dot_step` | 80 | `_ z y x *b *a` | `_ z+p2 y+p1 x+p0 *b+3 *a+3` | Reads two extension field elements from RAM located at the addresses corresponding to the two top stack elements, multiplies the extension field elements, and adds the product `(p0, p1, p2)` to an accumulator located on stack immediately below the two pointers. Also, increase the pointers by the number of words read. |
| `xb_dot_step` | 88 | `_ z y x *b *a` | `_ z+p2 y+p1 x+p0 *b+3 *a+1` | Reads one base field element from RAM located at the addresses corresponding to the top of the stack, one extension field element from RAM located at the address of the second stack element, multiplies the field elements, and adds the product `(p0, p1, p2)` to an accumulator located on stack immediately below the two pointers. Also, increase the pointers by the number of words read. |

The instruction `merkle_step` works as follows.
The 6th element of the stack `i` is taken as the node index for a Merkle tree that is claimed to include data whose digest is the content of stack registers `st4` through `st0`, i.e., `edcba`.
Expand All @@ -166,4 +167,14 @@ In either case,
1. the left and right digests are hashed, and the resulting digest `zyxwv` replaces the top of the stack, and
1. 6th register `i` is shifted by 1 bit to the right, _i.e._, the least-significant bit is dropped.

In conjunction with instruction `assert_vector`, the instruction `merkle_step` allows to efficiently verify a Merkle authentication path.
Instruction `merkle_step_mem` works very similarly to instruction `merkle_step`.
The main difference, as the name suggests, is the source of the sibling digest:
Instead of reading it from the input interface of secret data, it is supplied via RAM.
Stack element `st7` is taken as the RAM pointer, holding the memory address at which the next sibling digest is located in RAM.
Executing instruction `merkle_step_mem` increments the memory pointer by the length of one digest, anticipating an authentication path that is laid out continuously.
Stack element `st6` does not change when executing instruction `merkle_step_mem` in order to facilitate instruction `recurse_or_return`.

In conjunction with instructions `recurse_or_return` and `assert_vector`, the instructions `merkle_step` and `merkle_step_mem` allow efficient verification of a Merkle authentication path.
Furthermore, instruction `merkle_step_mem` allows verifiable _re_-use of an authentication path.
This is necessary, for example, when verifiably updating a Merkle tree:
first, the authentication path is used to confirm inclusion of some old leaf, and then to compute the tree's new root from the new leaf.
Loading