Skip to content

Commit

Permalink
Merge branch 'main' into sai/support_optional_table2
Browse files Browse the repository at this point in the history
  • Loading branch information
sai-deng authored Oct 5, 2024
2 parents 47511bb + 27a972f commit 5fb4d2b
Show file tree
Hide file tree
Showing 86 changed files with 3,014 additions and 749 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
rustdocflags = ["--html-in-header", ".cargo/katex-header.html"]
12 changes: 6 additions & 6 deletions .cargo/katex-header.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css"
integrity="sha384-zB1R0rpPzHqg7Kpt0Aljp8JPLqbXI3bhnPWROx27a9N0Ll6ZP/+DiW/UqRcLbRjq" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js"
integrity="sha384-y23I5Q6l+B6vatafAwxRu/0oK/79VlbSz7Q9aiSZUvyWYIYsd+qj+o24G5ZU2zJz"
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css"
integrity="sha384-nB0miv6/jRmo5UMMR1wu3Gz6NLsoTkbqJghGIsx//Rlm+ZU03BU6SQNC66uf4l5+" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.js"
integrity="sha384-7zkQWkzuo3B5mTepMUcHkMB5jZaolc2xDwL6VFqjFALcbeS9Ggm/Yr2r3Dy4lfFg"
crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/auto-render.min.js"
integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI"
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/contrib/auto-render.min.js"
integrity="sha384-43gviWU0YVjaDtb/GhzOouOXtZMP/7XUzwPTstBeZFe/+rCMvRwr4yROQP43s0Xk"
crossorigin="anonymous"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/pr_checking.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: PR check

on:
pull_request:
types: [opened, reopened, synchronize]

permissions:
pull-requests: write

jobs:
pr_check:
name: Validate PR
runs-on: ubuntu-latest
steps:
- name: Set up keywords
id: setup_keywords
run: echo "RESTRICTED_KEYWORDS=$(echo '${{ secrets.RESTRICTED_KEYWORDS }}' | jq -r '.[]' | tr '\n' ' ')" >> $GITHUB_ENV

- name: Check for spam PR
id: check
run: |
# Initialize variables to track spam presence
title_is_spam=false
description_is_spam=false
# Check title for spam
for keyword in $RESTRICTED_KEYWORDS; do
if echo "${{ github.event.pull_request.title }}" | grep -i -q "$keyword"; then
title_is_spam=true
break
fi
done
# Check description for spam
for keyword in $RESTRICTED_KEYWORDS; do
if echo "${{ github.event.pull_request.body }}" | grep -i -q "$keyword"; then
description_is_spam=true
break
fi
done
# Set the output based on the presence of spam
if [ "$title_is_spam" = true ] || [ "$description_is_spam" = true ]; then
echo "is_spam=true" >> $GITHUB_ENV
else
echo "is_spam=false" >> $GITHUB_ENV
fi
- name: Checkout repository
uses: actions/checkout@v4

- name: Close PR if spam are found and author is not a contributor or member
if: ${{ env.is_spam == 'true' && github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' }}
run: gh pr close ${{ github.event.pull_request.number }} --comment "Spam detected"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ homepage = "https://github.com/0xPolygonZero/plonky2"
repository = "https://github.com/0xPolygonZero/plonky2"
keywords = ["cryptography", "SNARK", "PLONK", "FRI", "plonky2"]
categories = ["cryptography"]

[workspace.lints.clippy]
too_long_first_doc_paragraph = "allow"
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ static GLOBAL: Jemalloc = Jemalloc;

Jemalloc is known to cause crashes when a binary compiled for x86 is run on an Apple silicon-based Mac under [Rosetta 2](https://support.apple.com/en-us/HT211861). If you are experiencing crashes on your Apple silicon Mac, run `rustc --print target-libdir`. The output should contain `aarch64-apple-darwin`. If the output contains `x86_64-apple-darwin`, then you are running the Rust toolchain for x86; we recommend switching to the native ARM version.

## Documentation

Generate documentation locally:

```sh
cargo doc --no-deps --open
```

## Contributing guidelines

See [CONTRIBUTING.md](./CONTRIBUTING.md).
Expand Down
Binary file not shown.
3 changes: 3 additions & 0 deletions field/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ plonky2_util = { version = "0.2.0", path = "../util", default-features = false }
# Display math equations properly in documentation
[package.metadata.docs.rs]
rustdoc-args = ["--html-in-header", ".cargo/katex-header.html"]

[lints]
workspace = true
2 changes: 1 addition & 1 deletion field/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#![feature(specialization)]
#![cfg_attr(target_arch = "x86_64", feature(stdarch_x86_avx512))]
#![cfg_attr(not(test), no_std)]
#![cfg(not(test))]

extern crate alloc;

pub(crate) mod arch;
Expand Down
48 changes: 47 additions & 1 deletion field/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,13 @@ pub trait Field:
}

fn powers(&self) -> Powers<Self> {
self.shifted_powers(Self::ONE)
}

fn shifted_powers(&self, start: Self) -> Powers<Self> {
Powers {
base: *self,
current: Self::ONE,
current: start,
}
}

Expand Down Expand Up @@ -563,6 +567,7 @@ pub trait PrimeField64: PrimeField + Field64 {
}

/// An iterator over the powers of a certain base element `b`: `b^0, b^1, b^2, ...`.
#[must_use = "iterators are lazy and do nothing unless consumed"]
#[derive(Clone, Debug)]
pub struct Powers<F: Field> {
base: F,
Expand All @@ -577,6 +582,24 @@ impl<F: Field> Iterator for Powers<F> {
self.current *= self.base;
Some(result)
}

fn size_hint(&self) -> (usize, Option<usize>) {
(usize::MAX, None)
}

fn nth(&mut self, n: usize) -> Option<F> {
let result = self.current * self.base.exp_u64(n.try_into().unwrap());
self.current = result * self.base;
Some(result)
}

fn last(self) -> Option<F> {
panic!("called `Iterator::last()` on an infinite sequence")
}

fn count(self) -> usize {
panic!("called `Iterator::count()` on an infinite sequence")
}
}

impl<F: Field> Powers<F> {
Expand All @@ -592,3 +615,26 @@ impl<F: Field> Powers<F> {
}
}
}

#[cfg(test)]
mod tests {
use super::Field;
use crate::goldilocks_field::GoldilocksField;

#[test]
fn test_powers_nth() {
type F = GoldilocksField;

const N: usize = 10;
let powers_of_two: Vec<F> = F::TWO.powers().take(N).collect();

for (n, &expect) in powers_of_two.iter().enumerate() {
let mut iter = F::TWO.powers();
assert_eq!(iter.nth(n), Some(expect));

for &expect_next in &powers_of_two[n + 1..] {
assert_eq!(iter.next(), Some(expect_next));
}
}
}
}
2 changes: 1 addition & 1 deletion maybe_rayon/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(not(std), no_std)]
#![no_std]

#[cfg(not(feature = "parallel"))]
extern crate alloc;
Expand Down
2 changes: 2 additions & 0 deletions plonky2/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
rustdocflags = ["--html-in-header", ".cargo/katex-header.html"]
4 changes: 4 additions & 0 deletions plonky2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ harness = false
# Display math equations properly in documentation
[package.metadata.docs.rs]
rustdoc-args = ["--html-in-header", ".cargo/katex-header.html"]
cargo-args = ["--no-deps"]

[lints]
workspace = true
4 changes: 2 additions & 2 deletions plonky2/benches/ffts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use plonky2::field::types::Field;
use tynm::type_name;

pub(crate) fn bench_ffts<F: Field>(c: &mut Criterion) {
let mut group = c.benchmark_group(&format!("fft<{}>", type_name::<F>()));
let mut group = c.benchmark_group(format!("fft<{}>", type_name::<F>()));

for size_log in [13, 14, 15, 16] {
let size = 1 << size_log;
Expand All @@ -21,7 +21,7 @@ pub(crate) fn bench_ffts<F: Field>(c: &mut Criterion) {
pub(crate) fn bench_ldes<F: Field>(c: &mut Criterion) {
const RATE_BITS: usize = 3;

let mut group = c.benchmark_group(&format!("lde<{}>", type_name::<F>()));
let mut group = c.benchmark_group(format!("lde<{}>", type_name::<F>()));

for size_log in [13, 14, 15, 16] {
let orig_size = 1 << (size_log - RATE_BITS);
Expand Down
2 changes: 1 addition & 1 deletion plonky2/benches/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tynm::type_name;
const ELEMS_PER_LEAF: usize = 135;

pub(crate) fn bench_merkle_tree<F: RichField, H: Hasher<F>>(c: &mut Criterion) {
let mut group = c.benchmark_group(&format!(
let mut group = c.benchmark_group(format!(
"merkle-tree<{}, {}>",
type_name::<F>(),
type_name::<H>()
Expand Down
8 changes: 4 additions & 4 deletions plonky2/examples/bench_recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn dummy_lookup_proof<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>,

let data = builder.build::<C>();
let mut inputs = PartialWitness::<F>::new();
inputs.set_target(initial_a, F::ONE);
inputs.set_target(initial_a, F::ONE)?;
let mut timing = TimingTree::new("prove with one lookup", Level::Debug);
let proof = prove(&data.prover_only, &data.common, inputs, &mut timing)?;
timing.print();
Expand Down Expand Up @@ -189,7 +189,7 @@ fn dummy_many_rows_proof<
builder.register_public_input(output);

let mut pw = PartialWitness::new();
pw.set_target(initial_a, F::ONE);
pw.set_target(initial_a, F::ONE)?;
let data = builder.build::<C>();
let mut timing = TimingTree::new("prove with many lookups", Level::Debug);
let proof = prove(&data.prover_only, &data.common, pw, &mut timing)?;
Expand Down Expand Up @@ -235,8 +235,8 @@ where
let data = builder.build::<C>();

let mut pw = PartialWitness::new();
pw.set_proof_with_pis_target(&pt, inner_proof);
pw.set_verifier_data_target(&inner_data, inner_vd);
pw.set_proof_with_pis_target(&pt, inner_proof)?;
pw.set_verifier_data_target(&inner_data, inner_vd)?;

let mut timing = TimingTree::new("prove", Level::Debug);
let proof = prove::<F, C, D>(&data.prover_only, &data.common, pw, &mut timing)?;
Expand Down
2 changes: 1 addition & 1 deletion plonky2/examples/factorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main() -> Result<()> {
builder.register_public_input(cur_target);

let mut pw = PartialWitness::new();
pw.set_target(initial, F::ONE);
pw.set_target(initial, F::ONE)?;

let data = builder.build::<C>();
let proof = data.prove(pw)?;
Expand Down
4 changes: 2 additions & 2 deletions plonky2/examples/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ fn main() -> Result<()> {

// Provide initial values.
let mut pw = PartialWitness::new();
pw.set_target(initial_a, F::ZERO);
pw.set_target(initial_b, F::ONE);
pw.set_target(initial_a, F::ZERO)?;
pw.set_target(initial_b, F::ONE)?;

let data = builder.build::<C>();
let proof = data.prove(pw)?;
Expand Down
4 changes: 2 additions & 2 deletions plonky2/examples/fibonacci_serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ fn main() -> Result<()> {

// Provide initial values.
let mut pw = PartialWitness::new();
pw.set_target(initial_a, F::ZERO);
pw.set_target(initial_b, F::ONE);
pw.set_target(initial_a, F::ZERO)?;
pw.set_target(initial_b, F::ONE)?;

let data = builder.build::<C>();

Expand Down
2 changes: 1 addition & 1 deletion plonky2/examples/range_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() -> Result<()> {
builder.range_check(value, log_max);

let mut pw = PartialWitness::new();
pw.set_target(value, F::from_canonical_usize(42));
pw.set_target(value, F::from_canonical_usize(42))?;

let data = builder.build::<C>();
let proof = data.prove(pw)?;
Expand Down
10 changes: 7 additions & 3 deletions plonky2/examples/square_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F, D>
vec![self.x_squared]
}

fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
fn run_once(
&self,
witness: &PartitionWitness<F>,
out_buffer: &mut GeneratedValues<F>,
) -> Result<()> {
let x_squared = witness.get_target(self.x_squared);
let x = x_squared.sqrt().unwrap();

println!("Square root: {x}");

out_buffer.set_target(self.x, x);
out_buffer.set_target(self.x, x)
}

fn serialize(&self, dst: &mut Vec<u8>, _common_data: &CommonCircuitData<F, D>) -> IoResult<()> {
Expand Down Expand Up @@ -121,7 +125,7 @@ fn main() -> Result<()> {
};

let mut pw = PartialWitness::new();
pw.set_target(x_squared, x_squared_value);
pw.set_target(x_squared, x_squared_value)?;

let data = builder.build::<C>();
let proof = data.prove(pw.clone())?;
Expand Down
4 changes: 4 additions & 0 deletions plonky2/src/batch_fri/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod oracle;
pub mod prover;
pub mod recursive_verifier;
pub mod verifier;
Loading

0 comments on commit 5fb4d2b

Please sign in to comment.