diff --git a/air-script/tests/aux_trace/aux_trace.air b/air-script/tests/aux_trace/aux_trace.air index 2f6141f74..be2f37fa9 100644 --- a/air-script/tests/aux_trace/aux_trace.air +++ b/air-script/tests/aux_trace/aux_trace.air @@ -23,6 +23,6 @@ integrity_constraints: enf b' = c + a' enf c = a + b - # integrity constraints against the auxiliary trace with random values - enf p0' = p0 * (a + $rand[0] + b + $rand[1]) - enf p1 = p1' * (c + $rand[0]) \ No newline at end of file + # integrity constraints against the auxiliary trace + enf p0' = p0 * (a + b) + enf p1 = p1' * c \ No newline at end of file diff --git a/air-script/tests/aux_trace/aux_trace.rs b/air-script/tests/aux_trace/aux_trace.rs index aeacdb202..a80d42571 100644 --- a/air-script/tests/aux_trace/aux_trace.rs +++ b/air-script/tests/aux_trace/aux_trace.rs @@ -92,7 +92,7 @@ impl Air for AuxiliaryAir { { let current = aux_frame.current(); let next = aux_frame.next(); - result[0] = next[0] - ((current[0]) * (current[0] + aux_rand_elements.get_segment_elements(0)[0] + current[1] + aux_rand_elements.get_segment_elements(0)[1])); - result[1] = current[1] - ((next[1]) * (current[2] + aux_rand_elements.get_segment_elements(0)[0])); + result[0] = next[0] - ((current[0]) * (current[0] + current[1])); + result[1] = current[1] - ((next[1]) * (current[2])); } } \ No newline at end of file diff --git a/air-script/tests/variables/variables.air b/air-script/tests/variables/variables.air index 409775f90..22499d0c1 100644 --- a/air-script/tests/variables/variables.air +++ b/air-script/tests/variables/variables.air @@ -35,5 +35,5 @@ integrity_constraints: # c = a * b when s = 1. enf s * (c - a * b) = o[0][0] - o[0][1] - o[1][0] - # the auxiliary column contains the product of values of c offset by a random value. - enf p' = p * (c + $rand[0]) + # the auxiliary column contains the product of values of c. + enf p' = p * c diff --git a/air-script/tests/variables/variables.rs b/air-script/tests/variables/variables.rs index 4583eedd3..be93717ee 100644 --- a/air-script/tests/variables/variables.rs +++ b/air-script/tests/variables/variables.rs @@ -92,6 +92,6 @@ impl Air for VariablesAir { { let current = aux_frame.current(); let next = aux_frame.next(); - result[0] = next[0] - ((current[0]) * (current[3] + aux_rand_elements.get_segment_elements(0)[0])); + result[0] = next[0] - ((current[0]) * (current[3])); } } \ No newline at end of file diff --git a/parser/src/ast/mod.rs b/parser/src/ast/mod.rs index ab5294ce9..30fac780b 100644 --- a/parser/src/ast/mod.rs +++ b/parser/src/ast/mod.rs @@ -34,6 +34,7 @@ pub struct Source(pub Vec); /// - PeriodicColumns: Periodic columns are each represented by a fixed-size array with all of its /// elements specified. The array length is expected to be a power of 2, but this is not checked /// during parsing. +/// - RandomValues: Random Values represent the randomness sent by the Verifier /// - BoundaryConstraints: Boundary Constraints to be enforced on the boundaries of columns defined /// in the TraceCols section. Currently there are two types of boundaries, First and Last /// representing the first and last rows of the column. diff --git a/parser/src/ast/random_values.rs b/parser/src/ast/random_values.rs index bbbccad60..145018729 100644 --- a/parser/src/ast/random_values.rs +++ b/parser/src/ast/random_values.rs @@ -4,9 +4,9 @@ use super::Identifier; // ================================================================================================ /// Declaration of random values for an AIR. Random values colud be represented by a named -/// identifier which is used to identify a fixed size array of length `size` and empty `values` -/// vector or by named identifier which is used to identify a `values` [RandomValue] vector and \ -/// zero `size` field. +/// identifier which is used to identify a fixed size array of length `size` and empty `bindings` +/// vector or by named identifier which is used to identify a `bindings` [RandBinding] vector and +/// its `size` field. /// /// # Examples /// @@ -15,34 +15,36 @@ use super::Identifier; /// ```airscript /// random_values: /// rand: [15] -/// /// ``` /// /// created [RandomValues] instance will look like /// -/// `RandomValues{name: "rand", size: 15, values: []}` +/// `RandomValues{name: "rand", size: 15, bindings: []}` /// /// If random values declared in form /// /// ```airscript /// random_values: /// rand: [a, b[12]] -/// /// ``` /// /// created [RandomValues] instance will look like /// -/// `RandomValues{name: "rand", size: 0, values: [RandomValue{name: "a", size: 1}, RandomValue{name: "b", size: 12}]}` +/// `RandomValues{name: "rand", size: 2, bindings: [RandBinding{name: "a", size: 1}, RandBinding{name: "b", size: 12}]}` #[derive(Debug, Eq, PartialEq)] pub struct RandomValues { name: Identifier, size: usize, - values: Vec, + bindings: Vec, } impl RandomValues { - pub(crate) fn new(name: Identifier, size: usize, values: Vec) -> Self { - Self { name, size, values } + pub(crate) fn new(name: Identifier, size: usize, bindings: Vec) -> Self { + Self { + name, + size, + bindings, + } } pub fn name(&self) -> &str { @@ -54,18 +56,19 @@ impl RandomValues { self.size } - pub fn values(&self) -> &Vec { - &self.values + pub fn bindings(&self) -> &Vec { + &self.bindings } } +/// Declaration of a random value used in [RandomValues]. It is represented by a named identifier and its size. #[derive(Debug, Eq, PartialEq)] -pub struct RandomValue { +pub struct RandBinding { name: Identifier, size: usize, } -impl RandomValue { +impl RandBinding { pub(crate) fn new(name: Identifier, size: usize) -> Self { Self { name, size } } diff --git a/parser/src/parser/grammar.lalrpop b/parser/src/parser/grammar.lalrpop index 518bceddc..209aad7a2 100644 --- a/parser/src/parser/grammar.lalrpop +++ b/parser/src/parser/grammar.lalrpop @@ -3,7 +3,7 @@ use crate::{ boundary_constraints::{Boundary, BoundaryConstraint, BoundaryStmt}, integrity_constraints::{IntegrityConstraint, IntegrityStmt}, Constant, ConstantType, Expression, Identifier, Variable, VariableType, - RandomValues, RandomValue, Source, SourceSection, Trace, TraceCols, PublicInput, + RandomValues, RandBinding, Source, SourceSection, Trace, TraceCols, PublicInput, PeriodicColumn, IndexedTraceAccess, NamedTraceAccess, MatrixAccess, VectorAccess }, error::{Error, ParseError::{InvalidInt, InvalidTraceCols, MissingMainTraceCols, InvalidConst, MissingBoundaryConstraint, MissingIntegrityConstraint}}, lexer::Token @@ -129,12 +129,12 @@ RandomValues: RandomValues = { RandValues: RandomValues = { ":" => RandomValues::new(name, index, vec![]), ":" "[" "]" => RandomValues::new(name, 0, vec![]), - ":" "[" > "]" => RandomValues::new(name, 0, rand_vec) + ":" "[" > "]" => RandomValues::new(name, rand_vec.iter().map(|v| v.size()).sum::(), rand_vec) } -RandElem: RandomValue = { - => RandomValue::new(name, 1), - => RandomValue::new(name, index) +RandElem: RandBinding = { + => RandBinding::new(name, 1), + => RandBinding::new(name, index) } // BOUNDARY STATEMENTS diff --git a/parser/src/parser/tests/random_values.rs b/parser/src/parser/tests/random_values.rs index 7760f441e..1383a46fb 100644 --- a/parser/src/parser/tests/random_values.rs +++ b/parser/src/parser/tests/random_values.rs @@ -1,4 +1,4 @@ -use super::{build_parse_test, Identifier, RandomValue, RandomValues, Source, SourceSection::*}; +use super::{build_parse_test, Identifier, RandBinding, RandomValues, Source, SourceSection::*}; // RANDOM VALUES // ================================================================================================ @@ -23,11 +23,11 @@ fn random_values_ident_vector_custom_name() { alphas: [a, b[12], c]"; let expected = Source(vec![RandomValues(RandomValues::new( Identifier("alphas".to_string()), - 0, + 14, vec![ - RandomValue::new(Identifier("a".to_string()), 1), - RandomValue::new(Identifier("b".to_string()), 12), - RandomValue::new(Identifier("c".to_string()), 1), + RandBinding::new(Identifier("a".to_string()), 1), + RandBinding::new(Identifier("b".to_string()), 12), + RandBinding::new(Identifier("c".to_string()), 1), ], ))]); build_parse_test!(source).expect_ast(expected);