Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add boundary constraints to the constraint graph #126

Merged
merged 4 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion air-script-core/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub type TraceSegment = u8;
/// of the column within that trace segment, and `row_offset` specifies the offset from the current
/// row. For example, an element in the "next" row of the "main" trace would be specified by
/// a trace_segment of 0 and a row_offset of 1.
#[derive(Debug, Eq, PartialEq, Clone)]
#[derive(Debug, Eq, PartialEq, Clone, Copy)]
pub struct IndexedTraceAccess {
trace_segment: TraceSegment,
col_idx: usize,
Expand Down
11 changes: 5 additions & 6 deletions air-script/tests/aux_trace/aux_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,18 @@ 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(0, self.last_step(), 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, last_step, E::from(1_u64)));
result.push(Assertion::single(1, self.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
15 changes: 7 additions & 8 deletions air-script/tests/constants/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,16 @@ 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])))));
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, 0, E::from(A) + (E::from(B[0])) * (E::from(C[0][1]))));
result.push(Assertion::single(0, self.last_step(), E::from(A) - ((E::from(B[1])) * (E::from(C[0][0])))));
result
}

Expand All @@ -105,7 +104,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
9 changes: 4 additions & 5 deletions air-script/tests/pub_inputs/pub_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@ impl Air for PubInputsAir {
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]));
result.push(Assertion::single(3, last_step, self.stack_outputs[3]));
result.push(Assertion::single(0, self.last_step(), self.stack_outputs[0]));
result.push(Assertion::single(1, self.last_step(), self.stack_outputs[1]));
result.push(Assertion::single(2, self.last_step(), self.stack_outputs[2]));
result.push(Assertion::single(3, self.last_step(), self.stack_outputs[3]));
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to keep the public inputs usage in the public inputs test. Once we add variables for the boundary constraints, we can test them here as well

enf a.last = 1

integrity_constraints:
Expand Down
11 changes: 5 additions & 6 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,9 +66,8 @@ 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]));
let last_step = self.last_step();
result.push(Assertion::single(1, last_step, Felt::new(1)));
result.push(Assertion::single(1, 0, Felt::new(0)));
result.push(Assertion::single(1, self.last_step(), Felt::new(1)));
result
}

Expand All @@ -81,8 +80,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
Loading