Skip to content

Commit

Permalink
compilable: first STARKY circuit: ProgramInstructionsSTARK
Browse files Browse the repository at this point in the history
  • Loading branch information
supragya committed Jul 7, 2024
1 parent 0b99bc6 commit 344e7e6
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ version = "0.1.0"
edition = "2021"

[dependencies]
plonky2 = { version = "0", default-features = false }
plonky2 = { git = "https://github.com/0xPolygonZero/plonky2" }
starky = { git = "https://github.com/0xPolygonZero/plonky2" }
anyhow = "1.0.86"
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ mod preflight_simulator;
#[allow(dead_code)]
mod vm_specs;

// STARK tables -------------
mod stark_program_instructions;

#[cfg(test)]
mod tests {
use std::collections::HashMap;
Expand Down
75 changes: 75 additions & 0 deletions src/stark_program_instructions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//! This file is an encoding of all the "Program". It is "static"
//! part of the proof generation process, in the sense that the "program"
//! a.k.a. resting code is known prior to proof generation. This
//! needs to be differentiated from actual running process trace, since
//! that may be longer than "program" owing to actual execution of jumps.

use plonky2::{
field::{
extension::{
Extendable,
FieldExtension,
},
packed::PackedField,
},
iop::ext_target::ExtensionTarget,
hash::hash_types::RichField,
};
use starky::{constraint_consumer::ConstraintConsumer, evaluation_frame::StarkFrame, stark::Stark};
use core::marker::PhantomData;

pub struct ProgramInstructions<T> {
pub program_counter: T,
pub instruction_data: T,
}

const NUMBER_OF_COLS: usize = 2;
const PUBLIC_INPUTS: usize = 0;

pub struct ProgramInstructionsStark<F, const D: usize> {
pub _f: PhantomData<F>,
}

impl<F, const D: usize> Stark<F, D> for ProgramInstructionsStark<F, D>
where
F: RichField + Extendable<D>,
{
const COLUMNS: usize = NUMBER_OF_COLS;
const PUBLIC_INPUTS: usize = PUBLIC_INPUTS;

type EvaluationFrame<FE, P, const D2: usize> = StarkFrame<P, P::Scalar, NUMBER_OF_COLS, PUBLIC_INPUTS>
where
FE: FieldExtension<D2, BaseField = F>,
P: PackedField<Scalar = FE>;

type EvaluationFrameTarget = StarkFrame<
ExtensionTarget<D>,
ExtensionTarget<D>,
NUMBER_OF_COLS,
PUBLIC_INPUTS,
>;

fn eval_packed_generic<FE, P, const D2: usize>(
&self,
vars: &Self::EvaluationFrame<FE, P, D2>,
yield_constr: &mut ConstraintConsumer<P>,
) where
FE: FieldExtension<D2, BaseField = F>,
P: PackedField<Scalar = FE>,
{

}

fn eval_ext_circuit(
&self,
builder: &mut plonky2::plonk::circuit_builder::CircuitBuilder<F, D>,
vars: &Self::EvaluationFrameTarget,
yield_constr: &mut starky::constraint_consumer::RecursiveConstraintConsumer<F, D>,
) {

}

fn constraint_degree(&self) -> usize {
3
}
}
17 changes: 17 additions & 0 deletions src/utility_macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! While macros shouln't really be used in a "toy" implementation,
//! they can help a lot! But they are also cumbersome to use. In the
//! sense that they are hard to read.
//!
//! Macros below are intended to be easy to read, comments are provided
//! where necessary

macro_rules! derive_get_number_of_columns {
($structure: ident) => {
impl<T> $structure<T> {
pub const fn get_number_of_columns() -> usize {
// `u8` is guaranteed to have a `size_of` of 1
std::mem::size_of::<$structure<u8>>();
}
}
};
}

0 comments on commit 344e7e6

Please sign in to comment.