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

feat: Preprocessing + recursion #450

Merged
merged 49 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
69d837b
efficient bits
tamirhemo Mar 27, 2024
4ba850c
small optimizations
tamirhemo Mar 28, 2024
4693648
some fixes
tamirhemo Mar 28, 2024
b60f737
uncomment
tamirhemo Mar 28, 2024
6b17225
delete num_cpu_cols
tamirhemo Mar 28, 2024
6032ec0
cleanup
tamirhemo Mar 28, 2024
9c83a30
Merge remote-tracking branch 'origin/main' into tamir/optimize
tamirhemo Mar 28, 2024
c522def
bits
tamirhemo Mar 28, 2024
302976a
shift checkpoint
tamirhemo Mar 28, 2024
0cde458
pointer arithmetic
tamirhemo Mar 28, 2024
aa9ead6
remove unecessary eval
tamirhemo Mar 28, 2024
e92eaaa
unrolling constant loops
tamirhemo Mar 28, 2024
365d0b7
cleanup
tamirhemo Mar 28, 2024
a330e35
Merge remote-tracking branch 'origin/main' into tamir/optimize
tamirhemo Mar 28, 2024
04b34de
count extension ops
tamirhemo Mar 28, 2024
d68bacf
fix constant loop bug
tamirhemo Mar 28, 2024
31e13b5
cleanup
tamirhemo Mar 28, 2024
8ff2d9f
merge main
tamirhemo Mar 28, 2024
6a286a4
cleanup v0
tamirhemo Mar 28, 2024
215134f
slight cleanup
tamirhemo Mar 28, 2024
ef7109c
reverse bits len opt
tamirhemo Mar 28, 2024
92d78d4
Merge remote-tracking branch 'origin/main' into tamir/optimize
tamirhemo Mar 28, 2024
8e946c2
docs
tamirhemo Mar 29, 2024
78f4c6f
checkpoint
tamirhemo Mar 29, 2024
1fe9158
step_by
tamirhemo Mar 29, 2024
9873bb5
hash
tamirhemo Mar 29, 2024
416e905
precomputed domains and gen
tamirhemo Mar 30, 2024
a2c3f5a
cleanup
tamirhemo Mar 30, 2024
fd6b1da
Merge remote-tracking branch 'origin/main' into tamir/optimize
tamirhemo Mar 30, 2024
354754b
cleanup
tamirhemo Mar 30, 2024
ec4941b
fri cleanup
tamirhemo Mar 30, 2024
db830bf
rm starkair
tamirhemo Mar 31, 2024
5865a8d
add program to machine-air
tamirhemo Mar 31, 2024
c361bbe
change prep width -> prep dims
tamirhemo Apr 1, 2024
240081e
setup function
tamirhemo Apr 1, 2024
9b9415e
interaction builder preprocessed
tamirhemo Apr 1, 2024
cc25406
return preprocessed_width
tamirhemo Apr 1, 2024
07419e5
prep in lookup builder
tamirhemo Apr 1, 2024
49f9f16
fix debug assert
tamirhemo Apr 1, 2024
2d2bebb
checkpoint
tamirhemo Apr 1, 2024
d811b3c
make program preprocessed
tamirhemo Apr 1, 2024
beb563b
make byte prep
tamirhemo Apr 1, 2024
39bb782
byte preprocessed
tamirhemo Apr 1, 2024
763d4b3
recursion works
tamirhemo Apr 1, 2024
5eda71f
remote branch
tamirhemo Apr 1, 2024
317f257
fix debug mode
tamirhemo Apr 1, 2024
3b64c06
observe challenges
tamirhemo Apr 1, 2024
7d35758
fix test
tamirhemo Apr 1, 2024
e0fdf74
sp1 branch
tamirhemo Apr 1, 2024
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
42 changes: 21 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ p3-maybe-rayon = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1
p3-bn254-fr = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }

# For local development.
#

# p3-air = { path = "../Plonky3/air" }
# p3-field = { path = "../Plonky3/field" }
# p3-commit = { path = "../Plonky3/commit" }
Expand All @@ -69,4 +69,4 @@ p3-bn254-fr = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
# p3-symmetric = { path = "../Plonky3/symmetric" }
# p3-uni-stark = { path = "../Plonky3/uni-stark" }
# p3-maybe-rayon = { path = "../Plonky3/maybe-rayon" }
# p3-bn254-fr = { path = "../Plonky3/bn254-fr" }
# p3-bn254-fr = { path = "../Plonky3/bn254-fr" }
14 changes: 7 additions & 7 deletions core/src/air/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,13 +624,13 @@ impl<'a, AB: AirBuilder + MessageBuilder<M>, M> MessageBuilder<M> for FilteredAi
}

impl<AB: AirBuilder + MessageBuilder<AirInteraction<AB::Expr>>> BaseAirBuilder for AB {}
impl<AB: AirBuilder + MessageBuilder<AirInteraction<AB::Expr>>> ByteAirBuilder for AB {}
impl<AB: AirBuilder + MessageBuilder<AirInteraction<AB::Expr>>> WordAirBuilder for AB {}
impl<AB: AirBuilder + MessageBuilder<AirInteraction<AB::Expr>>> AluAirBuilder for AB {}
impl<AB: AirBuilder + MessageBuilder<AirInteraction<AB::Expr>>> MemoryAirBuilder for AB {}
impl<AB: AirBuilder + MessageBuilder<AirInteraction<AB::Expr>>> ProgramAirBuilder for AB {}
impl<AB: AirBuilder + MessageBuilder<AirInteraction<AB::Expr>>> ExtensionAirBuilder for AB {}
impl<AB: AirBuilder + MessageBuilder<AirInteraction<AB::Expr>>> SP1AirBuilder for AB {}
impl<AB: BaseAirBuilder> ByteAirBuilder for AB {}
impl<AB: BaseAirBuilder> WordAirBuilder for AB {}
impl<AB: BaseAirBuilder> AluAirBuilder for AB {}
impl<AB: BaseAirBuilder> MemoryAirBuilder for AB {}
impl<AB: BaseAirBuilder> ProgramAirBuilder for AB {}
impl<AB: BaseAirBuilder> ExtensionAirBuilder for AB {}
impl<AB: BaseAirBuilder> SP1AirBuilder for AB {}

impl<'a, SC: StarkGenericConfig> EmptyMessageBuilder for ProverConstraintFolder<'a, SC> {}
impl<'a, SC: StarkGenericConfig> EmptyMessageBuilder for VerifierConstraintFolder<'a, SC> {}
Expand Down
14 changes: 9 additions & 5 deletions core/src/air/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ use p3_air::BaseAir;
use p3_field::Field;
use p3_matrix::dense::RowMajorMatrix;

use crate::{runtime::Program, stark::MachineRecord};
use crate::stark::MachineRecord;

pub use sp1_derive::MachineAir;

/// An AIR that is part of a Risc-V AIR arithmetization.
pub trait MachineAir<F: Field>: BaseAir<F> {
/// The execution record containing events for producing the air trace.
type Record: MachineRecord;

type Program;

/// A unique identifier for this AIR as part of a machine.
fn name(&self) -> String;

Expand All @@ -25,15 +28,16 @@ pub trait MachineAir<F: Field>: BaseAir<F> {
self.generate_trace(input, output);
}

/// The number of preprocessed columns in the trace.
/// Whether this execution record contains events for this air.
fn included(&self, shard: &Self::Record) -> bool;

fn preprocessed_width(&self) -> usize {
0
}

/// Generate the preprocessed trace given a specific program.
#[allow(unused_variables)]
fn generate_preprocessed_trace(&self, program: &Program) -> Option<RowMajorMatrix<F>> {
fn generate_preprocessed_trace(&self, program: &Self::Program) -> Option<RowMajorMatrix<F>> {
None
}

fn included(&self, shard: &Self::Record) -> bool;
}
4 changes: 3 additions & 1 deletion core/src/alu/add_sub/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tracing::instrument;
use crate::air::MachineAir;
use crate::air::{SP1AirBuilder, Word};
use crate::operations::AddOperation;
use crate::runtime::{ExecutionRecord, Opcode};
use crate::runtime::{ExecutionRecord, Opcode, Program};
use crate::stark::MachineRecord;
use crate::utils::pad_to_power_of_two;

Expand Down Expand Up @@ -51,6 +51,8 @@ pub struct AddSubCols<T> {
impl<F: PrimeField> MachineAir<F> for AddSubChip {
type Record = ExecutionRecord;

type Program = Program;

fn name(&self) -> String {
"AddSub".to_string()
}
Expand Down
4 changes: 3 additions & 1 deletion core/src/alu/bitwise/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tracing::instrument;
use crate::air::MachineAir;
use crate::air::{SP1AirBuilder, Word};
use crate::bytes::{ByteLookupEvent, ByteOpcode};
use crate::runtime::{ExecutionRecord, Opcode};
use crate::runtime::{ExecutionRecord, Opcode, Program};
use crate::utils::pad_to_power_of_two;

/// The number of main trace columns for `BitwiseChip`.
Expand Down Expand Up @@ -45,6 +45,8 @@ pub struct BitwiseCols<T> {
impl<F: PrimeField> MachineAir<F> for BitwiseChip {
type Record = ExecutionRecord;

type Program = Program;

fn name(&self) -> String {
"Bitwise".to_string()
}
Expand Down
4 changes: 3 additions & 1 deletion core/src/alu/divrem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ use crate::alu::AluEvent;
use crate::bytes::{ByteLookupEvent, ByteOpcode};
use crate::disassembler::WORD_SIZE;
use crate::operations::{IsEqualWordOperation, IsZeroWordOperation};
use crate::runtime::{ExecutionRecord, Opcode};
use crate::runtime::{ExecutionRecord, Opcode, Program};
use crate::utils::pad_to_power_of_two;

/// The number of main trace columns for `DivRemChip`.
Expand Down Expand Up @@ -184,6 +184,8 @@ pub struct DivRemCols<T> {
impl<F: PrimeField> MachineAir<F> for DivRemChip {
type Record = ExecutionRecord;

type Program = Program;

fn name(&self) -> String {
"DivRem".to_string()
}
Expand Down
4 changes: 3 additions & 1 deletion core/src/alu/lt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tracing::instrument;

use crate::air::{SP1AirBuilder, Word};

use crate::runtime::{ExecutionRecord, Opcode};
use crate::runtime::{ExecutionRecord, Opcode, Program};
use crate::utils::pad_to_power_of_two;

/// The number of main trace columns for `LtChip`.
Expand Down Expand Up @@ -76,6 +76,8 @@ impl LtCols<u32> {
impl<F: PrimeField> MachineAir<F> for LtChip {
type Record = ExecutionRecord;

type Program = Program;

fn name(&self) -> String {
"Lt".to_string()
}
Expand Down
4 changes: 3 additions & 1 deletion core/src/alu/mul/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use crate::air::{SP1AirBuilder, Word};
use crate::alu::mul::utils::get_msb;
use crate::bytes::{ByteLookupEvent, ByteOpcode};
use crate::disassembler::WORD_SIZE;
use crate::runtime::{ExecutionRecord, Opcode};
use crate::runtime::{ExecutionRecord, Opcode, Program};
use crate::stark::MachineRecord;
use crate::utils::pad_to_power_of_two;

Expand Down Expand Up @@ -118,6 +118,8 @@ pub struct MulCols<T> {
impl<F: PrimeField> MachineAir<F> for MulChip {
type Record = ExecutionRecord;

type Program = Program;

fn name(&self) -> String {
"Mul".to_string()
}
Expand Down
4 changes: 3 additions & 1 deletion core/src/alu/sll/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use tracing::instrument;
use crate::air::MachineAir;
use crate::air::{SP1AirBuilder, Word};
use crate::disassembler::WORD_SIZE;
use crate::runtime::{ExecutionRecord, Opcode};
use crate::runtime::{ExecutionRecord, Opcode, Program};
use crate::utils::pad_to_power_of_two;

/// The number of main trace columns for `ShiftLeft`.
Expand Down Expand Up @@ -93,6 +93,8 @@ pub struct ShiftLeftCols<T> {
impl<F: PrimeField> MachineAir<F> for ShiftLeft {
type Record = ExecutionRecord;

type Program = Program;

fn name(&self) -> String {
"ShiftLeft".to_string()
}
Expand Down
4 changes: 3 additions & 1 deletion core/src/alu/sr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use crate::alu::sr::utils::{nb_bits_to_shift, nb_bytes_to_shift};
use crate::bytes::utils::shr_carry;
use crate::bytes::{ByteLookupEvent, ByteOpcode};
use crate::disassembler::WORD_SIZE;
use crate::runtime::{ExecutionRecord, Opcode};
use crate::runtime::{ExecutionRecord, Opcode, Program};
use crate::utils::pad_to_power_of_two;

/// The number of main trace columns for `ShiftRightChip`.
Expand Down Expand Up @@ -125,6 +125,8 @@ pub struct ShiftRightCols<T> {
impl<F: PrimeField> MachineAir<F> for ShiftRightChip {
type Record = ExecutionRecord;

type Program = Program;

fn name(&self) -> String {
"ShiftRight".to_string()
}
Expand Down
Loading
Loading