Skip to content

Commit

Permalink
test: update tests for boundary constraint changes
Browse files Browse the repository at this point in the history
  • Loading branch information
grjte committed Jan 30, 2023
1 parent a0418d4 commit cb45670
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 37 deletions.
8 changes: 4 additions & 4 deletions air-script/tests/aux_trace/aux_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ impl Air for AuxiliaryAir {
fn get_aux_assertions<E: FieldElement<BaseField = Felt>>(&self, aux_rand_elements: &AuxTraceRandElements<E>) -> Vec<Assertion<E>> {
let mut result = Vec::new();
result.push(Assertion::single(0, 0, E::from(1_u64)));
result.push(Assertion::single(1, 0, aux_rand_elements.get_segment_elements(0)[0]));
let last_step = self.last_step();
result.push(Assertion::single(0, last_step, E::from(1_u64)));
result.push(Assertion::single(1, 0, aux_rand_elements.get_segment_elements(0)[0]));
result.push(Assertion::single(1, last_step, E::from(1_u64)));
result
}

fn evaluate_transition<E: FieldElement<BaseField = Felt>>(&self, frame: &EvaluationFrame<E>, periodic_values: &[E], result: &mut [E]) {
let current = frame.current();
let next = frame.next();
result[0] = next[0] - (current[1] + current[2]);
result[1] = next[1] - (current[2] + next[0]);
result[2] = current[2] - (current[0] + current[1]);
result[0] = current[2] - (current[0] + current[1]);
result[1] = next[0] - (current[1] + current[2]);
result[2] = next[1] - (current[2] + next[0]);
}

fn evaluate_aux_transition<F, E>(&self, main_frame: &EvaluationFrame<F>, aux_frame: &EvaluationFrame<E>, _periodic_values: &[F], aux_rand_elements: &AuxTraceRandElements<E>, result: &mut [E])
Expand Down
34 changes: 17 additions & 17 deletions air-script/tests/bitwise/bitwise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Air for BitwiseAir {
}

fn new(trace_info: TraceInfo, public_inputs: PublicInputs, options: WinterProofOptions) -> Self {
let main_degrees = vec![TransitionConstraintDegree::new(2), TransitionConstraintDegree::with_cycles(1, vec![8]), TransitionConstraintDegree::new(2), TransitionConstraintDegree::new(2), TransitionConstraintDegree::new(2), TransitionConstraintDegree::new(2), TransitionConstraintDegree::new(2), TransitionConstraintDegree::new(2), TransitionConstraintDegree::new(2), TransitionConstraintDegree::new(2), TransitionConstraintDegree::with_cycles(1, vec![8]), TransitionConstraintDegree::with_cycles(1, vec![8]), TransitionConstraintDegree::with_cycles(1, vec![8]), TransitionConstraintDegree::with_cycles(1, vec![8]), TransitionConstraintDegree::with_cycles(1, vec![8]), TransitionConstraintDegree::with_cycles(1, vec![8]), TransitionConstraintDegree::new(3)];
let main_degrees = vec![TransitionConstraintDegree::new(2), TransitionConstraintDegree::new(2), TransitionConstraintDegree::new(2), TransitionConstraintDegree::new(2), TransitionConstraintDegree::new(2), TransitionConstraintDegree::new(2), TransitionConstraintDegree::new(2), TransitionConstraintDegree::new(2), TransitionConstraintDegree::new(2), TransitionConstraintDegree::with_cycles(1, vec![8]), TransitionConstraintDegree::with_cycles(1, vec![8]), TransitionConstraintDegree::with_cycles(1, vec![8]), TransitionConstraintDegree::new(3), TransitionConstraintDegree::with_cycles(1, vec![8]), TransitionConstraintDegree::with_cycles(1, vec![8]), TransitionConstraintDegree::with_cycles(1, vec![8]), TransitionConstraintDegree::with_cycles(1, vec![8])];
let aux_degrees = vec![];
let num_main_assertions = 1;
let num_aux_assertions = 0;
Expand Down Expand Up @@ -76,22 +76,22 @@ impl Air for BitwiseAir {
let current = frame.current();
let next = frame.next();
result[0] = (current[0]).exp(E::PositiveInteger::from(2_u64)) - (current[0]) - (E::from(0_u64));
result[1] = (periodic_values[1]) * (next[0] - (current[0])) - (E::from(0_u64));
result[2] = (current[3]).exp(E::PositiveInteger::from(2_u64)) - (current[3]) - (E::from(0_u64));
result[3] = (current[4]).exp(E::PositiveInteger::from(2_u64)) - (current[4]) - (E::from(0_u64));
result[4] = (current[5]).exp(E::PositiveInteger::from(2_u64)) - (current[5]) - (E::from(0_u64));
result[5] = (current[6]).exp(E::PositiveInteger::from(2_u64)) - (current[6]) - (E::from(0_u64));
result[6] = (current[7]).exp(E::PositiveInteger::from(2_u64)) - (current[7]) - (E::from(0_u64));
result[7] = (current[8]).exp(E::PositiveInteger::from(2_u64)) - (current[8]) - (E::from(0_u64));
result[8] = (current[9]).exp(E::PositiveInteger::from(2_u64)) - (current[9]) - (E::from(0_u64));
result[9] = (current[10]).exp(E::PositiveInteger::from(2_u64)) - (current[10]) - (E::from(0_u64));
result[10] = (periodic_values[0]) * (current[1] - (((E::from(2_u64)).exp(E::PositiveInteger::from(0_u64))) * (current[3]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(1_u64))) * (current[4]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(2_u64))) * (current[5]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(3_u64))) * (current[6]))) - (E::from(0_u64));
result[11] = (periodic_values[0]) * (current[2] - (((E::from(2_u64)).exp(E::PositiveInteger::from(0_u64))) * (current[7]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(1_u64))) * (current[8]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(2_u64))) * (current[9]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(3_u64))) * (current[10]))) - (E::from(0_u64));
result[12] = (periodic_values[1]) * (next[1] - ((current[1]) * (E::from(16_u64)) + ((E::from(2_u64)).exp(E::PositiveInteger::from(0_u64))) * (current[3]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(1_u64))) * (current[4]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(2_u64))) * (current[5]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(3_u64))) * (current[6]))) - (E::from(0_u64));
result[13] = (periodic_values[1]) * (next[2] - ((current[2]) * (E::from(16_u64)) + ((E::from(2_u64)).exp(E::PositiveInteger::from(0_u64))) * (current[7]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(1_u64))) * (current[8]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(2_u64))) * (current[9]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(3_u64))) * (current[10]))) - (E::from(0_u64));
result[14] = (periodic_values[0]) * (current[11]) - (E::from(0_u64));
result[15] = (periodic_values[1]) * (current[12] - (next[11])) - (E::from(0_u64));
result[16] = (E::from(1_u64) - (current[0])) * (current[12] - ((current[11]) * (E::from(16_u64)) + (((E::from(2_u64)).exp(E::PositiveInteger::from(0_u64))) * (current[3])) * (current[7]) + (((E::from(2_u64)).exp(E::PositiveInteger::from(1_u64))) * (current[4])) * (current[8]) + (((E::from(2_u64)).exp(E::PositiveInteger::from(2_u64))) * (current[5])) * (current[9]) + (((E::from(2_u64)).exp(E::PositiveInteger::from(3_u64))) * (current[6])) * (current[10]))) + (current[0]) * (current[12] - ((current[11]) * (E::from(16_u64)) + ((E::from(2_u64)).exp(E::PositiveInteger::from(0_u64))) * (current[3] + current[7] - (((E::from(2_u64)) * (current[3])) * (current[7]))) + ((E::from(2_u64)).exp(E::PositiveInteger::from(1_u64))) * (current[4] + current[8] - (((E::from(2_u64)) * (current[4])) * (current[8]))) + ((E::from(2_u64)).exp(E::PositiveInteger::from(2_u64))) * (current[5] + current[9] - (((E::from(2_u64)) * (current[5])) * (current[9]))) + ((E::from(2_u64)).exp(E::PositiveInteger::from(3_u64))) * (current[6] + current[10] - (((E::from(2_u64)) * (current[6])) * (current[10]))))) - (E::from(0_u64));
result[1] = (current[3]).exp(E::PositiveInteger::from(2_u64)) - (current[3]) - (E::from(0_u64));
result[2] = (current[4]).exp(E::PositiveInteger::from(2_u64)) - (current[4]) - (E::from(0_u64));
result[3] = (current[5]).exp(E::PositiveInteger::from(2_u64)) - (current[5]) - (E::from(0_u64));
result[4] = (current[6]).exp(E::PositiveInteger::from(2_u64)) - (current[6]) - (E::from(0_u64));
result[5] = (current[7]).exp(E::PositiveInteger::from(2_u64)) - (current[7]) - (E::from(0_u64));
result[6] = (current[8]).exp(E::PositiveInteger::from(2_u64)) - (current[8]) - (E::from(0_u64));
result[7] = (current[9]).exp(E::PositiveInteger::from(2_u64)) - (current[9]) - (E::from(0_u64));
result[8] = (current[10]).exp(E::PositiveInteger::from(2_u64)) - (current[10]) - (E::from(0_u64));
result[9] = (periodic_values[0]) * (current[1] - (((E::from(2_u64)).exp(E::PositiveInteger::from(0_u64))) * (current[3]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(1_u64))) * (current[4]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(2_u64))) * (current[5]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(3_u64))) * (current[6]))) - (E::from(0_u64));
result[10] = (periodic_values[0]) * (current[2] - (((E::from(2_u64)).exp(E::PositiveInteger::from(0_u64))) * (current[7]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(1_u64))) * (current[8]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(2_u64))) * (current[9]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(3_u64))) * (current[10]))) - (E::from(0_u64));
result[11] = (periodic_values[0]) * (current[11]) - (E::from(0_u64));
result[12] = (E::from(1_u64) - (current[0])) * (current[12] - ((current[11]) * (E::from(16_u64)) + (((E::from(2_u64)).exp(E::PositiveInteger::from(0_u64))) * (current[3])) * (current[7]) + (((E::from(2_u64)).exp(E::PositiveInteger::from(1_u64))) * (current[4])) * (current[8]) + (((E::from(2_u64)).exp(E::PositiveInteger::from(2_u64))) * (current[5])) * (current[9]) + (((E::from(2_u64)).exp(E::PositiveInteger::from(3_u64))) * (current[6])) * (current[10]))) + (current[0]) * (current[12] - ((current[11]) * (E::from(16_u64)) + ((E::from(2_u64)).exp(E::PositiveInteger::from(0_u64))) * (current[3] + current[7] - (((E::from(2_u64)) * (current[3])) * (current[7]))) + ((E::from(2_u64)).exp(E::PositiveInteger::from(1_u64))) * (current[4] + current[8] - (((E::from(2_u64)) * (current[4])) * (current[8]))) + ((E::from(2_u64)).exp(E::PositiveInteger::from(2_u64))) * (current[5] + current[9] - (((E::from(2_u64)) * (current[5])) * (current[9]))) + ((E::from(2_u64)).exp(E::PositiveInteger::from(3_u64))) * (current[6] + current[10] - (((E::from(2_u64)) * (current[6])) * (current[10]))))) - (E::from(0_u64));
result[13] = (periodic_values[1]) * (next[0] - (current[0])) - (E::from(0_u64));
result[14] = (periodic_values[1]) * (next[1] - ((current[1]) * (E::from(16_u64)) + ((E::from(2_u64)).exp(E::PositiveInteger::from(0_u64))) * (current[3]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(1_u64))) * (current[4]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(2_u64))) * (current[5]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(3_u64))) * (current[6]))) - (E::from(0_u64));
result[15] = (periodic_values[1]) * (next[2] - ((current[2]) * (E::from(16_u64)) + ((E::from(2_u64)).exp(E::PositiveInteger::from(0_u64))) * (current[7]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(1_u64))) * (current[8]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(2_u64))) * (current[9]) + ((E::from(2_u64)).exp(E::PositiveInteger::from(3_u64))) * (current[10]))) - (E::from(0_u64));
result[16] = (periodic_values[1]) * (current[12] - (next[11])) - (E::from(0_u64));
}

fn evaluate_aux_transition<F, E>(&self, main_frame: &EvaluationFrame<F>, aux_frame: &EvaluationFrame<E>, _periodic_values: &[F], aux_rand_elements: &AuxTraceRandElements<E>, result: &mut [E])
Expand Down
14 changes: 7 additions & 7 deletions air-script/tests/constants/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ impl Air for ConstantsAir {
fn get_assertions(&self) -> Vec<Assertion<Felt>> {
let mut result = Vec::new();
result.push(Assertion::single(0, 0, A));
result.push(Assertion::single(1, 0, (A) + ((B[0]) * (C[0][1]))));
result.push(Assertion::single(2, 0, ((B[0]) - (C[1][1])) * (A)));
result.push(Assertion::single(3, 0, ((((((A) + (B[0])) - (B[1])) + (C[0][0])) - (C[0][1])) + (C[1][0])) - (C[1][1])));
result.push(Assertion::single(1, 0, A + (B[0]) * (C[0][1])));
result.push(Assertion::single(2, 0, (B[0] - (C[1][1])) * (A)));
result.push(Assertion::single(3, 0, A + B[0] - (B[1]) + C[0][0] - (C[0][1]) + C[1][0] - (C[1][1])));
result
}

fn get_aux_assertions<E: FieldElement<BaseField = Felt>>(&self, aux_rand_elements: &AuxTraceRandElements<E>) -> Vec<Assertion<E>> {
let mut result = Vec::new();
result.push(Assertion::single(0, 0, (E::from(A)) + ((E::from(B[0])) * (E::from(C[0][1])))));
result.push(Assertion::single(0, 0, E::from(A) + (E::from(B[0])) * (E::from(C[0][1]))));
let last_step = self.last_step();
result.push(Assertion::single(0, last_step, (E::from(A)) - ((E::from(B[1])) * (E::from(C[0][0])))));
result.push(Assertion::single(0, last_step, E::from(A) - ((E::from(B[1])) * (E::from(C[0][0])))));
result
}

Expand All @@ -105,7 +105,7 @@ impl Air for ConstantsAir {
{
let current = aux_frame.current();
let next = aux_frame.next();
result[0] = next[0] - (current[0] + E::from(A) + (E::from(B[0])) * (E::from(C[0][1])));
result[1] = current[0] - (E::from(A) + (E::from(B[1])) * (E::from(C[1][1])));
result[0] = current[0] - (E::from(A) + (E::from(B[1])) * (E::from(C[1][1])));
result[1] = next[0] - (current[0] + E::from(A) + (E::from(B[0])) * (E::from(C[0][1])));
}
}
3 changes: 3 additions & 0 deletions air-script/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ fn periodic_columns() {
expected.assert_eq(&generated_air);
}

/// TODO: restore this test after public inputs are re-implemented for boundary constraints in the
/// graph
#[test]
#[ignore]
fn pub_inputs() {
let generated_air = Test::new("tests/pub_inputs/pub_inputs.air".to_string())
.transpile()
Expand Down
3 changes: 2 additions & 1 deletion air-script/tests/pub_inputs/pub_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ impl Air for PubInputsAir {

fn get_assertions(&self) -> Vec<Assertion<Felt>> {
let mut result = Vec::new();
let last_step = self.last_step();
result.push(Assertion::single(0, 0, self.stack_inputs[0]));
result.push(Assertion::single(1, 0, self.stack_inputs[1]));
result.push(Assertion::single(2, 0, self.stack_inputs[2]));
result.push(Assertion::single(3, 0, self.stack_inputs[3]));
let last_step = self.last_step();
result.push(Assertion::single(0, last_step, self.stack_outputs[0]));
result.push(Assertion::single(1, last_step, self.stack_outputs[1]));
result.push(Assertion::single(2, last_step, self.stack_outputs[2]));
Expand All @@ -86,6 +86,7 @@ impl Air for PubInputsAir {

fn get_aux_assertions<E: FieldElement<BaseField = Felt>>(&self, aux_rand_elements: &AuxTraceRandElements<E>) -> Vec<Assertion<E>> {
let mut result = Vec::new();
let last_step = self.last_step();
result
}

Expand Down
2 changes: 1 addition & 1 deletion air-script/tests/variables/variables.air
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ periodic_columns:
k0: [1, 1, 1, 1, 1, 1, 1, 0]

boundary_constraints:
enf a.first = stack_inputs[0]
enf a.first = 0
enf a.last = 1

integrity_constraints:
Expand Down
8 changes: 4 additions & 4 deletions air-script/tests/variables/variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Air for VariablesAir {
}

fn new(trace_info: TraceInfo, public_inputs: PublicInputs, options: WinterProofOptions) -> Self {
let main_degrees = vec![TransitionConstraintDegree::new(2), TransitionConstraintDegree::with_cycles(1, vec![8]), TransitionConstraintDegree::new(2), TransitionConstraintDegree::new(3)];
let main_degrees = vec![TransitionConstraintDegree::new(2), TransitionConstraintDegree::new(2), TransitionConstraintDegree::with_cycles(1, vec![8]), TransitionConstraintDegree::new(3)];
let aux_degrees = vec![TransitionConstraintDegree::new(2)];
let num_main_assertions = 2;
let num_aux_assertions = 0;
Expand All @@ -66,7 +66,7 @@ impl Air for VariablesAir {

fn get_assertions(&self) -> Vec<Assertion<Felt>> {
let mut result = Vec::new();
result.push(Assertion::single(1, 0, self.stack_inputs[0]));
result.push(Assertion::single(1, 0, Felt::new(0)));
let last_step = self.last_step();
result.push(Assertion::single(1, last_step, Felt::new(1)));
result
Expand All @@ -81,8 +81,8 @@ impl Air for VariablesAir {
let current = frame.current();
let next = frame.next();
result[0] = (current[0]).exp(E::PositiveInteger::from(2_u64)) - (current[0]);
result[1] = (periodic_values[0]) * (next[0] - (current[0])) - (E::from(0_u64));
result[2] = (E::from(1_u64) - (current[0])) * (current[3] - (current[1]) + current[2]) - ((E::from(2_u64)) * (E::from(3_u64)) - (current[0]));
result[1] = (E::from(1_u64) - (current[0])) * (current[3] - (current[1]) + current[2]) - ((E::from(2_u64)) * (E::from(3_u64)) - (current[0]));
result[2] = (periodic_values[0]) * (next[0] - (current[0])) - (E::from(0_u64));
result[3] = (current[0]) * (current[3] - ((current[1]) * (current[2]))) - (next[0] - (E::from(3_u64)) - (E::from(4_u64) - (E::from(2_u64))));
}

Expand Down
15 changes: 12 additions & 3 deletions ir/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn trace_cols_groups() {
}

#[test]
fn err_trace_cols_access_out_of_bounds() {
fn err_ic_trace_cols_access_out_of_bounds() {
// out of bounds in integrity constraints
let source = "
const A = 123
Expand All @@ -122,7 +122,12 @@ fn err_trace_cols_access_out_of_bounds() {

let result = AirIR::from_source(&parsed);
assert!(result.is_err());
}

/// TODO: add validation for boundary constraints, then turn this test on.
#[test]
#[ignore]
fn err_bc_trace_cols_access_out_of_bounds() {
// out of bounds in boundary constraints
let source = "
const A = 123
Expand All @@ -145,7 +150,7 @@ fn err_trace_cols_access_out_of_bounds() {
}

#[test]
fn err_tc_invalid_vector_access() {
fn err_ic_invalid_vector_access() {
let source = "
const A = 123
const B = [1, 2, 3]
Expand Down Expand Up @@ -251,7 +256,9 @@ fn err_bc_empty_or_omitted() {
assert!(result.is_err());
}

/// TODO: add validation for boundary constraints, then turn this test on.
#[test]
#[ignore]
fn err_bc_duplicate_first() {
let source = "
trace_columns:
Expand All @@ -270,7 +277,9 @@ fn err_bc_duplicate_first() {
assert!(result.is_err());
}

/// TODO: add validation for boundary constraints, then turn this test on.
#[test]
#[ignore]
fn err_bc_duplicate_last() {
let source = "
trace_columns:
Expand Down Expand Up @@ -598,7 +607,7 @@ fn err_bc_variable_access_before_declaration() {
}

#[test]
fn err_tc_variable_access_before_declaration() {
fn err_ic_variable_access_before_declaration() {
let source = "
const A = [[2, 3], [1, 0]]
trace_columns:
Expand Down

0 comments on commit cb45670

Please sign in to comment.