Skip to content

Commit

Permalink
simplify BaseField for 0 and 1
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger committed Nov 12, 2024
1 parent 283cfaf commit 54f56ac
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
8 changes: 4 additions & 4 deletions crates/brainfuck_prover/src/components/instruction/table.rs
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion crates/brainfuck_vm/src/registers.rs
Original file line number Diff line number Diff line change
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

0 comments on commit 54f56ac

Please sign in to comment.