use account public key in snarkos dpc

This commit is contained in:
collin 2020-07-06 03:18:20 -07:00
parent d5bdda89e7
commit 8ca5f5ce66
6 changed files with 121 additions and 28 deletions

92
Cargo.lock generated
View File

@ -179,6 +179,18 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "chrono"
version = "0.4.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c74d84029116787153e02106bf53e66828452a4b325cc8652b788b5967c0a0b6"
dependencies = [
"num-integer",
"num-traits",
"serde",
"time",
]
[[package]]
name = "ci_info"
version = "0.10.1"
@ -574,9 +586,11 @@ dependencies = [
"rand",
"sha2",
"snarkos-curves",
"snarkos-dpc",
"snarkos-errors",
"snarkos-gadgets",
"snarkos-models",
"snarkos-objects",
"snarkos-utilities",
"thiserror",
]
@ -666,6 +680,25 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab250442c86f1850815b5d268639dff018c0627022bc1940eb2d642ca1ce12f0"
[[package]]
name = "num-integer"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611"
dependencies = [
"autocfg",
]
[[package]]
name = "num_cpus"
version = "1.13.0"
@ -682,6 +715,12 @@ version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5"
[[package]]
name = "once_cell"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d"
[[package]]
name = "opaque-debug"
version = "0.2.3"
@ -1056,6 +1095,26 @@ dependencies = [
"syn 1.0.33",
]
[[package]]
name = "snarkos-dpc"
version = "0.8.0"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git?rev=c7a56d9#c7a56d97a76dd6e7841aa6bb86e086f7128e5620"
dependencies = [
"blake2",
"derivative",
"hex",
"rand",
"snarkos-algorithms",
"snarkos-curves",
"snarkos-errors",
"snarkos-gadgets",
"snarkos-models",
"snarkos-objects",
"snarkos-parameters",
"snarkos-profiler",
"snarkos-utilities",
]
[[package]]
name = "snarkos-errors"
version = "0.8.0"
@ -1098,6 +1157,39 @@ dependencies = [
"snarkos-utilities",
]
[[package]]
name = "snarkos-objects"
version = "0.8.0"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git?rev=c7a56d9#c7a56d97a76dd6e7841aa6bb86e086f7128e5620"
dependencies = [
"base58",
"bech32",
"chrono",
"derivative",
"hex",
"once_cell",
"rand",
"serde",
"sha2",
"snarkos-algorithms",
"snarkos-curves",
"snarkos-errors",
"snarkos-models",
"snarkos-utilities",
]
[[package]]
name = "snarkos-parameters"
version = "0.8.0"
source = "git+ssh://git@github.com/AleoHQ/snarkOS.git?rev=c7a56d9#c7a56d97a76dd6e7841aa6bb86e086f7128e5620"
dependencies = [
"hex",
"snarkos-algorithms",
"snarkos-errors",
"snarkos-models",
"snarkos-utilities",
]
[[package]]
name = "snarkos-profiler"
version = "0.8.0"

View File

@ -10,9 +10,11 @@ leo-types = { path = "../types", version = "0.1.0" }
leo-inputs = { path = "../leo-inputs", version = "0.1.0" }
snarkos-curves = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", rev = "c7a56d9", default-features = false }
snarkos-dpc = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", rev = "c7a56d9", default-features = false }
snarkos-errors = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", rev = "c7a56d9", default-features = false }
snarkos-gadgets = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", rev = "c7a56d9", default-features = false }
snarkos-models = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", rev = "c7a56d9", default-features = false }
snarkos-objects = { git = "ssh://git@github.com/AleoHQ/snarkOS.git", rev = "c7a56d9", default-features = false }
bincode = { version = "1.0" }
hex = { version = "0.4.2" }

View File

@ -1,32 +1,23 @@
use crate::errors::AddressError;
use leo_types::Span;
use snarkos_errors::gadgets::SynthesisError;
use snarkos_models::{
curves::{Field, PrimeField},
gadgets::r1cs::ConstraintSystem,
};
use snarkos_dpc::base_dpc::instantiated::Components;
use snarkos_objects::account::AccountPublicKey;
use std::str::FromStr;
#[derive(Clone, Debug)]
pub struct Address(pub String);
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Address(pub AccountPublicKey<Components>);
impl Address {
pub(crate) fn constant(address: String, span: Span) -> Result<Self, AddressError> {
Ok(Self(address))
}
pub(crate) fn new(address: String, span: Span) -> Result<Self, AddressError> {
let address = AccountPublicKey::from_str(&address).map_err(|error| AddressError::account_error(error, span))?;
// pub(crate) fn allocate<F: Field + PrimeField, CS: ConstraintSystem<F>>(
// cs: &mut CS,
// name: String,
// option: Option<bool>,
// span: Span,
// ) -> Result<Self, AddressError> {
// let boolean_name = format!("{}: bool", name);
// let boolean_name_unique = format!("`{}` {}:{}", boolean_name, span.line, span.start);
//
// Self::alloc(cs.ns(|| boolean_name_unique), || {
// option.ok_or(SynthesisError::AssignmentMissing)
// })
// .map_err(|_| AddressError::missing_boolean(boolean_name, span))
// }
Ok(Address(address))
}
}
impl std::fmt::Display for Address {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}

View File

@ -934,7 +934,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
}
// Values
Expression::Address(address, span) => Ok(ConstrainedValue::Address(Address::constant(address, span)?)),
Expression::Address(address, span) => Ok(ConstrainedValue::Address(Address::new(address, span)?)),
Expression::Boolean(boolean, span) => Ok(ConstrainedValue::Boolean(new_bool_constant(boolean, span)?)),
Expression::Field(field, span) => Ok(ConstrainedValue::Field(FieldType::constant(field, span)?)),
Expression::Group(group_affine, span) => Ok(ConstrainedValue::Group(G::constant(group_affine, span)?)),

View File

@ -64,7 +64,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedValue<F, G> {
pub(crate) fn from_type(value: String, _type: &Type, span: Span) -> Result<Self, ValueError> {
match _type {
// Data types
Type::Address => Ok(ConstrainedValue::Address(Address::constant(value, span)?)),
Type::Address => Ok(ConstrainedValue::Address(Address::new(value, span)?)),
Type::Boolean => Ok(ConstrainedValue::Boolean(new_bool_constant(value, span)?)),
Type::Field => Ok(ConstrainedValue::Field(FieldType::constant(value, span)?)),
Type::Group => Ok(ConstrainedValue::Group(G::constant(value, span)?)),
@ -169,7 +169,9 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedValue<F, G> {
pub(crate) fn allocate_value<CS: ConstraintSystem<F>>(&mut self, mut cs: CS, span: Span) -> Result<(), ValueError> {
match self {
// Data types
ConstrainedValue::Address(address) => unimplemented!("allocating addresses not impl"),
ConstrainedValue::Address(address) => {
// allow `let address()` syntax to pass through for now
}
ConstrainedValue::Boolean(boolean) => {
let option = boolean.get_value();
let name = option.map(|b| b.to_string()).unwrap_or(format!("[allocated]"));

View File

@ -1,6 +1,6 @@
use leo_types::{Error as FormattedError, Span};
use snarkos_errors::gadgets::SynthesisError;
use snarkos_errors::{gadgets::SynthesisError, objects::account::AccountError};
use std::path::PathBuf;
#[derive(Debug, Error)]
@ -20,6 +20,12 @@ impl AddressError {
AddressError::Error(FormattedError::new_from_span(message, span))
}
pub fn account_error(error: AccountError, span: Span) -> Self {
let message = format!("account creation failed due to `{}`", error);
Self::new_from_span(message, span)
}
pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self {
let message = format!(
"the address operation `{}` failed due to the synthesis error `{}`",