Skip to content

Commit

Permalink
constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
soumyathakur44 committed Dec 14, 2024
1 parent 77fec34 commit 032cb56
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 29 deletions.
2 changes: 2 additions & 0 deletions src/stark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ pub fn prove(
let mut processor_table = ProcessorTable::new(
field,
matrices[0].clone().len() as u128,
roundup_npow2(matrices[2].len() as u128),
generator,
order,
matrices[0].clone(),
);
let mut memory_table = MemoryTable::new(
field,
matrices[1].len() as u128,
roundup_npow2(matrices[2].len() as u128),
generator,
order,
matrices[1].clone(),
Expand Down
5 changes: 4 additions & 1 deletion src/tables/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ mod test_instruction {
use crate::tables::memory::MemoryTable;
use crate::tables::processor::ProcessorTable;
use crate::vm::VirtualMachine;
use crate::tables::roundup_npow2;

#[test]
fn test_padding() {
Expand Down Expand Up @@ -346,7 +347,7 @@ mod test_instruction {
let omicron = generator.clone();
let order = 1 << 32;
// let code = "++>+++++[<+>-]++++++++[<++++++>-]<.".to_string();
let code2 = ">>+.[++-]+.".to_string();
let code2 = ">>[++-]+-".to_string();
let program = vm.compile(code2);
println!("{:?}", program.clone());
let (rt, _, _) = vm.run(&program, "".to_string());
Expand All @@ -358,13 +359,15 @@ mod test_instruction {
let mut processor_table = ProcessorTable::new(
field,
processor_matrix.len() as u128,
roundup_npow2(instruction_matrix.len() as u128),
generator,
order,
processor_matrix,
);
let mut memory_table = MemoryTable::new(
field,
memory_matrix.len() as u128,
roundup_npow2(instruction_matrix.len() as u128),
generator,
order,
memory_matrix,
Expand Down
10 changes: 9 additions & 1 deletion src/tables/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ impl MemoryTable {
pub fn new(
field: Field,
length: u128,
height: u128,
generator: FieldElement,
order: u128,
matrix: Vec<Vec<FieldElement>>,
) -> Self {
let base_width = 3;
let full_width = base_width + 1;
let height = roundup_npow2(length);
let height = height;
let omicron = derive_omicron(generator, order, height);

let mut gmatrix =
Expand Down Expand Up @@ -274,6 +275,7 @@ mod test_memory_table {
use crate::tables::processor::ProcessorTable;
use crate::tables::Table;
use crate::vm::VirtualMachine;
use crate::tables::roundup_npow2;

#[test]
fn test_padding() {
Expand All @@ -289,6 +291,7 @@ mod test_memory_table {
let mut memory_table = MemoryTable::new(
field,
memory_matrix.len() as u128,
roundup_npow2(instruction_matrix.len() as u128),
generator,
order,
memory_matrix.clone(),
Expand Down Expand Up @@ -316,6 +319,7 @@ mod test_memory_table {
let mut mem = MemoryTable::new(
field,
memory_matrix.len() as u128,
roundup_npow2(instruction_matrix.len() as u128),
generator,
order,
memory_matrix,
Expand Down Expand Up @@ -424,13 +428,15 @@ mod test_memory_table {
let mut processor_table = ProcessorTable::new(
field,
processor_matrix.len() as u128,
roundup_npow2(instruction_matrix.len() as u128),
generator,
order,
processor_matrix,
);
let mut memory_table = MemoryTable::new(
field,
memory_matrix.len() as u128,
roundup_npow2(instruction_matrix.len() as u128),
generator,
order,
memory_matrix,
Expand Down Expand Up @@ -518,13 +524,15 @@ mod test_memory_table {
let mut processor_table = ProcessorTable::new(
field,
processor_matrix.len() as u128,
roundup_npow2(instruction_matrix.len() as u128),
generator,
order,
processor_matrix,
);
let mut memory_table = MemoryTable::new(
field,
memory_matrix.len() as u128,
roundup_npow2(instruction_matrix.len() as u128),
generator,
order,
memory_matrix,
Expand Down
74 changes: 47 additions & 27 deletions src/tables/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ impl ProcessorTable {
pub fn new(
field: Field,
length: u128,
height: u128,
generator: FieldElement,
order: u128,
matrix: Vec<Vec<FieldElement>>,
) -> Self {
let base_width = 7;
let full_width = base_width + 4;
let height = roundup_npow2(length);
let height = height;
let omicron = derive_omicron(generator, order, height);
let mut gmatrix =
vec![vec![FieldElement::zero(field); full_width as usize]; height as usize];
Expand Down Expand Up @@ -489,7 +490,7 @@ impl ProcessorTable {
//ci =<
// ip⋆−ip−1
// mp⋆−mp+1
let trasition_i2 = (ip_next.clone() - ip.clone() - poly_one.clone())
let trasition_i2 = (ip_next.clone() - ip.clone() - poly_one.clone())*poly_two.clone()
+ (mp_next.clone() - mp.clone() + poly_one.clone());
air.push(trasition_i2);
//ci=>
Expand All @@ -512,7 +513,7 @@ impl ProcessorTable {
// mp⋆−mp
// mv⋆−mv+1
// ci = -
let trasition_i5 = (ip_next.clone() - ip.clone() - poly_one.clone())
let trasition_i5 = (ip_next.clone() - ip.clone() - poly_one.clone())*poly_two.clone()
+ (mp_next.clone() - mp.clone())
+ (mv_next.clone() - mv.clone() + poly_one.clone());
air.push(trasition_i5);
Expand Down Expand Up @@ -677,6 +678,7 @@ mod test_processor {
use crate::tables::io::IOTable;
use crate::tables::memory::MemoryTable;
use crate::tables::processor::Indices;
use crate::tables::roundup_npow2;
use crate::vm::VirtualMachine;

#[test]
Expand All @@ -694,6 +696,7 @@ mod test_processor {
let mut processor_table = ProcessorTable::new(
field,
processor_matrix.len() as u128,
roundup_npow2(processor_matrix.len() as u128),
generator,
order,
processor_matrix,
Expand Down Expand Up @@ -731,13 +734,15 @@ mod test_processor {
let mut processor_table = ProcessorTable::new(
field,
processor_matrix.len() as u128,
roundup_npow2(instruction_matrix.len() as u128),
generator,
order,
processor_matrix,
);
let mut memory_table = MemoryTable::new(
field,
memory_matrix.len() as u128,
roundup_npow2(instruction_matrix.len() as u128),
generator,
order,
memory_matrix,
Expand Down Expand Up @@ -769,12 +774,21 @@ mod test_processor {
instruction_table.pad();
input_table.pad();
output_table.pad();

let terminal = processor_table.extend_columns(challenges.clone());
let terminal2 = memory_table.extend_column_ppa(1, challenges.clone());

println!("processor table after extending columns");
for row in processor_table.table.matrix.clone() {
println!("{:?}", row);
}
println!("memory table after extending columns");
for row in memory_table.table.matrix.clone() {
println!("{:?}", row);
}

println!("tmpa: {:?}", terminal[1]);
println!("tppa: {:?}", terminal2[0]);
let mut omicron_domain: Vec<FieldElement> = Vec::new();
for i in 0..processor_table.table.height {
omicron_domain.push(processor_table.table.omicron.pow(i));
Expand Down Expand Up @@ -819,7 +833,7 @@ mod test_processor {
// let omicron = generator.clone();
let order = 1 << 32;
// let code = "++>+++++[<+>-]++++++++[<++++++>-]<.".to_string();
let code2 = ">>[++-]<".to_string();
let code2 = ">>[++-]<+-".to_string();
let program = vm.compile(code2);
println!("{:?}", program.clone());
let (rt, _, _) = vm.run(&program, "".to_string());
Expand All @@ -831,13 +845,15 @@ mod test_processor {
let mut processor_table = ProcessorTable::new(
field,
processor_matrix.len() as u128,
roundup_npow2(instruction_matrix.len() as u128),
generator,
order,
processor_matrix,
);
let mut memory_table = MemoryTable::new(
field,
memory_matrix.len() as u128,
roundup_npow2(instruction_matrix.len() as u128),
generator,
order,
memory_matrix,
Expand Down Expand Up @@ -899,29 +915,33 @@ mod test_processor {
assert_eq!(t_all, zero);
}

let v =omicron_domain[3];

let t_air1 = air[10].evaluate(v);
assert_ne!(t_air1, zero);
for v in omicron_domain.clone(){
println!("{:?}",air[3].evaluate(v))
}
for v in omicron_domain.clone(){
println!("{:?}",air[4].evaluate(v))
}
for v in omicron_domain.clone(){
println!("{:?}",air[5].evaluate(v))
}
for v in omicron_domain.clone(){
println!("{:?}",air[6].evaluate(v))
}




//let v =omicron_domain[1];
// let t_air1 = air[10].evaluate(v);
// println!("{:?}",air[0].evaluate(v));
//assert_ne!(t_air1, zero);


for v in omicron_domain.clone(){
println!("{:?}", air[3].evaluate(v))
}
println!("this was <");
for v in omicron_domain.clone(){
println!("{:?}",air[4].evaluate(v))
}
println!("this was >");
for v in omicron_domain.clone(){
println!("{:?}",air[5].evaluate(v))
}
println!("this was +");
for v in omicron_domain.clone(){
println!("{:?}",air[6].evaluate(v))
}
println!("this was -");

assert_eq!(air[4].evaluate(omicron_domain[1]), zero);
assert_eq!(air[4].evaluate(omicron_domain[0]), zero);
assert!(air[4].evaluate(omicron_domain[2]) != zero);
assert_eq!(air[4].evaluate(omicron_domain[1]), zero);
assert_eq!(air[4].evaluate(omicron_domain[0]), zero);
assert!(air[4].evaluate(omicron_domain[2]) != zero);

}

}

0 comments on commit 032cb56

Please sign in to comment.