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

Support proof generation from the wasm: #6

Open
wants to merge 1 commit into
base: testnet3
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions algorithms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ version = "1.0"
version = "0.4"
optional = true

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

[dev-dependencies.expect-test]
version = "1.4.1"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ impl<F: PrimeField, MM: MarlinMode> AHPForR1CS<F, MM> {
let round_time = start_timer!(|| "AHP::Prover::FirstRound");
let constraint_domain = state.constraint_domain;
let batch_size = state.batch_size;

let z_a = state.z_a.take().unwrap();
let z_b = state.z_b.take().unwrap();
let private_variables = core::mem::take(&mut state.private_variables);

assert_eq!(z_a.len(), batch_size);
assert_eq!(z_b.len(), batch_size);
assert_eq!(private_variables.len(), batch_size);

let mut r_b_s = Vec::with_capacity(batch_size);

let mut job_pool = snarkvm_utilities::ExecutionPool::with_capacity(3 * batch_size);
Expand Down Expand Up @@ -109,8 +111,8 @@ impl<F: PrimeField, MM: MarlinMode> AHPForR1CS<F, MM> {
assert_eq!(batches.len(), batch_size);

let mask_poly = Self::calculate_mask_poly(constraint_domain, rng);

let oracles = prover::FirstOracles { batches, mask_poly };

assert!(oracles.matches_info(&Self::first_round_polynomial_info(batch_size)));
state.first_round_oracles = Some(Arc::new(oracles));
state.mz_poly_randomizer = MM::ZK.then_some(r_b_s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ use crate::snark::marlin::{
prover,
MarlinMode,
};
use itertools::Itertools;
use snarkvm_fields::PrimeField;
use snarkvm_r1cs::ConstraintSynthesizer;
use itertools::Itertools;

use snarkvm_utilities::cfg_iter;
#[cfg(not(feature = "std"))]
Expand Down
8 changes: 8 additions & 0 deletions algorithms/src/snark/marlin/marlin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ impl<E: PairingEngine, FS: AlgebraicSponge<E::Fq, 2>, MM: MarlinMode> MarlinSNAR
if terminator.load(Ordering::Relaxed) { Err(MarlinError::Terminated) } else { Ok(()) }
}

fn to_le_bytes_8(n: &usize) -> [u8; 8] {
let mut bytes = [0u8; 8];
let n_bytes = n.to_le_bytes();
let len = std::mem::size_of::<usize>();
bytes[..len].copy_from_slice(&n_bytes[..len]);
bytes
}

fn init_sponge(
fs_parameters: &FS::Parameters,
batch_size: usize,
Expand Down
4 changes: 4 additions & 0 deletions circuit/account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ version = "1.0.70"
[features]
default = [ "enable_console" ]
enable_console = [ "console" ]
parallel = [
"snarkvm-circuit-algorithms/parallel",
"snarkvm-circuit-network/parallel"
]
1 change: 1 addition & 0 deletions circuit/algorithms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ version = "1.0.70"
[features]
default = [ "enable_console" ]
enable_console = [ "console" ]
parallel = [ "snarkvm-fields/parallel" ]
4 changes: 4 additions & 0 deletions circuit/collections/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ version = "0.10.2"

[dev-dependencies.snarkvm-circuit-network]
path = "../network"
features = [ "parallel" ]

[dev-dependencies.snarkvm-console-algorithms]
path = "../../console/algorithms"
features = [ "parallel" ]

[dev-dependencies.snarkvm-console-network]
path = "../../console/network"
features = [ "parallel" ]

[dev-dependencies.snarkvm-utilities]
path = "../../utilities"
Expand All @@ -38,3 +41,4 @@ version = "1.0.70"
[features]
default = [ "enable_console" ]
enable_console = [ "console" ]
parallel = [ "snarkvm-circuit-algorithms/parallel" ]
4 changes: 4 additions & 0 deletions circuit/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ path = "../../console/types"
[features]
default = [ "enable_console" ]
enable_console = [ "console" ]
parallel = [
"snarkvm-circuit-algorithms/parallel",
"snarkvm-circuit-collections/parallel"
]
5 changes: 5 additions & 0 deletions circuit/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ version = "0.8"
[features]
default = [ "enable_console" ]
enable_console = [ "console" ]
parallel = [
"snarkvm-circuit-account/parallel",
"snarkvm-circuit-collections/parallel",
"snarkvm-circuit-network/parallel"
]
1 change: 1 addition & 0 deletions console/account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ default = [
"signature",
"view_key"
]
parallel = [ "snarkvm-console-network/parallel" ]
compute_key = [ "private_key" ]
graph_key = [ "private_key" ]
private_key = [ "compute_key" ]
Expand Down
4 changes: 4 additions & 0 deletions console/algorithms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ version = "1.0"
[dev-dependencies.serde_json]
version = "1.0"
features = [ "preserve_order" ]

[features]
default = [ ]
parallel = [ "snarkvm-fields/parallel" ]
1 change: 1 addition & 0 deletions console/collections/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ version = "1"

[dev-dependencies.snarkvm-console-network]
path = "../network"
features = [ "parallel" ]

[dev-dependencies.criterion]
version = "0.4.0"
Expand Down
4 changes: 4 additions & 0 deletions console/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ wasm = [
"snarkvm-algorithms/polycommit_wasm",
"snarkvm-parameters/wasm"
]
parallel = [
"snarkvm-console-collections/parallel",
"snarkvm-fields/parallel"
]

[dependencies.snarkvm-algorithms]
path = "../../algorithms"
Expand Down
4 changes: 4 additions & 0 deletions console/network/environment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ default-features = false

[dependencies.serde]
version = "1.0"

[features]
default = [ ]
parallel = [ "snarkvm-fields/parallel" ]
4 changes: 4 additions & 0 deletions console/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ edition = "2021"
[features]
default = [ ]
test = [ ]
parallel = [
"snarkvm-console-collections/parallel",
"snarkvm-console-network/parallel"
]

[dependencies.snarkvm-console-account]
path = "../account"
Expand Down
3 changes: 3 additions & 0 deletions parameters/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,15 @@ default-features = false

[dev-dependencies.snarkvm-circuit]
path = "../circuit"
features = [ "parallel" ]

[dev-dependencies.snarkvm-console]
path = "../console"
features = [ "parallel" ]

[dev-dependencies.snarkvm-synthesizer]
path = "../synthesizer"
features = [ "parallel" ]

[dev-dependencies.curl]
version = "0.4.34"
Expand Down
1 change: 1 addition & 0 deletions r1cs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ version = "1.0"

[features]
default = [ ]
parallel = [ "snarkvm-fields/parallel" ]
9 changes: 6 additions & 3 deletions synthesizer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ harness = false

[features]
default = [ ]
web = [
"snarkvm-utilities/web"
]
aleo-cli = [ ]
cuda = [ "snarkvm-algorithms/cuda" ]
serial = [
Expand Down Expand Up @@ -102,15 +105,15 @@ version = "2"
version = "1.9"
features = [ "serde", "rayon" ]

[dependencies.itertools]
version = "0.10.1"

[dependencies.once_cell]
version = "1.17"

[dependencies.parking_lot]
version = "0.12"

[dependencies.itertools]
version = "0.10.3"

[dependencies.paste]
version = "1.0.12"

Expand Down
2 changes: 1 addition & 1 deletion synthesizer/src/block/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<N: Network> Transactions<N> {
pub fn find_transaction_for_serial_number(&self, serial_number: &Field<N>) -> Option<&Transaction<N>> {
cfg_find!(self, serial_number, contains_serial_number)
}

/// Returns the transaction with the given commitment, if it exists.
pub fn find_transaction_for_commitment(&self, commitment: &Field<N>) -> Option<&Transaction<N>> {
cfg_find!(self, commitment, contains_commitment)
Expand Down
18 changes: 18 additions & 0 deletions synthesizer/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,24 @@ impl<N: Network> Process<N> {
Ok(process)
}

#[inline]
pub fn load_wasm() -> Result<Self> {
// Initialize the process.
let mut process = Self { universal_srs: Arc::new(UniversalSRS::load()?), stacks: IndexMap::new() };

// Initialize the 'credits.aleo' program.
let program = Program::credits()?;

// Compute the 'credits.aleo' program stack.
let stack = Stack::new(&process, &program)?;

// Add the stack to the process.
process.stacks.insert(*program.id(), stack);

// Return the process.
Ok(process)
}

/// Initializes a new process with a cache of previously used keys. This version is suitable for tests
/// (which often use nested loops that keep reusing those), as their deserialization is slow.
#[cfg(test)]
Expand Down
Loading