Skip to content

Commit

Permalink
Merge branch 'dw/mips-makefile-import' into martin/gen-state-json
Browse files Browse the repository at this point in the history
  • Loading branch information
martyall authored Jan 2, 2025
2 parents defd5cc + 2637499 commit d7a7e98
Show file tree
Hide file tree
Showing 42 changed files with 948 additions and 101 deletions.
2 changes: 1 addition & 1 deletion book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
- [Commitments](./fundamentals/zkbook_commitment.md)
- [Polynomial Commitments](./plonk/polynomial_commitments.md)
- [Inner Product Argument](./plonk/inner_product.md)
- [Different Functionnalities](./plonk/inner_product_api.md)
- [Different Functionalities](./plonk/inner_product_api.md)
- [Two Party Computation](./fundamentals/zkbook_2pc/overview.md)
- [Garbled Circuits](./fundamentals/zkbook_2pc/gc.md)
- [Basics](./fundamentals/zkbook_2pc/basics.md)
Expand Down
2 changes: 1 addition & 1 deletion book/src/plonk/zkpm.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ $$
= Z(\omega h)[(a(h) + \beta S_{\sigma1}(h) + \gamma)(b(h) + \beta S_{\sigma2}(h) + \gamma)(c(h) + \beta S_{\sigma3}(h) + \gamma)]$$


The modified permuation checks that ensures that the check is performed only on all the values except the last $k$ elements in the witness polynomials are as follows.
The modified permutation checks that ensures that the check is performed only on all the values except the last $k$ elements in the witness polynomials are as follows.

* For all $h \in H$, $L_1(h)(Z(h) - 1) = 0$
* For all $h \in \blue{H\setminus \{h_{n-k}, \ldots, h_n\}}$, $$\begin{aligned} & Z(h)[(a(h) + \beta h + \gamma)(b(h) + \beta k_1 h + \gamma)(c(h) + \beta k_2 h + \gamma)] \\
Expand Down
2 changes: 1 addition & 1 deletion o1vm/README-optimism.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Install the first dependencies:
```
sudo apt update
# chrony will ensure the system clock is open to date
# chrony will ensure the system clock is up to date
sudo apt install build-essential git vim chrony ufw -y
```

Expand Down
Binary file added o1vm/resources/programs/riscv32im/bin/add_sub_swap
Binary file not shown.
Binary file not shown.
Binary file modified o1vm/resources/programs/riscv32im/bin/addi_negative
Binary file not shown.
Binary file added o1vm/resources/programs/riscv32im/bin/addi_overflow
Binary file not shown.
Binary file added o1vm/resources/programs/riscv32im/bin/and
Binary file not shown.
Binary file added o1vm/resources/programs/riscv32im/bin/div_by_zero
Binary file not shown.
Binary file added o1vm/resources/programs/riscv32im/bin/divu_by_zero
Binary file not shown.
Binary file added o1vm/resources/programs/riscv32im/bin/jal
Binary file not shown.
Binary file added o1vm/resources/programs/riscv32im/bin/mul_overflow
Binary file not shown.
Binary file added o1vm/resources/programs/riscv32im/bin/rem_by_zero
Binary file not shown.
Binary file added o1vm/resources/programs/riscv32im/bin/remu_by_zero
Binary file not shown.
Binary file added o1vm/resources/programs/riscv32im/bin/slt
Binary file not shown.
Binary file added o1vm/resources/programs/riscv32im/bin/sub
Binary file not shown.
Binary file added o1vm/resources/programs/riscv32im/bin/sub_2
Binary file not shown.
Binary file added o1vm/resources/programs/riscv32im/bin/sub_3
Binary file not shown.
Binary file added o1vm/resources/programs/riscv32im/bin/xor
Binary file not shown.
22 changes: 22 additions & 0 deletions o1vm/resources/programs/riscv32im/src/add_sub_swap.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.section .text
.globl _start

_start:
li t0, 5 # t0 = 5
li t1, 10 # t1 = 10

# Swap t0 and t1 using add
add t2, t0, t1 # t2 = t0 + t1 (t2 = 5 + 10 = 15)
sub t0, t2, t0 # t0 = t2 - t0 (t0 = 15 - 5 = 10)
sub t1, t2, t1 # t1 = t2 - t1 (t1 = 15 - 10 = 5)

# Custom exit syscall
li a0, 0
li a1, 0
li a2, 0
li a3, 0
li a4, 0
li a5, 0
li a6, 0
li a7, 42
ecall
20 changes: 20 additions & 0 deletions o1vm/resources/programs/riscv32im/src/addi_boundary_immediate.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.section .text
.globl _start

_start:
li t0, 100 # t0 = 100
addi t1, t0, 2047 # t1 = t0 + 2047 (Expected: t1 = 2147)

li t2, 1000 # t2 = 1000
addi t3, t2, -2048 # t3 = t2 + (-2048) (Expected: t1 = -1048)

# Custom exit syscall
li a0, 0
li a1, 0
li a2, 0
li a3, 0
li a4, 0
li a5, 0
li a6, 0
li a7, 42
ecall
3 changes: 3 additions & 0 deletions o1vm/resources/programs/riscv32im/src/addi_negative.S
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ _start:
# Subtract 100 using addi (addi with negative immediate)
addi t2, t1, -100 # t2 = t1 + (-100) (Expected: t2 = -50)

li t3, -1000 # t3 = -1000
addi t4, t3, -500 # t4 = t0 + (-500) (Expected: t4 = -1500)

# Custom exit syscall
li a0, 0
li a1, 0
Expand Down
23 changes: 23 additions & 0 deletions o1vm/resources/programs/riscv32im/src/addi_overflow.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.section .text
.globl _start

_start:
li t0, 2147483647 # t0 = 2147483647 (Max 32-bit signed int)
addi t1, t0, 1 # t1 = t0 + 1 (Expected: overflow to -2147483648)

li t2, -2147483648 # t2 = -2147483648 (Min 32-bit signed int)
addi t3, t2, -1 # t3 = t2 + (-1) (Expected: overflow to 2147483647)

li t4, 123456789 # t4 = 123456789
addi t5, t4, 0 # t5 = t4 + 0 (Expected: t4 = 123456789)

# Custom exit syscall
li a0, 0
li a1, 0
li a2, 0
li a3, 0
li a4, 0
li a5, 0
li a6, 0
li a7, 42
ecall
30 changes: 30 additions & 0 deletions o1vm/resources/programs/riscv32im/src/and.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.section .text
.globl _start

_start:

# Simple AND
li t0, 0b1100 # t0 = 0b1100
li t1, 0b1010 # t1 = 0b1010
and t2, t0, t1 # t2 = t0 & t1 (Expected: t2 = 0b1000)

# AND with zero (result always zero)
li t3, 0b1111 # t3 = 0b1111
li t4, 0 # t4 = 0
and t5, t3, t4 # t5 = t3 & t4 (Expected: t5 = 0)

# AND of identical values (result same value)
li t6, 0b1010 # t6 = 0b1010
li t0, 0b1010 # t0 = 0b1010
and t1, t6, t0 # t1 = t6 & t0 (Expected: t1 = 0b1010)

# Custom exit syscall
li a0, 0
li a1, 0
li a2, 0
li a3, 0
li a4, 0
li a5, 0
li a6, 0
li a7, 42
ecall
19 changes: 19 additions & 0 deletions o1vm/resources/programs/riscv32im/src/div_by_zero.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.section .text
.globl _start

_start:
# Signed division by zero (div)
li t0, 42 # t0 = 42
li t1, 0 # t1 = 0
div t2, t0, t1 # t2 = t0 / t1 (Expected: division by zero)

# Custom exit syscall
li a0, 0
li a1, 0
li a2, 0
li a3, 0
li a4, 0
li a5, 0
li a6, 0
li a7, 42
ecall
19 changes: 19 additions & 0 deletions o1vm/resources/programs/riscv32im/src/divu_by_zero.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.section .text
.globl _start

_start:
# Unsigned division by zero (div)
li t0, 42 # t0 = 42
li t1, 0 # t1 = 0
divu t2, t0, t1 # t2 = t0 / t1 (Expected: division by zero)

# Custom exit syscall
li a0, 0
li a1, 0
li a2, 0
li a3, 0
li a4, 0
li a5, 0
li a6, 0
li a7, 42
ecall
25 changes: 25 additions & 0 deletions o1vm/resources/programs/riscv32im/src/jal.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.section .text
.global _start

# t0 <- t0 + t1
add_t0_t1:
add t0, t0, t1
ret

_start:
li t0, 5
li t1, 7
# Could be jalr
# jal without offset
jal ra, add_t0_t1

# exit
li a0, 0
li a1, 0
li a2, 0
li a3, 0
li a4, 0
li a5, 0
li a6, 0
li a7, 42
ecall
18 changes: 18 additions & 0 deletions o1vm/resources/programs/riscv32im/src/mul_overflow.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.section .text
.globl _start

_start:
li t0, 10000000 # Large number
li t1, 10000000 # Another large number
mul t2, t0, t1 # Test large multiplication (Expected overflow)

# Custom exit syscall
li a0, 0
li a1, 0
li a2, 0
li a3, 0
li a4, 0
li a5, 0
li a6, 0
li a7, 42
ecall
19 changes: 19 additions & 0 deletions o1vm/resources/programs/riscv32im/src/rem_by_zero.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.section .text
.globl _start

_start:
# Signed remainder by zero (rem)
li t0, 42 # t0 = 42
li t1, 0 # t1 = 0
rem t2, t0, t1 # t2 = t0 % t1 (Expected: remainder by zero)

# Custom exit syscall
li a0, 0
li a1, 0
li a2, 0
li a3, 0
li a4, 0
li a5, 0
li a6, 0
li a7, 42
ecall
19 changes: 19 additions & 0 deletions o1vm/resources/programs/riscv32im/src/remu_by_zero.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.section .text
.globl _start

_start:
# Unsigned remainder by zero (remu)
li t0, 42 # t0 = 42
li t1, 0 # t1 = 0
remu t2, t0, t1 # t2 = t0 % t1 (Expected: remainder by zero)

# Custom exit syscall
li a0, 0
li a1, 0
li a2, 0
li a3, 0
li a4, 0
li a5, 0
li a6, 0
li a7, 42
ecall
30 changes: 30 additions & 0 deletions o1vm/resources/programs/riscv32im/src/slt.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.section .text
.globl _start

_start:

# SLT with t0 < t1 (Expected: 1)
li t0, 100 # t0 = 100
li t1, 200 # t1 = 200
slt t2, t0, t1 # t2 = (t0 < t1) ? 1 : 0 (Expected: t2 = 1)

# SLT with t3 > t4 (Expected: 0)
li t3, 300 # t3 = 300
li t4, 200 # t4 = 200
slt t5, t3, t4 # t5 = (t3 < t4) ? 1 : 0 (Expected: t5 = 0)

# SLT with t0 == t1 (Expected: 0)
li t0, 150 # t6 = 150
li t1, 150 # t7 = 150
slt t6, t0, t1 # t6 = (t0 < t1) ? 1 : 0 (Expected: t6 = 0)

# Custom exit syscall
li a0, 0
li a1, 0
li a2, 0
li a3, 0
li a4, 0
li a5, 0
li a6, 0
li a7, 42
ecall
25 changes: 25 additions & 0 deletions o1vm/resources/programs/riscv32im/src/sub.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.section .text
.globl _start

_start:

# Test 1: Simple subtraction
li t0, 1000 # t0 = 1000
li t1, 500 # t1 = 500
sub t2, t0, t1 # t2 = t0 - t1 (Expected: t2 = 500)

# Test 2: Subtracting from zero
li t3, 0 # t3 = 0
li t4, 100 # t4 = 100
sub t5, t3, t4 # t5 = t3 - t4 (Expected: t5 = -100)

# Custom exit syscall
li a0, 0
li a1, 0
li a2, 0
li a3, 0
li a4, 0
li a5, 0
li a6, 0
li a7, 42
ecall
25 changes: 25 additions & 0 deletions o1vm/resources/programs/riscv32im/src/sub_2.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.section .text
.globl _start

_start:

# Test 3: Subtracting a larger value (result negative)
li t0, 300 # t0 = 300
li t1, 500 # t1 = 500
sub t2, t0, t1 # t2 = t0 - t1 (Expected: t2 = -200)

# Test 4: Subtracting negative values (result positive)
li t3, 100 # t3 = 100
li t4, -50 # t4 = -50
sub t5, t3, t4 # t5 = t3 - t4 (Expected: t5 = 150)

# Custom exit syscall
li a0, 0
li a1, 0
li a2, 0
li a3, 0
li a4, 0
li a5, 0
li a6, 0
li a7, 42
ecall
22 changes: 22 additions & 0 deletions o1vm/resources/programs/riscv32im/src/sub_3.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.section .text
.globl _start

_start:
# Test 5: Result of subtracting from a register (using same value)
li t0, 1234 # t0 = 1234
sub t1, t0, t0 # t1 = t0 - t0 (Expected: t1 = 0)

# Test 6: Handling overflow (large subtraction result)
li t2, 2147483647 # t2 = 2147483647 (max positive signed 32-bit)
li t3, -1 # t3 = -1
sub t4, t2, t3 # t4 = t2 - t3 (Expected: t0 = 2147483648, wraparound to -2147483648)
# Custom exit syscall
li a0, 0
li a1, 0
li a2, 0
li a3, 0
li a4, 0
li a5, 0
li a6, 0
li a7, 42
ecall
30 changes: 30 additions & 0 deletions o1vm/resources/programs/riscv32im/src/xor.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.section .text
.globl _start

_start:

# Simple XOR
li t0, 0b1100 # t0 = 0b1100
li t1, 0b1010 # t1 = 0b1010
xor t2, t0, t1 # t2 = t0 ^ t1 (Expected: t2 = 0b0110)

# XOR with zero (no change)
li t3, 0b1010 # t3 = 0b1010
li t4, 0 # t4 = 0
xor t5, t3, t4 # t5 = t3 ^ t4 (Expected: t5 = 0b1010)

# XOR of identical values (result 0)
li t6, 0b1111 # t6 = 0b1111
li t0, 0b1111 # t0 = 0b1111
xor t1, t6, t0 # t1 = t6 ^ t0 (Expected: t1 = 0)

# Custom exit syscall
li a0, 0
li a1, 0
li a2, 0
li a3, 0
li a4, 0
li a5, 0
li a6, 0
li a7, 42
ecall
Loading

0 comments on commit d7a7e98

Please sign in to comment.