mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-23 10:12:21 +03:00
feature: update to latest snarkvm rev
This commit is contained in:
parent
8bce3a396a
commit
0425a92c2b
943
Cargo.lock
generated
943
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
21
Cargo.toml
21
Cargo.toml
@ -73,9 +73,9 @@ version = "1.5.3"
|
||||
path = "./parser"
|
||||
version = "1.5.3"
|
||||
|
||||
[dependencies.leo-state]
|
||||
path = "./state"
|
||||
version = "1.5.3"
|
||||
#[dependencies.leo-state]
|
||||
#path = "./state"
|
||||
#version = "1.5.3"
|
||||
|
||||
[dependencies.leo-stdlib]
|
||||
path = "./stdlib"
|
||||
@ -86,22 +86,27 @@ path = "./synthesizer"
|
||||
version = "1.5.3"
|
||||
|
||||
[dependencies.snarkvm-algorithms]
|
||||
version = "0.7.9"
|
||||
git = "https://github.com/AleoHQ/snarkVM.git"
|
||||
rev = "2af7756"
|
||||
|
||||
[dependencies.snarkvm-curves]
|
||||
version = "0.7.9"
|
||||
git = "https://github.com/AleoHQ/snarkVM.git"
|
||||
rev = "2af7756"
|
||||
default-features = false
|
||||
|
||||
[dependencies.snarkvm-gadgets]
|
||||
version = "0.7.9"
|
||||
git = "https://github.com/AleoHQ/snarkVM.git"
|
||||
rev = "2af7756"
|
||||
default-features = false
|
||||
|
||||
[dependencies.snarkvm-r1cs]
|
||||
version = "0.7.9"
|
||||
git = "https://github.com/AleoHQ/snarkVM.git"
|
||||
rev = "2af7756"
|
||||
default-features = false
|
||||
|
||||
[dependencies.snarkvm-utilities]
|
||||
version = "0.7.9"
|
||||
git = "https://github.com/AleoHQ/snarkVM.git"
|
||||
rev = "2af7756"
|
||||
|
||||
[dependencies.structopt]
|
||||
version = "0.3"
|
||||
|
@ -37,9 +37,9 @@ version = "1.5.3"
|
||||
path = "../package"
|
||||
version = "1.5.3"
|
||||
|
||||
[dependencies.leo-state]
|
||||
path = "../state"
|
||||
version = "1.5.3"
|
||||
#[dependencies.leo-state]
|
||||
#path = "../state"
|
||||
#version = "1.5.3"
|
||||
|
||||
[dependencies.leo-asg]
|
||||
path = "../asg"
|
||||
@ -65,28 +65,34 @@ version = "1.5.3"
|
||||
version = "0.4"
|
||||
|
||||
[dependencies.snarkvm-curves]
|
||||
version = "0.7.9"
|
||||
git = "https://github.com/AleoHQ/snarkVM.git"
|
||||
rev = "2af7756"
|
||||
default-features = false
|
||||
|
||||
[dependencies.snarkvm-fields]
|
||||
version = "0.7.9"
|
||||
git = "https://github.com/AleoHQ/snarkVM.git"
|
||||
rev = "2af7756"
|
||||
default-features = false
|
||||
|
||||
[dependencies.snarkvm-dpc]
|
||||
version = "0.7.9"
|
||||
default-features = false
|
||||
git = "https://github.com/AleoHQ/snarkVM.git"
|
||||
rev = "2af7756"
|
||||
features = ["testnet2"]
|
||||
|
||||
[dependencies.snarkvm-gadgets]
|
||||
version = "0.7.9"
|
||||
git = "https://github.com/AleoHQ/snarkVM.git"
|
||||
rev = "2af7756"
|
||||
default-features = false
|
||||
features = [ "curves" ]
|
||||
|
||||
[dependencies.snarkvm-r1cs]
|
||||
version = "0.7.9"
|
||||
git = "https://github.com/AleoHQ/snarkVM.git"
|
||||
rev = "2af7756"
|
||||
default-features = false
|
||||
|
||||
[dependencies.snarkvm-utilities]
|
||||
version = "0.7.9"
|
||||
git = "https://github.com/AleoHQ/snarkVM.git"
|
||||
rev = "2af7756"
|
||||
|
||||
[dependencies.bincode]
|
||||
version = "1.3"
|
||||
|
@ -27,9 +27,8 @@ use leo_imports::ImportParser;
|
||||
use leo_input::LeoInputParser;
|
||||
use leo_package::inputs::InputPairs;
|
||||
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_r1cs::{ConstraintSynthesizer, ConstraintSystem, SynthesisError};
|
||||
|
||||
@ -364,16 +363,16 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
|
||||
Ok(format!("{:x}", hash))
|
||||
}
|
||||
|
||||
/// TODO (howardwu): Incorporate this for real program executions and intentionally-real
|
||||
/// test executions. Exclude it for test executions on dummy data.
|
||||
///
|
||||
/// Verifies the input to the program.
|
||||
///
|
||||
pub fn verify_local_data_commitment(&self, system_parameters: &SystemParameters<Components>) -> Result<bool> {
|
||||
let result = verify_local_data_commitment(system_parameters, &self.program_input)?;
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
// /// TODO (howardwu): Incorporate this for real program executions and intentionally-real
|
||||
// /// test executions. Exclude it for test executions on dummy data.
|
||||
// ///
|
||||
// /// Verifies the input to the program.
|
||||
// ///
|
||||
// pub fn verify_local_data_commitment(&self, system_parameters: &SystemParameters<Components>) -> Result<bool> {
|
||||
// let result = verify_local_data_commitment(system_parameters, &self.program_input)?;
|
||||
//
|
||||
// Ok(result)
|
||||
// }
|
||||
|
||||
///
|
||||
/// Manually sets main function input.
|
||||
|
@ -21,9 +21,10 @@ use crate::{
|
||||
logical::*,
|
||||
program::ConstrainedProgram,
|
||||
relational::*,
|
||||
resolve_core_circuit,
|
||||
// resolve_core_circuit,
|
||||
value::{Address, Char, CharType, ConstrainedCircuitMember, ConstrainedValue, Integer},
|
||||
FieldType, GroupType,
|
||||
FieldType,
|
||||
GroupType,
|
||||
};
|
||||
use leo_asg::{expression::*, ConstValue, Expression, Node};
|
||||
use leo_errors::{Result, Span};
|
||||
@ -178,26 +179,27 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
|
||||
// Functions
|
||||
Expression::Call(CallExpression {
|
||||
function,
|
||||
target,
|
||||
arguments,
|
||||
// function,
|
||||
// target,
|
||||
// arguments,
|
||||
..
|
||||
}) => {
|
||||
if let Some(circuit) = function.get().circuit.get() {
|
||||
let core_mapping = circuit.core_mapping.borrow();
|
||||
if let Some(core_mapping) = core_mapping.as_deref() {
|
||||
let core_circuit = resolve_core_circuit::<F, G>(core_mapping);
|
||||
return self.enforce_core_circuit_call_expression(
|
||||
cs,
|
||||
&core_circuit,
|
||||
function.get(),
|
||||
target.get(),
|
||||
&arguments[..],
|
||||
span,
|
||||
);
|
||||
}
|
||||
}
|
||||
self.enforce_function_call_expression(cs, function.get(), target.get(), &arguments[..], span)
|
||||
unimplemented!("core circuits are not supported yet")
|
||||
// if let Some(circuit) = function.get().circuit.get() {
|
||||
// let core_mapping = circuit.core_mapping.borrow();
|
||||
// if let Some(core_mapping) = core_mapping.as_deref() {
|
||||
// let core_circuit = resolve_core_circuit::<F, G>(core_mapping);
|
||||
// return self.enforce_core_circuit_call_expression(
|
||||
// cs,
|
||||
// &core_circuit,
|
||||
// function.get(),
|
||||
// target.get(),
|
||||
// &arguments[..],
|
||||
// span,
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// self.enforce_function_call_expression(cs, function.get(), target.get(), &arguments[..], span)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,8 +14,8 @@
|
||||
// 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/>.
|
||||
|
||||
pub mod blake2s;
|
||||
pub use blake2s::*;
|
||||
// pub mod blake2s;
|
||||
// pub use blake2s::*;
|
||||
|
||||
use crate::{ConstrainedValue, GroupType};
|
||||
use leo_asg::Function;
|
||||
@ -35,9 +35,9 @@ pub trait CoreCircuit<'a, F: PrimeField, G: GroupType<F>>: Send + Sync {
|
||||
) -> Result<ConstrainedValue<'a, F, G>>;
|
||||
}
|
||||
|
||||
pub fn resolve_core_circuit<'a, F: PrimeField, G: GroupType<F>>(name: &str) -> impl CoreCircuit<'a, F, G> {
|
||||
match name {
|
||||
"blake2s" => Blake2s,
|
||||
_ => unimplemented!("invalid core circuit: {}", name),
|
||||
}
|
||||
}
|
||||
// pub fn resolve_core_circuit<'a, F: PrimeField, G: GroupType<F>>(name: &str) -> impl CoreCircuit<'a, F, G> {
|
||||
// match name {
|
||||
// "blake2s" => Blake2s,
|
||||
// _ => unimplemented!("invalid core circuit: {}", name),
|
||||
// }
|
||||
// }
|
||||
|
@ -18,7 +18,7 @@ use crate::{ConstrainedValue, GroupType, IntegerTrait};
|
||||
use leo_ast::InputValue;
|
||||
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_gadgets::{
|
||||
boolean::Boolean,
|
||||
@ -36,17 +36,16 @@ use std::{borrow::Borrow, str::FromStr};
|
||||
/// A public address
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Address {
|
||||
pub address: Option<AleoAddress<Components>>,
|
||||
pub address: Option<AleoAddress<Testnet2>>,
|
||||
pub bytes: Vec<UInt8>,
|
||||
}
|
||||
|
||||
impl Address {
|
||||
pub(crate) fn constant(address: String, span: &Span) -> Result<Self> {
|
||||
let address =
|
||||
AleoAddress::from_str(&address).map_err(|e| CompilerError::address_value_account_error(e, span))?;
|
||||
let address = AleoAddress::<Testnet2>::from_str(&address)
|
||||
.map_err(|e| CompilerError::address_value_account_error(e, span))?;
|
||||
|
||||
let mut address_bytes = vec![];
|
||||
address.write_le(&mut address_bytes).unwrap();
|
||||
let address_bytes = address.to_bytes_le().unwrap();
|
||||
|
||||
let bytes = UInt8::constant_vec(&address_bytes[..]);
|
||||
|
||||
@ -95,9 +94,9 @@ impl Address {
|
||||
>(
|
||||
cs: CS,
|
||||
value_gen: Fn,
|
||||
) -> Result<AleoAddress<Components>, SynthesisError> {
|
||||
) -> Result<AleoAddress<Testnet2>, SynthesisError> {
|
||||
if cs.is_in_setup_mode() {
|
||||
Ok(AleoAddress::<Components>::default())
|
||||
Ok(AleoAddress::<Testnet2>::default())
|
||||
} else {
|
||||
let address_string = value_gen()?.borrow().clone();
|
||||
AleoAddress::from_str(&address_string).map_err(|_| SynthesisError::AssignmentMissing)
|
||||
@ -110,14 +109,11 @@ impl<F: PrimeField> AllocGadget<String, F> for Address {
|
||||
_cs: CS,
|
||||
value_gen: Fn,
|
||||
) -> Result<Self, SynthesisError> {
|
||||
let address = {
|
||||
let address: AleoAddress<Testnet2> = {
|
||||
let address_string = value_gen()?.borrow().clone();
|
||||
AleoAddress::from_str(&address_string).map_err(|_| SynthesisError::AssignmentMissing)?
|
||||
};
|
||||
let mut address_bytes = vec![];
|
||||
address
|
||||
.write_le(&mut address_bytes)
|
||||
.map_err(|_| SynthesisError::AssignmentMissing)?;
|
||||
let address_bytes = address.to_bytes_le().map_err(|_| SynthesisError::AssignmentMissing)?;
|
||||
|
||||
let bytes = UInt8::constant_vec(&address_bytes[..]);
|
||||
|
||||
@ -131,11 +127,8 @@ impl<F: PrimeField> AllocGadget<String, F> for Address {
|
||||
mut cs: CS,
|
||||
value_gen: Fn,
|
||||
) -> Result<Self, SynthesisError> {
|
||||
let address = Self::alloc_helper(cs.ns(|| "allocate the address"), value_gen)?;
|
||||
let mut address_bytes = vec![];
|
||||
address
|
||||
.write_le(&mut address_bytes)
|
||||
.map_err(|_| SynthesisError::AssignmentMissing)?;
|
||||
let address: AleoAddress<Testnet2> = Self::alloc_helper(cs.ns(|| "allocate the address"), value_gen)?;
|
||||
let address_bytes = address.to_bytes_le().map_err(|_| SynthesisError::AssignmentMissing)?;
|
||||
|
||||
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,
|
||||
) -> Result<Self, SynthesisError> {
|
||||
let address = Self::alloc_helper(cs.ns(|| "allocate the address"), value_gen)?;
|
||||
let mut address_bytes = vec![];
|
||||
address
|
||||
.write_le(&mut address_bytes)
|
||||
.map_err(|_| SynthesisError::AssignmentMissing)?;
|
||||
let address_bytes = address.to_bytes_le().map_err(|_| SynthesisError::AssignmentMissing)?;
|
||||
|
||||
let bytes = UInt8::alloc_input_vec_le(cs.ns(|| "allocate the address bytes"), &address_bytes[..])?;
|
||||
|
||||
|
@ -41,7 +41,7 @@ version = "0.3.63"
|
||||
version = "2.0"
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0.130"
|
||||
version = "1.0"
|
||||
features = [ "derive", "rc" ]
|
||||
|
||||
[dependencies.tendril]
|
||||
|
@ -68,7 +68,7 @@ impl Command for Prove {
|
||||
let rng = &mut thread_rng();
|
||||
// TODO fix this once snarkvm has better errors.
|
||||
let program_proof =
|
||||
Groth16::<Bls12_377, _, Vec<Fr>>::prove(¶meters, &program, rng).map_err(|_| SnarkVMError::default())?;
|
||||
Groth16::<Bls12_377, Vec<Fr>>::prove(¶meters, &program, rng).map_err(|_| SnarkVMError::default())?;
|
||||
|
||||
// Write the proof file to the output directory
|
||||
let mut proof = vec![];
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
use super::{build::BuildOptions, prove::Prove};
|
||||
use crate::{commands::Command, context::Context};
|
||||
use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType};
|
||||
use leo_errors::{Result, SnarkVMError};
|
||||
|
||||
use snarkvm_algorithms::{snark::groth16::Groth16, traits::SNARK};
|
||||
@ -57,12 +56,8 @@ impl Command for Run {
|
||||
tracing::info!("Starting...");
|
||||
|
||||
// Run the verifier
|
||||
let is_success = Groth16::<Bls12_377, Compiler<Fr, EdwardsGroupType>, Vec<Fr>>::verify(
|
||||
&prepared_verifying_key,
|
||||
&vec![],
|
||||
&proof,
|
||||
)
|
||||
.map_err(|_| SnarkVMError::default())?;
|
||||
let is_success = Groth16::<Bls12_377, Vec<Fr>>::verify_prepared(&prepared_verifying_key, &vec![], &proof)
|
||||
.map_err(|_| SnarkVMError::default())?;
|
||||
|
||||
// Log the verifier output
|
||||
match is_success {
|
||||
|
@ -23,6 +23,7 @@ use leo_package::outputs::{ProvingKeyFile, VerificationKeyFile};
|
||||
use snarkvm_algorithms::{
|
||||
snark::groth16::{Groth16, PreparedVerifyingKey, ProvingKey, VerifyingKey},
|
||||
traits::snark::SNARK,
|
||||
SRS,
|
||||
};
|
||||
use snarkvm_curves::bls12_377::{Bls12_377, Fr};
|
||||
use snarkvm_utilities::ToBytes;
|
||||
@ -78,8 +79,8 @@ impl Command for Setup {
|
||||
|
||||
// Run the program setup operation
|
||||
let rng = &mut thread_rng();
|
||||
let (proving_key, prepared_verifying_key) =
|
||||
Groth16::<Bls12_377, Compiler<Fr, _>, Vec<Fr>>::setup(&program, rng)
|
||||
let (proving_key, verifying_key) =
|
||||
Groth16::<Bls12_377, Vec<Fr>>::setup(&program, &mut SRS::CircuitSpecific(rng))
|
||||
.map_err(|_| CliError::unable_to_setup())?;
|
||||
|
||||
// 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)?;
|
||||
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)
|
||||
} else {
|
||||
tracing::info!("Detected saved setup");
|
||||
|
@ -30,18 +30,22 @@ path = "../input"
|
||||
version = "1.5.3"
|
||||
|
||||
[dependencies.snarkvm-algorithms]
|
||||
version = "0.7.9"
|
||||
git = "https://github.com/AleoHQ/snarkVM.git"
|
||||
rev = "2af7756"
|
||||
|
||||
[dependencies.snarkvm-curves]
|
||||
version = "0.7.9"
|
||||
git = "https://github.com/AleoHQ/snarkVM.git"
|
||||
rev = "2af7756"
|
||||
default-features = false
|
||||
|
||||
[dependencies.snarkvm-dpc]
|
||||
version = "0.7.9"
|
||||
features = [ "testnet1" ]
|
||||
git = "https://github.com/AleoHQ/snarkVM.git"
|
||||
rev = "2af7756"
|
||||
features = [ "testnet2" ]
|
||||
|
||||
[dependencies.snarkvm-utilities]
|
||||
version = "0.7.9"
|
||||
git = "https://github.com/AleoHQ/snarkVM.git"
|
||||
rev = "2af7756"
|
||||
|
||||
[dependencies.indexmap]
|
||||
version = "1.7.0"
|
||||
|
@ -18,7 +18,8 @@ license = "GPL-3.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies.snarkvm-curves]
|
||||
version = "0.7.9"
|
||||
git = "https://github.com/AleoHQ/snarkVM.git"
|
||||
rev = "2af7756"
|
||||
default-features = false
|
||||
|
||||
[dependencies.leo-errors]
|
||||
@ -30,14 +31,17 @@ version = "0.6.5"
|
||||
default-features = false
|
||||
|
||||
[dependencies.snarkvm-fields]
|
||||
version = "0.7.9"
|
||||
git = "https://github.com/AleoHQ/snarkVM.git"
|
||||
rev = "2af7756"
|
||||
default-features = false
|
||||
|
||||
[dependencies.snarkvm-gadgets]
|
||||
version = "0.7.9"
|
||||
git = "https://github.com/AleoHQ/snarkVM.git"
|
||||
rev = "2af7756"
|
||||
|
||||
[dependencies.snarkvm-r1cs]
|
||||
version = "0.7.9"
|
||||
git = "https://github.com/AleoHQ/snarkVM.git"
|
||||
rev = "2af7756"
|
||||
default-features = false
|
||||
|
||||
[dependencies.num-bigint]
|
||||
|
Loading…
Reference in New Issue
Block a user