fix value.field bug

This commit is contained in:
collin 2020-07-08 03:30:15 -07:00
parent 7a0827af48
commit aa708b8084
17 changed files with 27 additions and 27 deletions

View File

@ -115,9 +115,9 @@ function main() -> u32 {
### Field Elements
```js
function main() -> value.field {
function main() -> field {
let a = 1000field; // explicit type
let a: value.field = 21888242871839275222246405745257275088548364400416034343698204186575808495617; // explicit type
let a: field = 21888242871839275222246405745257275088548364400416034343698204186575808495617; // explicit type
let b = a + 1; // implicit type
let c = b - 1;
let d = c * 4;
@ -173,7 +173,7 @@ function main() -> u32[2] {
// initialize an array copying a slice from `c`
let d = c[1..3];
// initialize a value.field array
// initialize a field array
let e = [5field; 2];
// initialize a boolean array
@ -248,7 +248,7 @@ function test1(a : u32) -> u32 {
return a + 1
}
function test2(b: fe) -> value.field {
function test2(b: fe) -> field {
return b * 2field
}
@ -264,12 +264,12 @@ function main() -> u32 {
### Function Scope
```js
function foo() -> value.field {
function foo() -> field {
// return myGlobal <- not allowed
return 42field
}
function main() -> value.field {
function main() -> field {
let myGlobal = 42field;
return foo()
}
@ -293,7 +293,7 @@ function main() -> u32[3] {
Main function inputs are allocated private variables in the program's constraint system.
`a` is implicitly private.
```js
function main(a: value.field) -> value.field {
function main(a: field) -> field {
return a
}
```
@ -578,7 +578,7 @@ function main(a: u32, b: u32) -> u32 {
[main]
a: bool = true; // <- booleans
b: u8 = 2; // <- integers
c: value.field = 0; // <- fields
c: field = 0; // <- fields
d: group = (0, 1)group // <- group tuples
```

View File

@ -13,7 +13,7 @@ impl From<Error<Rule>> for SyntaxError {
error = error.renamed_rules(|rule| match *rule {
Rule::LINE_END => "`;`".to_owned(),
Rule::type_integer => "`u32`".to_owned(),
Rule::type_field => "`value.field`".to_owned(),
Rule::type_field => "`field`".to_owned(),
Rule::type_group => "`group`".to_owned(),
Rule::file => "an import, circuit, or function".to_owned(),
Rule::identifier => "a variable name".to_owned(),

View File

@ -22,7 +22,7 @@ impl FieldError {
pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self {
let message = format!(
"the value.field binary operation `{}` failed due to synthesis error `{}`",
"the field binary operation `{}` failed due to synthesis error `{}`",
operation, error,
);
@ -30,25 +30,25 @@ impl FieldError {
}
pub fn invalid_field(actual: String, span: Span) -> Self {
let message = format!("expected value.field element input type, found `{}`", actual);
let message = format!("expected field element input type, found `{}`", actual);
Self::new_from_span(message, span)
}
pub fn missing_field(expected: String, span: Span) -> Self {
let message = format!("expected value.field input `{}` not found", expected);
let message = format!("expected field input `{}` not found", expected);
Self::new_from_span(message, span)
}
pub fn no_inverse(field: String, span: Span) -> Self {
let message = format!("no multiplicative inverse found for value.field `{}`", field);
let message = format!("no multiplicative inverse found for field `{}`", field);
Self::new_from_span(message, span)
}
pub fn synthesis_error(error: SynthesisError, span: Span) -> Self {
let message = format!("compilation failed due to value.field synthesis error `{}`", error);
let message = format!("compilation failed due to field synthesis error `{}`", error);
Self::new_from_span(message, span)
}

View File

@ -8,7 +8,7 @@ pub mod compiler;
pub mod constraints;
pub use self::constraints::*;
pub mod definitions;
pub mod definition;
pub mod errors;

View File

@ -25,7 +25,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
match self.get_mutable_assignee(circuit_name, span.clone())? {
ConstrainedValue::CircuitExpression(_variable, members) => {
// Modify the circuit value.field in place
// Modify the circuit field in place
let matched_field = members.into_iter().find(|object| object.0 == object_name);
match matched_field {

View File

@ -15,7 +15,7 @@ pub(crate) fn allocate_field<F: Field + PrimeField, CS: ConstraintSystem<F>>(
option: Option<String>,
span: Span,
) -> Result<FieldType<F>, FieldError> {
let field_name = format!("{}: value.field", name);
let field_name = format!("{}: field", name);
let field_name_unique = format!("`{}` {}:{}", field_name, span.line, span.start);
FieldType::alloc(cs.ns(|| field_name_unique), || {

View File

@ -180,7 +180,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedValue<F, G> {
}
ConstrainedValue::Field(field) => {
let gadget = field
.allocated(cs.ns(|| format!("allocate value.field {}:{}", span.line, span.start)))
.allocated(cs.ns(|| format!("allocate field {}:{}", span.line, span.start)))
.map_err(|error| ValueError::FieldError(FieldError::synthesis_error(error, span)))?;
*field = FieldType::Allocated(gadget)

View File

@ -364,7 +364,7 @@ macro_rules! test_uint {
let mut program_2 = program_1.clone();
// true -> value.field 1
// true -> field 1
program_1.set_inputs(vec![
Some(InputValue::Boolean(true)),
Some(InputValue::Integer($integer_type, r1 as u128)),
@ -373,7 +373,7 @@ macro_rules! test_uint {
output_expected_allocated(program_1, g1);
// false -> value.field 2
// false -> field 2
program_2.set_inputs(vec![
Some(InputValue::Boolean(false)),
Some(InputValue::Integer($integer_type, r1 as u128)),

View File

@ -1,4 +1,4 @@
// The program inputs for square_root/src/main.leo
[main]
a: value.field = 337;
b: value.field = 113569;
a: field = 337;
b: field = 113569;

View File

@ -1,5 +1,5 @@
// The 'square_root' main function.
// prove knowledge of the square root `a` of a number `b`:
function main(a: value.field, b: value.field) -> bool {
function main(a: field, b: field) -> bool {
return a * a == b
}

View File

@ -13,7 +13,7 @@ impl From<Error<Rule>> for SyntaxError {
error = error.renamed_rules(|rule| match *rule {
Rule::LINE_END => "`;`".to_owned(),
Rule::type_integer => "`u32`".to_owned(),
Rule::type_field => "`value.field`".to_owned(),
Rule::type_field => "`field`".to_owned(),
Rule::type_group => "`group`".to_owned(),
Rule::file => "an import, circuit, or function".to_owned(),
Rule::identifier => "a variable name".to_owned(),

View File

@ -21,7 +21,7 @@ impl std::fmt::Display for DataType {
match self {
DataType::Address(_) => write!(f, "address"),
DataType::Boolean(_) => write!(f, "bool"),
DataType::Field(_) => write!(f, "value.field"),
DataType::Field(_) => write!(f, "field"),
DataType::Group(_) => write!(f, "group"),
DataType::Integer(ref integer) => write!(f, "{}", integer),
}

View File

@ -12,7 +12,7 @@ use std::fmt;
pub enum Assignee {
Identifier(Identifier),
Array(Box<Assignee>, RangeOrExpression),
CircuitField(Box<Assignee>, Identifier), // (circuit name, circuit value.field name)
CircuitField(Box<Assignee>, Identifier), // (circuit name, circuit field name)
}
impl<'ast> From<AstIdentifier<'ast>> for Assignee {

View File

@ -113,7 +113,7 @@ impl fmt::Display for Type {
match *self {
Type::Address => write!(f, "address"),
Type::Boolean => write!(f, "bool"),
Type::Field => write!(f, "value.field"),
Type::Field => write!(f, "field"),
Type::Group => write!(f, "group"),
Type::IntegerType(ref integer_type) => write!(f, "{}", integer_type),
Type::Circuit(ref variable) => write!(f, "circuit {}", variable),