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

simplify BaseField for 0 and 1 #51

Merged
merged 2 commits into from
Nov 13, 2024
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
10 changes: 5 additions & 5 deletions crates/brainfuck_prover/src/components/instruction/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl InstructionTable {
#[cfg(test)]
mod tests {
use super::*;
use num_traits::Zero;
use num_traits::{One, Zero};

#[test]
fn test_instruction_table_new() {
Expand Down Expand Up @@ -139,12 +139,12 @@ mod tests {
// Create a vector of rows to add to the table
let rows = vec![
InstructionTableRow {
ip: BaseField::from(0),
ip: BaseField::zero(),
ci: BaseField::from(43),
ni: BaseField::from(91),
},
InstructionTableRow {
ip: BaseField::from(1),
ip: BaseField::one(),
ci: BaseField::from(91),
ni: BaseField::from(9),
},
Expand All @@ -165,7 +165,7 @@ mod tests {
let mut instruction_table = InstructionTable::new();
// Create a row to add to the table
let row = InstructionTableRow {
ip: BaseField::from(0),
ip: BaseField::zero(),
ci: BaseField::from(43),
ni: BaseField::from(91),
};
Expand All @@ -182,7 +182,7 @@ mod tests {
let instruction_table = InstructionTable::new();
// Create a row to search for in the table
let row = InstructionTableRow {
ip: BaseField::from(0),
ip: BaseField::zero(),
ci: BaseField::from(43),
ni: BaseField::from(91),
};
Expand Down
6 changes: 3 additions & 3 deletions crates/brainfuck_prover/src/components/memory/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ mod tests {
let mut memory_table = MemoryTable::new();
// Create a row to add to the table
let row = MemoryTableRow {
clk: BaseField::from(0),
clk: BaseField::zero(),
mp: BaseField::from(43),
mv: BaseField::from(91),
d: BaseField::zero(),
Expand All @@ -296,7 +296,7 @@ mod tests {
let memory_table = MemoryTable::new();
// Create a row to search for in the table
let row = MemoryTableRow {
clk: BaseField::from(0),
clk: BaseField::zero(),
mp: BaseField::from(43),
mv: BaseField::from(91),
d: BaseField::zero(),
Expand Down Expand Up @@ -337,7 +337,7 @@ mod tests {
expected_memory_table.add_rows(vec![
row1,
row2,
MemoryTableRow::new_dummy(BaseField::from(1), BaseField::one(), BaseField::zero()),
MemoryTableRow::new_dummy(BaseField::one(), BaseField::one(), BaseField::zero()),
MemoryTableRow::new_dummy(BaseField::from(2), BaseField::one(), BaseField::zero()),
MemoryTableRow::new_dummy(BaseField::from(3), BaseField::one(), BaseField::zero()),
MemoryTableRow::new_dummy(BaseField::from(4), BaseField::one(), BaseField::zero()),
Expand Down
3 changes: 2 additions & 1 deletion crates/brainfuck_vm/src/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Adapted from rkdud007 brainfuck-zkvm https://github.com/rkdud007/brainfuck-zkvm/blob/main/src/compiler.rs

use num_traits::Zero;
use stwo_prover::core::fields::m31::BaseField;

#[derive(Debug, Clone, Default)]
Expand All @@ -20,7 +21,7 @@ impl Compiler {

match *symbol {
'[' => {
self.instructions.push(BaseField::from(0));
self.instructions.push(BaseField::zero());
loop_stack.push(self.instructions.len() - 1);
}
']' => {
Expand Down
14 changes: 7 additions & 7 deletions crates/brainfuck_vm/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ mod tests {
let (mut machine, _) = create_test_machine(&code, &[]);
machine.execute()?;

assert_eq!(machine.state.registers.mp, BaseField::from(1));
assert_eq!(machine.state.registers.mp, BaseField::one());
Ok(())
}

Expand All @@ -312,8 +312,8 @@ mod tests {
let (mut machine, _) = create_test_machine(&code, &[]);
machine.execute()?;

assert_eq!(machine.state.ram[0], BaseField::from(1));
assert_eq!(machine.state.registers.mv, BaseField::from(1));
assert_eq!(machine.state.ram[0], BaseField::one());
assert_eq!(machine.state.registers.mv, BaseField::one());
Ok(())
}

Expand Down Expand Up @@ -415,8 +415,8 @@ mod tests {
let final_state = Registers {
clk: BaseField::from(2),
ip: BaseField::from(2),
ci: BaseField::from(0),
ni: BaseField::from(0),
ci: BaseField::zero(),
ni: BaseField::zero(),
mp: BaseField::zero(),
mv: BaseField::from(2),
mvi: BaseField::from(2).inverse(),
Expand Down Expand Up @@ -456,8 +456,8 @@ mod tests {
let final_state = Registers {
clk: BaseField::from(2),
ip: BaseField::from(2),
ci: BaseField::from(0),
ni: BaseField::from(0),
ci: BaseField::zero(),
ni: BaseField::zero(),
mp: BaseField::zero(),
mv: BaseField::from(2),
mvi: BaseField::from(2).inverse(),
Expand Down
4 changes: 2 additions & 2 deletions crates/brainfuck_vm/src/registers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl std::fmt::Debug for Registers {
#[cfg(test)]
mod tests {
use super::*;
use num_traits::Zero;
use num_traits::{One, Zero};

// Test default and new() implementation
#[test]
Expand Down Expand Up @@ -83,7 +83,7 @@ mod tests {
#[test]
fn test_registers_display() {
let registers = Registers {
clk: BaseField::from(1),
clk: BaseField::one(),
ip: BaseField::from(2),
ci: BaseField::from(3),
ni: BaseField::from(4),
Expand Down