Files
powdr/std/field.asm
Georg Wiese 52148be547 Add std::field::known_field() (#1328)
Similar to what we have in Rust, this adds a function that detects
"known" fields (Goldilocks and BN254 for now). Planning to use that in
#1310 to assert that the field extension module is only used with
compatible fields.
2024-04-30 14:19:01 +00:00

24 lines
724 B
Rust

/// A function that returns the current field modulus as an integer.
/// The actual implementation is replaced by a built-in function.
let modulus: -> int = [];
let GOLDILOCKS_PRIME: int = 0xffffffff00000001;
let BN254_PRIME: int = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001;
/// All known fields
enum KnownField {
Goldilocks,
BN254
}
/// Checks whether the function is called in a context where it is operating on
/// any of the known fields.
let known_field: -> Option<KnownField> = || if modulus() == GOLDILOCKS_PRIME {
Option::Some(KnownField::Goldilocks)
} else {
if modulus() == BN254_PRIME {
Option::Some(KnownField::BN254)
} else {
Option::None
}
};