Skip to content

Commit

Permalink
feat: generic const expr (#854)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Tian <[email protected]>
  • Loading branch information
ratankaliani and ctian1 authored May 31, 2024
1 parent af7c26c commit 27c1741
Show file tree
Hide file tree
Showing 16 changed files with 12 additions and 50 deletions.
3 changes: 0 additions & 3 deletions core/benches/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use sp1_core::io::SP1Stdin;
use sp1_core::runtime::{Program, Runtime};
Expand Down
1 change: 0 additions & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
deprecated,
incomplete_features
)]
#![feature(generic_const_exprs)]
#![warn(unused_extern_crates)]

extern crate alloc;
Expand Down
9 changes: 3 additions & 6 deletions core/src/syscall/precompiles/weierstrass/weierstrass_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ use crate::utils::ec::weierstrass::WeierstrassParameters;
use crate::utils::ec::AffinePoint;
use crate::utils::ec::CurveType;
use crate::utils::ec::EllipticCurve;
use crate::utils::limbs_from_prev_access;
use crate::utils::pad_rows;
use crate::utils::{limbs_from_prev_access, pad_rows};

pub const fn num_weierstrass_add_cols<P: FieldParameters + NumWords>() -> usize {
size_of::<WeierstrassAddAssignCols<u8, P>>()
Expand Down Expand Up @@ -202,8 +201,6 @@ impl<E: EllipticCurve> WeierstrassAddAssignChip<E> {

impl<F: PrimeField32, E: EllipticCurve + WeierstrassParameters> MachineAir<F>
for WeierstrassAddAssignChip<E>
where
[(); num_weierstrass_add_cols::<E::BaseField>()]:,
{
type Record = ExecutionRecord;
type Program = Program;
Expand Down Expand Up @@ -235,7 +232,7 @@ where

for i in 0..events.len() {
let event = &events[i];
let mut row = [F::zero(); num_weierstrass_add_cols::<E::BaseField>()];
let mut row = vec![F::zero(); num_weierstrass_add_cols::<E::BaseField>()];
let cols: &mut WeierstrassAddAssignCols<F, E::BaseField> =
row.as_mut_slice().borrow_mut();

Expand Down Expand Up @@ -287,7 +284,7 @@ where
output.add_byte_lookup_events(new_byte_lookup_events);

pad_rows(&mut rows, || {
let mut row = [F::zero(); num_weierstrass_add_cols::<E::BaseField>()];
let mut row = vec![F::zero(); num_weierstrass_add_cols::<E::BaseField>()];
let cols: &mut WeierstrassAddAssignCols<F, E::BaseField> =
row.as_mut_slice().borrow_mut();
let zero = BigUint::zero();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ use crate::runtime::Syscall;
use crate::runtime::SyscallCode;
use crate::syscall::precompiles::create_ec_decompress_event;
use crate::syscall::precompiles::SyscallContext;
use crate::utils::bytes_to_words_le_vec;
use crate::utils::ec::weierstrass::bls12_381::bls12381_sqrt;
use crate::utils::ec::weierstrass::secp256k1::secp256k1_sqrt;
use crate::utils::ec::weierstrass::WeierstrassParameters;
use crate::utils::ec::CurveType;
use crate::utils::ec::EllipticCurve;
use crate::utils::limbs_from_access;
use crate::utils::limbs_from_prev_access;
use crate::utils::pad_rows;
use crate::utils::{bytes_to_words_le_vec, pad_rows};

pub const fn num_weierstrass_decompress_cols<P: FieldParameters + NumWords>() -> usize {
size_of::<WeierstrassDecompressCols<u8, P>>()
Expand Down Expand Up @@ -137,8 +136,6 @@ impl<E: EllipticCurve + WeierstrassParameters> WeierstrassDecompressChip<E> {

impl<F: PrimeField32, E: EllipticCurve + WeierstrassParameters> MachineAir<F>
for WeierstrassDecompressChip<E>
where
[(); num_weierstrass_decompress_cols::<E::BaseField>()]:,
{
type Record = ExecutionRecord;
type Program = Program;
Expand Down Expand Up @@ -168,7 +165,7 @@ where

for i in 0..events.len() {
let event = events[i].clone();
let mut row = [F::zero(); num_weierstrass_decompress_cols::<E::BaseField>()];
let mut row = vec![F::zero(); num_weierstrass_decompress_cols::<E::BaseField>()];
let cols: &mut WeierstrassDecompressCols<F, E::BaseField> =
row.as_mut_slice().borrow_mut();

Expand Down Expand Up @@ -209,7 +206,7 @@ where
output.add_byte_lookup_events(new_byte_lookup_events);

pad_rows(&mut rows, || {
let mut row = [F::zero(); num_weierstrass_decompress_cols::<E::BaseField>()];
let mut row = vec![F::zero(); num_weierstrass_decompress_cols::<E::BaseField>()];
let cols: &mut WeierstrassDecompressCols<F, E::BaseField> =
row.as_mut_slice().borrow_mut();

Expand Down
10 changes: 4 additions & 6 deletions core/src/syscall/precompiles/weierstrass/weierstrass_double.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ use crate::utils::ec::weierstrass::WeierstrassParameters;
use crate::utils::ec::AffinePoint;
use crate::utils::ec::CurveType;
use crate::utils::ec::EllipticCurve;
use crate::utils::limbs_from_prev_access;
use crate::utils::pad_rows;
use crate::utils::{limbs_from_prev_access, pad_rows};

pub const fn num_weierstrass_double_cols<P: FieldParameters + NumWords>() -> usize {
size_of::<WeierstrassDoubleAssignCols<u8, P>>()
Expand Down Expand Up @@ -221,8 +220,6 @@ impl<E: EllipticCurve + WeierstrassParameters> WeierstrassDoubleAssignChip<E> {

impl<F: PrimeField32, E: EllipticCurve + WeierstrassParameters> MachineAir<F>
for WeierstrassDoubleAssignChip<E>
where
[(); num_weierstrass_double_cols::<E::BaseField>()]:,
{
type Record = ExecutionRecord;
type Program = Program;
Expand Down Expand Up @@ -261,7 +258,8 @@ where
let rows = events
.iter()
.map(|event| {
let mut row = [F::zero(); num_weierstrass_double_cols::<E::BaseField>()];
let mut row =
vec![F::zero(); num_weierstrass_double_cols::<E::BaseField>()];
let cols: &mut WeierstrassDoubleAssignCols<F, E::BaseField> =
row.as_mut_slice().borrow_mut();

Expand Down Expand Up @@ -310,7 +308,7 @@ where
}

pad_rows(&mut rows, || {
let mut row = [F::zero(); num_weierstrass_double_cols::<E::BaseField>()];
let mut row = vec![F::zero(); num_weierstrass_double_cols::<E::BaseField>()];
let cols: &mut WeierstrassDoubleAssignCols<F, E::BaseField> =
row.as_mut_slice().borrow_mut();
let zero = BigUint::zero();
Expand Down
2 changes: 1 addition & 1 deletion core/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn limbs_from_access<T: Copy, N: ArrayLength, M: MemoryCols<T>>(cols: &[M])
Limbs(sized)
}

pub fn pad_rows<T: Clone, const N: usize>(rows: &mut Vec<[T; N]>, row_fn: impl Fn() -> [T; N]) {
pub fn pad_rows<T: Clone>(rows: &mut Vec<T>, row_fn: impl Fn() -> T) {
let nb_rows = rows.len();
let mut padded_nb_rows = nb_rows.next_power_of_two();
if padded_nb_rows < 16 {
Expand Down
3 changes: 0 additions & 3 deletions eval/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

use clap::{command, Parser};
use csv::WriterBuilder;
use serde::Serialize;
Expand Down
3 changes: 0 additions & 3 deletions prover/scripts/build_plonk_bn254.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

use std::path::PathBuf;

use clap::Parser;
Expand Down
3 changes: 0 additions & 3 deletions prover/scripts/e2e.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

use std::borrow::Borrow;
use std::path::PathBuf;

Expand Down
3 changes: 0 additions & 3 deletions prover/scripts/fibonacci_groth16.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//! Tests end-to-end performance of wrapping a recursion proof to PLONK.
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

use std::time::Instant;

use itertools::iproduct;
Expand Down
3 changes: 0 additions & 3 deletions prover/scripts/fibonacci_sweep.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//! Sweeps end-to-end prover performance across a wide range of parameters for Fibonacci.
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

use std::{fs::File, io::BufWriter, io::Write, time::Instant};

use itertools::iproduct;
Expand Down
3 changes: 0 additions & 3 deletions prover/scripts/tendermint_sweep.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//! Sweeps end-to-end prover performance across a wide range of parameters for Tendermint.
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

use std::{fs::File, io::BufWriter, io::Write, time::Instant};

use itertools::iproduct;
Expand Down
2 changes: 0 additions & 2 deletions prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
//! 3. Wrap the shard proof into a SNARK-friendly field.
//! 4. Wrap the last shard proof, proven over the SNARK-friendly field, into a PLONK proof.
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::new_without_default)]

Expand Down
3 changes: 1 addition & 2 deletions recursion/core/src/poseidon2_wide/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ impl<F: PrimeField32, const DEGREE: usize> MachineAir<F> for Poseidon2WideChip<D
let num_columns = <Self as BaseAir<F>>::width(self);

for event in &input.poseidon2_events {
let mut row = Vec::new();
row.resize(num_columns, F::zero());
let mut row = vec![F::zero(); num_columns];

let mut cols = if use_sbox_3 {
let cols: &mut Poseidon2SBoxCols<F> = row.as_mut_slice().borrow_mut();
Expand Down
2 changes: 0 additions & 2 deletions recursion/program/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]
#![allow(type_alias_bounds)]
#![allow(clippy::type_complexity)]
#![allow(clippy::too_many_arguments)]
Expand Down
3 changes: 0 additions & 3 deletions sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
//! Visit the [Getting Started](https://succinctlabs.github.io/sp1/getting-started.html) section
//! in the official SP1 documentation for a quick start guide.
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

#[rustfmt::skip]
pub mod proto {
pub mod network;
Expand Down

0 comments on commit 27c1741

Please sign in to comment.