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

Development #1

Merged
merged 53 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
c798635
basic program compilation from ast
collinc97 Mar 23, 2020
4a83a0e
program a==1 compiles and generates constraints
collinc97 Mar 28, 2020
c4f233e
add constraints and snark functions
collinc97 Mar 31, 2020
82eaba4
impl add, sub, mul, div
collinc97 Apr 1, 2020
acd8992
composable return statements working
collinc97 Apr 3, 2020
eb56ad6
return and assign statements working.
collinc97 Apr 4, 2020
f19eb4f
basic assign and returns
collinc97 Apr 7, 2020
9b4bd25
impl variable declaration resolution
collinc97 Apr 7, 2020
62fa831
all field operators working with constraints
collinc97 Apr 9, 2020
d9b0fa9
impl conditional if then else fi
collinc97 Apr 10, 2020
030699b
pest array, postfix, array access
collinc97 Apr 13, 2020
54ad1af
pest increment decrement
collinc97 Apr 13, 2020
3f59714
pest function defs
collinc97 Apr 13, 2020
940806e
pest for loop
collinc97 Apr 13, 2020
1903858
program structs
collinc97 Apr 14, 2020
2f9e4b3
constraint structs and function definitions
collinc97 Apr 14, 2020
83763a6
constraints inline array
collinc97 Apr 14, 2020
3f83786
constraints array initializer
collinc97 Apr 15, 2020
c14ed23
constraints inline structs
collinc97 Apr 15, 2020
025d9ab
constraints array access
collinc97 Apr 15, 2020
3bc7118
constraint struct access
collinc97 Apr 15, 2020
ac48138
constraints function calls, params, returns
collinc97 Apr 16, 2020
833590a
clean up output
collinc97 Apr 16, 2020
59d2fa8
Fix bug: parse mixed space and tab case
howardwu Apr 16, 2020
0a8cda3
Rename Function's name from 'variable' to 'function_name', and adds F…
howardwu Apr 16, 2020
455c0b6
constraints for loops
collinc97 Apr 16, 2020
6b6bce3
impl function scope
collinc97 Apr 16, 2020
e1db8ed
constraints modify array and struct values in place
collinc97 Apr 17, 2020
1743c7a
constraints bool and field spreads
collinc97 Apr 17, 2020
1e9e49d
parse imports
collinc97 Apr 17, 2020
dbbf816
constraints basic imports
collinc97 Apr 17, 2020
1bbe71d
add and constrain explict type for u32
collinc97 Apr 20, 2020
16d2762
impl field element operations
collinc97 Apr 21, 2020
9bf0dc9
refactor constraints module
collinc97 Apr 21, 2020
ff4fc0c
add file docs
collinc97 Apr 21, 2020
26d8010
remove zokrates progam
collinc97 Apr 21, 2020
0d71b00
Update README.md
howardwu Apr 21, 2020
0cfcc8d
Removes the csv example
howardwu Apr 21, 2020
db4cea8
Update .program to .leo
howardwu Apr 21, 2020
a42d9ee
Updates Cargo.toml
howardwu Apr 21, 2020
f1c318d
Migrate aleo_program to program
howardwu Apr 21, 2020
966f4c9
Rename language.pest to leo.pest
howardwu Apr 21, 2020
8702ad5
Clean up
howardwu Apr 21, 2020
51c52c8
Updates
howardwu Apr 21, 2020
6a6197d
Update logging
howardwu Apr 21, 2020
ffedd29
impl and constrain function parameter visibility
collinc97 Apr 22, 2020
ccd6092
merge development
collinc97 Apr 22, 2020
fa37bc4
add implicit integer type. various fixes
collinc97 Apr 22, 2020
1e5c2a7
enforce function return type
collinc97 Apr 22, 2020
34d8a55
refactor type resolution
collinc97 Apr 23, 2020
ac9707d
remove old code
collinc97 Apr 23, 2020
2255bac
add function and {}
collinc97 Apr 23, 2020
6ec4f99
add readme
collinc97 Apr 24, 2020
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
30 changes: 17 additions & 13 deletions Cargo.lock

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

32 changes: 22 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
[package]
name = "language"
name = "leo"
version = "0.1.0"
authors = ["howardwu <howardwu@berkeley.edu>"]
authors = ["The Aleo Team <hello@aleo.org>"]
edition = "2018"

[lib]
name = "leo"
path = "src/lib.rs"

[[bin]]
name = "leo"
path = "src/main.rs"

[dependencies]
from-pest = "0.3.1"
lazy_static = "1.3.0"
pest = "2.0"
pest_derive = "2.0"
pest-ast = "0.3.3"

snarkos-gadgets = { path = "../snarkOS/gadgets" }
snarkos-models = { path = "../snarkOS/models" }
snarkos-algorithms = { path = "../snarkOS/algorithms", version = "0.8.0" }
snarkos-curves = { path = "../snarkOS/curves", version = "0.8.0" }
snarkos-errors = { path = "../snarkOS/errors", version = "0.8.0" }
snarkos-gadgets = { path = "../snarkOS/gadgets", version = "0.8.0" }
snarkos-models = { path = "../snarkOS/models", version = "0.8.0" }

from-pest = { version = "0.3.1" }
lazy_static = { version = "1.3.0" }
pest = { version = "2.0" }
pest-ast = { version = "0.3.3" }
pest_derive = { version = "2.0" }
rand = { version = "0.7" }
265 changes: 264 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,264 @@
# language
# The Leo Language
* All code examples can be copied and pasted into simple.program directly and executed with cargo run
* Programs should be formatted:
1. Import definitions
2. Stuct definitions
3. Function definitions

### Integers:
Currently, all integers are parsed as u32.
You can choose to explicitly add the type or let the compiler interpret implicitly.
```rust
function main() -> (u32) {
a = 1u32 + 1u32
b = 1 - 1
c = 2 * 2
d = 4 / 2
e = 2 ** 3
return a
}
```

### Field Elements:
Field elements must have the type added explicitly.
```rust
function main() -> (fe) {
f = 21888242871839275222246405745257275088548364400416034343698204186575808495617fe
a = 1fe + 1fe
b = 1fe - 1fe
c = 2fe * 2fe
d = 4fe / 2fe
return a
}
```


### Booleans:
```rust
function main() -> (bool) {
a = true || false
b = false && false
c = 1 == 1
return a
}
```

### Arrays:
Leo supports static arrays with fixed length.
Array type must be explicitly stated
```rust
function main() -> (u32[2]) {
// initialize an integer array with integer values
u32[3] a = [1, 2, 3]

// set a member to a value
a[2] = 4

// initialize an array of 4 values all equal to 42
u32[4] b = [42; 4]

// initialize an array of 5 values copying all elements of b using a spread
u32[5] c = [1, ...b]

// initialize an array copying a slice from `c`
d = c[1..3]

// initialize a field array
fe[2] e = [5fe; 2]

// initialize a boolean array
bool[3] f = [true, false || true, true]

// return an array
return d
}
```
### Structs:
```rust
struct Point {
u32 x
u32 y
}
function main() -> (u32) {
Point p = Point {x: 1, y: 0}
return p.x
}
```
```rust
struct Foo {
bool x
}
function main() -> (Foo) {
Foo f = Foo {x: true}
f.x = false
return f
}
```

### Conditionals:
```rust
function main() -> (u32) {
y = if 3==3 then 1 else 5 fi
return y
}
```
```rust
function main() -> (fe) {
a = 1fe
for i in 0..4 do
a = a + 1fe
endfor
return a
}
```

### Functions:
```rust
function test1(a : u32) -> (u32) {
return a + 1
}

function test2(b: fe) -> (fe) {
return b * 2fe
}

function test3(c: bool) -> (bool) {
return c && true
}

function main() -> (u32) {
return test1(5)
}
```


#### Function Scope:
```rust
function foo() -> (field) {
// return myGlobal <- not allowed
return 42fe
}

function main() -> (field) {
myGlobal = 42fe
return foo()
}
```

### Parameters:
Main function arguments are allocated as public or private variables in the program's constaint system.
```rust
function main(a: private fe) -> (fe) {
return a
}
```
```rust
function main(a: public fe) -> (fe) {
return a
}
```

### Imports:
Note that there can only be one main function across all imported files.
/simple_import.leo
```rust
struct Point {
u32 x
u32 y
}
```

/simple.leo
```rust
from "./simple_import" import Point

function main() -> (Point) {
Point p = Point { x: 1, y: 2}
return p
}
```

Default exports are not currently supported.
There should only be one main function across all files.

# Leo CLI

## Develop

To compile your program and verify that it builds properly, run:
```
leo build
```

To execute unit tests on your program, run:
```
leo test
```

## Run

To perform the program setup, producing a proving key and verification key, run:
```
leo setup
```
Leo uses cryptographic randomness from your machine to perform the setup. The proving key and verification key are stored in the `target` directory as `.leo.pk` and `.leo.vk`:

```
{$LIBRARY}/target/{$PROGRAM}.leo.pk
{$LIBRARY}/target/{$PROGRAM}.leo.vk
```

To execute the program and produce an execution proof, run:
```
leo prove
```
Leo starts by checking the `target` directory for an existing `.leo.pk` file. If it doesn't exist, it will proceed to run `leo setup` and then continue.

Once again, Leo uses cryptographic randomness from your machine to produce the proof. The proof is stored in the `target` directory as `.leo.proof`:

```
{$LIBRARY}/target/{$PROGRAM}.leo.proof
```

To verify the program proof, run:
```
leo verify
```
Leo starts by checking the `target` directory for an existing `.leo.proof` file. If it doesn't exist, it will proceed to run `leo prove` and then continue.

After the verifier is run, Leo will output either `true` or `false` based on the verification.

## Remote

To use remote compilation features, start by authentication with:
```
leo login
```
You will proceed to authenticate using your username and password. Next, Leo will parse your `Leo.toml` file for `remote = True` to confirm whether remote compilation is enabled.

If remote compilation is enabled, Leo syncs your workspace so when you run `leo build`, `leo test`, `leo setup` and `leo prove`, your program will run the program setup and execution performantly on remote machines.

This speeds up the testing cycle and helps the developer to iterate significantly faster.

## Publish

To package your program as a gadget and publish it online, run:
```
leo publish
```
Leo will proceed to snapshot your directory and upload your directory to the circuit manager. Leo will verify that `leo build` succeeds and that `leo test` passes without error.

If your gadget name has already been taken, `leo publish` will fail.

## Deploy

To deploy your program to the blockchain, run:
```
leo deploy
```

## TODO

- Change `target` directory to some other directory to avoid collision.
- Figure out how `leo prove` should take in assignments.
- Come up with a serialization format for `.leo.pk`, `.leo.vk`, and `.leo.proof`.
5 changes: 0 additions & 5 deletions numbers.csv

This file was deleted.

4 changes: 4 additions & 0 deletions simple.leo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function main() -> (u32) {
a = 1 + 1
return a
}
2 changes: 0 additions & 2 deletions simple.program

This file was deleted.

4 changes: 4 additions & 0 deletions simple_import.leo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
struct Point {
u32 x
u32 y
}
Loading