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

chore(ssa refactor): cp working tests #1619

Merged
merged 14 commits into from
Jun 12, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x = "1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main(x: Field) {
assert(x == 1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = "0x00"
y = "0x10"
18 changes: 18 additions & 0 deletions crates/nargo_cli/tests/test_data_ssa_refactor/bit_and/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// You can only do bit operations with integers.
// (Kobi/Daira/Circom/#37) https://github.com/iden3/circom/issues/37
fn main(x : Field, y : Field) {
let x_as_u8 = x as u8;
let y_as_u8 = y as u8;

assert((x_as_u8 & y_as_u8) == x_as_u8);

//bitwise and with 1 bit:
let flag = (x == 0) & (y == 16);
assert(flag);

//bitwise and with odd bits:
let x_as_u11 = x as u11;
let y_as_u11 = y as u11;
assert((x_as_u11 & y_as_u11) == x_as_u11);
}

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

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x = 64
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fn main(x: u64) {
let two: u64 = 2;
let three: u64 = 3;

// comptime shifts on comptime values
assert(two << 2 == 8);
assert((two << 3) / 8 == two);
assert((three >> 1) == 1);

// comptime shifts on runtime values
assert(x << 1 == 128);
assert(x >> 2 == 16);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

[package]
authors = [""]
compiler_version = "0.1"

[dependencies]

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x = "1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use dep::std;
fn main(x: u1) {
assert(!x == 0);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

[package]
authors = [""]
compiler_version = "0.1"

[dependencies]

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = "1"
y = "0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use dep::std;
fn main(x: u1, y: u1) {
assert(x | y == 1);

assert(x | y | x == 1);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

[package]
authors = [""]
compiler_version = "0.1"

[dependencies]

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = "10"
y = "10"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main(x: Field, y: Field) {
let z = x == y;
let t = z as u8;
assert(t == 1);
}

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

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a = [1, 2, 3]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
fn main(a: [Field; 3]) {
let i = 1;

// Using a comptime variable as a parameter should not make it non-comptime
let ii = foo(i);
let elem1 = a[i];

// Nor should using it in an expression with a non-comptime variable.
let two = i + ii;
assert(i == ii);

let elem2 = a[i];
assert(elem1 == elem2);
assert(two == 2);
}

fn foo(x: Field) -> Field { x }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = 5
y = 6
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main(x: Field, y: Field) {
let flag = (x == 1) | (y == 2);
assert(flag | false == flag);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = 3
y = 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main(x : Field, y : pub Field) {
assert(x * 2 == y * 3);
}

contract Foo {
fn double(x: Field) -> pub Field { x * 2 }
fn triple(x: Field) -> pub Field { x * 3 }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
input = "1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use dep::std;

fn main(input : Field) -> pub Field {
std::hash::hash_to_field([input])
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = true
y = [true, false]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main(x : bool, y: [bool;2]) {
if x {
assert(1 != 2);
}

assert(x);
assert(y[0] != y[1]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x = "8"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main(x: pub Field) -> pub Field {
x
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = "2"
y = "13"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn hello(x : Field) -> Field {
x
}
14 changes: 14 additions & 0 deletions crates/nargo_cli/tests/test_data_ssa_refactor/modules/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
mod foo;
// This is a comment.
//
// `main` is the entry point to a binary
//
// You can have a `Binary` or a `Library`
// Release : 0.2
//
// To run a proof on the command line, type `cargo run prove {proof_name}`
//
// To verify that proof, type `cargo run verify {proof_name}`
fn main(x: Field, y: pub Field) {
assert(x != foo::hello(y));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

x = "5"
y = "15"

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod bar;

fn hello(x : Field) -> Field {
x
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn from_bar(x : Field) -> Field {
x
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mod foo;

// An example of the module system
fn main(x: Field, y: Field) {
assert(x != foo::bar::from_bar(y));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
Loading