From c4c5019a932233266c07e5d238878bab72ff52b2 Mon Sep 17 00:00:00 2001 From: malatrax <71888134+zmalatrax@users.noreply.github.com> Date: Tue, 12 Nov 2024 17:17:43 +0100 Subject: [PATCH] feat: add utils mod for constants needed accross brainfuck_prover (#50) --- crates/brainfuck_prover/src/lib.rs | 1 + crates/brainfuck_prover/src/utils/mod.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 crates/brainfuck_prover/src/utils/mod.rs diff --git a/crates/brainfuck_prover/src/lib.rs b/crates/brainfuck_prover/src/lib.rs index 8913003..d75d437 100644 --- a/crates/brainfuck_prover/src/lib.rs +++ b/crates/brainfuck_prover/src/lib.rs @@ -1,2 +1,3 @@ pub mod brainfuck_air; pub mod components; +pub mod utils; diff --git a/crates/brainfuck_prover/src/utils/mod.rs b/crates/brainfuck_prover/src/utils/mod.rs new file mode 100644 index 0000000..a50e04c --- /dev/null +++ b/crates/brainfuck_prover/src/utils/mod.rs @@ -0,0 +1,21 @@ +use stwo_prover::core::fields::m31::BaseField; + +pub const SHIFT_RIGHT_INSTRUCTION: u32 = b'>' as u32; +pub const SHIFT_LEFT_INSTRUCTION: u32 = b'<' as u32; +pub const INCREMENT_INSTRUCTION: u32 = b'+' as u32; +pub const DECREMENT_INSTRUCTION: u32 = b'-' as u32; +pub const INPUT_INSTRUCTION: u32 = b',' as u32; +pub const OUTPUT_INSTRUCTION: u32 = b'.' as u32; +pub const JUMP_IF_ZERO_INSTRUCTION: u32 = b'[' as u32; +pub const JUMP_IF_NON_ZERO_INSTRUCTION: u32 = b']' as u32; + +pub const VALID_INSTRUCTIONS: [BaseField; 8] = [ + BaseField::from_u32_unchecked(SHIFT_RIGHT_INSTRUCTION), + BaseField::from_u32_unchecked(SHIFT_LEFT_INSTRUCTION), + BaseField::from_u32_unchecked(INCREMENT_INSTRUCTION), + BaseField::from_u32_unchecked(DECREMENT_INSTRUCTION), + BaseField::from_u32_unchecked(INPUT_INSTRUCTION), + BaseField::from_u32_unchecked(OUTPUT_INSTRUCTION), + BaseField::from_u32_unchecked(JUMP_IF_ZERO_INSTRUCTION), + BaseField::from_u32_unchecked(JUMP_IF_NON_ZERO_INSTRUCTION), +];