Skip to content

Commit

Permalink
Add wasm proof generation with inclusion proof
Browse files Browse the repository at this point in the history
  • Loading branch information
evanmarshall committed Mar 1, 2023
1 parent f70e92c commit 35824d8
Show file tree
Hide file tree
Showing 23 changed files with 1,310 additions and 195 deletions.
182 changes: 62 additions & 120 deletions Cargo.lock

Large diffs are not rendered by default.

98 changes: 51 additions & 47 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,20 @@ members = [ "rust", "wasm" ]

[workspace.dependencies.snarkvm]
version = "0.9.13"
path="../snarkVM"

[workspace.dependencies.snarkvm-wasm]
version = "0.9.13"
default-features = false
path="../snarkVM/wasm"

[workspace.dependencies.snarkvm-synthesizer]
path="../snarkVM/synthesizer"
version = "0.9.13"

[workspace.dependencies.snarkvm-console]
path="../snarkVM/console"
version = "0.9.13"

[lib]
path = "cli/lib.rs"
Expand All @@ -41,68 +51,62 @@ wasm = [ "aleo-wasm" ]
[dependencies]
num-format = "0.4.4"

[dependencies.aleo-rust]
path = "rust"
version = "0.3.5"
optional = true
[dependencies.aleo-rust]
path = "rust"
version = "0.3.5"
optional = true

[dependencies.aleo-wasm]
path = "wasm"
version = "0.3.5"
optional = true
[dependencies.aleo-wasm]
path = "wasm"
version = "0.3.5"
optional = true

[dependencies.anyhow]
version = "1.0"
[dependencies.anyhow]
version = "1.0"

[dependencies.clap]
version = "3.2"
features = [ "derive" ]
[dependencies.clap]
version = "3.2"
features = [ "derive" ]

[dependencies.colored]
version = "2"
[dependencies.colored]
version = "2"

[dependencies.parking_lot]
version = "0.12"
[dependencies.parking_lot]
version = "0.12"

[dependencies.rand]
version = "0.8"
default-features = false
[dependencies.rand]
version = "0.8"
default-features = false

[dependencies.rand_chacha]
version = "0.3.0"
default-features = false
[dependencies.rand_chacha]
version = "0.3.0"
default-features = false

[dependencies.rpassword]
version = "7.2.0"
[dependencies.rpassword]
version = "7.2.0"

[dependencies.self_update]
version = "0.32"
[dependencies.self_update]
version = "0.32"

[dependencies.serde]
version = "1"
[dependencies.serde]
version = "1"

[dependencies.serde_json]
version = "1"
[dependencies.serde_json]
version = "1"

[dependencies.snarkvm]
workspace = true
features = [
"aleo-cli",
"circuit",
"console",
"parallel",
"snarkvm-synthesizer"
]
[dependencies.snarkvm]
workspace = true
features = [ "aleo-cli", "circuit", "console", "snarkvm-synthesizer"]

[dependencies.thiserror]
version = "1.0"
[dependencies.thiserror]
version = "1.0"

[dependencies.tokio]
version = "1.22"
features = [ "rt" ]
[dependencies.tokio]
version = "1.22"
features = [ "rt" ]

[dependencies.warp]
version = "0.3"
[dependencies.warp]
version = "0.3"

[dev-dependencies.rusty-hook]
version = "0.11.2"
Expand Down
21 changes: 14 additions & 7 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,26 @@ optional = true
[dependencies.serde_json]
version = "1.0.91"

[dependencies.snarkvm-console]
features = [ "parallel" ]
optional = true
[dependencies.snarkvm-wasm]
version = "0.9.13"
path="../../snarkVM/wasm"

[dependencies.snarkvm-utilities]
version = "0.9.13"
path="../../snarkVM/utilities"

[dependencies.snarkvm-synthesizer]
features = [ "parallel" ]
optional = true
version = "0.9.13"
path = "../../snarkVM/synthesizer"
default-features = false
features = [ "wasm" ]
optional = true

[dependencies.snarkvm-utilities]
features = [ "parallel" ]
[dependencies.snarkvm-console]
path = "../../snarkVM/console"
default-features = false
version = "0.9.13"
optional = true

[dev-dependencies.bencher]
version = "0.1.5"
Expand Down
5 changes: 4 additions & 1 deletion rust/src/account/encryptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
use snarkvm_console::{
account::PrivateKey,
network::Network,
program::{Ciphertext, Identifier, Literal, Plaintext},
types::Field,
};
use snarkvm_utilities::Uniform;

use snarkvm_console::{
program::{Ciphertext, Identifier, Literal, Plaintext}
};

use anyhow::{anyhow, Result};
use once_cell::sync::OnceCell;
use std::{iter::FromIterator, str::FromStr};
Expand Down
40 changes: 38 additions & 2 deletions wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,53 @@ version = "0.8"

[dependencies.serde_json]
version = "1.0"
features = [ "preserve_order" ]

[dependencies.snarkvm-synthesizer]
path="../../snarkVM/synthesizer"
version = "0.9.13"
default-features = false
features = [ "wasm" ]

[dependencies.snarkvm-console]
path="../../snarkVM/console"
version = "0.9.13"
default-features = false

[dependencies.snarkvm-wasm]
workspace = true
features = [ "console", "fields", "utilities" ]
path="../../snarkVM/wasm"
version = "0.9.13"

[dependencies.wasm-bindgen]
version = "0.2"
features = [ "serde-serialize" ]

[dependencies.js-sys]
version = "0.3"

[dependencies.web-sys]
version = "0.3"
features = ["console"]

[dependencies.serde]
version = "1.0"
features = ["derive"]

[dependencies.serde-wasm-bindgen]
version = "0.4"

[dependencies.console_error_panic_hook]
version = "0.1.7"

[dependencies.rand_chacha]
version = "0.3.1"

[dev-dependencies.wasm-bindgen-test]
version = "0.3.33"

[profile.release]
opt-level = 3
lto = true

[package.metadata.wasm-pack.profile.release]
wasm-opt = ["-O4", "--fast-math"]
3 changes: 3 additions & 0 deletions wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ pub use account::*;
pub mod record;
pub use record::*;

pub mod program;
pub use program::*;

pub(crate) mod types;
28 changes: 28 additions & 0 deletions wasm/src/program/intermediate_transaction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2019-2023 Aleo Systems Inc.
// This file is part of the Aleo library.

// The Aleo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// The Aleo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with the Aleo library. If not, see <https://www.gnu.org/licenses/>.

use crate::types::{
InputIDNative,
TransitionNative,
};

use serde::{Serialize, Deserialize};

#[derive(Clone, Serialize, Deserialize)]
pub struct IntermediateTransaction {
pub transition: TransitionNative,
pub input_ids: Vec<InputIDNative>
}
30 changes: 30 additions & 0 deletions wasm/src/program/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (C) 2019-2023 Aleo Systems Inc.
// This file is part of the Aleo library.

// The Aleo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// The Aleo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with the Aleo library. If not, see <https://www.gnu.org/licenses/>.

pub mod proving_key;
pub use proving_key::*;

pub mod verifying_key;
pub use verifying_key::*;

pub mod program;
pub use program::*;

pub mod intermediate_transaction;
pub use intermediate_transaction::*;

pub mod transaction;
pub use transaction::*;
81 changes: 81 additions & 0 deletions wasm/src/program/program.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (C) 2019-2023 Aleo Systems Inc.
// This file is part of the Aleo library.

// The Aleo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// The Aleo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with the Aleo library. If not, see <https://www.gnu.org/licenses/>.

use crate::types::ProgramNative;

use core::{ops::Deref, str::FromStr};
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
#[derive(Clone, Debug)]
pub struct Program(ProgramNative);

#[wasm_bindgen]
impl Program {
/// Get the id of the program
pub fn id(&self) -> String {
self.0.id().to_string()
}

/// Create a program from a string representation
///
/// This function will fail if the text is not a valid program
pub fn from_string(program: &str) -> Result<Program, String> {
Self::from_str(program).map_err(|_| "Invalid program".to_string())
}

/// Get a string representation of the program
#[allow(clippy::inherent_to_string_shadow_display)]
pub fn to_string(&self) -> String {
self.0.to_string()
}

/// Get the default credits program
///
/// This function shouldn't fail as the credits program is always defined
pub fn credits() -> Result<Program, String> {
let credits_program = ProgramNative::credits().map_err(|_| "Could not load credits program".to_string())?;
Ok(Self(credits_program))
}
}

impl From<ProgramNative> for Program {
fn from(program: ProgramNative) -> Self {
Self(program)
}
}

impl From<Program> for ProgramNative {
fn from(program: Program) -> Self {
program.0
}
}

impl FromStr for Program {
type Err = anyhow::Error;

fn from_str(program: &str) -> Result<Self, Self::Err> {
Ok(Self(ProgramNative::from_str(program)?))
}
}

impl Deref for Program {
type Target = ProgramNative;

fn deref(&self) -> &Self::Target {
&self.0
}
}
Loading

0 comments on commit 35824d8

Please sign in to comment.