Skip to content

Commit d04f1f5

Browse files
Merge branch 'main' into add_bn254_to_prover_example
2 parents 61c9765 + 3b16015 commit d04f1f5

File tree

4 files changed

+824
-0
lines changed

4 files changed

+824
-0
lines changed

math/src/field/fields/fft_friendly/quartic_babybear.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ use crate::field::{
88
#[cfg(feature = "lambdaworks-serde-binary")]
99
use crate::traits::ByteConversion;
1010

11+
#[cfg(all(feature = "lambdaworks-serde-binary", feature = "alloc"))]
12+
use crate::traits::AsBytes;
13+
1114
/// We are implementig the extension of Baby Bear of degree 4 using the irreducible polynomial x^4 + 11.
1215
/// BETA = 11 and -BETA = -11 is the non-residue.
1316
pub const BETA: FieldElement<Babybear31PrimeField> =
@@ -262,6 +265,59 @@ impl ByteConversion for [FieldElement<Babybear31PrimeField>; 4] {
262265
}
263266
}
264267

268+
#[cfg(feature = "lambdaworks-serde-binary")]
269+
impl ByteConversion for FieldElement<Degree4BabyBearExtensionField> {
270+
fn to_bytes_be(&self) -> alloc::vec::Vec<u8> {
271+
let mut byte_slice = ByteConversion::to_bytes_be(&self.value()[0]);
272+
byte_slice.extend(ByteConversion::to_bytes_be(&self.value()[1]));
273+
byte_slice.extend(ByteConversion::to_bytes_be(&self.value()[2]));
274+
byte_slice.extend(ByteConversion::to_bytes_be(&self.value()[3]));
275+
byte_slice
276+
}
277+
278+
fn to_bytes_le(&self) -> alloc::vec::Vec<u8> {
279+
let mut byte_slice = ByteConversion::to_bytes_le(&self.value()[0]);
280+
byte_slice.extend(ByteConversion::to_bytes_le(&self.value()[1]));
281+
byte_slice.extend(ByteConversion::to_bytes_le(&self.value()[2]));
282+
byte_slice.extend(ByteConversion::to_bytes_le(&self.value()[3]));
283+
byte_slice
284+
}
285+
286+
fn from_bytes_be(bytes: &[u8]) -> Result<Self, crate::errors::ByteConversionError>
287+
where
288+
Self: Sized,
289+
{
290+
const BYTES_PER_FIELD: usize = 8;
291+
let x0 = FieldElement::from_bytes_be(&bytes[0..BYTES_PER_FIELD])?;
292+
let x1 = FieldElement::from_bytes_be(&bytes[BYTES_PER_FIELD..BYTES_PER_FIELD * 2])?;
293+
let x2 = FieldElement::from_bytes_be(&bytes[BYTES_PER_FIELD * 2..BYTES_PER_FIELD * 3])?;
294+
let x3 = FieldElement::from_bytes_be(&bytes[BYTES_PER_FIELD * 3..BYTES_PER_FIELD * 4])?;
295+
296+
Ok(Self::new([x0, x1, x2, x3]))
297+
}
298+
299+
fn from_bytes_le(bytes: &[u8]) -> Result<Self, crate::errors::ByteConversionError>
300+
where
301+
Self: Sized,
302+
{
303+
const BYTES_PER_FIELD: usize = 8;
304+
let x0 = FieldElement::from_bytes_le(&bytes[0..BYTES_PER_FIELD])?;
305+
let x1 = FieldElement::from_bytes_le(&bytes[BYTES_PER_FIELD..BYTES_PER_FIELD * 2])?;
306+
let x2 = FieldElement::from_bytes_le(&bytes[BYTES_PER_FIELD * 2..BYTES_PER_FIELD * 3])?;
307+
let x3 = FieldElement::from_bytes_le(&bytes[BYTES_PER_FIELD * 3..BYTES_PER_FIELD * 4])?;
308+
309+
Ok(Self::new([x0, x1, x2, x3]))
310+
}
311+
}
312+
313+
#[cfg(feature = "lambdaworks-serde-binary")]
314+
#[cfg(feature = "alloc")]
315+
impl AsBytes for FieldElement<Degree4BabyBearExtensionField> {
316+
fn as_bytes(&self) -> alloc::vec::Vec<u8> {
317+
self.to_bytes_be()
318+
}
319+
}
320+
265321
impl IsFFTField for Degree4BabyBearExtensionField {
266322
const TWO_ADICITY: u64 = 29;
267323
const TWO_ADIC_PRIMITVE_ROOT_OF_UNITY: Self::BaseType = [

provers/stark/src/examples/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ pub mod fibonacci_2_columns;
55
pub mod fibonacci_rap;
66
pub mod quadratic_air;
77
pub mod read_only_memory;
8+
pub mod read_only_memory_logup;
89
pub mod simple_fibonacci;
910
pub mod simple_periodic_cols;

0 commit comments

Comments
 (0)