Skip to content

Commit

Permalink
Merge branch '0xPolygonZero:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sai-deng authored Jun 29, 2024
2 parents 49e663d + cedffae commit 2917226
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 3 deletions.
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 }}
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));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ unsafe fn mds_multiply_and_add_round_const_s(
// Fall through for MDS matrix multiplication on low 32 bits

// This is a GCC _local label_. For details, see
// https://doc.rust-lang.org/beta/unstable-book/library-features/asm.html#labels
// https://doc.rust-lang.org/rust-by-example/unsafe/asm.html#labels
// In short, the assembler makes sure to assign a unique name to replace `2:` with a unique
// name, so the label does not clash with any compiler-generated label. `2:` can appear
// multiple times; to disambiguate, we must refer to it as `2b` or `2f`, specifying the
Expand Down

0 comments on commit 2917226

Please sign in to comment.