Skip to content

Commit 344e7e6

Browse files
committed
compilable: first STARKY circuit: ProgramInstructionsSTARK
1 parent 0b99bc6 commit 344e7e6

File tree

4 files changed

+97
-1
lines changed

4 files changed

+97
-1
lines changed

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
plonky2 = { version = "0", default-features = false }
7+
plonky2 = { git = "https://github.com/0xPolygonZero/plonky2" }
8+
starky = { git = "https://github.com/0xPolygonZero/plonky2" }
89
anyhow = "1.0.86"

src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ mod preflight_simulator;
1616
#[allow(dead_code)]
1717
mod vm_specs;
1818

19+
// STARK tables -------------
20+
mod stark_program_instructions;
21+
1922
#[cfg(test)]
2023
mod tests {
2124
use std::collections::HashMap;

src/stark_program_instructions.rs

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//! This file is an encoding of all the "Program". It is "static"
2+
//! part of the proof generation process, in the sense that the "program"
3+
//! a.k.a. resting code is known prior to proof generation. This
4+
//! needs to be differentiated from actual running process trace, since
5+
//! that may be longer than "program" owing to actual execution of jumps.
6+
7+
use plonky2::{
8+
field::{
9+
extension::{
10+
Extendable,
11+
FieldExtension,
12+
},
13+
packed::PackedField,
14+
},
15+
iop::ext_target::ExtensionTarget,
16+
hash::hash_types::RichField,
17+
};
18+
use starky::{constraint_consumer::ConstraintConsumer, evaluation_frame::StarkFrame, stark::Stark};
19+
use core::marker::PhantomData;
20+
21+
pub struct ProgramInstructions<T> {
22+
pub program_counter: T,
23+
pub instruction_data: T,
24+
}
25+
26+
const NUMBER_OF_COLS: usize = 2;
27+
const PUBLIC_INPUTS: usize = 0;
28+
29+
pub struct ProgramInstructionsStark<F, const D: usize> {
30+
pub _f: PhantomData<F>,
31+
}
32+
33+
impl<F, const D: usize> Stark<F, D> for ProgramInstructionsStark<F, D>
34+
where
35+
F: RichField + Extendable<D>,
36+
{
37+
const COLUMNS: usize = NUMBER_OF_COLS;
38+
const PUBLIC_INPUTS: usize = PUBLIC_INPUTS;
39+
40+
type EvaluationFrame<FE, P, const D2: usize> = StarkFrame<P, P::Scalar, NUMBER_OF_COLS, PUBLIC_INPUTS>
41+
where
42+
FE: FieldExtension<D2, BaseField = F>,
43+
P: PackedField<Scalar = FE>;
44+
45+
type EvaluationFrameTarget = StarkFrame<
46+
ExtensionTarget<D>,
47+
ExtensionTarget<D>,
48+
NUMBER_OF_COLS,
49+
PUBLIC_INPUTS,
50+
>;
51+
52+
fn eval_packed_generic<FE, P, const D2: usize>(
53+
&self,
54+
vars: &Self::EvaluationFrame<FE, P, D2>,
55+
yield_constr: &mut ConstraintConsumer<P>,
56+
) where
57+
FE: FieldExtension<D2, BaseField = F>,
58+
P: PackedField<Scalar = FE>,
59+
{
60+
61+
}
62+
63+
fn eval_ext_circuit(
64+
&self,
65+
builder: &mut plonky2::plonk::circuit_builder::CircuitBuilder<F, D>,
66+
vars: &Self::EvaluationFrameTarget,
67+
yield_constr: &mut starky::constraint_consumer::RecursiveConstraintConsumer<F, D>,
68+
) {
69+
70+
}
71+
72+
fn constraint_degree(&self) -> usize {
73+
3
74+
}
75+
}

src/utility_macros.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! While macros shouln't really be used in a "toy" implementation,
2+
//! they can help a lot! But they are also cumbersome to use. In the
3+
//! sense that they are hard to read.
4+
//!
5+
//! Macros below are intended to be easy to read, comments are provided
6+
//! where necessary
7+
8+
macro_rules! derive_get_number_of_columns {
9+
($structure: ident) => {
10+
impl<T> $structure<T> {
11+
pub const fn get_number_of_columns() -> usize {
12+
// `u8` is guaranteed to have a `size_of` of 1
13+
std::mem::size_of::<$structure<u8>>();
14+
}
15+
}
16+
};
17+
}

0 commit comments

Comments
 (0)