Skip to content

Commit

Permalink
0.1.1
Browse files Browse the repository at this point in the history
0.1.1
  • Loading branch information
Ethan-000 authored Jun 13, 2023
2 parents 406a1a1 + e925673 commit 9da297d
Show file tree
Hide file tree
Showing 28 changed files with 479 additions and 13 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
name: cargo build, fmt & clippy

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
on: [push, pull_request]

env:
CARGO_TERM_COLOR: always

jobs:
Expand All @@ -24,3 +21,4 @@ jobs:
- run: cargo hack build --verbose --each-feature --exclude-features --all-features
- run: cargo fmt --all -- --check
- run: cargo hack clippy --all-targets --each-feature --exclude-features --all-features -- -D warnings
- run: cargo test --release --verbose -- --test-threads=1
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ pkg/
*.tr
*.pk
*.vk
**/Verifier.toml
**/Verifier.toml

*.sol
**/target
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
authors = [""]
compiler_version = "0.6.0"
compiler_version = "0.1"

[dependencies]
3 changes: 3 additions & 0 deletions tests/test_programs/1_mul/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
x = "3"
y = "4"
z = "429981696"
9 changes: 9 additions & 0 deletions tests/test_programs/1_mul/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Test unsafe integer multiplication with overflow: 12^8 = 429 981 696
// The circuit should handle properly the growth of the bit size
fn main(mut x: u32, y: u32, z: u32) {
x *= y;
x *= x; //144
x *= x; //20736
x *= x; //429 981 696
assert(x == z);
}
5 changes: 5 additions & 0 deletions tests/test_programs/2_div/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
3 changes: 3 additions & 0 deletions tests/test_programs/2_div/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
x = "7"
y = "3"
z = "2"
7 changes: 7 additions & 0 deletions tests/test_programs/2_div/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Testing integer division: 7/3 = 2
fn main(mut x: u32, y: u32, z: u32) {
let a = x % y;
assert(x / y == z);
assert(a == x - z*y);
assert((50 as u64) % (9 as u64) == 5);
}
5 changes: 5 additions & 0 deletions tests/test_programs/3_add/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Test integer addition: 3 + 4 = 7
fn main(mut x: u32, y: u32, z: pub u32) {
fn main(mut x: u32, y: u32, z: u32) {
x += y;
assert(x == z);

Expand Down
5 changes: 5 additions & 0 deletions tests/test_programs/4_sub/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
3 changes: 3 additions & 0 deletions tests/test_programs/4_sub/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
x = "12"
y = "2418266113"
z = "1876701195"
5 changes: 5 additions & 0 deletions tests/test_programs/4_sub/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Test unsafe integer subtraction with underflow: 12 - 2418266113 = 1876701195 modulo 2^32
fn main(mut x: u32, y: u32, z: u32) {
x -= y;
assert(x == z);
}
5 changes: 5 additions & 0 deletions tests/test_programs/5_over/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
2 changes: 2 additions & 0 deletions tests/test_programs/5_over/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = "43046721"
y = "3793632897"
9 changes: 9 additions & 0 deletions tests/test_programs/5_over/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Test unsafe integer arithmetic
// Test odd bits integer
fn main(mut x: u32, y: u32) {
x = x * x;
assert(y == x);

let c:u3 = 2;
assert(c > x as u3);
}
5 changes: 5 additions & 0 deletions tests/test_programs/6_array/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
9 changes: 9 additions & 0 deletions tests/test_programs/6_array/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
x = [104, 101, 108, 108, 111]
y = [10, 81, 18, 48, 0]
z = "59"
t = "10"

#7128
#15309
#16349

54 changes: 54 additions & 0 deletions tests/test_programs/6_array/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//Basic tests for arrays
fn main(x: [u32; 5], y: [u32; 5], mut z: u32, t: u32) {
let mut c = 2301;
z = y[4];
//Test 1:
for i in 0..5 {
c = z*z*y[i];
z -= c;
}
assert(z==0); //y[4]=0, so c and z are always 0

//Test 2:
c = 2301 as u32;
for i in 0..5 {
c = t+2 as u32;
c = z*z*x[i];
z += x[i]*y[i] - c;
}
assert(z==3814912846);

//Test 3:
c = 2300001 as u32;
z = y[4];
for i in 0..5 {
z = z + x[i]*y[i];
for _i in 0..3 {
c = i as u32 - 2 as u32;
z *= c;
}
}
assert(z==41472);

//Test 4:
z = y[4];
for i in 0..3 {
z += x[i] * y[i];
for j in 0..2 {
z += x[i+j] - y[i+j];
}
}
assert(z ==11539);

//Test 5:
let cc = if z < 1 { x } else { y };
assert(cc[0] == y[0]);

// Test 6: for-each loops
for y_elem in y {
for x_elem in x {
assert(x_elem != y_elem);
}
}
}

5 changes: 5 additions & 0 deletions tests/test_programs/7_function/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
6 changes: 6 additions & 0 deletions tests/test_programs/7_function/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
x = "59"
y = "5"
a = "1"

arr1=[3320379920, 1938147428, 1942509796, 1795943184, 24853, 0, 0, 0, 0]
arr2=[2912727897, 3590519536, 1687587470, 3896107618, 1092831095, 0, 0, 0, 0]
149 changes: 149 additions & 0 deletions tests/test_programs/7_function/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
//Tests for function calling
use dep::std;

fn f1(mut x: Field) -> Field {
x = x + 1;
x = f2(x);
x
}

fn f2(mut x: Field) -> Field{
x += 2;
x
}

// Simple example
fn test0(mut a: Field) {
a = f2(a);
assert(a == 3);
}

// Nested call
fn test1(mut a: Field) {
a = f1(a);
assert(a == 4);
}

fn test2(z: Field, t: u32 ) {
let a = z + t as Field;
assert(a == 64);
let e = pow(z, t as Field);
assert(e == 714924299);
}

fn pow(base: Field, exponent: Field) -> Field {
let mut r = 1 as Field;
let b = exponent.to_le_bits(32 as u32);
for i in 1..33 {
r = r*r;
r = (b[32-i] as Field) * (r * base) + (1 - b[32-i] as Field) * r;
}
r
}

fn test3(x: [u8; 3]) -> [u8; 3] {
let mut buffer = [0 as u8; 3];
for i in 0..3 {
buffer[i] = x[i];
}
assert(buffer == x);
buffer
}

fn test_multiple(x: u32, y: u32) -> (u32, u32) {
(y,x)
}

fn test_multiple2() -> my_struct {
my_struct { a: 5 as u32, b: 7 as u32 }
}

fn test_multiple3(x: u32, y: u32) {
assert(x == y);
}

struct my_struct {
a: u32,
b: u32,
}

struct my2 {
aa: my_struct,
bb: my_struct,
}

fn test_multiple4(s: my_struct) {
assert(s.a == s.b+2);
}

fn test_multiple5(a: (u32, u32)) {
assert(a.0 == a.1+2);
}


fn test_multiple6(a: my2, b: my_struct, c: (my2, my_struct)) {
test_multiple4(a.aa);
test_multiple5((b.a, b.b));
assert(c.0.aa.a == c.1.a);
}


fn foo(a: [Field]) -> [Field] {
a
}
fn bar() -> [Field] {
foo([0])
}
fn main(x: u32 , y: u32 , a: Field, arr1: [u32; 9], arr2: [u32; 9]) {
let mut ss: my_struct = my_struct { b: x, a: x+2, };
test_multiple4(ss);
test_multiple5((ss.a,ss.b));
let my = my2 {
aa: ss,
bb: ss,
};
ss.a = 61;
test_multiple6(my, ss, (my,ss));

let my_block = {
let mut ab = f2(a);
ab = ab + a;
(x,ab)
};
assert(my_block.1 == 4);

test0(a);
test1(a);
test2(x as Field, y);
assert(bar()[0] == 0);

let mut b = [0 as u8, 5 as u8, 2 as u8];
let c = test3(b);
assert(b == c);
b[0] = 1 as u8;
let cc = test3(b);
assert(c != cc);
let e = test_multiple(x, y);
assert(e.1 == e.0 + 54 as u32);
let d = test_multiple2();
assert(d.b == d.a + 2 as u32);
test_multiple3(y, y);

//Regression test for issue #628:
let result = first(arr_to_field(arr1), arr_to_field(arr2));
assert(result[0] == arr1[0] as Field);
}


// Issue #628
fn arr_to_field(arr: [u32; 9]) -> [Field; 9] {
let mut as_field: [Field; 9] = [0 as Field; 9];
for i in 0..9 {
as_field[i] = arr[i] as Field;
}
as_field
}

fn first(a: [Field; 9], _b: [Field; 9]) -> [Field; 9] {
a
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 9da297d

Please sign in to comment.