Skip to content

Commit 162b01e

Browse files
committed
Add wasm proof generation with inclusion proof
1 parent f70e92c commit 162b01e

23 files changed

+1310
-195
lines changed

Cargo.lock

Lines changed: 62 additions & 120 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,20 @@ members = [ "rust", "wasm" ]
2222

2323
[workspace.dependencies.snarkvm]
2424
version = "0.9.13"
25+
path="../snarkVM"
2526

2627
[workspace.dependencies.snarkvm-wasm]
2728
version = "0.9.13"
2829
default-features = false
30+
path="../snarkVM/wasm"
31+
32+
[workspace.dependencies.snarkvm-synthesizer]
33+
path="../snarkVM/synthesizer"
34+
version = "0.9.13"
35+
36+
[workspace.dependencies.snarkvm-console]
37+
path="../snarkVM/console"
38+
version = "0.9.13"
2939

3040
[lib]
3141
path = "cli/lib.rs"
@@ -41,68 +51,62 @@ wasm = [ "aleo-wasm" ]
4151
[dependencies]
4252
num-format = "0.4.4"
4353

44-
[dependencies.aleo-rust]
45-
path = "rust"
46-
version = "0.3.5"
47-
optional = true
54+
[dependencies.aleo-rust]
55+
path = "rust"
56+
version = "0.3.5"
57+
optional = true
4858

49-
[dependencies.aleo-wasm]
50-
path = "wasm"
51-
version = "0.3.5"
52-
optional = true
59+
[dependencies.aleo-wasm]
60+
path = "wasm"
61+
version = "0.3.5"
62+
optional = true
5363

54-
[dependencies.anyhow]
55-
version = "1.0"
64+
[dependencies.anyhow]
65+
version = "1.0"
5666

57-
[dependencies.clap]
58-
version = "3.2"
59-
features = [ "derive" ]
67+
[dependencies.clap]
68+
version = "3.2"
69+
features = [ "derive" ]
6070

61-
[dependencies.colored]
62-
version = "2"
71+
[dependencies.colored]
72+
version = "2"
6373

64-
[dependencies.parking_lot]
65-
version = "0.12"
74+
[dependencies.parking_lot]
75+
version = "0.12"
6676

67-
[dependencies.rand]
68-
version = "0.8"
69-
default-features = false
77+
[dependencies.rand]
78+
version = "0.8"
79+
default-features = false
7080

71-
[dependencies.rand_chacha]
72-
version = "0.3.0"
73-
default-features = false
81+
[dependencies.rand_chacha]
82+
version = "0.3.0"
83+
default-features = false
7484

75-
[dependencies.rpassword]
76-
version = "7.2.0"
85+
[dependencies.rpassword]
86+
version = "7.2.0"
7787

78-
[dependencies.self_update]
79-
version = "0.32"
88+
[dependencies.self_update]
89+
version = "0.32"
8090

81-
[dependencies.serde]
82-
version = "1"
91+
[dependencies.serde]
92+
version = "1"
8393

84-
[dependencies.serde_json]
85-
version = "1"
94+
[dependencies.serde_json]
95+
version = "1"
8696

87-
[dependencies.snarkvm]
88-
workspace = true
89-
features = [
90-
"aleo-cli",
91-
"circuit",
92-
"console",
93-
"parallel",
94-
"snarkvm-synthesizer"
95-
]
97+
[dependencies.snarkvm]
98+
workspace = true
99+
features = [ "aleo-cli", "circuit", "console", "snarkvm-synthesizer"]
96100

97-
[dependencies.thiserror]
98-
version = "1.0"
101+
[dependencies.thiserror]
102+
version = "1.0"
99103

100-
[dependencies.tokio]
101-
version = "1.22"
102-
features = [ "rt" ]
104+
[dependencies.tokio]
105+
version = "1.22"
106+
features = [ "rt" ]
103107

104-
[dependencies.warp]
105-
version = "0.3"
108+
[dependencies.warp]
109+
version = "0.3"
106110

107111
[dev-dependencies.rusty-hook]
108112
version = "0.11.2"

rust/Cargo.toml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,26 @@ optional = true
5252
[dependencies.serde_json]
5353
version = "1.0.91"
5454

55-
[dependencies.snarkvm-console]
56-
features = [ "parallel" ]
57-
optional = true
55+
[dependencies.snarkvm-wasm]
56+
version = "0.9.13"
57+
path="../../snarkVM/wasm"
58+
59+
[dependencies.snarkvm-utilities]
5860
version = "0.9.13"
61+
path="../../snarkVM/utilities"
5962

6063
[dependencies.snarkvm-synthesizer]
61-
features = [ "parallel" ]
62-
optional = true
6364
version = "0.9.13"
65+
path = "../../snarkVM/synthesizer"
66+
default-features = false
67+
features = [ "wasm" ]
68+
optional = true
6469

65-
[dependencies.snarkvm-utilities]
66-
features = [ "parallel" ]
70+
[dependencies.snarkvm-console]
71+
path = "../../snarkVM/console"
72+
default-features = false
6773
version = "0.9.13"
74+
optional = true
6875

6976
[dev-dependencies.bencher]
7077
version = "0.1.5"

rust/src/account/encryptor.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
use snarkvm_console::{
1818
account::PrivateKey,
1919
network::Network,
20-
program::{Ciphertext, Identifier, Literal, Plaintext},
2120
types::Field,
2221
};
2322
use snarkvm_utilities::Uniform;
2423

24+
use snarkvm_console::{
25+
program::{Ciphertext, Identifier, Literal, Plaintext}
26+
};
27+
2528
use anyhow::{anyhow, Result};
2629
use once_cell::sync::OnceCell;
2730
use std::{iter::FromIterator, str::FromStr};

wasm/Cargo.toml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,53 @@ version = "0.8"
4141

4242
[dependencies.serde_json]
4343
version = "1.0"
44+
features = [ "preserve_order" ]
45+
46+
[dependencies.snarkvm-synthesizer]
47+
path="../../snarkVM/synthesizer"
48+
version = "0.9.13"
49+
default-features = false
50+
features = [ "wasm" ]
51+
52+
[dependencies.snarkvm-console]
53+
path="../../snarkVM/console"
54+
version = "0.9.13"
55+
default-features = false
4456

4557
[dependencies.snarkvm-wasm]
46-
workspace = true
47-
features = [ "console", "fields", "utilities" ]
58+
path="../../snarkVM/wasm"
59+
version = "0.9.13"
4860

4961
[dependencies.wasm-bindgen]
5062
version = "0.2"
5163
features = [ "serde-serialize" ]
5264

65+
[dependencies.js-sys]
66+
version = "0.3"
67+
68+
[dependencies.web-sys]
69+
version = "0.3"
70+
features = ["console"]
71+
72+
[dependencies.serde]
73+
version = "1.0"
74+
features = ["derive"]
75+
76+
[dependencies.serde-wasm-bindgen]
77+
version = "0.4"
78+
5379
[dependencies.console_error_panic_hook]
5480
version = "0.1.7"
5581

82+
[dependencies.rand_chacha]
83+
version = "0.3.1"
84+
5685
[dev-dependencies.wasm-bindgen-test]
5786
version = "0.3.33"
87+
88+
[profile.release]
89+
opt-level = 3
90+
lto = true
91+
92+
[package.metadata.wasm-pack.profile.release]
93+
wasm-opt = ["-O4", "--fast-math"]

wasm/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ pub use account::*;
2020
pub mod record;
2121
pub use record::*;
2222

23+
pub mod program;
24+
pub use program::*;
25+
2326
pub(crate) mod types;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (C) 2019-2023 Aleo Systems Inc.
2+
// This file is part of the Aleo library.
3+
4+
// The Aleo library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// The Aleo library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with the Aleo library. If not, see <https://www.gnu.org/licenses/>.
16+
17+
use crate::types::{
18+
InputIDNative,
19+
TransitionNative,
20+
};
21+
22+
use serde::{Serialize, Deserialize};
23+
24+
#[derive(Clone, Serialize, Deserialize)]
25+
pub struct IntermediateTransaction {
26+
pub transition: TransitionNative,
27+
pub input_ids: Vec<InputIDNative>
28+
}

wasm/src/program/mod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (C) 2019-2023 Aleo Systems Inc.
2+
// This file is part of the Aleo library.
3+
4+
// The Aleo library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// The Aleo library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with the Aleo library. If not, see <https://www.gnu.org/licenses/>.
16+
17+
pub mod proving_key;
18+
pub use proving_key::*;
19+
20+
pub mod verifying_key;
21+
pub use verifying_key::*;
22+
23+
pub mod program;
24+
pub use program::*;
25+
26+
pub mod intermediate_transaction;
27+
pub use intermediate_transaction::*;
28+
29+
pub mod transaction;
30+
pub use transaction::*;

wasm/src/program/program.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright (C) 2019-2023 Aleo Systems Inc.
2+
// This file is part of the Aleo library.
3+
4+
// The Aleo library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// The Aleo library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with the Aleo library. If not, see <https://www.gnu.org/licenses/>.
16+
17+
use crate::types::ProgramNative;
18+
19+
use core::{ops::Deref, str::FromStr};
20+
use wasm_bindgen::prelude::*;
21+
22+
#[wasm_bindgen]
23+
#[derive(Clone, Debug)]
24+
pub struct Program(ProgramNative);
25+
26+
#[wasm_bindgen]
27+
impl Program {
28+
/// Get the id of the program
29+
pub fn id(&self) -> String {
30+
self.0.id().to_string()
31+
}
32+
33+
/// Create a program from a string representation
34+
///
35+
/// This function will fail if the text is not a valid program
36+
pub fn from_string(program: &str) -> Result<Program, String> {
37+
Self::from_str(program).map_err(|_| "Invalid program".to_string())
38+
}
39+
40+
/// Get a string representation of the program
41+
#[allow(clippy::inherent_to_string_shadow_display)]
42+
pub fn to_string(&self) -> String {
43+
self.0.to_string()
44+
}
45+
46+
/// Get the default credits program
47+
///
48+
/// This function shouldn't fail as the credits program is always defined
49+
pub fn credits() -> Result<Program, String> {
50+
let credits_program = ProgramNative::credits().map_err(|_| "Could not load credits program".to_string())?;
51+
Ok(Self(credits_program))
52+
}
53+
}
54+
55+
impl From<ProgramNative> for Program {
56+
fn from(program: ProgramNative) -> Self {
57+
Self(program)
58+
}
59+
}
60+
61+
impl From<Program> for ProgramNative {
62+
fn from(program: Program) -> Self {
63+
program.0
64+
}
65+
}
66+
67+
impl FromStr for Program {
68+
type Err = anyhow::Error;
69+
70+
fn from_str(program: &str) -> Result<Self, Self::Err> {
71+
Ok(Self(ProgramNative::from_str(program)?))
72+
}
73+
}
74+
75+
impl Deref for Program {
76+
type Target = ProgramNative;
77+
78+
fn deref(&self) -> &Self::Target {
79+
&self.0
80+
}
81+
}

0 commit comments

Comments
 (0)