Skip to content

Link file for air #728

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

Closed
wants to merge 59 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
b9aab28
minor: initial draft
InfiniteEchoes Apr 16, 2025
0b3591e
feat: update `blacklist.txt` for plonky3
InfiniteEchoes Apr 16, 2025
86cb2c9
feat: Initial draft for plonky3 CI
InfiniteEchoes Apr 16, 2025
2e943fe
feat: Only import files under `src`
InfiniteEchoes Apr 16, 2025
0aa8f7d
feat: Add `plonky3` as submodule
InfiniteEchoes Apr 16, 2025
d19f077
minor: typo in workflow
InfiniteEchoes Apr 16, 2025
8c4524b
add plonky3 submodule
InfiniteEchoes Apr 16, 2025
8a6ef44
feat: Add preprocessing for `plonky3`
InfiniteEchoes Apr 16, 2025
e34cf39
minor: fix submodule routine
InfiniteEchoes Apr 16, 2025
50644e8
minor: add working `touch` commands
InfiniteEchoes Apr 16, 2025
f037433
minor: correct path
InfiniteEchoes Apr 16, 2025
1786253
feat: remove untranslated files and sync with git
InfiniteEchoes Apr 16, 2025
8f3d7a8
minor: increase wait time for python script(?)
InfiniteEchoes Apr 17, 2025
2c9e255
minor: initial draft
InfiniteEchoes Apr 18, 2025
4140b4c
minor: progress
InfiniteEchoes Apr 21, 2025
a68059c
minor: progress
InfiniteEchoes Apr 22, 2025
d661ce3
feat: Defined struct `Blake3Air`
InfiniteEchoes Apr 22, 2025
3aa58bd
minor: typo(?)
InfiniteEchoes Apr 22, 2025
1c08e79
minior: progress
InfiniteEchoes Apr 22, 2025
071c6a5
minor: progress
InfiniteEchoes Apr 22, 2025
b94f37e
Merge branch 'main' into gy@AirLink
InfiniteEchoes Apr 28, 2025
abb4822
minor: rename folder for syntax validity
InfiniteEchoes Apr 28, 2025
44e7a24
minor: progress
InfiniteEchoes Apr 29, 2025
b79f4fd
minor: progress
InfiniteEchoes May 2, 2025
c6cda99
feat: Initial draft for `field`
InfiniteEchoes May 12, 2025
342caeb
feat: Initial stub for `dense`
InfiniteEchoes May 12, 2025
e7d5a32
minor: removed unneeded link
InfiniteEchoes May 12, 2025
364ff19
minor: progress on `field`
InfiniteEchoes May 12, 2025
3af05bd
minor: progress
InfiniteEchoes May 12, 2025
cc56e2a
feat: Initially define `dense.v`
InfiniteEchoes May 12, 2025
5bd2a74
minor: progress on `air`
InfiniteEchoes May 12, 2025
14f5abe
minor: more dependency stubs
InfiniteEchoes May 12, 2025
c669f56
minor: progress on `air`
InfiniteEchoes May 12, 2025
3a9b0bf
minor: progress on `air`
InfiniteEchoes May 13, 2025
b248939
minor: update according to comments
InfiniteEchoes May 13, 2025
b0fe937
minor: finish `of_ty` in `dense`
InfiniteEchoes May 13, 2025
2c64b6e
minor: more templates for `air`
InfiniteEchoes May 13, 2025
921461f
minor: update on `columns`
InfiniteEchoes May 13, 2025
30bd5a4
minor: small update on `field`
InfiniteEchoes May 13, 2025
417700d
minor: rename `link` to `links`
InfiniteEchoes May 13, 2025
5aca14f
minor: finish importing missing dependencies
InfiniteEchoes May 13, 2025
6d5101a
minor: progress
InfiniteEchoes May 13, 2025
e4c9a83
minor: update on `field`
InfiniteEchoes May 13, 2025
4b327fc
minor: progress
InfiniteEchoes May 13, 2025
9fad710
minor: progress
InfiniteEchoes May 13, 2025
8352379
minor: progress
InfiniteEchoes May 13, 2025
3af2f54
minor: progress on `columns`
InfiniteEchoes May 14, 2025
9bf6980
minor: fix typo on `dense`
InfiniteEchoes May 14, 2025
99ed392
minor: fix path in `air`
InfiniteEchoes May 14, 2025
5e6572f
minor: progress on `columns`
InfiniteEchoes May 14, 2025
7c5f144
minor: note bug for `dense`
InfiniteEchoes May 14, 2025
5f8c957
minor: snapshot for current progress
InfiniteEchoes May 15, 2025
d6c8d31
minor: attempt to delete `matrix/src`
InfiniteEchoes May 15, 2025
e03ebf1
minor: fix bug in `dense`
InfiniteEchoes May 17, 2025
13a6b64
minor: progress on `columns`
InfiniteEchoes May 17, 2025
db2830c
minor: tiny comment for `air`
InfiniteEchoes May 17, 2025
a45b679
minor: fix bug for `air`
InfiniteEchoes May 17, 2025
0eda6a0
Merge branch 'main' into gy@AirLink
InfiniteEchoes May 17, 2025
dc04985
minor: deleting `air/src` with bugged code
InfiniteEchoes May 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 7 additions & 1 deletion CoqOfRust/blacklist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ move_sui/links/
move_sui/simulations/move_bytecode_verifier_meter/lib.v
# Because it does not change much right now and takes a long time to compile
move_sui/proofs
move_sui/simulations
move_sui/simulations
# Plonky3 related files that does not pass
plonky3/commit/src/adapters/extension_mmcs.v
plonky3/merkle-tree/src/hiding_mmcs.v
plonky3/merkle-tree/src/mmcs.v
plonky3/monty-31/src/monty_31.v
plonky3/poseidon2/src/external.v
95 changes: 95 additions & 0 deletions CoqOfRust/plonky3/air/links/air.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
Require Import CoqOfRust.CoqOfRust.
Require Import CoqOfRust.links.M.
Require Import plonky3.air.air.

(* pub trait AirBuilder: Sized { *)
Module AirBuilder.
(*
type F: Field;

type Expr: Algebra<Self::F> + Algebra<Self::Var>;

type Var: Into<Self::Expr>
+ Copy
+ Send
+ Sync
+ Add<Self::F, Output = Self::Expr>
+ Add<Self::Var, Output = Self::Expr>
+ Add<Self::Expr, Output = Self::Expr>
+ Sub<Self::F, Output = Self::Expr>
+ Sub<Self::Var, Output = Self::Expr>
+ Sub<Self::Expr, Output = Self::Expr>
+ Mul<Self::F, Output = Self::Expr>
+ Mul<Self::Var, Output = Self::Expr>
+ Mul<Self::Expr, Output = Self::Expr>;

type M: Matrix<Self::Var>;

fn main(&self) -> Self::M;

fn is_first_row(&self) -> Self::Expr;
fn is_last_row(&self) -> Self::Expr;
fn is_transition(&self) -> Self::Expr {
self.is_transition_window(2)
}
fn is_transition_window(&self, size: usize) -> Self::Expr;

fn when<I: Into<Self::Expr>>(&mut self, condition: I) -> FilteredAirBuilder<'_, Self> {
FilteredAirBuilder {
inner: self,
condition: condition.into(),
}
}

fn when_ne<I1: Into<Self::Expr>, I2: Into<Self::Expr>>(
&mut self,
x: I1,
y: I2,
) -> FilteredAirBuilder<'_, Self> {
self.when(x.into() - y.into())
}

fn when_first_row(&mut self) -> FilteredAirBuilder<'_, Self> {
self.when(self.is_first_row())
}

fn when_last_row(&mut self) -> FilteredAirBuilder<'_, Self> {
self.when(self.is_last_row())
}

fn when_transition(&mut self) -> FilteredAirBuilder<'_, Self> {
self.when(self.is_transition())
}

fn when_transition_window(&mut self, size: usize) -> FilteredAirBuilder<'_, Self> {
self.when(self.is_transition_window(size))
}

fn assert_zero<I: Into<Self::Expr>>(&mut self, x: I);

fn assert_zeros<const N: usize, I: Into<Self::Expr>>(&mut self, array: [I; N]) {
for elem in array {
self.assert_zero(elem);
}
}

fn assert_bools<const N: usize, I: Into<Self::Expr>>(&mut self, array: [I; N]) {
let zero_array = array.map(|x| x.into().bool_check());
self.assert_zeros(zero_array);
}

fn assert_one<I: Into<Self::Expr>>(&mut self, x: I) {
self.assert_zero(x.into() - Self::Expr::ONE);
}

fn assert_eq<I1: Into<Self::Expr>, I2: Into<Self::Expr>>(&mut self, x: I1, y: I2) {
self.assert_zero(x.into() - y.into());
}

fn assert_bool<I: Into<Self::Expr>>(&mut self, x: I) {
self.assert_zero(x.into().bool_check());
}
*)
Class Run (Self : Set) `{Link Self} : Set := {
}.
End AirBuilder.
4 changes: 4 additions & 0 deletions CoqOfRust/plonky3/baby-bear/src/aarch64_neon/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mod packing;
mod poseidon2;

pub use packing::*;
36 changes: 36 additions & 0 deletions CoqOfRust/plonky3/baby-bear/src/aarch64_neon/packing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use core::arch::aarch64::{int32x4_t, uint32x4_t};
use core::mem::transmute;

use p3_monty_31::{MontyParametersNeon, PackedMontyField31Neon};

use crate::BabyBearParameters;

const WIDTH: usize = 4;

impl MontyParametersNeon for BabyBearParameters {
// SAFETY: This is a valid packed representation of P.
const PACKED_P: uint32x4_t = unsafe { transmute::<[u32; WIDTH], _>([0x78000001; WIDTH]) };
// This MU is the same 0x88000001 as elsewhere, just interpreted as an `i32`.
// SAFETY: This is a valid packed representation of MU.
const PACKED_MU: int32x4_t = unsafe { transmute::<[i32; WIDTH], _>([-0x77ffffff; WIDTH]) };
}

pub type PackedBabyBearNeon = PackedMontyField31Neon<BabyBearParameters>;

#[cfg(test)]
mod tests {
use p3_field_testing::test_packed_field;

use super::WIDTH;
use crate::BabyBear;

const SPECIAL_VALS: [BabyBear; WIDTH] =
BabyBear::new_array([0x00000000, 0x00000001, 0x00000002, 0x78000000]);

test_packed_field!(
crate::PackedBabyBearNeon,
&[crate::PackedBabyBearNeon::ZERO],
&[crate::PackedBabyBearNeon::ONE],
p3_monty_31::PackedMontyField31Neon::<crate::BabyBearParameters>(super::SPECIAL_VALS)
);
}
59 changes: 59 additions & 0 deletions CoqOfRust/plonky3/baby-bear/src/aarch64_neon/poseidon2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//! Eventually this will hold a vectorized Neon implementation of Poseidon2 for PackedBabyBearNeon
//! Currently this is essentially a placeholder to allow compilation and testing on Neon devices.
//!
//! Converting the AVX2/AVX512 code across to Neon is on the TODO list.

#[cfg(test)]
mod tests {
use p3_symmetric::Permutation;
use rand::rngs::SmallRng;
use rand::{Rng, SeedableRng};

use crate::{BabyBear, PackedBabyBearNeon, Poseidon2BabyBear};

type F = BabyBear;
type Perm16 = Poseidon2BabyBear<16>;
type Perm24 = Poseidon2BabyBear<24>;

/// Test that the output is the same as the scalar version on a random input.
#[test]
fn test_neon_poseidon2_width_16() {
let mut rng = SmallRng::seed_from_u64(1);

// Our Poseidon2 implementation.
let poseidon2 = Perm16::new_from_rng_128(&mut rng);

let input: [F; 16] = rng.random();

let mut expected = input;
poseidon2.permute_mut(&mut expected);

let mut neon_input = input.map(Into::<PackedBabyBearNeon>::into);
poseidon2.permute_mut(&mut neon_input);

let neon_output = neon_input.map(|x| x.0[0]);

assert_eq!(neon_output, expected);
}

/// Test that the output is the same as the scalar version on a random input.
#[test]
fn test_neon_poseidon2_width_24() {
let mut rng = SmallRng::seed_from_u64(1);

// Our Poseidon2 implementation.
let poseidon2 = Perm24::new_from_rng_128(&mut rng);

let input: [F; 24] = rng.random();

let mut expected = input;
poseidon2.permute_mut(&mut expected);

let mut neon_input = input.map(Into::<PackedBabyBearNeon>::into);
poseidon2.permute_mut(&mut neon_input);

let neon_output = neon_input.map(|x| x.0[0]);

assert_eq!(neon_output, expected);
}
}
Loading
Loading