mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-25 19:22:01 +03:00
Merge branch 'master' of github.com:AleoHQ/leo
This commit is contained in:
commit
c2d2b0363c
86
.github/workflows/leo.yml
vendored
Normal file
86
.github/workflows/leo.yml
vendored
Normal file
@ -0,0 +1,86 @@
|
||||
name: Leo Programs
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
env:
|
||||
RUST_BACKTRACE: 1
|
||||
|
||||
jobs:
|
||||
new:
|
||||
name: Hello Leo (from 'leo new')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v1
|
||||
|
||||
- name: Load snarkOS
|
||||
run: |
|
||||
mkdir ~/.ssh
|
||||
echo "${{ secrets.SNARKOS_DEPLOY_KEY }}" > ~/.ssh/id_rsa
|
||||
chmod 600 ~/.ssh/id_rsa
|
||||
eval $(ssh-agent -s)
|
||||
ssh-add -k ~/.ssh/id_rsa
|
||||
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: nightly
|
||||
override: true
|
||||
components: rustfmt
|
||||
|
||||
- name: Install Leo
|
||||
uses: actions-rs/cargo@v1
|
||||
env:
|
||||
CARGO_NET_GIT_FETCH_WITH_CLI: true
|
||||
with:
|
||||
command: install
|
||||
args: --path .
|
||||
|
||||
- name: 'leo new'
|
||||
run: |
|
||||
cd ..
|
||||
leo new hello_world
|
||||
ls -la
|
||||
cd hello_world && ls -la
|
||||
leo run
|
||||
|
||||
init:
|
||||
name: Hello Leo (from 'leo init')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v1
|
||||
|
||||
- name: Load snarkOS
|
||||
run: |
|
||||
mkdir ~/.ssh
|
||||
echo "${{ secrets.SNARKOS_DEPLOY_KEY }}" > ~/.ssh/id_rsa
|
||||
chmod 600 ~/.ssh/id_rsa
|
||||
eval $(ssh-agent -s)
|
||||
ssh-add -k ~/.ssh/id_rsa
|
||||
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: nightly
|
||||
override: true
|
||||
components: rustfmt
|
||||
|
||||
- name: Install Leo
|
||||
uses: actions-rs/cargo@v1
|
||||
env:
|
||||
CARGO_NET_GIT_FETCH_WITH_CLI: true
|
||||
with:
|
||||
command: install
|
||||
args: --path .
|
||||
|
||||
- name: 'leo init'
|
||||
run: |
|
||||
cd .. && mkdir hello_world && cd hello_world
|
||||
leo init
|
||||
ls -la
|
||||
leo run
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,4 @@
|
||||
**/target
|
||||
/tmp/
|
||||
**.idea/
|
||||
outputs/
|
||||
*.DS_Store
|
||||
|
38
Cargo.lock
generated
38
Cargo.lock
generated
@ -661,6 +661,7 @@ dependencies = [
|
||||
"leo-compiler",
|
||||
"leo-gadgets",
|
||||
"leo-input",
|
||||
"leo-package",
|
||||
"log",
|
||||
"rand",
|
||||
"rand_core",
|
||||
@ -675,8 +676,6 @@ dependencies = [
|
||||
"snarkos-utilities",
|
||||
"thiserror",
|
||||
"toml",
|
||||
"walkdir",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -754,6 +753,19 @@ dependencies = [
|
||||
name = "leo-linter"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "leo-package"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"log",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"toml",
|
||||
"walkdir",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "leo-typed"
|
||||
version = "0.1.0"
|
||||
@ -1272,7 +1284,7 @@ checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f"
|
||||
[[package]]
|
||||
name = "snarkos-algorithms"
|
||||
version = "0.8.0"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#d80ce42f37c8dbdd8dcb0ab9574361aea3276dc3"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
|
||||
dependencies = [
|
||||
"blake2",
|
||||
"derivative",
|
||||
@ -1292,7 +1304,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "snarkos-curves"
|
||||
version = "0.8.0"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#d80ce42f37c8dbdd8dcb0ab9574361aea3276dc3"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
|
||||
dependencies = [
|
||||
"derivative",
|
||||
"rand",
|
||||
@ -1307,7 +1319,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "snarkos-derives"
|
||||
version = "0.1.0"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#d80ce42f37c8dbdd8dcb0ab9574361aea3276dc3"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.19",
|
||||
"quote 1.0.7",
|
||||
@ -1317,7 +1329,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "snarkos-dpc"
|
||||
version = "0.8.0"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#d80ce42f37c8dbdd8dcb0ab9574361aea3276dc3"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
|
||||
dependencies = [
|
||||
"blake2",
|
||||
"derivative",
|
||||
@ -1338,7 +1350,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "snarkos-errors"
|
||||
version = "0.8.0"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#d80ce42f37c8dbdd8dcb0ab9574361aea3276dc3"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
|
||||
dependencies = [
|
||||
"base58",
|
||||
"bech32",
|
||||
@ -1351,7 +1363,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "snarkos-gadgets"
|
||||
version = "0.8.0"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#d80ce42f37c8dbdd8dcb0ab9574361aea3276dc3"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
|
||||
dependencies = [
|
||||
"derivative",
|
||||
"digest 0.8.1",
|
||||
@ -1366,7 +1378,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "snarkos-models"
|
||||
version = "0.8.0"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#d80ce42f37c8dbdd8dcb0ab9574361aea3276dc3"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"derivative",
|
||||
@ -1382,7 +1394,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "snarkos-objects"
|
||||
version = "0.8.0"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#d80ce42f37c8dbdd8dcb0ab9574361aea3276dc3"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
|
||||
dependencies = [
|
||||
"base58",
|
||||
"bech32",
|
||||
@ -1403,7 +1415,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "snarkos-parameters"
|
||||
version = "0.8.0"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#d80ce42f37c8dbdd8dcb0ab9574361aea3276dc3"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
|
||||
dependencies = [
|
||||
"hex",
|
||||
"snarkos-algorithms",
|
||||
@ -1415,12 +1427,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "snarkos-profiler"
|
||||
version = "0.8.0"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#d80ce42f37c8dbdd8dcb0ab9574361aea3276dc3"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
|
||||
|
||||
[[package]]
|
||||
name = "snarkos-utilities"
|
||||
version = "0.8.0"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#d80ce42f37c8dbdd8dcb0ab9574361aea3276dc3"
|
||||
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#c1bab103254631c892fade02662eaa66cc145d58"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"rand",
|
||||
|
@ -13,12 +13,13 @@ name = "leo"
|
||||
path = "leo/main.rs"
|
||||
|
||||
[workspace]
|
||||
members = [ "ast", "compiler", "gadgets", "input", "linter", "typed" ]
|
||||
members = [ "ast", "compiler", "gadgets", "input", "linter", "package", "typed" ]
|
||||
|
||||
[dependencies]
|
||||
leo-compiler = { path = "compiler", version = "0.1.0" }
|
||||
leo-gadgets = { path = "gadgets", version = "0.1.0" }
|
||||
leo-input = { path = "input", version = "0.1.0" }
|
||||
leo-package = { path = "package", version = "0.1.0" }
|
||||
|
||||
snarkos-algorithms = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", package = "snarkos-algorithms", default-features = false }
|
||||
snarkos-curves = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", package = "snarkos-curves", default-features = false }
|
||||
@ -38,8 +39,6 @@ serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = { version = "1.0" }
|
||||
toml = { version = "0.5" }
|
||||
thiserror = { version = "1.0" }
|
||||
walkdir = { version = "2" }
|
||||
zip = { version = "0.5" }
|
||||
|
||||
[dev-dependencies]
|
||||
rusty-hook = { version = "0.11.2" }
|
||||
|
@ -345,8 +345,8 @@ input_keyword = { "input" }
|
||||
|
||||
// Declared in functions/input/input.rs
|
||||
input = {
|
||||
input_keyword
|
||||
| function_input
|
||||
function_input
|
||||
| input_keyword
|
||||
}
|
||||
input_list = _{ (input ~ ("," ~ NEWLINE* ~ input)*)? }
|
||||
|
||||
|
@ -15,7 +15,7 @@ use leo_typed::{Input, LeoTypedAst, MainInput, Program};
|
||||
use snarkos_errors::gadgets::SynthesisError;
|
||||
use snarkos_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::{ConstraintSynthesizer, ConstraintSystem, TestConstraintSystem},
|
||||
gadgets::r1cs::{ConstraintSynthesizer, ConstraintSystem},
|
||||
};
|
||||
|
||||
use sha2::{Digest, Sha256};
|
||||
@ -150,8 +150,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
|
||||
}
|
||||
|
||||
/// Synthesizes the circuit for test functions with program input.
|
||||
pub fn compile_test_constraints(self, cs: &mut TestConstraintSystem<F>) -> Result<(), CompilerError> {
|
||||
generate_test_constraints::<F, G>(cs, self.program, self.program_input, &self.imported_programs)
|
||||
pub fn compile_test_constraints(self) -> Result<(), CompilerError> {
|
||||
generate_test_constraints::<F, G>(self.program, self.program_input, &self.imported_programs)
|
||||
}
|
||||
|
||||
/// Calls the internal generate_constraints method with arguments
|
||||
|
@ -42,7 +42,6 @@ pub fn generate_constraints<F: Field + PrimeField, G: GroupType<F>, CS: Constrai
|
||||
}
|
||||
|
||||
pub fn generate_test_constraints<F: Field + PrimeField, G: GroupType<F>>(
|
||||
cs: &mut TestConstraintSystem<F>,
|
||||
program: Program,
|
||||
input: Input,
|
||||
imported_programs: &ImportParser,
|
||||
@ -57,6 +56,7 @@ pub fn generate_test_constraints<F: Field + PrimeField, G: GroupType<F>>(
|
||||
log::info!("Running {} tests", tests.len());
|
||||
|
||||
for (test_name, test_function) in tests.into_iter() {
|
||||
let cs = &mut TestConstraintSystem::<F>::new();
|
||||
let full_test_name = format!("{}::{}", program_name.clone(), test_name.to_string());
|
||||
|
||||
let result = resolved_program.enforce_main_function(
|
||||
@ -68,7 +68,7 @@ pub fn generate_test_constraints<F: Field + PrimeField, G: GroupType<F>>(
|
||||
|
||||
if result.is_ok() {
|
||||
log::info!(
|
||||
"test {} passed. Constraint system satisfied: {}",
|
||||
"test {} compiled successfully. Constraint system satisfied: {}",
|
||||
full_test_name,
|
||||
cs.is_satisfied()
|
||||
);
|
||||
|
@ -8,7 +8,7 @@ use std::{
|
||||
path::PathBuf,
|
||||
};
|
||||
|
||||
pub static OUTPUT_DIRECTORY_NAME: &str = "output/";
|
||||
pub static OUTPUTS_DIRECTORY_NAME: &str = "outputs/";
|
||||
pub static OUTPUT_FILE_EXTENSION: &str = ".out";
|
||||
|
||||
pub struct OutputFile {
|
||||
@ -48,8 +48,8 @@ impl OutputFile {
|
||||
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
if !path.ends_with(OUTPUT_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME));
|
||||
if !path.ends_with(OUTPUTS_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME));
|
||||
}
|
||||
path.push(PathBuf::from(format!("{}{}", self.package_name, OUTPUT_FILE_EXTENSION)));
|
||||
}
|
||||
|
@ -115,11 +115,18 @@ macro_rules! test_int {
|
||||
let a: $type_ = rand::random();
|
||||
let b: $type_ = rand::random();
|
||||
|
||||
// make sure that we can calculate the inverse of each number
|
||||
// Leo signed integer division is non-wrapping. Thus attempting to calculate a
|
||||
// division result that wraps should be ignored here.
|
||||
if a.checked_neg().is_none() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let bytes = include_bytes!("div.leo");
|
||||
let mut program = parse_program(bytes).unwrap();
|
||||
|
||||
// expect an error when dividing by zero
|
||||
if b == 0 || b == <$type_>::MIN {
|
||||
if b == 0 {
|
||||
let main_input = generate_main_input(vec![
|
||||
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
|
||||
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
|
||||
|
2
examples/fibonacci/.gitignore
vendored
2
examples/fibonacci/.gitignore
vendored
@ -1,2 +1,2 @@
|
||||
/output
|
||||
outputs/
|
||||
/.leo
|
||||
|
2
examples/fibonacci/inputs/fibonacci.in
Normal file
2
examples/fibonacci/inputs/fibonacci.in
Normal file
@ -0,0 +1,2 @@
|
||||
[registers]
|
||||
r0: u32 = 0;
|
2
examples/hello_world/.gitignore
vendored
Normal file
2
examples/hello_world/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
outputs/
|
||||
/.leo
|
2
examples/hello_world/inputs/hello_world.in
Normal file
2
examples/hello_world/inputs/hello_world.in
Normal file
@ -0,0 +1,2 @@
|
||||
[registers]
|
||||
r0: u32 = 0;
|
2
examples/pedersen_hash/.gitignore
vendored
2
examples/pedersen_hash/.gitignore
vendored
@ -1,2 +1,2 @@
|
||||
/output
|
||||
outputs/
|
||||
/.leo
|
||||
|
@ -1 +1,4 @@
|
||||
[main]
|
||||
|
||||
[registers]
|
||||
r0: group = (1, 0)group;
|
0
examples/pedersen_hash/inputs/pedersen_hash.state
Normal file
0
examples/pedersen_hash/inputs/pedersen_hash.state
Normal file
1
examples/square_root/.gitignore
vendored
1
examples/square_root/.gitignore
vendored
@ -1 +1,2 @@
|
||||
outputs/
|
||||
/.leo
|
@ -1,4 +1,7 @@
|
||||
// The program input for square_root/src/main.leo
|
||||
[main]
|
||||
a: field = 337;
|
||||
b: field = 113569;
|
||||
b: field = 113569;
|
||||
|
||||
[registers]
|
||||
r0: bool = false;
|
0
examples/square_root/inputs/square_root.state
Normal file
0
examples/square_root/inputs/square_root.state
Normal file
@ -9,7 +9,6 @@ use crate::{
|
||||
Int64,
|
||||
Int8,
|
||||
};
|
||||
|
||||
use snarkos_models::{
|
||||
curves::PrimeField,
|
||||
gadgets::{
|
||||
@ -24,7 +23,7 @@ use snarkos_models::{
|
||||
};
|
||||
|
||||
macro_rules! div_int_impl {
|
||||
($($gadget:ident)*) => ($(
|
||||
($($gadget:ident),*) => ($(
|
||||
impl<F: PrimeField> Div<F> for $gadget {
|
||||
type ErrorType = SignedIntegerError;
|
||||
|
||||
@ -86,15 +85,52 @@ macro_rules! div_int_impl {
|
||||
&allocated_zero,
|
||||
)?;
|
||||
|
||||
// if the numerator is 0, return 0
|
||||
let self_is_zero = Boolean::Constant(self.eq(&Self::constant(0 as <$gadget as Int>::IntegerType)));
|
||||
|
||||
// if other is the minimum number, the result will be zero or one
|
||||
// -128 / -128 = 1
|
||||
// x / -128 = 0 fractional result rounds to 0
|
||||
let min = Self::constant(<$gadget as Int>::IntegerType::MIN);
|
||||
let other_is_min = other.evaluate_equal(
|
||||
&mut cs.ns(|| "other_min_check"),
|
||||
&min
|
||||
)?;
|
||||
let self_is_min = self.evaluate_equal(
|
||||
&mut cs.ns(|| "self_min_check"),
|
||||
&min
|
||||
)?;
|
||||
let both_min = Boolean::and(
|
||||
&mut cs.ns(|| "both_min"),
|
||||
&other_is_min,
|
||||
&self_is_min
|
||||
)?;
|
||||
|
||||
|
||||
// if other is the minimum, set other to -1 so the calculation will not fail
|
||||
let negative_one = allocated_one.neg(&mut cs.ns(|| "allocated_one"))?;
|
||||
let a_valid = min.add(&mut cs.ns(||"a_valid"), &allocated_one);
|
||||
let a_set = Self::conditionally_select(
|
||||
&mut cs.ns(|| "a_set"),
|
||||
&self_is_min,
|
||||
&a_valid?,
|
||||
&self
|
||||
)?;
|
||||
|
||||
let b_set = Self::conditionally_select(
|
||||
&mut cs.ns(|| "b_set"),
|
||||
&other_is_min,
|
||||
&negative_one,
|
||||
&other
|
||||
)?;
|
||||
|
||||
// If the most significant bits of both numbers are equal, the quotient will be positive
|
||||
let a_msb = self.bits.last().unwrap();
|
||||
let b_msb = other.bits.last().unwrap();
|
||||
let a_msb = self.bits.last().unwrap();
|
||||
let positive = a_msb.evaluate_equal(cs.ns(|| "compare_msb"), &b_msb)?;
|
||||
|
||||
// Get the absolute value of each number
|
||||
let a_comp = self.neg(&mut cs.ns(|| "a_neg"))?;
|
||||
let a_comp = a_set.neg(&mut cs.ns(|| "a_neg"))?;
|
||||
let a = Self::conditionally_select(
|
||||
&mut cs.ns(|| "a_abs"),
|
||||
&a_msb,
|
||||
@ -102,12 +138,12 @@ macro_rules! div_int_impl {
|
||||
&self
|
||||
)?;
|
||||
|
||||
let b_comp = other.neg(&mut cs.ns(|| "b_neg"))?;
|
||||
let b_comp = b_set.neg(&mut cs.ns(|| "b_neg"))?;
|
||||
let b = Self::conditionally_select(
|
||||
&mut cs.ns(|| "b_abs"),
|
||||
&b_msb,
|
||||
&b_comp,
|
||||
&other,
|
||||
&b_set,
|
||||
)?;
|
||||
|
||||
let mut q = zero.clone();
|
||||
@ -142,13 +178,11 @@ macro_rules! div_int_impl {
|
||||
&b
|
||||
)?;
|
||||
|
||||
|
||||
let sub = r.sub(
|
||||
&mut cs.ns(|| format!("subtract_divisor_{}", i)),
|
||||
&b
|
||||
);
|
||||
|
||||
|
||||
r = Self::conditionally_select(
|
||||
&mut cs.ns(|| format!("subtract_or_same_{}", i)),
|
||||
&can_sub,
|
||||
@ -182,6 +216,22 @@ macro_rules! div_int_impl {
|
||||
&q_neg,
|
||||
)?;
|
||||
|
||||
// set to zero if we know result is fractional
|
||||
q = Self::conditionally_select(
|
||||
&mut cs.ns(|| "fraction"),
|
||||
&other_is_min,
|
||||
&allocated_zero,
|
||||
&q,
|
||||
)?;
|
||||
|
||||
// set to one if we know result is division of the minimum number by itself
|
||||
q = Self::conditionally_select(
|
||||
&mut cs.ns(|| "one_result"),
|
||||
&both_min,
|
||||
&allocated_one,
|
||||
&q,
|
||||
)?;
|
||||
|
||||
Ok(Self::conditionally_select(
|
||||
&mut cs.ns(|| "self_or_quotient"),
|
||||
&self_is_zero,
|
||||
@ -193,4 +243,4 @@ macro_rules! div_int_impl {
|
||||
)*)
|
||||
}
|
||||
|
||||
div_int_impl!(Int8 Int16 Int32 Int64 Int128);
|
||||
div_int_impl!(Int8, Int16, Int32, Int64, Int128);
|
||||
|
@ -282,12 +282,16 @@ fn test_int8_div_constants() {
|
||||
for _ in 0..1000 {
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
|
||||
let a: i8 = rng.gen_range(-127i8, i8::MAX);
|
||||
let b: i8 = rng.gen_range(-127i8, i8::MAX);
|
||||
let a: i8 = rng.gen();
|
||||
let b: i8 = rng.gen();
|
||||
|
||||
if a.checked_neg().is_none() {
|
||||
return;
|
||||
}
|
||||
|
||||
let expected = match a.checked_div(b) {
|
||||
Some(valid) => valid,
|
||||
None => continue,
|
||||
None => return,
|
||||
};
|
||||
|
||||
let a_bit = Int8::constant(a);
|
||||
@ -308,12 +312,16 @@ fn test_int8_div() {
|
||||
for _ in 0..100 {
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
|
||||
let a: i8 = rng.gen_range(-127i8, i8::MAX);
|
||||
let b: i8 = rng.gen_range(-127i8, i8::MAX);
|
||||
let a: i8 = rng.gen();
|
||||
let b: i8 = rng.gen();
|
||||
|
||||
if a.checked_neg().is_none() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let expected = match a.checked_div(b) {
|
||||
Some(valid) => valid,
|
||||
None => continue,
|
||||
None => return,
|
||||
};
|
||||
|
||||
let a_bit = Int8::alloc(cs.ns(|| "a_bit"), || Ok(a)).unwrap();
|
||||
|
@ -1,11 +1,11 @@
|
||||
use crate::{
|
||||
cli::*,
|
||||
cli_types::*,
|
||||
directories::{source::SOURCE_DIRECTORY_NAME, OutputDirectory, OUTPUT_DIRECTORY_NAME},
|
||||
errors::CLIError,
|
||||
files::{ChecksumFile, InputFile, LibFile, MainFile, Manifest, StateFile, LIB_FILE_NAME, MAIN_FILE_NAME},
|
||||
};
|
||||
use crate::{cli::*, cli_types::*, errors::CLIError};
|
||||
use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType};
|
||||
use leo_package::{
|
||||
inputs::*,
|
||||
outputs::{ChecksumFile, OutputsDirectory, OUTPUTS_DIRECTORY_NAME},
|
||||
root::Manifest,
|
||||
source::{LibFile, MainFile, LIB_FILE_NAME, MAIN_FILE_NAME, SOURCE_DIRECTORY_NAME},
|
||||
};
|
||||
|
||||
use snarkos_algorithms::snark::groth16::KeypairAssembly;
|
||||
use snarkos_curves::{bls12_377::Bls12_377, edwards_bls12::Fq};
|
||||
@ -49,7 +49,7 @@ impl CLI for BuildCommand {
|
||||
|
||||
// Construct the path to the output directory
|
||||
let mut output_directory = package_path.clone();
|
||||
output_directory.push(OUTPUT_DIRECTORY_NAME);
|
||||
output_directory.push(OUTPUTS_DIRECTORY_NAME);
|
||||
|
||||
// Compile the package starting with the lib.leo file
|
||||
if LibFile::exists_at(&package_path) {
|
||||
@ -71,7 +71,7 @@ impl CLI for BuildCommand {
|
||||
// Compile the main.leo file along with constraints
|
||||
if MainFile::exists_at(&package_path) {
|
||||
// Create the output directory
|
||||
OutputDirectory::create(&package_path)?;
|
||||
OutputsDirectory::create(&package_path)?;
|
||||
|
||||
// Construct the path to the main file in the source directory
|
||||
let mut main_file_path = package_path.clone();
|
||||
|
@ -1,8 +1,7 @@
|
||||
use crate::{
|
||||
cli::*,
|
||||
cli_types::*,
|
||||
errors::CLIError,
|
||||
files::{ChecksumFile, Manifest, ProofFile, ProvingKeyFile, VerificationKeyFile},
|
||||
use crate::{cli::*, cli_types::*, errors::CLIError};
|
||||
use leo_package::{
|
||||
outputs::{ChecksumFile, ProofFile, ProvingKeyFile, VerificationKeyFile},
|
||||
root::Manifest,
|
||||
};
|
||||
|
||||
use clap::ArgMatches;
|
||||
|
@ -2,9 +2,11 @@ use crate::{
|
||||
cli::*,
|
||||
cli_types::*,
|
||||
commands::BuildCommand,
|
||||
directories::SOURCE_DIRECTORY_NAME,
|
||||
errors::{CLIError, RunError},
|
||||
files::{Manifest, MAIN_FILE_NAME},
|
||||
};
|
||||
use leo_package::{
|
||||
root::Manifest,
|
||||
source::{MAIN_FILE_NAME, SOURCE_DIRECTORY_NAME},
|
||||
};
|
||||
|
||||
use clap::ArgMatches;
|
||||
|
@ -1,9 +1,12 @@
|
||||
use crate::{
|
||||
cli::*,
|
||||
cli_types::*,
|
||||
directories::{InputDirectory, SourceDirectory},
|
||||
errors::{CLIError, InitError},
|
||||
files::{Gitignore, InputFile, LibFile, MainFile, Manifest},
|
||||
};
|
||||
use leo_package::{
|
||||
inputs::*,
|
||||
root::{Gitignore, Manifest},
|
||||
source::{LibFile, MainFile, SourceDirectory},
|
||||
};
|
||||
|
||||
use clap::ArgMatches;
|
||||
@ -68,15 +71,22 @@ impl CLI for InitCommand {
|
||||
}
|
||||
} else {
|
||||
// Create the input directory
|
||||
InputDirectory::create(&path)?;
|
||||
InputsDirectory::create(&path)?;
|
||||
|
||||
// Verify the input file does not exist
|
||||
let input_file = InputFile::new(&package_name);
|
||||
if !input_file.exists_at(&path) {
|
||||
// Create the input file in the input directory
|
||||
// Create the input file in the inputs directory
|
||||
input_file.write_to(&path)?;
|
||||
}
|
||||
|
||||
// Verify the state file does not exist
|
||||
let state_file = StateFile::new(&package_name);
|
||||
if !state_file.exists_at(&path) {
|
||||
// Create the state file in the inputs directory
|
||||
state_file.write_to(&path)?;
|
||||
}
|
||||
|
||||
// Verify the main file does not exist
|
||||
if !MainFile::exists_at(&path) {
|
||||
// Create the main file in the source directory
|
||||
|
@ -2,9 +2,11 @@ use crate::{
|
||||
cli::*,
|
||||
cli_types::*,
|
||||
commands::BuildCommand,
|
||||
directories::SOURCE_DIRECTORY_NAME,
|
||||
errors::{CLIError, RunError},
|
||||
files::{Manifest, MAIN_FILE_NAME},
|
||||
};
|
||||
use leo_package::{
|
||||
root::Manifest,
|
||||
source::{MAIN_FILE_NAME, SOURCE_DIRECTORY_NAME},
|
||||
};
|
||||
|
||||
use clap::ArgMatches;
|
||||
|
@ -2,9 +2,11 @@ use crate::{
|
||||
cli::*,
|
||||
cli_types::*,
|
||||
commands::BuildCommand,
|
||||
directories::SOURCE_DIRECTORY_NAME,
|
||||
errors::{CLIError, RunError},
|
||||
files::{Manifest, MAIN_FILE_NAME},
|
||||
};
|
||||
use leo_package::{
|
||||
root::Manifest,
|
||||
source::{MAIN_FILE_NAME, SOURCE_DIRECTORY_NAME},
|
||||
};
|
||||
|
||||
use clap::ArgMatches;
|
||||
|
@ -1,9 +1,12 @@
|
||||
use crate::{
|
||||
cli::*,
|
||||
cli_types::*,
|
||||
directories::{InputDirectory, SourceDirectory},
|
||||
errors::{CLIError, NewError},
|
||||
files::{Gitignore, InputFile, LibFile, MainFile, Manifest},
|
||||
};
|
||||
use leo_package::{
|
||||
inputs::*,
|
||||
root::{Gitignore, Manifest},
|
||||
source::{LibFile, MainFile, SourceDirectory},
|
||||
};
|
||||
|
||||
use clap::ArgMatches;
|
||||
@ -81,11 +84,14 @@ impl CLI for NewCommand {
|
||||
LibFile::new(&package_name).write_to(&path)?;
|
||||
} else {
|
||||
// Create the input directory
|
||||
InputDirectory::create(&path)?;
|
||||
InputsDirectory::create(&path)?;
|
||||
|
||||
// Create the input file in the input directory
|
||||
// Create the input file in the inputs directory
|
||||
InputFile::new(&package_name).write_to(&path)?;
|
||||
|
||||
// Create the state file in the inputs directory
|
||||
StateFile::new(&package_name).write_to(&path)?;
|
||||
|
||||
// Create the main file in the source directory
|
||||
MainFile::new(&package_name).write_to(&path)?;
|
||||
}
|
||||
|
@ -1,10 +1,5 @@
|
||||
use crate::{
|
||||
cli::*,
|
||||
cli_types::*,
|
||||
commands::SetupCommand,
|
||||
errors::CLIError,
|
||||
files::{Manifest, ProofFile},
|
||||
};
|
||||
use crate::{cli::*, cli_types::*, commands::SetupCommand, errors::CLIError};
|
||||
use leo_package::{outputs::ProofFile, root::Manifest};
|
||||
|
||||
use snarkos_algorithms::snark::groth16::{Groth16, PreparedVerifyingKey, Proof};
|
||||
use snarkos_curves::bls12_377::{Bls12_377, Fr};
|
||||
|
@ -1,10 +1,7 @@
|
||||
use crate::{
|
||||
cli::*,
|
||||
cli_types::*,
|
||||
commands::BuildCommand,
|
||||
directories::output::OutputDirectory,
|
||||
errors::CLIError,
|
||||
files::{Manifest, ZipFile},
|
||||
use crate::{cli::*, cli_types::*, commands::BuildCommand, errors::CLIError};
|
||||
use leo_package::{
|
||||
outputs::OutputsDirectory,
|
||||
root::{Manifest, ZipFile},
|
||||
};
|
||||
|
||||
use clap::ArgMatches;
|
||||
@ -40,7 +37,7 @@ impl CLI for PublishCommand {
|
||||
let package_name = Manifest::try_from(&path)?.get_package_name();
|
||||
|
||||
// Create the output directory
|
||||
OutputDirectory::create(&path)?;
|
||||
OutputsDirectory::create(&path)?;
|
||||
|
||||
// Create zip file
|
||||
let zip_file = ZipFile::new(&package_name);
|
||||
|
@ -2,11 +2,14 @@ use crate::{
|
||||
cli::*,
|
||||
cli_types::*,
|
||||
commands::BuildCommand,
|
||||
directories::SOURCE_DIRECTORY_NAME,
|
||||
errors::{CLIError, RunError},
|
||||
files::{Manifest, ProvingKeyFile, VerificationKeyFile, MAIN_FILE_NAME},
|
||||
};
|
||||
use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType};
|
||||
use leo_package::{
|
||||
outputs::{ProvingKeyFile, VerificationKeyFile},
|
||||
root::Manifest,
|
||||
source::{MAIN_FILE_NAME, SOURCE_DIRECTORY_NAME},
|
||||
};
|
||||
|
||||
use snarkos_algorithms::snark::groth16::{Groth16, Parameters, PreparedVerifyingKey, VerifyingKey};
|
||||
use snarkos_curves::bls12_377::{Bls12_377, Fr};
|
||||
|
@ -1,14 +1,17 @@
|
||||
use crate::{
|
||||
cli::*,
|
||||
cli_types::*,
|
||||
directories::{output::OUTPUT_DIRECTORY_NAME, source::SOURCE_DIRECTORY_NAME},
|
||||
errors::{CLIError, TestError},
|
||||
files::{InputFile, MainFile, Manifest, StateFile, MAIN_FILE_NAME},
|
||||
};
|
||||
use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType};
|
||||
use leo_package::{
|
||||
inputs::*,
|
||||
outputs::OUTPUTS_DIRECTORY_NAME,
|
||||
root::Manifest,
|
||||
source::{MainFile, MAIN_FILE_NAME, SOURCE_DIRECTORY_NAME},
|
||||
};
|
||||
|
||||
use snarkos_curves::edwards_bls12::Fq;
|
||||
use snarkos_models::gadgets::r1cs::TestConstraintSystem;
|
||||
|
||||
use clap::ArgMatches;
|
||||
use std::{convert::TryFrom, env::current_dir};
|
||||
@ -58,7 +61,7 @@ impl CLI for TestCommand {
|
||||
|
||||
// Construct the path to the output directory;
|
||||
let mut output_directory = package_path.clone();
|
||||
output_directory.push(OUTPUT_DIRECTORY_NAME);
|
||||
output_directory.push(OUTPUTS_DIRECTORY_NAME);
|
||||
|
||||
// Load the input file at `package_name`
|
||||
let input_string = InputFile::new(&package_name).read_from(&path)?;
|
||||
@ -77,9 +80,8 @@ impl CLI for TestCommand {
|
||||
|
||||
// Generate the program on the constraint system and verify correctness
|
||||
{
|
||||
let mut cs = TestConstraintSystem::<Fq>::new();
|
||||
let temporary_program = program.clone();
|
||||
let output = temporary_program.compile_test_constraints(&mut cs)?;
|
||||
let output = temporary_program.compile_test_constraints()?;
|
||||
log::debug!("Compiled constraints - {:#?}", output);
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,11 @@ use crate::{
|
||||
cli::*,
|
||||
cli_types::*,
|
||||
commands::BuildCommand,
|
||||
directories::SOURCE_DIRECTORY_NAME,
|
||||
errors::{CLIError, RunError},
|
||||
files::{Manifest, MAIN_FILE_NAME},
|
||||
};
|
||||
use leo_package::{
|
||||
root::Manifest,
|
||||
source::{MAIN_FILE_NAME, SOURCE_DIRECTORY_NAME},
|
||||
};
|
||||
|
||||
use clap::ArgMatches;
|
||||
|
@ -1,60 +0,0 @@
|
||||
use crate::errors::InputDirectoryError;
|
||||
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
pub(crate) static INPUT_DIRECTORY_NAME: &str = "input/";
|
||||
|
||||
static INPUT_FILE_EXTENSION: &str = "leo.in";
|
||||
|
||||
pub struct InputDirectory;
|
||||
|
||||
impl InputDirectory {
|
||||
/// Creates a directory at the provided path with the default directory name.
|
||||
pub fn create(path: &PathBuf) -> Result<(), InputDirectoryError> {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() && !path.ends_with(INPUT_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(INPUT_DIRECTORY_NAME));
|
||||
}
|
||||
|
||||
fs::create_dir_all(&path).map_err(InputDirectoryError::Creating)
|
||||
}
|
||||
|
||||
/// Returns a list of files in the source directory.
|
||||
pub fn files(path: &PathBuf) -> Result<Vec<PathBuf>, InputDirectoryError> {
|
||||
let mut path = path.to_owned();
|
||||
path.push(PathBuf::from(INPUT_DIRECTORY_NAME));
|
||||
let directory = fs::read_dir(&path).map_err(InputDirectoryError::Reading)?;
|
||||
|
||||
let mut file_paths = Vec::new();
|
||||
for file_entry in directory.into_iter() {
|
||||
let file_entry = file_entry.map_err(InputDirectoryError::GettingFileEntry)?;
|
||||
let file_path = file_entry.path();
|
||||
|
||||
// Verify that the entry is structured as a valid file
|
||||
let file_type = file_entry
|
||||
.file_type()
|
||||
.map_err(|error| InputDirectoryError::GettingFileType(file_path.as_os_str().to_owned(), error))?;
|
||||
if !file_type.is_file() {
|
||||
return Err(InputDirectoryError::InvalidFileType(
|
||||
file_path.as_os_str().to_owned(),
|
||||
file_type,
|
||||
));
|
||||
}
|
||||
|
||||
// Verify that the file has the default file extension
|
||||
let file_extension = file_path
|
||||
.extension()
|
||||
.ok_or_else(|| InputDirectoryError::GettingFileExtension(file_path.as_os_str().to_owned()))?;
|
||||
if file_extension != INPUT_FILE_EXTENSION {
|
||||
return Err(InputDirectoryError::InvalidFileExtension(
|
||||
file_path.as_os_str().to_owned(),
|
||||
file_extension.to_owned(),
|
||||
));
|
||||
}
|
||||
|
||||
file_paths.push(file_path);
|
||||
}
|
||||
|
||||
Ok(file_paths)
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
pub mod imports;
|
||||
pub use self::imports::*;
|
||||
|
||||
pub mod input;
|
||||
pub use self::input::*;
|
||||
|
||||
pub mod output;
|
||||
pub use self::output::*;
|
||||
|
||||
pub mod source;
|
||||
pub use self::source::*;
|
@ -1,33 +0,0 @@
|
||||
use crate::errors::OutputDirectoryError;
|
||||
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
pub(crate) static OUTPUT_DIRECTORY_NAME: &str = "output/";
|
||||
|
||||
pub struct OutputDirectory;
|
||||
|
||||
impl OutputDirectory {
|
||||
/// Creates a directory at the provided path with the default directory name.
|
||||
pub fn create(path: &PathBuf) -> Result<(), OutputDirectoryError> {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() && !path.ends_with(OUTPUT_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME));
|
||||
}
|
||||
|
||||
fs::create_dir_all(&path).map_err(OutputDirectoryError::Creating)
|
||||
}
|
||||
|
||||
/// Removes the directory at the provided path.
|
||||
pub fn remove(path: &PathBuf) -> Result<(), OutputDirectoryError> {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() && !path.ends_with(OUTPUT_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME));
|
||||
}
|
||||
|
||||
if path.exists() {
|
||||
fs::remove_dir_all(&path).map_err(OutputDirectoryError::Removing)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
use crate::errors::*;
|
||||
use leo_package::errors::*;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum CLIError {
|
||||
@ -21,7 +22,7 @@ pub enum CLIError {
|
||||
InitError(InitError),
|
||||
|
||||
#[error("{}", _0)]
|
||||
InputDirectoryError(InputDirectoryError),
|
||||
InputDirectoryError(InputsDirectoryError),
|
||||
|
||||
#[error("{}", _0)]
|
||||
InputFileError(InputFileError),
|
||||
@ -39,7 +40,7 @@ pub enum CLIError {
|
||||
NewError(NewError),
|
||||
|
||||
#[error("{}", _0)]
|
||||
OutputDirectoryError(OutputDirectoryError),
|
||||
OutputDirectoryError(OutputsDirectoryError),
|
||||
|
||||
#[error("{}", _0)]
|
||||
ProofFileError(ProofFileError),
|
||||
@ -101,8 +102,8 @@ impl From<InitError> for CLIError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<InputDirectoryError> for CLIError {
|
||||
fn from(error: InputDirectoryError) -> Self {
|
||||
impl From<InputsDirectoryError> for CLIError {
|
||||
fn from(error: InputsDirectoryError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
CLIError::InputDirectoryError(error)
|
||||
}
|
||||
@ -143,8 +144,8 @@ impl From<NewError> for CLIError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<OutputDirectoryError> for CLIError {
|
||||
fn from(error: OutputDirectoryError) -> Self {
|
||||
impl From<OutputsDirectoryError> for CLIError {
|
||||
fn from(error: OutputsDirectoryError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
CLIError::OutputDirectoryError(error)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::errors::ManifestError;
|
||||
use leo_package::errors::ManifestError;
|
||||
|
||||
use std::ffi::OsString;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::errors::ManifestError;
|
||||
use leo_package::errors::ManifestError;
|
||||
|
||||
use std::{ffi::OsString, io};
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::errors::ManifestError;
|
||||
use leo_package::errors::ManifestError;
|
||||
|
||||
use std::{ffi::OsString, io};
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::errors::ManifestError;
|
||||
use leo_package::errors::ManifestError;
|
||||
|
||||
use std::ffi::OsString;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::errors::ManifestError;
|
||||
use leo_package::errors::ManifestError;
|
||||
|
||||
use std::ffi::OsString;
|
||||
|
||||
|
@ -1,11 +0,0 @@
|
||||
pub mod imports;
|
||||
pub use self::imports::*;
|
||||
|
||||
pub mod input;
|
||||
pub use self::input::*;
|
||||
|
||||
pub mod output;
|
||||
pub use self::output::*;
|
||||
|
||||
pub mod source;
|
||||
pub use self::source::*;
|
@ -1,32 +0,0 @@
|
||||
pub mod zip;
|
||||
pub use self::zip::*;
|
||||
|
||||
pub mod checksum;
|
||||
pub use self::checksum::*;
|
||||
|
||||
pub mod gitignore;
|
||||
pub use self::gitignore::*;
|
||||
|
||||
pub mod input;
|
||||
pub use self::input::*;
|
||||
|
||||
pub mod lib;
|
||||
pub use self::lib::*;
|
||||
|
||||
pub mod main;
|
||||
pub use self::main::*;
|
||||
|
||||
pub mod manifest;
|
||||
pub use self::manifest::*;
|
||||
|
||||
pub mod proof;
|
||||
pub use self::proof::*;
|
||||
|
||||
pub mod proving_key;
|
||||
pub use self::proving_key::*;
|
||||
|
||||
pub mod state;
|
||||
pub use self::state::*;
|
||||
|
||||
pub mod verification_key;
|
||||
pub use self::verification_key::*;
|
@ -3,9 +3,3 @@ pub use self::cli::*;
|
||||
|
||||
pub mod commands;
|
||||
pub use self::commands::*;
|
||||
|
||||
pub mod directory;
|
||||
pub use self::directory::*;
|
||||
|
||||
pub mod files;
|
||||
pub use self::files::*;
|
||||
|
@ -1,32 +0,0 @@
|
||||
pub mod zip;
|
||||
pub use self::zip::*;
|
||||
|
||||
pub mod checksum;
|
||||
pub use self::checksum::*;
|
||||
|
||||
pub mod input;
|
||||
pub use self::input::*;
|
||||
|
||||
pub mod gitignore;
|
||||
pub use self::gitignore::*;
|
||||
|
||||
pub mod lib;
|
||||
pub use self::lib::*;
|
||||
|
||||
pub mod main;
|
||||
pub use self::main::*;
|
||||
|
||||
pub mod manifest;
|
||||
pub use self::manifest::*;
|
||||
|
||||
pub mod proof;
|
||||
pub use self::proof::*;
|
||||
|
||||
pub mod proving_key;
|
||||
pub use self::proving_key::*;
|
||||
|
||||
pub mod state;
|
||||
pub use self::state::*;
|
||||
|
||||
pub mod verification_key;
|
||||
pub use self::verification_key::*;
|
@ -5,7 +5,5 @@ extern crate thiserror;
|
||||
pub mod cli;
|
||||
pub mod cli_types;
|
||||
pub mod commands;
|
||||
pub mod directories;
|
||||
pub mod errors;
|
||||
pub mod files;
|
||||
pub mod logger;
|
||||
|
14
package/Cargo.toml
Normal file
14
package/Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "leo-package"
|
||||
version = "0.1.0"
|
||||
authors = ["The Aleo Team <hello@aleo.org>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
log = { version = "0.4" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = { version = "1.0" }
|
||||
thiserror = { version = "1.0" }
|
||||
toml = { version = "0.5" }
|
||||
walkdir = { version = "2" }
|
||||
zip = { version = "0.5" }
|
2
package/src/errors/imports/mod.rs
Normal file
2
package/src/errors/imports/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
pub mod directory;
|
||||
pub use directory::*;
|
@ -1,7 +1,7 @@
|
||||
use std::{ffi::OsString, fs::FileType, io};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum InputDirectoryError {
|
||||
pub enum InputsDirectoryError {
|
||||
#[error("creating: {}", _0)]
|
||||
Creating(io::Error),
|
||||
|
8
package/src/errors/inputs/mod.rs
Normal file
8
package/src/errors/inputs/mod.rs
Normal file
@ -0,0 +1,8 @@
|
||||
pub mod directory;
|
||||
pub use directory::*;
|
||||
|
||||
pub mod input;
|
||||
pub use input::*;
|
||||
|
||||
pub mod state;
|
||||
pub use state::*;
|
14
package/src/errors/mod.rs
Normal file
14
package/src/errors/mod.rs
Normal file
@ -0,0 +1,14 @@
|
||||
pub mod imports;
|
||||
pub use imports::*;
|
||||
|
||||
pub mod inputs;
|
||||
pub use inputs::*;
|
||||
|
||||
pub mod outputs;
|
||||
pub use outputs::*;
|
||||
|
||||
pub mod root;
|
||||
pub use self::root::*;
|
||||
|
||||
pub mod source;
|
||||
pub use self::source::*;
|
@ -1,7 +1,7 @@
|
||||
use std::{ffi::OsString, fs::FileType, io};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum OutputDirectoryError {
|
||||
pub enum OutputsDirectoryError {
|
||||
#[error("creating: {}", _0)]
|
||||
Creating(io::Error),
|
||||
|
14
package/src/errors/outputs/mod.rs
Normal file
14
package/src/errors/outputs/mod.rs
Normal file
@ -0,0 +1,14 @@
|
||||
pub mod checksum;
|
||||
pub use checksum::*;
|
||||
|
||||
pub mod directory;
|
||||
pub use self::directory::*;
|
||||
|
||||
pub mod proof;
|
||||
pub use proof::*;
|
||||
|
||||
pub mod proving_key;
|
||||
pub use proving_key::*;
|
||||
|
||||
pub mod verification_key;
|
||||
pub use verification_key::*;
|
8
package/src/errors/root/mod.rs
Normal file
8
package/src/errors/root/mod.rs
Normal file
@ -0,0 +1,8 @@
|
||||
pub mod gitignore;
|
||||
pub use self::gitignore::*;
|
||||
|
||||
pub mod manifest;
|
||||
pub use self::manifest::*;
|
||||
|
||||
pub mod zip;
|
||||
pub use self::zip::*;
|
8
package/src/errors/source/mod.rs
Normal file
8
package/src/errors/source/mod.rs
Normal file
@ -0,0 +1,8 @@
|
||||
pub mod directory;
|
||||
pub use directory::*;
|
||||
|
||||
pub mod lib;
|
||||
pub use lib::*;
|
||||
|
||||
pub mod main;
|
||||
pub use main::*;
|
@ -2,7 +2,7 @@ use crate::errors::ImportsDirectoryError;
|
||||
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
pub(crate) static IMPORTS_DIRECTORY_NAME: &str = "imports/";
|
||||
pub static IMPORTS_DIRECTORY_NAME: &str = "imports/";
|
||||
|
||||
pub struct ImportsDirectory;
|
||||
|
2
package/src/imports/mod.rs
Normal file
2
package/src/imports/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
pub mod directory;
|
||||
pub use directory::*;
|
58
package/src/inputs/directory.rs
Normal file
58
package/src/inputs/directory.rs
Normal file
@ -0,0 +1,58 @@
|
||||
use crate::{errors::InputsDirectoryError, inputs::INPUT_FILE_EXTENSION};
|
||||
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
pub static INPUTS_DIRECTORY_NAME: &str = "inputs/";
|
||||
|
||||
pub struct InputsDirectory;
|
||||
|
||||
impl InputsDirectory {
|
||||
/// Creates a directory at the provided path with the default directory name.
|
||||
pub fn create(path: &PathBuf) -> Result<(), InputsDirectoryError> {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() && !path.ends_with(INPUTS_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(INPUTS_DIRECTORY_NAME));
|
||||
}
|
||||
|
||||
fs::create_dir_all(&path).map_err(InputsDirectoryError::Creating)
|
||||
}
|
||||
|
||||
/// Returns a list of files in the source directory.
|
||||
pub fn files(path: &PathBuf) -> Result<Vec<PathBuf>, InputsDirectoryError> {
|
||||
let mut path = path.to_owned();
|
||||
path.push(PathBuf::from(INPUTS_DIRECTORY_NAME));
|
||||
let directory = fs::read_dir(&path).map_err(InputsDirectoryError::Reading)?;
|
||||
|
||||
let mut file_paths = Vec::new();
|
||||
for file_entry in directory.into_iter() {
|
||||
let file_entry = file_entry.map_err(InputsDirectoryError::GettingFileEntry)?;
|
||||
let file_path = file_entry.path();
|
||||
|
||||
// Verify that the entry is structured as a valid file
|
||||
let file_type = file_entry
|
||||
.file_type()
|
||||
.map_err(|error| InputsDirectoryError::GettingFileType(file_path.as_os_str().to_owned(), error))?;
|
||||
if !file_type.is_file() {
|
||||
return Err(InputsDirectoryError::InvalidFileType(
|
||||
file_path.as_os_str().to_owned(),
|
||||
file_type,
|
||||
));
|
||||
}
|
||||
|
||||
// Verify that the file has the default file extension
|
||||
let file_extension = file_path
|
||||
.extension()
|
||||
.ok_or_else(|| InputsDirectoryError::GettingFileExtension(file_path.as_os_str().to_owned()))?;
|
||||
if file_extension != INPUT_FILE_EXTENSION {
|
||||
return Err(InputsDirectoryError::InvalidFileExtension(
|
||||
file_path.as_os_str().to_owned(),
|
||||
file_extension.to_owned(),
|
||||
));
|
||||
}
|
||||
|
||||
file_paths.push(file_path);
|
||||
}
|
||||
|
||||
Ok(file_paths)
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
//! The `program.in` file.
|
||||
|
||||
use crate::{directories::input::INPUT_DIRECTORY_NAME, errors::InputFileError};
|
||||
use crate::{errors::InputFileError, inputs::INPUTS_DIRECTORY_NAME};
|
||||
|
||||
use serde::Deserialize;
|
||||
use std::{
|
||||
@ -50,6 +50,9 @@ impl InputFile {
|
||||
[main]
|
||||
a: u32 = 1;
|
||||
b: u32 = 2;
|
||||
|
||||
[registers]
|
||||
r0: u32 = 0;
|
||||
"#,
|
||||
self.package_name
|
||||
)
|
||||
@ -58,8 +61,8 @@ b: u32 = 2;
|
||||
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
if !path.ends_with(INPUT_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(INPUT_DIRECTORY_NAME));
|
||||
if !path.ends_with(INPUTS_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(INPUTS_DIRECTORY_NAME));
|
||||
}
|
||||
path.push(PathBuf::from(format!("{}{}", self.package_name, INPUT_FILE_EXTENSION)));
|
||||
}
|
8
package/src/inputs/mod.rs
Normal file
8
package/src/inputs/mod.rs
Normal file
@ -0,0 +1,8 @@
|
||||
pub mod directory;
|
||||
pub use directory::*;
|
||||
|
||||
pub mod input;
|
||||
pub use input::*;
|
||||
|
||||
pub mod state;
|
||||
pub use state::*;
|
@ -1,6 +1,6 @@
|
||||
//! The `program.state` file.
|
||||
|
||||
use crate::{directories::input::INPUT_DIRECTORY_NAME, errors::StateFileError};
|
||||
use crate::{errors::StateFileError, inputs::INPUTS_DIRECTORY_NAME};
|
||||
|
||||
use serde::Deserialize;
|
||||
use std::{
|
||||
@ -79,8 +79,8 @@ leaf_randomness: u8[32] = [0u8; 32];
|
||||
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
if !path.ends_with(INPUT_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(INPUT_DIRECTORY_NAME));
|
||||
if !path.ends_with(INPUTS_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(INPUTS_DIRECTORY_NAME));
|
||||
}
|
||||
path.push(PathBuf::from(format!("{}{}", self.package_name, STATE_FILE_EXTENSION)));
|
||||
}
|
11
package/src/lib.rs
Normal file
11
package/src/lib.rs
Normal file
@ -0,0 +1,11 @@
|
||||
#[macro_use]
|
||||
extern crate thiserror;
|
||||
|
||||
pub mod errors;
|
||||
pub use errors::*;
|
||||
|
||||
pub mod imports;
|
||||
pub mod inputs;
|
||||
pub mod outputs;
|
||||
pub mod root;
|
||||
pub mod source;
|
@ -1,6 +1,6 @@
|
||||
//! The build checksum file.
|
||||
|
||||
use crate::{directories::output::OUTPUT_DIRECTORY_NAME, errors::ChecksumFileError};
|
||||
use crate::{errors::ChecksumFileError, outputs::OUTPUTS_DIRECTORY_NAME};
|
||||
|
||||
use serde::Deserialize;
|
||||
use std::{
|
||||
@ -60,8 +60,8 @@ impl ChecksumFile {
|
||||
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
if !path.ends_with(OUTPUT_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME));
|
||||
if !path.ends_with(OUTPUTS_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME));
|
||||
}
|
||||
path.push(PathBuf::from(format!(
|
||||
"{}{}",
|
33
package/src/outputs/directory.rs
Normal file
33
package/src/outputs/directory.rs
Normal file
@ -0,0 +1,33 @@
|
||||
use crate::errors::OutputsDirectoryError;
|
||||
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
pub static OUTPUTS_DIRECTORY_NAME: &str = "outputs/";
|
||||
|
||||
pub struct OutputsDirectory;
|
||||
|
||||
impl OutputsDirectory {
|
||||
/// Creates a directory at the provided path with the default directory name.
|
||||
pub fn create(path: &PathBuf) -> Result<(), OutputsDirectoryError> {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() && !path.ends_with(OUTPUTS_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME));
|
||||
}
|
||||
|
||||
fs::create_dir_all(&path).map_err(OutputsDirectoryError::Creating)
|
||||
}
|
||||
|
||||
/// Removes the directory at the provided path.
|
||||
pub fn remove(path: &PathBuf) -> Result<(), OutputsDirectoryError> {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() && !path.ends_with(OUTPUTS_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME));
|
||||
}
|
||||
|
||||
if path.exists() {
|
||||
fs::remove_dir_all(&path).map_err(OutputsDirectoryError::Removing)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
14
package/src/outputs/mod.rs
Normal file
14
package/src/outputs/mod.rs
Normal file
@ -0,0 +1,14 @@
|
||||
pub mod checksum;
|
||||
pub use self::checksum::*;
|
||||
|
||||
pub mod directory;
|
||||
pub use directory::*;
|
||||
|
||||
pub mod proof;
|
||||
pub use self::proof::*;
|
||||
|
||||
pub mod proving_key;
|
||||
pub use self::proving_key::*;
|
||||
|
||||
pub mod verification_key;
|
||||
pub use self::verification_key::*;
|
@ -1,6 +1,6 @@
|
||||
//! The proof file.
|
||||
|
||||
use crate::{directories::output::OUTPUT_DIRECTORY_NAME, errors::ProofFileError};
|
||||
use crate::{errors::ProofFileError, outputs::OUTPUTS_DIRECTORY_NAME};
|
||||
|
||||
use serde::Deserialize;
|
||||
use std::{
|
||||
@ -63,8 +63,8 @@ impl ProofFile {
|
||||
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
if !path.ends_with(OUTPUT_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME));
|
||||
if !path.ends_with(OUTPUTS_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME));
|
||||
}
|
||||
path.push(PathBuf::from(format!("{}{}", self.package_name, PROOF_FILE_EXTENSION)));
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
//! The proving key file.
|
||||
|
||||
use crate::{directories::output::OUTPUT_DIRECTORY_NAME, errors::ProvingKeyFileError};
|
||||
use crate::{errors::ProvingKeyFileError, outputs::OUTPUTS_DIRECTORY_NAME};
|
||||
|
||||
use serde::Deserialize;
|
||||
use std::{
|
||||
@ -60,8 +60,8 @@ impl ProvingKeyFile {
|
||||
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
if !path.ends_with(OUTPUT_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME));
|
||||
if !path.ends_with(OUTPUTS_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME));
|
||||
}
|
||||
path.push(PathBuf::from(format!(
|
||||
"{}{}",
|
@ -1,6 +1,6 @@
|
||||
//! The verification key file.
|
||||
|
||||
use crate::{directories::output::OUTPUT_DIRECTORY_NAME, errors::VerificationKeyFileError};
|
||||
use crate::{errors::VerificationKeyFileError, outputs::OUTPUTS_DIRECTORY_NAME};
|
||||
|
||||
use serde::Deserialize;
|
||||
use std::{
|
||||
@ -60,8 +60,8 @@ impl VerificationKeyFile {
|
||||
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
if !path.ends_with(OUTPUT_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME));
|
||||
if !path.ends_with(OUTPUTS_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME));
|
||||
}
|
||||
path.push(PathBuf::from(format!(
|
||||
"{}{}",
|
@ -35,7 +35,7 @@ impl Gitignore {
|
||||
|
||||
fn template(&self) -> String {
|
||||
format!(
|
||||
r#"output/
|
||||
r#"outputs/
|
||||
"#,
|
||||
)
|
||||
}
|
8
package/src/root/mod.rs
Normal file
8
package/src/root/mod.rs
Normal file
@ -0,0 +1,8 @@
|
||||
pub mod gitignore;
|
||||
pub use self::gitignore::*;
|
||||
|
||||
pub mod manifest;
|
||||
pub use self::manifest::*;
|
||||
|
||||
pub mod zip;
|
||||
pub use self::zip::*;
|
@ -1,11 +1,12 @@
|
||||
//! The program package zip file.
|
||||
|
||||
use crate::{
|
||||
directories::{IMPORTS_DIRECTORY_NAME, INPUT_DIRECTORY_NAME, OUTPUT_DIRECTORY_NAME},
|
||||
errors::ZipFileError,
|
||||
files::{
|
||||
imports::IMPORTS_DIRECTORY_NAME,
|
||||
inputs::{INPUTS_DIRECTORY_NAME, INPUT_FILE_EXTENSION},
|
||||
outputs::{
|
||||
CHECKSUM_FILE_EXTENSION,
|
||||
INPUT_FILE_EXTENSION,
|
||||
OUTPUTS_DIRECTORY_NAME,
|
||||
PROOF_FILE_EXTENSION,
|
||||
PROVING_KEY_FILE_EXTENSION,
|
||||
VERIFICATION_KEY_FILE_EXTENSION,
|
||||
@ -99,8 +100,8 @@ impl ZipFile {
|
||||
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
if !path.ends_with(OUTPUT_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(OUTPUT_DIRECTORY_NAME));
|
||||
if !path.ends_with(OUTPUTS_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(OUTPUTS_DIRECTORY_NAME));
|
||||
}
|
||||
path.push(PathBuf::from(format!("{}{}", self.package_name, ZIP_FILE_EXTENSION)));
|
||||
}
|
||||
@ -110,8 +111,8 @@ impl ZipFile {
|
||||
|
||||
fn is_excluded(path: &Path) -> bool {
|
||||
// excluded directories: `input`, `output`, `imports`
|
||||
if path.ends_with(INPUT_DIRECTORY_NAME.trim_end_matches("/"))
|
||||
| path.ends_with(OUTPUT_DIRECTORY_NAME.trim_end_matches("/"))
|
||||
if path.ends_with(INPUTS_DIRECTORY_NAME.trim_end_matches("/"))
|
||||
| path.ends_with(OUTPUTS_DIRECTORY_NAME.trim_end_matches("/"))
|
||||
| path.ends_with(IMPORTS_DIRECTORY_NAME.trim_end_matches("/"))
|
||||
{
|
||||
return true;
|
@ -2,7 +2,7 @@ use crate::errors::SourceDirectoryError;
|
||||
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
pub(crate) static SOURCE_DIRECTORY_NAME: &str = "src/";
|
||||
pub static SOURCE_DIRECTORY_NAME: &str = "src/";
|
||||
|
||||
static SOURCE_FILE_EXTENSION: &str = "leo";
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! The `lib.leo` file.
|
||||
|
||||
use crate::{directories::source::SOURCE_DIRECTORY_NAME, errors::LibFileError};
|
||||
use crate::{errors::LibFileError, source::directory::SOURCE_DIRECTORY_NAME};
|
||||
|
||||
use serde::Deserialize;
|
||||
use std::{fs::File, io::Write, path::PathBuf};
|
@ -1,6 +1,6 @@
|
||||
//! The `main.leo` file.
|
||||
|
||||
use crate::{directories::source::SOURCE_DIRECTORY_NAME, errors::MainFileError};
|
||||
use crate::{errors::MainFileError, source::directory::SOURCE_DIRECTORY_NAME};
|
||||
|
||||
use serde::Deserialize;
|
||||
use std::{fs::File, io::Write, path::PathBuf};
|
8
package/src/source/mod.rs
Normal file
8
package/src/source/mod.rs
Normal file
@ -0,0 +1,8 @@
|
||||
pub mod directory;
|
||||
pub use directory::*;
|
||||
|
||||
pub mod lib;
|
||||
pub use lib::*;
|
||||
|
||||
pub mod main;
|
||||
pub use main::*;
|
Loading…
Reference in New Issue
Block a user