Skip to content

Commit 095596d

Browse files
Add example
1 parent fddba57 commit 095596d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

docs/vm/README.md

+38
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,44 @@ CASM instruction have the following format. If the instruction uses an immediate
157157

158158
For an in-depth explanation, you can see Cairo whitepaper, page 33 - https://eprint.iacr.org/2021/1063.pdf, or checkout [our implementation](/vm/src/vm/vm_core.rs).
159159

160+
Take, for example, the following instruction:
161+
162+
```bash
163+
[ap + 1] = [fp + 2] + 3
164+
```
165+
166+
The instruction (at `[pc]`) will be encoded as:
167+
168+
```bash
169+
off_dst = 1
170+
off_op0 = 2
171+
off_op1 = 1 # It's always 1 when op1 is an immediate
172+
dst_reg = 0 # AP
173+
op0_reg = 1 # FP
174+
op1_src = 1 # Immediate
175+
res_logic = 1 # Add
176+
pc_update = 0 # Regular (advance)
177+
ap_update = 0 # Regular (no update)
178+
opcode = 4 # Assert
179+
```
180+
181+
The next instruction (at `[pc + 1]`) will be the immediate, and it will have a value of `3`.
182+
183+
Given the following initial register values:
184+
```bash
185+
fp = 5
186+
ap = 10
187+
pc = 15
188+
```
189+
Then:
190+
- `op1` is `[fp + 2]`, which is resolved to `[7]`.
191+
- `op2` is `[pc + 1]`, which is resolved to `[16] == 3`.
192+
- `dst` is `[ap + 1]`, which is resolved to `[11]`
193+
- The result of `op1 + op2` is stored at `dst`
194+
- The register `pc` is increased by 2, we skip the next instruction because it was the immediate.
195+
- The register `fp` is not updated
196+
- The register `ap` is not updated
197+
160198
## Hints
161199

162200
So far we have been thinking about the VM mostly abstracted from the prover and verifier it's meant to feed its results to. The last main feature we need to talk about, however, requires keeping this proving/verifying logic in mind.

0 commit comments

Comments
 (0)