feature: update to latest snarkvm rev

This commit is contained in:
collin 2022-01-11 16:22:34 -08:00
parent 8bce3a396a
commit 0425a92c2b
13 changed files with 689 additions and 463 deletions

943
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -73,9 +73,9 @@ version = "1.5.3"
path = "./parser" path = "./parser"
version = "1.5.3" version = "1.5.3"
[dependencies.leo-state] #[dependencies.leo-state]
path = "./state" #path = "./state"
version = "1.5.3" #version = "1.5.3"
[dependencies.leo-stdlib] [dependencies.leo-stdlib]
path = "./stdlib" path = "./stdlib"
@ -86,22 +86,27 @@ path = "./synthesizer"
version = "1.5.3" version = "1.5.3"
[dependencies.snarkvm-algorithms] [dependencies.snarkvm-algorithms]
version = "0.7.9" git = "https://github.com/AleoHQ/snarkVM.git"
rev = "2af7756"
[dependencies.snarkvm-curves] [dependencies.snarkvm-curves]
version = "0.7.9" git = "https://github.com/AleoHQ/snarkVM.git"
rev = "2af7756"
default-features = false default-features = false
[dependencies.snarkvm-gadgets] [dependencies.snarkvm-gadgets]
version = "0.7.9" git = "https://github.com/AleoHQ/snarkVM.git"
rev = "2af7756"
default-features = false default-features = false
[dependencies.snarkvm-r1cs] [dependencies.snarkvm-r1cs]
version = "0.7.9" git = "https://github.com/AleoHQ/snarkVM.git"
rev = "2af7756"
default-features = false default-features = false
[dependencies.snarkvm-utilities] [dependencies.snarkvm-utilities]
version = "0.7.9" git = "https://github.com/AleoHQ/snarkVM.git"
rev = "2af7756"
[dependencies.structopt] [dependencies.structopt]
version = "0.3" version = "0.3"

View File

@ -37,9 +37,9 @@ version = "1.5.3"
path = "../package" path = "../package"
version = "1.5.3" version = "1.5.3"
[dependencies.leo-state] #[dependencies.leo-state]
path = "../state" #path = "../state"
version = "1.5.3" #version = "1.5.3"
[dependencies.leo-asg] [dependencies.leo-asg]
path = "../asg" path = "../asg"
@ -65,28 +65,34 @@ version = "1.5.3"
version = "0.4" version = "0.4"
[dependencies.snarkvm-curves] [dependencies.snarkvm-curves]
version = "0.7.9" git = "https://github.com/AleoHQ/snarkVM.git"
rev = "2af7756"
default-features = false default-features = false
[dependencies.snarkvm-fields] [dependencies.snarkvm-fields]
version = "0.7.9" git = "https://github.com/AleoHQ/snarkVM.git"
rev = "2af7756"
default-features = false default-features = false
[dependencies.snarkvm-dpc] [dependencies.snarkvm-dpc]
version = "0.7.9" git = "https://github.com/AleoHQ/snarkVM.git"
default-features = false rev = "2af7756"
features = ["testnet2"]
[dependencies.snarkvm-gadgets] [dependencies.snarkvm-gadgets]
version = "0.7.9" git = "https://github.com/AleoHQ/snarkVM.git"
rev = "2af7756"
default-features = false default-features = false
features = [ "curves" ] features = [ "curves" ]
[dependencies.snarkvm-r1cs] [dependencies.snarkvm-r1cs]
version = "0.7.9" git = "https://github.com/AleoHQ/snarkVM.git"
rev = "2af7756"
default-features = false default-features = false
[dependencies.snarkvm-utilities] [dependencies.snarkvm-utilities]
version = "0.7.9" git = "https://github.com/AleoHQ/snarkVM.git"
rev = "2af7756"
[dependencies.bincode] [dependencies.bincode]
version = "1.3" version = "1.3"

View File

@ -27,9 +27,8 @@ use leo_imports::ImportParser;
use leo_input::LeoInputParser; use leo_input::LeoInputParser;
use leo_package::inputs::InputPairs; use leo_package::inputs::InputPairs;
use leo_parser::parse_ast; use leo_parser::parse_ast;
use leo_state::verify_local_data_commitment; // use leo_state::verify_local_data_commitment;
use snarkvm_dpc::testnet1::{instantiated::Components, parameters::SystemParameters};
use snarkvm_fields::PrimeField; use snarkvm_fields::PrimeField;
use snarkvm_r1cs::{ConstraintSynthesizer, ConstraintSystem, SynthesisError}; use snarkvm_r1cs::{ConstraintSynthesizer, ConstraintSystem, SynthesisError};
@ -364,16 +363,16 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
Ok(format!("{:x}", hash)) Ok(format!("{:x}", hash))
} }
/// TODO (howardwu): Incorporate this for real program executions and intentionally-real // /// TODO (howardwu): Incorporate this for real program executions and intentionally-real
/// test executions. Exclude it for test executions on dummy data. // /// test executions. Exclude it for test executions on dummy data.
/// // ///
/// Verifies the input to the program. // /// Verifies the input to the program.
/// // ///
pub fn verify_local_data_commitment(&self, system_parameters: &SystemParameters<Components>) -> Result<bool> { // pub fn verify_local_data_commitment(&self, system_parameters: &SystemParameters<Components>) -> Result<bool> {
let result = verify_local_data_commitment(system_parameters, &self.program_input)?; // let result = verify_local_data_commitment(system_parameters, &self.program_input)?;
//
Ok(result) // Ok(result)
} // }
/// ///
/// Manually sets main function input. /// Manually sets main function input.

View File

@ -21,9 +21,10 @@ use crate::{
logical::*, logical::*,
program::ConstrainedProgram, program::ConstrainedProgram,
relational::*, relational::*,
resolve_core_circuit, // resolve_core_circuit,
value::{Address, Char, CharType, ConstrainedCircuitMember, ConstrainedValue, Integer}, value::{Address, Char, CharType, ConstrainedCircuitMember, ConstrainedValue, Integer},
FieldType, GroupType, FieldType,
GroupType,
}; };
use leo_asg::{expression::*, ConstValue, Expression, Node}; use leo_asg::{expression::*, ConstValue, Expression, Node};
use leo_errors::{Result, Span}; use leo_errors::{Result, Span};
@ -178,26 +179,27 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
// Functions // Functions
Expression::Call(CallExpression { Expression::Call(CallExpression {
function, // function,
target, // target,
arguments, // arguments,
.. ..
}) => { }) => {
if let Some(circuit) = function.get().circuit.get() { unimplemented!("core circuits are not supported yet")
let core_mapping = circuit.core_mapping.borrow(); // if let Some(circuit) = function.get().circuit.get() {
if let Some(core_mapping) = core_mapping.as_deref() { // let core_mapping = circuit.core_mapping.borrow();
let core_circuit = resolve_core_circuit::<F, G>(core_mapping); // if let Some(core_mapping) = core_mapping.as_deref() {
return self.enforce_core_circuit_call_expression( // let core_circuit = resolve_core_circuit::<F, G>(core_mapping);
cs, // return self.enforce_core_circuit_call_expression(
&core_circuit, // cs,
function.get(), // &core_circuit,
target.get(), // function.get(),
&arguments[..], // target.get(),
span, // &arguments[..],
); // span,
} // );
} // }
self.enforce_function_call_expression(cs, function.get(), target.get(), &arguments[..], span) // }
// self.enforce_function_call_expression(cs, function.get(), target.get(), &arguments[..], span)
} }
} }
} }

View File

@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
pub mod blake2s; // pub mod blake2s;
pub use blake2s::*; // pub use blake2s::*;
use crate::{ConstrainedValue, GroupType}; use crate::{ConstrainedValue, GroupType};
use leo_asg::Function; use leo_asg::Function;
@ -35,9 +35,9 @@ pub trait CoreCircuit<'a, F: PrimeField, G: GroupType<F>>: Send + Sync {
) -> Result<ConstrainedValue<'a, F, G>>; ) -> Result<ConstrainedValue<'a, F, G>>;
} }
pub fn resolve_core_circuit<'a, F: PrimeField, G: GroupType<F>>(name: &str) -> impl CoreCircuit<'a, F, G> { // pub fn resolve_core_circuit<'a, F: PrimeField, G: GroupType<F>>(name: &str) -> impl CoreCircuit<'a, F, G> {
match name { // match name {
"blake2s" => Blake2s, // "blake2s" => Blake2s,
_ => unimplemented!("invalid core circuit: {}", name), // _ => unimplemented!("invalid core circuit: {}", name),
} // }
} // }

View File

@ -18,7 +18,7 @@ use crate::{ConstrainedValue, GroupType, IntegerTrait};
use leo_ast::InputValue; use leo_ast::InputValue;
use leo_errors::{CompilerError, Result, Span}; use leo_errors::{CompilerError, Result, Span};
use snarkvm_dpc::{account::Address as AleoAddress, testnet1::instantiated::Components}; use snarkvm_dpc::{account::Address as AleoAddress, network::testnet2::Testnet2};
use snarkvm_fields::PrimeField; use snarkvm_fields::PrimeField;
use snarkvm_gadgets::{ use snarkvm_gadgets::{
boolean::Boolean, boolean::Boolean,
@ -36,17 +36,16 @@ use std::{borrow::Borrow, str::FromStr};
/// A public address /// A public address
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct Address { pub struct Address {
pub address: Option<AleoAddress<Components>>, pub address: Option<AleoAddress<Testnet2>>,
pub bytes: Vec<UInt8>, pub bytes: Vec<UInt8>,
} }
impl Address { impl Address {
pub(crate) fn constant(address: String, span: &Span) -> Result<Self> { pub(crate) fn constant(address: String, span: &Span) -> Result<Self> {
let address = let address = AleoAddress::<Testnet2>::from_str(&address)
AleoAddress::from_str(&address).map_err(|e| CompilerError::address_value_account_error(e, span))?; .map_err(|e| CompilerError::address_value_account_error(e, span))?;
let mut address_bytes = vec![]; let address_bytes = address.to_bytes_le().unwrap();
address.write_le(&mut address_bytes).unwrap();
let bytes = UInt8::constant_vec(&address_bytes[..]); let bytes = UInt8::constant_vec(&address_bytes[..]);
@ -95,9 +94,9 @@ impl Address {
>( >(
cs: CS, cs: CS,
value_gen: Fn, value_gen: Fn,
) -> Result<AleoAddress<Components>, SynthesisError> { ) -> Result<AleoAddress<Testnet2>, SynthesisError> {
if cs.is_in_setup_mode() { if cs.is_in_setup_mode() {
Ok(AleoAddress::<Components>::default()) Ok(AleoAddress::<Testnet2>::default())
} else { } else {
let address_string = value_gen()?.borrow().clone(); let address_string = value_gen()?.borrow().clone();
AleoAddress::from_str(&address_string).map_err(|_| SynthesisError::AssignmentMissing) AleoAddress::from_str(&address_string).map_err(|_| SynthesisError::AssignmentMissing)
@ -110,14 +109,11 @@ impl<F: PrimeField> AllocGadget<String, F> for Address {
_cs: CS, _cs: CS,
value_gen: Fn, value_gen: Fn,
) -> Result<Self, SynthesisError> { ) -> Result<Self, SynthesisError> {
let address = { let address: AleoAddress<Testnet2> = {
let address_string = value_gen()?.borrow().clone(); let address_string = value_gen()?.borrow().clone();
AleoAddress::from_str(&address_string).map_err(|_| SynthesisError::AssignmentMissing)? AleoAddress::from_str(&address_string).map_err(|_| SynthesisError::AssignmentMissing)?
}; };
let mut address_bytes = vec![]; let address_bytes = address.to_bytes_le().map_err(|_| SynthesisError::AssignmentMissing)?;
address
.write_le(&mut address_bytes)
.map_err(|_| SynthesisError::AssignmentMissing)?;
let bytes = UInt8::constant_vec(&address_bytes[..]); let bytes = UInt8::constant_vec(&address_bytes[..]);
@ -131,11 +127,8 @@ impl<F: PrimeField> AllocGadget<String, F> for Address {
mut cs: CS, mut cs: CS,
value_gen: Fn, value_gen: Fn,
) -> Result<Self, SynthesisError> { ) -> Result<Self, SynthesisError> {
let address = Self::alloc_helper(cs.ns(|| "allocate the address"), value_gen)?; let address: AleoAddress<Testnet2> = Self::alloc_helper(cs.ns(|| "allocate the address"), value_gen)?;
let mut address_bytes = vec![]; let address_bytes = address.to_bytes_le().map_err(|_| SynthesisError::AssignmentMissing)?;
address
.write_le(&mut address_bytes)
.map_err(|_| SynthesisError::AssignmentMissing)?;
let bytes = UInt8::alloc_vec(cs.ns(|| "allocate the address bytes"), &address_bytes[..])?; let bytes = UInt8::alloc_vec(cs.ns(|| "allocate the address bytes"), &address_bytes[..])?;
@ -150,10 +143,7 @@ impl<F: PrimeField> AllocGadget<String, F> for Address {
value_gen: Fn, value_gen: Fn,
) -> Result<Self, SynthesisError> { ) -> Result<Self, SynthesisError> {
let address = Self::alloc_helper(cs.ns(|| "allocate the address"), value_gen)?; let address = Self::alloc_helper(cs.ns(|| "allocate the address"), value_gen)?;
let mut address_bytes = vec![]; let address_bytes = address.to_bytes_le().map_err(|_| SynthesisError::AssignmentMissing)?;
address
.write_le(&mut address_bytes)
.map_err(|_| SynthesisError::AssignmentMissing)?;
let bytes = UInt8::alloc_input_vec_le(cs.ns(|| "allocate the address bytes"), &address_bytes[..])?; let bytes = UInt8::alloc_input_vec_le(cs.ns(|| "allocate the address bytes"), &address_bytes[..])?;

View File

@ -41,7 +41,7 @@ version = "0.3.63"
version = "2.0" version = "2.0"
[dependencies.serde] [dependencies.serde]
version = "1.0.130" version = "1.0"
features = [ "derive", "rc" ] features = [ "derive", "rc" ]
[dependencies.tendril] [dependencies.tendril]

View File

@ -68,7 +68,7 @@ impl Command for Prove {
let rng = &mut thread_rng(); let rng = &mut thread_rng();
// TODO fix this once snarkvm has better errors. // TODO fix this once snarkvm has better errors.
let program_proof = let program_proof =
Groth16::<Bls12_377, _, Vec<Fr>>::prove(&parameters, &program, rng).map_err(|_| SnarkVMError::default())?; Groth16::<Bls12_377, Vec<Fr>>::prove(&parameters, &program, rng).map_err(|_| SnarkVMError::default())?;
// Write the proof file to the output directory // Write the proof file to the output directory
let mut proof = vec![]; let mut proof = vec![];

View File

@ -16,7 +16,6 @@
use super::{build::BuildOptions, prove::Prove}; use super::{build::BuildOptions, prove::Prove};
use crate::{commands::Command, context::Context}; use crate::{commands::Command, context::Context};
use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType};
use leo_errors::{Result, SnarkVMError}; use leo_errors::{Result, SnarkVMError};
use snarkvm_algorithms::{snark::groth16::Groth16, traits::SNARK}; use snarkvm_algorithms::{snark::groth16::Groth16, traits::SNARK};
@ -57,12 +56,8 @@ impl Command for Run {
tracing::info!("Starting..."); tracing::info!("Starting...");
// Run the verifier // Run the verifier
let is_success = Groth16::<Bls12_377, Compiler<Fr, EdwardsGroupType>, Vec<Fr>>::verify( let is_success = Groth16::<Bls12_377, Vec<Fr>>::verify_prepared(&prepared_verifying_key, &vec![], &proof)
&prepared_verifying_key, .map_err(|_| SnarkVMError::default())?;
&vec![],
&proof,
)
.map_err(|_| SnarkVMError::default())?;
// Log the verifier output // Log the verifier output
match is_success { match is_success {

View File

@ -23,6 +23,7 @@ use leo_package::outputs::{ProvingKeyFile, VerificationKeyFile};
use snarkvm_algorithms::{ use snarkvm_algorithms::{
snark::groth16::{Groth16, PreparedVerifyingKey, ProvingKey, VerifyingKey}, snark::groth16::{Groth16, PreparedVerifyingKey, ProvingKey, VerifyingKey},
traits::snark::SNARK, traits::snark::SNARK,
SRS,
}; };
use snarkvm_curves::bls12_377::{Bls12_377, Fr}; use snarkvm_curves::bls12_377::{Bls12_377, Fr};
use snarkvm_utilities::ToBytes; use snarkvm_utilities::ToBytes;
@ -78,8 +79,8 @@ impl Command for Setup {
// Run the program setup operation // Run the program setup operation
let rng = &mut thread_rng(); let rng = &mut thread_rng();
let (proving_key, prepared_verifying_key) = let (proving_key, verifying_key) =
Groth16::<Bls12_377, Compiler<Fr, _>, Vec<Fr>>::setup(&program, rng) Groth16::<Bls12_377, Vec<Fr>>::setup(&program, &mut SRS::CircuitSpecific(rng))
.map_err(|_| CliError::unable_to_setup())?; .map_err(|_| CliError::unable_to_setup())?;
// TODO (howardwu): Convert parameters to a 'proving key' struct for serialization. // TODO (howardwu): Convert parameters to a 'proving key' struct for serialization.
@ -104,6 +105,9 @@ impl Command for Setup {
let _ = verification_key_file.write_to(&path, &verification_key)?; let _ = verification_key_file.write_to(&path, &verification_key)?;
tracing::info!("Complete"); tracing::info!("Complete");
// Derive the prepared verifying key file from the verifying key
let prepared_verifying_key = PreparedVerifyingKey::<Bls12_377>::from(verifying_key);
(proving_key, prepared_verifying_key) (proving_key, prepared_verifying_key)
} else { } else {
tracing::info!("Detected saved setup"); tracing::info!("Detected saved setup");

View File

@ -30,18 +30,22 @@ path = "../input"
version = "1.5.3" version = "1.5.3"
[dependencies.snarkvm-algorithms] [dependencies.snarkvm-algorithms]
version = "0.7.9" git = "https://github.com/AleoHQ/snarkVM.git"
rev = "2af7756"
[dependencies.snarkvm-curves] [dependencies.snarkvm-curves]
version = "0.7.9" git = "https://github.com/AleoHQ/snarkVM.git"
rev = "2af7756"
default-features = false default-features = false
[dependencies.snarkvm-dpc] [dependencies.snarkvm-dpc]
version = "0.7.9" git = "https://github.com/AleoHQ/snarkVM.git"
features = [ "testnet1" ] rev = "2af7756"
features = [ "testnet2" ]
[dependencies.snarkvm-utilities] [dependencies.snarkvm-utilities]
version = "0.7.9" git = "https://github.com/AleoHQ/snarkVM.git"
rev = "2af7756"
[dependencies.indexmap] [dependencies.indexmap]
version = "1.7.0" version = "1.7.0"

View File

@ -18,7 +18,8 @@ license = "GPL-3.0"
edition = "2018" edition = "2018"
[dependencies.snarkvm-curves] [dependencies.snarkvm-curves]
version = "0.7.9" git = "https://github.com/AleoHQ/snarkVM.git"
rev = "2af7756"
default-features = false default-features = false
[dependencies.leo-errors] [dependencies.leo-errors]
@ -30,14 +31,17 @@ version = "0.6.5"
default-features = false default-features = false
[dependencies.snarkvm-fields] [dependencies.snarkvm-fields]
version = "0.7.9" git = "https://github.com/AleoHQ/snarkVM.git"
rev = "2af7756"
default-features = false default-features = false
[dependencies.snarkvm-gadgets] [dependencies.snarkvm-gadgets]
version = "0.7.9" git = "https://github.com/AleoHQ/snarkVM.git"
rev = "2af7756"
[dependencies.snarkvm-r1cs] [dependencies.snarkvm-r1cs]
version = "0.7.9" git = "https://github.com/AleoHQ/snarkVM.git"
rev = "2af7756"
default-features = false default-features = false
[dependencies.num-bigint] [dependencies.num-bigint]