Skip to content

Commit 43c5d33

Browse files
committed
feat: sample test and merge with add, uncomment mul_u8
1 parent abe64c8 commit 43c5d33

File tree

6 files changed

+70
-65578
lines changed

6 files changed

+70
-65578
lines changed

pkg/test/assembly_test.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,17 @@ func Test_Asm_Trim(t *testing.T) {
107107
test_util.CheckWithFields(t, false, "asm/trim", sc.BLS12_377, sc.KOALABEAR_16)
108108
}
109109

110-
func Test_Asm_Gf251_Add(t *testing.T) {
111-
test_util.Check(t, false, "asm/gf251_add")
112-
}
113-
114-
func Test_Asm_Gf251_Mul(t *testing.T) {
110+
func Test_Asm_Gf251(t *testing.T) {
115111
// Testing reduce_u8 for now
116112
// Test mul once fn call in fn has been fixed
117-
test_util.Check(t, false, "asm/gf251_mul")
113+
test_util.Check(t, false, "asm/gf251")
118114
}
119115

120116
// Recusion
121117
//
122-
// func Test_Asm_RecPow(t *testing.T) {
123-
// test_util.Check(t, false, "asm/rec_pow")
124-
// }
118+
// func Test_Asm_RecPow(t *testing.T) {
119+
// test_util.Check(t, false, "asm/rec_pow")
120+
// }
125121
func Test_Asm_RecPow(t *testing.T) {
126122
test_util.Check(t, false, "asm/rec_pow")
127123
}

testdata/asm/gf251.accepts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
;; add function testing
2+
{ "add": { "x": [0], "y": [0], "RESULT": [0] } }
3+
{ "add": { "x": [249], "y": [1], "RESULT": [250] }}
4+
{ "add": { "x": [250], "y": [1], "RESULT": [0] }}
5+
;; Sample reduction_u8 testing
6+
{ "reduction_u8": { "z": [35762], "RESULT": [24] }}
7+
{ "reduction_u8": { "z": [4500], "RESULT": [147] }}
8+
{ "reduction_u8": { "z": [789], "RESULT": [208] }}
9+
{ "reduction_u8": { "z": [6813], "RESULT": [208] }}
10+
{ "reduction_u8": { "z": [38185], "RESULT": [107] }}
11+
{ "reduction_u8": { "z": [48523], "RESULT": [16] }}
12+
{ "reduction_u8": { "z": [59879], "RESULT": [229] }}
13+
{ "reduction_u8": { "z": [21014], "RESULT": [237] }}
14+
{ "reduction_u8": { "z": [2086], "RESULT": [116] }}
15+
{ "reduction_u8": { "z": [39580], "RESULT": [135] }}
16+
{ "reduction_u8": { "z": [27408], "RESULT": [60] }}
17+
{ "reduction_u8": { "z": [47161], "RESULT": [95] }}
18+
{ "reduction_u8": { "z": [34804], "RESULT": [234] }}
19+
{ "reduction_u8": { "z": [34429], "RESULT": [159] }}
20+
{ "reduction_u8": { "z": [64506], "RESULT": [50] }}
21+
{ "reduction_u8": { "z": [15154], "RESULT": [69] }}
22+
{ "reduction_u8": { "z": [61300], "RESULT": [212] }}
23+
{ "reduction_u8": { "z": [30339], "RESULT": [94] }}
24+
{ "reduction_u8": { "z": [46744], "RESULT": [112] }}
25+
{ "reduction_u8": { "z": [35608], "RESULT": [194] }}
26+
{ "reduction_u8": { "z": [49715], "RESULT": [154] }}
27+
{ "reduction_u8": { "z": [44827], "RESULT": [80] }}
28+
{ "reduction_u8": { "z": [4979], "RESULT": [42] }}
29+
{ "reduction_u8": { "z": [56211], "RESULT": [148] }}
30+
{ "reduction_u8": { "z": [50776], "RESULT": [65] }}
31+
{ "reduction_u8": { "z": [47703], "RESULT": [103] }}
32+
{ "reduction_u8": { "z": [17809], "RESULT": [98] }}
33+
{ "reduction_u8": { "z": [43469], "RESULT": [210] }}
34+
{ "reduction_u8": { "z": [33652], "RESULT": [104] }}
35+
{ "reduction_u8": { "z": [52797], "RESULT": [168] }}
36+
;; add function testing
37+
{ "mul_u8": { "x": [0], "y": [0], "RESULT": [0] } }
38+
{ "mul_u8": { "x": [1], "y": [1], "RESULT": [201] }}
39+
{ "mul_u8": { "x": [232], "y": [232], "RESULT": [22] }}

testdata/asm/gf251_mul.zkasm renamed to testdata/asm/gf251.zkasm

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
;; GF251 curve
2+
;; Add on u256
23
;; Mul on u8, to be able to test all cases
34

5+
fn add(x u256, y u256) -> (RESULT u256) {
6+
7+
var c0, c1 u1
8+
var res u256
9+
var red u256
10+
11+
c0, res = x + y
12+
c1, red = res - 251
13+
;; if c1 is 0, it means the diff is positive and res is >= 251
14+
;; if c1 is 1, diff is negative, res < 251
15+
if c1==0 goto exit0
16+
RESULT = res
17+
return
18+
exit0:
19+
RESULT = red
20+
return
21+
22+
}
23+
424
;; u8 version of mul and reduction to be able to test all cases
525

626
fn reduction_u8(z u16) -> (RESULT u8) {
@@ -48,10 +68,9 @@ exit_1:
4868
return
4969
}
5070

51-
;; TODO: uncomment once fn call in fn is fixed
52-
;;fn mul_u8(x u8, y u8) -> (RESULT u8) {
53-
;; var z u16
54-
;; z = x * y
55-
;; RESULT = reduction_u8(z)
56-
;; return
57-
;;}
71+
fn mul_u8(x u8, y u8) -> (RESULT u8) {
72+
var z u16
73+
z = x * y
74+
RESULT = reduction_u8(z)
75+
return
76+
}

testdata/asm/gf251_add.accepts

Lines changed: 0 additions & 3 deletions
This file was deleted.

testdata/asm/gf251_add.zkasm

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)