From 825f36ee7223a26cbe8896213ce16f5e7369ba98 Mon Sep 17 00:00:00 2001 From: Jan Ferdinand Sauer Date: Tue, 15 Nov 2022 22:01:58 +0100 Subject: [PATCH] WIP: produce initial constraints --- constraint-evaluation-generator/src/main.rs | 68 ++++++++++++++++----- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/constraint-evaluation-generator/src/main.rs b/constraint-evaluation-generator/src/main.rs index 0e995386c..6631f4735 100644 --- a/constraint-evaluation-generator/src/main.rs +++ b/constraint-evaluation-generator/src/main.rs @@ -18,33 +18,57 @@ fn main() { println!("Generate those constraint evaluators!"); // Program table - let mut circuits = ExtProgramTable::ext_transition_constraints_as_circuits(); - let source_code = gen("program_table", "ProgramTable", &mut circuits); + let source_code = gen( + "program_table", + "ProgramTable", + &mut ExtProgramTable::ext_initial_constraints_as_circuits(), + &mut ExtProgramTable::ext_transition_constraints_as_circuits(), + ); write("program_table", source_code); // Instruction table - let mut circuits = ExtInstructionTable::ext_transition_constraints_as_circuits(); - let source_code = gen("instruction_table", "InstructionTable", &mut circuits); + let source_code = gen( + "instruction_table", + "InstructionTable", + &mut ExtInstructionTable::ext_initial_constraints_as_circuits(), + &mut ExtInstructionTable::ext_transition_constraints_as_circuits(), + ); write("instruction_table", source_code); // Processor table - let mut circuits = ExtProcessorTable::ext_transition_constraints_as_circuits(); - let source_code = gen("processor_table", "ProcessorTable", &mut circuits); + let source_code = gen( + "processor_table", + "ProcessorTable", + &mut ExtProcessorTable::ext_initial_constraints_as_circuits(), + &mut ExtProcessorTable::ext_transition_constraints_as_circuits(), + ); write("processor_table", source_code); // Opstack table - let mut constraint_circuits = ExtOpStackTable::ext_transition_constraints_as_circuits(); - let source_code = gen("op_stack_table", "OpStackTable", &mut constraint_circuits); + let source_code = gen( + "op_stack_table", + "OpStackTable", + &mut ExtOpStackTable::ext_initial_constraints_as_circuits(), + &mut ExtOpStackTable::ext_transition_constraints_as_circuits(), + ); write("op_stack_table", source_code); // RAM table - let mut circuits = ExtRamTable::ext_transition_constraints_as_circuits(); - let source_code = gen("ram_table", "RamTable", &mut circuits); + let source_code = gen( + "ram_table", + "RamTable", + &mut ExtRamTable::ext_initial_constraints_as_circuits(), + &mut ExtRamTable::ext_transition_constraints_as_circuits(), + ); write("ram_table", source_code); // JumpStack table - let mut circuits = ExtJumpStackTable::ext_transition_constraints_as_circuits(); - let source_code = gen("jump_stack_table", "JumpStackTable", &mut circuits); + let source_code = gen( + "jump_stack_table", + "JumpStackTable", + &mut ExtJumpStackTable::ext_initial_constraints_as_circuits(), + &mut ExtJumpStackTable::ext_transition_constraints_as_circuits(), + ); write("jump_stack_table", source_code); } @@ -55,15 +79,17 @@ fn write(table_name_snake: &str, rust_source_code: String) { std::fs::write(output_filename, rust_source_code).expect("Write Rust source code"); } -fn gen( +fn gen( table_name_snake: &str, table_id_name: &str, - constraint_circuits: &mut [ConstraintCircuit], + initial_constraint_circuits: &mut [ConstraintCircuit], + transition_constraint_circuits: &mut [ConstraintCircuit], ) -> String { let challenge_enum_name = format!("{table_id_name}ChallengeId"); let table_mod_name = format!("Ext{table_id_name}"); - let circuits_as_string = turn_circuits_into_string(constraint_circuits); + let initial_constraint_strings = turn_circuits_into_string(initial_constraint_circuits); + let transition_constraint_strings = turn_circuits_into_string(transition_constraint_circuits); format!( " @@ -77,6 +103,16 @@ use crate::table::{table_name_snake}::{table_mod_name}; use crate::table::{table_name_snake}::{challenge_enum_name}::*; impl Evaluable for {table_mod_name} {{ + #[inline] + fn evaluate_initial_constraints( + &self, + row: &[XFieldElement], + challenges: &AllChallenges, + ) -> Vec {{ + let challenges = &challenges.{table_name_snake}_challenges; + {initial_constraint_strings} + }} + #[inline] fn evaluate_transition_constraints( &self, @@ -85,7 +121,7 @@ impl Evaluable for {table_mod_name} {{ challenges: &AllChallenges, ) -> Vec {{ let challenges = &challenges.{table_name_snake}_challenges; - {circuits_as_string} + {transition_constraint_strings} }} }} "