diff --git a/circuits/src/builtins/poseidon/poseidon_chunk_stark.rs b/circuits/src/builtins/poseidon/poseidon_chunk_stark.rs index b7a377aa..3adc6d6c 100644 --- a/circuits/src/builtins/poseidon/poseidon_chunk_stark.rs +++ b/circuits/src/builtins/poseidon/poseidon_chunk_stark.rs @@ -284,87 +284,87 @@ impl, const D: usize> Stark for PoseidonChunk } } -// mod test { -// use core::trace::trace::{PoseidonChunkRow, Trace}; -// use core::types::Field; -// use std::path::PathBuf; -// -// use crate::builtins::poseidon::columns::{ -// get_poseidon_chunk_col_name_map, NUM_POSEIDON_CHUNK_COLS, -// }; -// use crate::builtins::poseidon::poseidon_chunk_stark::PoseidonChunkStark; -// use crate::generation::poseidon_chunk::generate_poseidon_chunk_trace; -// use crate::stark::stark::Stark; -// use crate::{ -// stark::{constraint_consumer::ConstraintConsumer, vars::StarkEvaluationVars}, -// test_utils::test_stark_with_asm_path, -// }; -// use plonky2::{ -// field::goldilocks_field::GoldilocksField, -// plonk::config::{GenericConfig, PoseidonGoldilocksConfig}, -// }; -// -// #[test] -// fn test_poseidon_chunk() { -// let call_data = vec![ -// GoldilocksField::ZERO, -// GoldilocksField::from_canonical_u64(1239976900), -// ]; -// let file_name = "poseidon_hash.json".to_string(); -// test_poseidon_chunk_with_asm_file_name(file_name, Some(call_data)); -// } -// -// #[allow(unused)] -// fn test_poseidon_chunk_with_asm_file_name( -// file_name: String, -// call_data: Option>, -// ) { -// let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); -// path.push("../assembler/test_data/asm/"); -// path.push(file_name); -// let program_path = path.display().to_string(); -// -// const D: usize = 2; -// type C = PoseidonGoldilocksConfig; -// type F = >::F; -// type S = PoseidonChunkStark; -// let stark = S::default(); -// -// let get_trace_rows = |trace: Trace| trace.builtin_poseidon_chunk; -// let generate_trace = |rows: &[PoseidonChunkRow]| generate_poseidon_chunk_trace(rows); -// let eval_packed_generic = -// |vars: StarkEvaluationVars< -// GoldilocksField, -// GoldilocksField, -// NUM_POSEIDON_CHUNK_COLS, -// >, -// constraint_consumer: &mut ConstraintConsumer| { -// stark.eval_packed_generic(vars, constraint_consumer); -// }; -// let error_hook = |i: usize, -// vars: StarkEvaluationVars< -// GoldilocksField, -// GoldilocksField, -// NUM_POSEIDON_CHUNK_COLS, -// >| { -// println!("constraint error in line {}", i); -// let m = get_poseidon_chunk_col_name_map(); -// println!("{:>32}\t{:>22}\t{:>22}", "name", "lv", "nv"); -// for col in m.keys() { -// let name = m.get(col).unwrap(); -// let lv = vars.local_values[*col].0; -// let nv = vars.next_values[*col].0; -// println!("{:>32}\t{:>22}\t{:>22}", name, lv, nv); -// } -// }; -// test_stark_with_asm_path( -// program_path.to_string(), -// get_trace_rows, -// generate_trace, -// eval_packed_generic, -// Some(error_hook), -// call_data, -// None, -// ); -// } -// } +mod test { + use core::trace::trace::{PoseidonChunkRow, Trace}; + use core::types::Field; + use std::path::PathBuf; + + use crate::builtins::poseidon::columns::{ + get_poseidon_chunk_col_name_map, NUM_POSEIDON_CHUNK_COLS, + }; + use crate::builtins::poseidon::poseidon_chunk_stark::PoseidonChunkStark; + use crate::generation::poseidon_chunk::generate_poseidon_chunk_trace; + use crate::stark::stark::Stark; + use crate::{ + stark::{constraint_consumer::ConstraintConsumer, vars::StarkEvaluationVars}, + test_utils::test_stark_with_asm_path, + }; + use plonky2::{ + field::goldilocks_field::GoldilocksField, + plonk::config::{GenericConfig, PoseidonGoldilocksConfig}, + }; + + #[test] + fn test_poseidon_chunk() { + let call_data = vec![ + GoldilocksField::ZERO, + GoldilocksField::from_canonical_u64(1239976900), + ]; + let file_name = "poseidon_hash.json".to_string(); + test_poseidon_chunk_with_asm_file_name(file_name, Some(call_data)); + } + + #[allow(unused)] + fn test_poseidon_chunk_with_asm_file_name( + file_name: String, + call_data: Option>, + ) { + let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + path.push("../assembler/test_data/asm/"); + path.push(file_name); + let program_path = path.display().to_string(); + + const D: usize = 2; + type C = PoseidonGoldilocksConfig; + type F = >::F; + type S = PoseidonChunkStark; + let stark = S::default(); + + let get_trace_rows = |trace: Trace| trace.builtin_poseidon_chunk; + let generate_trace = |rows: &Vec| generate_poseidon_chunk_trace(rows); + let eval_packed_generic = + |vars: StarkEvaluationVars< + GoldilocksField, + GoldilocksField, + NUM_POSEIDON_CHUNK_COLS, + >, + constraint_consumer: &mut ConstraintConsumer| { + stark.eval_packed_generic(vars, constraint_consumer); + }; + let error_hook = |i: usize, + vars: StarkEvaluationVars< + GoldilocksField, + GoldilocksField, + NUM_POSEIDON_CHUNK_COLS, + >| { + println!("constraint error in line {}", i); + let m = get_poseidon_chunk_col_name_map(); + println!("{:>32}\t{:>22}\t{:>22}", "name", "lv", "nv"); + for col in m.keys() { + let name = m.get(col).unwrap(); + let lv = vars.local_values[*col].0; + let nv = vars.next_values[*col].0; + println!("{:>32}\t{:>22}\t{:>22}", name, lv, nv); + } + }; + test_stark_with_asm_path( + program_path.to_string(), + get_trace_rows, + generate_trace, + eval_packed_generic, + Some(error_hook), + call_data, + None, + ); + } +} diff --git a/circuits/src/builtins/poseidon/poseidon_stark.rs b/circuits/src/builtins/poseidon/poseidon_stark.rs index a3a8fc43..e475f09f 100644 --- a/circuits/src/builtins/poseidon/poseidon_stark.rs +++ b/circuits/src/builtins/poseidon/poseidon_stark.rs @@ -181,92 +181,92 @@ pub fn ctl_filter_with_storage() -> Column { Column::sum([FILTER_LOOKED_STORAGE_LEAF, FILTER_LOOKED_STORAGE_BRANCH]) } -// mod test { -// use core::trace::trace::{PoseidonRow, Trace}; -// use core::types::Field; -// use std::path::PathBuf; -// -// use crate::stark::stark::Stark; -// use crate::{ -// builtins::poseidon::{ -// columns::{get_poseidon_col_name_map, NUM_POSEIDON_COLS}, -// poseidon_stark::PoseidonStark, -// }, -// generation::poseidon::generate_poseidon_trace, -// stark::{constraint_consumer::ConstraintConsumer, vars::StarkEvaluationVars}, -// test_utils::test_stark_with_asm_path, -// }; -// use plonky2::{ -// field::goldilocks_field::GoldilocksField, -// plonk::config::{GenericConfig, PoseidonGoldilocksConfig}, -// }; -// -// #[test] -// fn test_poseidon() { -// let call_data = vec![ -// GoldilocksField::ZERO, -// GoldilocksField::from_canonical_u64(1239976900), -// ]; -// let file_name = "poseidon_hash.json".to_string(); -// test_poseidon_with_asm_file_name(file_name, Some(call_data)); -// } -// -// #[test] -// fn test_storage() { -// let call_data = vec![ -// GoldilocksField::from_canonical_u64(0), -// GoldilocksField::from_canonical_u64(2364819430), -// ]; -// test_poseidon_with_asm_file_name("storage_u32.json".to_string(), Some(call_data)); -// } -// -// #[allow(unused)] -// fn test_poseidon_with_asm_file_name( -// file_name: String, -// call_data: Option>, -// ) { -// let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); -// path.push("../assembler/test_data/asm/"); -// path.push(file_name); -// let program_path = path.display().to_string(); -// -// const D: usize = 2; -// type C = PoseidonGoldilocksConfig; -// type F = >::F; -// type S = PoseidonStark; -// let stark = S::default(); -// -// let get_trace_rows = |trace: Trace| trace.builtin_poseidon; -// let generate_trace = |rows: &[PoseidonRow]| generate_poseidon_trace(rows); -// let eval_packed_generic = -// |vars: StarkEvaluationVars, -// constraint_consumer: &mut ConstraintConsumer| { -// stark.eval_packed_generic(vars, constraint_consumer); -// }; -// let error_hook = |i: usize, -// vars: StarkEvaluationVars< -// GoldilocksField, -// GoldilocksField, -// NUM_POSEIDON_COLS, -// >| { -// println!("constraint error in line {}", i); -// let m = get_poseidon_col_name_map(); -// println!("{:>32}\t{:>22}\t{:>22}", "name", "lv", "nv"); -// for col in m.keys() { -// let name = m.get(col).unwrap(); -// let lv = vars.local_values[*col].0; -// let nv = vars.next_values[*col].0; -// println!("{:>32}\t{:>22}\t{:>22}", name, lv, nv); -// } -// }; -// test_stark_with_asm_path( -// program_path.to_string(), -// get_trace_rows, -// generate_trace, -// eval_packed_generic, -// Some(error_hook), -// call_data, -// None, -// ); -// } -// } +mod test { + use core::trace::trace::{PoseidonRow, Trace}; + use core::types::Field; + use std::path::PathBuf; + + use crate::stark::stark::Stark; + use crate::{ + builtins::poseidon::{ + columns::{get_poseidon_col_name_map, NUM_POSEIDON_COLS}, + poseidon_stark::PoseidonStark, + }, + generation::poseidon::generate_poseidon_trace, + stark::{constraint_consumer::ConstraintConsumer, vars::StarkEvaluationVars}, + test_utils::test_stark_with_asm_path, + }; + use plonky2::{ + field::goldilocks_field::GoldilocksField, + plonk::config::{GenericConfig, PoseidonGoldilocksConfig}, + }; + + #[test] + fn test_poseidon() { + let call_data = vec![ + GoldilocksField::ZERO, + GoldilocksField::from_canonical_u64(1239976900), + ]; + let file_name = "poseidon_hash.json".to_string(); + test_poseidon_with_asm_file_name(file_name, Some(call_data)); + } + + #[test] + fn test_storage() { + let call_data = vec![ + GoldilocksField::from_canonical_u64(0), + GoldilocksField::from_canonical_u64(2364819430), + ]; + test_poseidon_with_asm_file_name("storage_u32.json".to_string(), Some(call_data)); + } + + #[allow(unused)] + fn test_poseidon_with_asm_file_name( + file_name: String, + call_data: Option>, + ) { + let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + path.push("../assembler/test_data/asm/"); + path.push(file_name); + let program_path = path.display().to_string(); + + const D: usize = 2; + type C = PoseidonGoldilocksConfig; + type F = >::F; + type S = PoseidonStark; + let stark = S::default(); + + let get_trace_rows = |trace: Trace| trace.builtin_poseidon; + let generate_trace = |rows: &Vec| generate_poseidon_trace(rows); + let eval_packed_generic = + |vars: StarkEvaluationVars, + constraint_consumer: &mut ConstraintConsumer| { + stark.eval_packed_generic(vars, constraint_consumer); + }; + let error_hook = |i: usize, + vars: StarkEvaluationVars< + GoldilocksField, + GoldilocksField, + NUM_POSEIDON_COLS, + >| { + println!("constraint error in line {}", i); + let m = get_poseidon_col_name_map(); + println!("{:>32}\t{:>22}\t{:>22}", "name", "lv", "nv"); + for col in m.keys() { + let name = m.get(col).unwrap(); + let lv = vars.local_values[*col].0; + let nv = vars.next_values[*col].0; + println!("{:>32}\t{:>22}\t{:>22}", name, lv, nv); + } + }; + test_stark_with_asm_path( + program_path.to_string(), + get_trace_rows, + generate_trace, + eval_packed_generic, + Some(error_hook), + call_data, + None, + ); + } +} diff --git a/circuits/src/builtins/sccall/sccall_stark.rs b/circuits/src/builtins/sccall/sccall_stark.rs index 2ac232d5..cf67cf37 100644 --- a/circuits/src/builtins/sccall/sccall_stark.rs +++ b/circuits/src/builtins/sccall/sccall_stark.rs @@ -94,79 +94,79 @@ impl, const D: usize> Stark for SCCallStark>::F; -// type S = SCCallStark; -// let stark = S::default(); -// -// let get_trace_rows = |trace: Trace| trace.sc_call; -// let generate_trace = |rows: &[SCCallRow]| generate_sccall_trace(rows); -// let eval_packed_generic = -// |vars: StarkEvaluationVars, -// constraint_consumer: &mut ConstraintConsumer| { -// stark.eval_packed_generic(vars, constraint_consumer); -// }; -// let error_hook = |i: usize, -// vars: StarkEvaluationVars< -// GoldilocksField, -// GoldilocksField, -// NUM_COL_SCCALL, -// >| { -// println!("constraint error in line {}", i); -// let m = get_sccall_col_name_map(); -// println!("{:>32}\t{:>22}\t{:>22}", "name", "lv", "nv"); -// for col in m.keys() { -// let name = m.get(col).unwrap(); -// let lv = vars.local_values[*col].0; -// let nv = vars.next_values[*col].0; -// println!("{:>32}\t{:>22}\t{:>22}", name, lv, nv); -// } -// }; -// test_stark_with_asm_path( -// program_path.to_string(), -// get_trace_rows, -// generate_trace, -// eval_packed_generic, -// Some(error_hook), -// None, -// None, -// ); -// } -// } +#[cfg(test)] +mod tests { + use crate::{ + builtins::sccall::{ + columns::{get_sccall_col_name_map, NUM_COL_SCCALL}, + sccall_stark::SCCallStark, + }, + generation::sccall::generate_sccall_trace, + stark::stark::Stark, + }; + use core::{ + trace::trace::{SCCallRow, Trace}, + types::GoldilocksField, + }; + use std::path::PathBuf; + + use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig}; + + use crate::{ + stark::{constraint_consumer::ConstraintConsumer, vars::StarkEvaluationVars}, + test_utils::test_stark_with_asm_path, + }; + + #[test] + fn test_sccall_with_program() { + let program_path = "sc_input.json"; + test_sccall_with_asm_file_name(program_path.to_string()); + } + + #[allow(unused)] + fn test_sccall_with_asm_file_name(file_name: String) { + let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + path.push("../assembler/test_data/asm/"); + path.push(file_name); + let program_path = path.display().to_string(); + + const D: usize = 2; + type C = PoseidonGoldilocksConfig; + type F = >::F; + type S = SCCallStark; + let stark = S::default(); + + let get_trace_rows = |trace: Trace| trace.sc_call; + let generate_trace = |rows: &Vec| generate_sccall_trace(rows); + let eval_packed_generic = + |vars: StarkEvaluationVars, + constraint_consumer: &mut ConstraintConsumer| { + stark.eval_packed_generic(vars, constraint_consumer); + }; + let error_hook = |i: usize, + vars: StarkEvaluationVars< + GoldilocksField, + GoldilocksField, + NUM_COL_SCCALL, + >| { + println!("constraint error in line {}", i); + let m = get_sccall_col_name_map(); + println!("{:>32}\t{:>22}\t{:>22}", "name", "lv", "nv"); + for col in m.keys() { + let name = m.get(col).unwrap(); + let lv = vars.local_values[*col].0; + let nv = vars.next_values[*col].0; + println!("{:>32}\t{:>22}\t{:>22}", name, lv, nv); + } + }; + test_stark_with_asm_path( + program_path.to_string(), + get_trace_rows, + generate_trace, + eval_packed_generic, + Some(error_hook), + None, + None, + ); + } +} diff --git a/circuits/src/builtins/storage/storage_access_stark.rs b/circuits/src/builtins/storage/storage_access_stark.rs index 81389343..2bd5433a 100644 --- a/circuits/src/builtins/storage/storage_access_stark.rs +++ b/circuits/src/builtins/storage/storage_access_stark.rs @@ -314,79 +314,79 @@ impl, const D: usize> Stark for StorageAccess } } -// #[cfg(test)] -// mod tests { -// use crate::{ -// builtins::storage::{ -// columns::{get_storage_access_col_name_map, NUM_COL_ST}, -// storage_access_stark::StorageAccessStark, -// }, -// generation::storage::generate_storage_access_trace, -// stark::stark::Stark, -// }; -// use core::{ -// trace::trace::{StorageHashRow, Trace}, -// types::{Field, GoldilocksField}, -// }; -// use std::path::PathBuf; -// -// use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig}; -// -// use crate::{ -// stark::{constraint_consumer::ConstraintConsumer, vars::StarkEvaluationVars}, -// test_utils::test_stark_with_asm_path, -// }; -// -// #[test] -// fn test_storage_with_program() { -// let call_data = vec![ -// GoldilocksField::from_canonical_u64(0), -// GoldilocksField::from_canonical_u64(2364819430), -// ]; -// let program_path = "storage_u32.json"; -// test_storage_with_asm_file_name(program_path.to_string(), Some(call_data)); -// } -// -// #[allow(unused)] -// fn test_storage_with_asm_file_name(file_name: String, call_data: Option>) { -// let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); -// path.push("../assembler/test_data/asm/"); -// path.push(file_name); -// let program_path = path.display().to_string(); -// -// const D: usize = 2; -// type C = PoseidonGoldilocksConfig; -// type F = >::F; -// type S = StorageAccessStark; -// let stark = S::default(); -// -// let get_trace_rows = |trace: Trace| trace.builtin_storage_hash; -// let generate_trace = |rows: &[StorageHashRow]| generate_storage_access_trace(rows); -// let eval_packed_generic = -// |vars: StarkEvaluationVars, -// constraint_consumer: &mut ConstraintConsumer| { -// stark.eval_packed_generic(vars, constraint_consumer); -// }; -// let error_hook = -// |i: usize, vars: StarkEvaluationVars| { -// println!("constraint error in line {}", i); -// let m = get_storage_access_col_name_map(); -// println!("{:>32}\t{:>22}\t{:>22}", "name", "lv", "nv"); -// for col in m.keys() { -// let name = m.get(col).unwrap(); -// let lv = vars.local_values[*col].0; -// let nv = vars.next_values[*col].0; -// println!("{:>32}\t{:>22}\t{:>22}", name, lv, nv); -// } -// }; -// test_stark_with_asm_path( -// program_path.to_string(), -// get_trace_rows, -// generate_trace, -// eval_packed_generic, -// Some(error_hook), -// call_data, -// None, -// ); -// } -// } +#[cfg(test)] +mod tests { + use crate::{ + builtins::storage::{ + columns::{get_storage_access_col_name_map, NUM_COL_ST}, + storage_access_stark::StorageAccessStark, + }, + generation::storage::generate_storage_access_trace, + stark::stark::Stark, + }; + use core::{ + trace::trace::{StorageHashRow, Trace}, + types::{Field, GoldilocksField}, + }; + use std::path::PathBuf; + + use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig}; + + use crate::{ + stark::{constraint_consumer::ConstraintConsumer, vars::StarkEvaluationVars}, + test_utils::test_stark_with_asm_path, + }; + + #[test] + fn test_storage_with_program() { + let call_data = vec![ + GoldilocksField::from_canonical_u64(0), + GoldilocksField::from_canonical_u64(2364819430), + ]; + let program_path = "storage_u32.json"; + test_storage_with_asm_file_name(program_path.to_string(), Some(call_data)); + } + + #[allow(unused)] + fn test_storage_with_asm_file_name(file_name: String, call_data: Option>) { + let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + path.push("../assembler/test_data/asm/"); + path.push(file_name); + let program_path = path.display().to_string(); + + const D: usize = 2; + type C = PoseidonGoldilocksConfig; + type F = >::F; + type S = StorageAccessStark; + let stark = S::default(); + + let get_trace_rows = |trace: Trace| trace.builtin_storage_hash; + let generate_trace = |rows: &Vec| generate_storage_access_trace(rows); + let eval_packed_generic = + |vars: StarkEvaluationVars, + constraint_consumer: &mut ConstraintConsumer| { + stark.eval_packed_generic(vars, constraint_consumer); + }; + let error_hook = + |i: usize, vars: StarkEvaluationVars| { + println!("constraint error in line {}", i); + let m = get_storage_access_col_name_map(); + println!("{:>32}\t{:>22}\t{:>22}", "name", "lv", "nv"); + for col in m.keys() { + let name = m.get(col).unwrap(); + let lv = vars.local_values[*col].0; + let nv = vars.next_values[*col].0; + println!("{:>32}\t{:>22}\t{:>22}", name, lv, nv); + } + }; + test_stark_with_asm_path( + program_path.to_string(), + get_trace_rows, + generate_trace, + eval_packed_generic, + Some(error_hook), + call_data, + None, + ); + } +} diff --git a/circuits/src/builtins/tape/tape_stark.rs b/circuits/src/builtins/tape/tape_stark.rs index d5b0e124..477ea5ea 100644 --- a/circuits/src/builtins/tape/tape_stark.rs +++ b/circuits/src/builtins/tape/tape_stark.rs @@ -143,87 +143,87 @@ impl, const D: usize> Stark for TapeStark>) { -// let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); -// path.push("../assembler/test_data/asm/"); -// path.push(file_name); -// let program_path = path.display().to_string(); -// -// const D: usize = 2; -// type C = PoseidonGoldilocksConfig; -// type F = >::F; -// type S = TapeStark; -// let stark = S::default(); -// -// let get_trace_rows = |trace: Trace| trace.tape; -// let generate_trace = |rows: &[TapeRow]| generate_tape_trace(rows); -// let eval_packed_generic = -// |vars: StarkEvaluationVars, -// constraint_consumer: &mut ConstraintConsumer| { -// stark.eval_packed_generic(vars, constraint_consumer); -// }; -// let error_hook = |i: usize, -// vars: StarkEvaluationVars< -// GoldilocksField, -// GoldilocksField, -// NUM_COL_TAPE, -// >| { -// println!("constraint error in line {}", i); -// let m = get_tape_col_name_map(); -// println!("{:>32}\t{:>22}\t{:>22}", "name", "lv", "nv"); -// for col in m.keys() { -// let name = m.get(col).unwrap(); -// let lv = vars.local_values[*col].0; -// let nv = vars.next_values[*col].0; -// println!("{:>32}\t{:>22}\t{:>22}", name, lv, nv); -// } -// }; -// test_stark_with_asm_path( -// program_path.to_string(), -// get_trace_rows, -// generate_trace, -// eval_packed_generic, -// Some(error_hook), -// call_data, -// None, -// ); -// } -// } +#[cfg(test)] +mod tests { + use crate::stark::stark::Stark; + use core::{ + trace::trace::{TapeRow, Trace}, + types::{Field, GoldilocksField}, + }; + use std::path::PathBuf; + + use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig}; + + use crate::{ + builtins::tape::{ + columns::{get_tape_col_name_map, NUM_COL_TAPE}, + tape_stark::TapeStark, + }, + generation::tape::generate_tape_trace, + stark::{constraint_consumer::ConstraintConsumer, vars::StarkEvaluationVars}, + test_utils::test_stark_with_asm_path, + }; + + #[test] + fn test_tape_with_program() { + let program_path = "tape.json"; + test_tape_with_asm_file_name(program_path.to_string(), None); + } + + #[test] + fn test_tape_poseidon_with_program() { + let call_data = vec![ + GoldilocksField::ZERO, + GoldilocksField::from_canonical_u64(1239976900), + ]; + let program_path = "poseidon_hash.json"; + test_tape_with_asm_file_name(program_path.to_string(), Some(call_data)); + } + + #[allow(unused)] + fn test_tape_with_asm_file_name(file_name: String, call_data: Option>) { + let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + path.push("../assembler/test_data/asm/"); + path.push(file_name); + let program_path = path.display().to_string(); + + const D: usize = 2; + type C = PoseidonGoldilocksConfig; + type F = >::F; + type S = TapeStark; + let stark = S::default(); + + let get_trace_rows = |trace: Trace| trace.tape; + let generate_trace = |rows: &Vec| generate_tape_trace(rows); + let eval_packed_generic = + |vars: StarkEvaluationVars, + constraint_consumer: &mut ConstraintConsumer| { + stark.eval_packed_generic(vars, constraint_consumer); + }; + let error_hook = |i: usize, + vars: StarkEvaluationVars< + GoldilocksField, + GoldilocksField, + NUM_COL_TAPE, + >| { + println!("constraint error in line {}", i); + let m = get_tape_col_name_map(); + println!("{:>32}\t{:>22}\t{:>22}", "name", "lv", "nv"); + for col in m.keys() { + let name = m.get(col).unwrap(); + let lv = vars.local_values[*col].0; + let nv = vars.next_values[*col].0; + println!("{:>32}\t{:>22}\t{:>22}", name, lv, nv); + } + }; + test_stark_with_asm_path( + program_path.to_string(), + get_trace_rows, + generate_trace, + eval_packed_generic, + Some(error_hook), + call_data, + None, + ); + } +} diff --git a/circuits/src/generation/mod.rs b/circuits/src/generation/mod.rs index 3f3f2341..ae11b0a9 100644 --- a/circuits/src/generation/mod.rs +++ b/circuits/src/generation/mod.rs @@ -81,7 +81,7 @@ pub fn generate_traces, const D: usize>( ) -> ([Vec>; NUM_TABLES], PublicValues) { let (cpu_tx, cpu_rx) = channel(); let exec = std::mem::replace(&mut program.trace.exec, Vec::new()); - let handle = thread::spawn(move || { + thread::spawn(move || { let cpu_rows = generate_cpu_trace::(&exec); cpu_tx.send(trace_to_poly_values(cpu_rows)); }); diff --git a/circuits/src/memory/memory_stark.rs b/circuits/src/memory/memory_stark.rs index 87b26f07..ed3baaa8 100644 --- a/circuits/src/memory/memory_stark.rs +++ b/circuits/src/memory/memory_stark.rs @@ -315,108 +315,108 @@ impl, const D: usize> Stark for MemoryStark>) { -// let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); -// path.push("../assembler/test_data/asm/"); -// path.push(file_name); -// let program_path = path.display().to_string(); -// -// const D: usize = 2; -// type C = PoseidonGoldilocksConfig; -// type F = >::F; -// type S = MemoryStark; -// let stark = S::default(); -// -// let get_trace_rows = |trace: Trace| trace.memory; -// let generate_trace = |rows: &[MemoryTraceCell]| generate_memory_trace(rows); -// let eval_packed_generic = -// |vars: StarkEvaluationVars, -// constraint_consumer: &mut ConstraintConsumer| { -// stark.eval_packed_generic(vars, constraint_consumer); -// }; -// let error_hook = |i: usize, -// vars: StarkEvaluationVars< -// GoldilocksField, -// GoldilocksField, -// NUM_MEM_COLS, -// >| { -// println!("constraint error in line {}", i); -// let m = get_memory_col_name_map(); -// println!("{:>32}\t{:>22}\t{:>22}", "name", "lv", "nv"); -// for col in m.keys() { -// let name = m.get(col).unwrap(); -// let lv = vars.local_values[*col].0; -// let nv = vars.next_values[*col].0; -// println!("{:>32}\t{:>22}\t{:>22}", name, lv, nv); -// } -// }; -// test_stark_with_asm_path( -// program_path.to_string(), -// get_trace_rows, -// generate_trace, -// eval_packed_generic, -// Some(error_hook), -// call_data, -// None, -// ); -// } -// } +#[cfg(test)] +mod tests { + use crate::generation::memory::generate_memory_trace; + use crate::memory::columns::{get_memory_col_name_map, NUM_MEM_COLS}; + use crate::memory::memory_stark::MemoryStark; + use crate::stark::constraint_consumer::ConstraintConsumer; + use crate::stark::stark::Stark; + use crate::stark::vars::StarkEvaluationVars; + use crate::test_utils::test_stark_with_asm_path; + use core::trace::trace::{MemoryTraceCell, Trace}; + use core::types::Field; + + use plonky2::{ + field::goldilocks_field::GoldilocksField, + plonk::config::{GenericConfig, PoseidonGoldilocksConfig}, + }; + use std::path::PathBuf; + + #[test] + fn test_memory_with_program() { + let program_path = "memory.json"; + test_memory_with_asm_file_name(program_path.to_string(), None); + } + + #[test] + fn test_memory_fib_loop() { + let program_path = "fibo_loop.json"; + test_memory_with_asm_file_name(program_path.to_string(), None); + } + + // #[test] + // fn test_memory_sqrt() { + // let program_path = "sqrt.json"; + // test_memory_with_asm_file_name(program_path.to_string(), None); + // } + + #[test] + fn test_memory_malloc() { + let program_path = "malloc.json"; + test_memory_with_asm_file_name(program_path.to_string(), None); + } + + // #[test] + // fn test_memory_vote() { + // let program_path = "vote.json"; + // test_memory_with_asm_file_name(program_path.to_string(), None); + // } + + #[test] + fn test_memory_poseidon() { + let call_data = vec![ + GoldilocksField::ZERO, + GoldilocksField::from_canonical_u64(1239976900), + ]; + let program_path = "poseidon_hash.json"; + test_memory_with_asm_file_name(program_path.to_string(), Some(call_data)); + } + + #[allow(unused)] + fn test_memory_with_asm_file_name(file_name: String, call_data: Option>) { + let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + path.push("../assembler/test_data/asm/"); + path.push(file_name); + let program_path = path.display().to_string(); + + const D: usize = 2; + type C = PoseidonGoldilocksConfig; + type F = >::F; + type S = MemoryStark; + let stark = S::default(); + + let get_trace_rows = |trace: Trace| trace.memory; + let generate_trace = |rows: &Vec| generate_memory_trace(rows); + let eval_packed_generic = + |vars: StarkEvaluationVars, + constraint_consumer: &mut ConstraintConsumer| { + stark.eval_packed_generic(vars, constraint_consumer); + }; + let error_hook = |i: usize, + vars: StarkEvaluationVars< + GoldilocksField, + GoldilocksField, + NUM_MEM_COLS, + >| { + println!("constraint error in line {}", i); + let m = get_memory_col_name_map(); + println!("{:>32}\t{:>22}\t{:>22}", "name", "lv", "nv"); + for col in m.keys() { + let name = m.get(col).unwrap(); + let lv = vars.local_values[*col].0; + let nv = vars.next_values[*col].0; + println!("{:>32}\t{:>22}\t{:>22}", name, lv, nv); + } + }; + test_stark_with_asm_path( + program_path.to_string(), + get_trace_rows, + generate_trace, + eval_packed_generic, + Some(error_hook), + call_data, + None, + ); + } +} diff --git a/circuits/src/program/prog_chunk_stark.rs b/circuits/src/program/prog_chunk_stark.rs index b42d16a3..a2444277 100644 --- a/circuits/src/program/prog_chunk_stark.rs +++ b/circuits/src/program/prog_chunk_stark.rs @@ -132,98 +132,98 @@ impl, const D: usize> Stark for ProgChunkStar } } -// #[cfg(test)] -// mod tests { -// use crate::{ -// generation::prog::generate_prog_chunk_trace, -// program::{ -// columns::{get_prog_chunk_col_name_map, NUM_PROG_CHUNK_COLS}, -// prog_chunk_stark::ProgChunkStark, -// }, -// stark::stark::Stark, -// }; -// use core::{ -// trace::trace::Trace, -// types::{Field, GoldilocksField}, -// vm::vm_state::Address, -// }; -// use std::{path::PathBuf, vec}; -// -// use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig}; -// -// use crate::{ -// stark::{constraint_consumer::ConstraintConsumer, vars::StarkEvaluationVars}, -// test_utils::test_stark_with_asm_path, -// }; -// -// #[test] -// fn test_prog_chunk_storage() { -// let call_data = vec![ -// GoldilocksField::from_canonical_u64(0), -// GoldilocksField::from_canonical_u64(2364819430), -// ]; -// test_prog_chunk_with_asm_file_name("storage_u32.json".to_string(), Some(call_data)); -// } -// -// #[allow(unused)] -// fn test_prog_chunk_with_asm_file_name( -// file_name: String, -// call_data: Option>, -// ) { -// let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); -// path.push("../assembler/test_data/asm/"); -// path.push(file_name); -// let program_path = path.display().to_string(); -// -// const D: usize = 2; -// type C = PoseidonGoldilocksConfig; -// type F = >::F; -// type S = ProgChunkStark; -// let stark = S::default(); -// -// let get_trace_rows = |trace: Trace| trace.raw_binary_instructions; -// let generate_trace = |rows: &[String]| { -// let addr = Address::default(); -// let insts = rows -// .iter() -// .map(|s| { -// let instruction_without_prefix = s.trim_start_matches("0x"); -// let inst_u64 = u64::from_str_radix(instruction_without_prefix, 16).unwrap(); -// GoldilocksField::from_canonical_u64(inst_u64) -// }) -// .collect::>(); -// generate_prog_chunk_trace(vec![(addr, insts)]) -// }; -// let eval_packed_generic = -// |vars: StarkEvaluationVars, -// constraint_consumer: &mut ConstraintConsumer| { -// stark.eval_packed_generic(vars, constraint_consumer); -// }; -// let error_hook = |i: usize, -// vars: StarkEvaluationVars< -// GoldilocksField, -// GoldilocksField, -// NUM_PROG_CHUNK_COLS, -// >| { -// println!("constraint error in line {}", i); -// let m = get_prog_chunk_col_name_map(); -// println!("{:>32}\t{:>22}\t{:>22}", "name", "lv", "nv"); -// for col in m.keys() { -// let name = m.get(col).unwrap(); -// let lv = vars.local_values[*col].0; -// let nv = vars.next_values[*col].0; -// println!("{:>32}\t{:>22}\t{:>22}", name, lv, nv); -// } -// }; -// -// test_stark_with_asm_path( -// program_path.to_string(), -// get_trace_rows, -// generate_trace, -// eval_packed_generic, -// Some(error_hook), -// call_data, -// None, -// ); -// } -// } +#[cfg(test)] +mod tests { + use crate::{ + generation::prog::generate_prog_chunk_trace, + program::{ + columns::{get_prog_chunk_col_name_map, NUM_PROG_CHUNK_COLS}, + prog_chunk_stark::ProgChunkStark, + }, + stark::stark::Stark, + }; + use core::{ + trace::trace::Trace, + types::{Field, GoldilocksField}, + vm::vm_state::Address, + }; + use std::{path::PathBuf, vec}; + + use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig}; + + use crate::{ + stark::{constraint_consumer::ConstraintConsumer, vars::StarkEvaluationVars}, + test_utils::test_stark_with_asm_path, + }; + + #[test] + fn test_prog_chunk_storage() { + let call_data = vec![ + GoldilocksField::from_canonical_u64(0), + GoldilocksField::from_canonical_u64(2364819430), + ]; + test_prog_chunk_with_asm_file_name("storage_u32.json".to_string(), Some(call_data)); + } + + #[allow(unused)] + fn test_prog_chunk_with_asm_file_name( + file_name: String, + call_data: Option>, + ) { + let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + path.push("../assembler/test_data/asm/"); + path.push(file_name); + let program_path = path.display().to_string(); + + const D: usize = 2; + type C = PoseidonGoldilocksConfig; + type F = >::F; + type S = ProgChunkStark; + let stark = S::default(); + + let get_trace_rows = |trace: Trace| trace.raw_binary_instructions; + let generate_trace = |rows: &Vec| { + let addr = Address::default(); + let insts = rows + .iter() + .map(|s| { + let instruction_without_prefix = s.trim_start_matches("0x"); + let inst_u64 = u64::from_str_radix(instruction_without_prefix, 16).unwrap(); + GoldilocksField::from_canonical_u64(inst_u64) + }) + .collect::>(); + generate_prog_chunk_trace(vec![(addr, insts)]) + }; + let eval_packed_generic = + |vars: StarkEvaluationVars, + constraint_consumer: &mut ConstraintConsumer| { + stark.eval_packed_generic(vars, constraint_consumer); + }; + let error_hook = |i: usize, + vars: StarkEvaluationVars< + GoldilocksField, + GoldilocksField, + NUM_PROG_CHUNK_COLS, + >| { + println!("constraint error in line {}", i); + let m = get_prog_chunk_col_name_map(); + println!("{:>32}\t{:>22}\t{:>22}", "name", "lv", "nv"); + for col in m.keys() { + let name = m.get(col).unwrap(); + let lv = vars.local_values[*col].0; + let nv = vars.next_values[*col].0; + println!("{:>32}\t{:>22}\t{:>22}", name, lv, nv); + } + }; + + test_stark_with_asm_path( + program_path.to_string(), + get_trace_rows, + generate_trace, + eval_packed_generic, + Some(error_hook), + call_data, + None, + ); + } +} diff --git a/client/src/main.rs b/client/src/main.rs index eecc1ba4..db4b4765 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -195,7 +195,7 @@ fn main() { let mut ola_stark = OlaStark::::default(); let config = StarkConfig::standard_fast_config(); let proof = prove::( - &program, + program, &mut ola_stark, inputs, &config,