Skip to content

Commit

Permalink
Add Poseidon const tables and deduce_output (#444)
Browse files Browse the repository at this point in the history
Co-Authored-By: Dan Carmon <[email protected]>
  • Loading branch information
anatgstarkware and Dan Carmon authored Feb 18, 2025
1 parent 7952d80 commit 6a879b6
Show file tree
Hide file tree
Showing 4 changed files with 409 additions and 2 deletions.
17 changes: 16 additions & 1 deletion stwo_cairo_prover/crates/common/src/prover_types/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ pub const FELT252WIDTH27_BITS_PER_WORD: usize = 27;

pub const P_PACKED27_FELTS: [u32; FELT252WIDTH27_N_WORDS] = [1, 0, 0, 0, 0, 0, 0, 136, 0, 256];
/// A version of Felt252 whose values are packed into 27-bit limbs instead of 9-bit.
/// The only supported operations are conversions to and from Felt252.
/// The only supported operations are conversions to and from Felt252 and FieldElement.
#[derive(Copy, Clone, Debug, Serialize, Deserialize, Default, Eq, PartialEq, Hash)]
pub struct Felt252Width27 {
pub limbs: [u64; 4],
Expand Down Expand Up @@ -648,6 +648,21 @@ impl From<Felt252Width27> for Felt252 {
}
}

// Convert between Felt252Width27 and FieldElement for performing field operations.
// See the documentation of the conversions between Felt252<>FieldElement for more details.
impl From<Felt252Width27> for FieldElement {
fn from(n: Felt252Width27) -> FieldElement {
FieldElement::from_mont(n.limbs) + FieldElement::ZERO
}
}
impl From<FieldElement> for Felt252Width27 {
fn from(n: FieldElement) -> Felt252Width27 {
Felt252Width27 {
limbs: n.into_mont(),
}
}
}

impl ProverType for Felt252Width27 {
fn calc(&self) -> String {
format!(
Expand Down
Loading

0 comments on commit 6a879b6

Please sign in to comment.