-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add integration tests for constants codegen
- Loading branch information
Showing
7 changed files
with
158 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
def PubInputsAir | ||
|
||
constants: | ||
A: 1 | ||
B: [0, 1] | ||
C: [[1, 2], [2, 0]] | ||
|
||
trace_columns: | ||
main: [a, b, c, d] | ||
|
||
public_inputs: | ||
program_hash: [4] | ||
stack_inputs: [4] | ||
stack_outputs: [20] | ||
overflow_addrs: [4] | ||
|
||
boundary_constraints: | ||
enf a.first = A | ||
enf b.first = A + B[0] * C[0][1] | ||
enf c.first = (B[0] - C[1][1]) * A | ||
enf d.first = A + B[0] - B[1] + C[0][0] - C[0][1] + C[1][0] - C[1][1] | ||
|
||
transition_constraints: | ||
enf a' = a + A | ||
enf b' = B[0] * b | ||
enf c' = (C[0][0] + B[0]) * c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
use winter_air::{Air, AirContext, Assertion, AuxTraceRandElements, EvaluationFrame, ProofOptions as WinterProofOptions, TransitionConstraintDegree, TraceInfo}; | ||
use winter_math::{fields, ExtensionOf, FieldElement}; | ||
use winter_utils::{collections, ByteWriter, Serializable}; | ||
|
||
const A: u64 = 1; | ||
const B: Vec<u64> = vec![0, 1]; | ||
const C: Vec<Vec<u64>> = vec![vec![1, 2], vec![2, 0]]; | ||
|
||
pub struct PublicInputs { | ||
program_hash: [Felt; 4], | ||
stack_inputs: [Felt; 4], | ||
stack_outputs: [Felt; 20], | ||
overflow_addrs: [Felt; 4], | ||
} | ||
|
||
impl PublicInputs { | ||
pub fn new(program_hash: [Felt; 4], stack_inputs: [Felt; 4], stack_outputs: [Felt; 20], overflow_addrs: [Felt; 4]) -> Self { | ||
Self { program_hash, stack_inputs, stack_outputs, overflow_addrs } | ||
} | ||
} | ||
|
||
impl Serializable for PublicInputs { | ||
fn write_into<W: ByteWriter>(&self, target: &mut W) { | ||
target.write(self.program_hash.as_slice()); | ||
target.write(self.stack_inputs.as_slice()); | ||
target.write(self.stack_outputs.as_slice()); | ||
target.write(self.overflow_addrs.as_slice()); | ||
} | ||
} | ||
|
||
pub struct PubInputsAir { | ||
context: AirContext<Felt>, | ||
program_hash: [Felt; 4], | ||
stack_inputs: [Felt; 4], | ||
stack_outputs: [Felt; 20], | ||
overflow_addrs: [Felt; 4], | ||
} | ||
|
||
impl PubInputsAir { | ||
pub fn last_step(&self) -> usize { | ||
self.trace_length() - self.context().num_transition_exemptions() | ||
} | ||
} | ||
|
||
impl Air for PubInputsAir { | ||
type BaseField = Felt; | ||
type PublicInputs = PublicInputs; | ||
|
||
fn context(&self) -> &AirContext<Felt> { | ||
&self.context | ||
} | ||
|
||
fn new(trace_info: TraceInfo, public_inputs: PublicInputs, options: WinterProofOptions) -> Self { | ||
let main_degrees = vec![TransitionConstraintDegree::new(1), TransitionConstraintDegree::new(1), TransitionConstraintDegree::new(1)]; | ||
let aux_degrees = vec![]; | ||
let num_main_assertions = 4; | ||
let num_aux_assertions = 0; | ||
|
||
let context = AirContext::new_multi_segment( | ||
trace_info, | ||
main_degrees, | ||
aux_degrees, | ||
num_main_assertions, | ||
num_aux_assertions, | ||
options, | ||
) | ||
.set_num_transition_exemptions(2); | ||
Self { context, program_hash: public_inputs.program_hash, stack_inputs: public_inputs.stack_inputs, stack_outputs: public_inputs.stack_outputs, overflow_addrs: public_inputs.overflow_addrs } | ||
} | ||
|
||
fn get_periodic_column_values(&self) -> Vec<Vec<Felt>> { | ||
vec![] | ||
} | ||
|
||
fn get_assertions(&self) -> Vec<Assertion<Felt>> { | ||
let mut result = Vec::new(); | ||
result.push(Assertion::single(0, 0, E::from(A))); | ||
result.push(Assertion::single(1, 0, (E::from(A)) + ((E::from(B[0])) * (E::from(C[0][1]))))); | ||
result.push(Assertion::single(2, 0, ((E::from(B[0])) - (E::from(C[1][1]))) * (E::from(A)))); | ||
result.push(Assertion::single(3, 0, ((((((E::from(A)) + (E::from(B[0]))) - (E::from(B[1]))) + (E::from(C[0][0]))) - (E::from(C[0][1]))) + (E::from(C[1][0]))) - (E::from(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 | ||
} | ||
|
||
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[0] + E::from(A)); | ||
result[1] = next[1] - ((E::from(B[0])) * (current[1])); | ||
result[2] = next[2] - ((E::from(C[0][0]) + E::from(B[0])) * (current[2])); | ||
} | ||
|
||
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]) | ||
where F: FieldElement<BaseField = Felt>, | ||
E: FieldElement<BaseField = Felt> + ExtensionOf<F>, | ||
{ | ||
let current = aux_frame.current(); | ||
let next = aux_frame.next(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters