Skip to content
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

Add M31 as known field #2341

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pipeline/tests/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::BTreeMap;

use powdr_executor::constant_evaluator;
use powdr_linker::{LinkerMode, LinkerParams};
use powdr_number::{BabyBearField, FieldElement, GoldilocksField};
use powdr_number::{BabyBearField, FieldElement, GoldilocksField, Mersenne31Field};
use powdr_pipeline::{
test_util::{
asm_string_to_pil, make_prepared_pipeline, make_simple_prepared_pipeline,
Expand Down Expand Up @@ -187,6 +187,9 @@ fn block_to_block_with_bus_monolithic() {
let pipeline = make_simple_prepared_pipeline::<BabyBearField>(f, LinkerMode::Bus);
test_mock_backend(pipeline.clone());
test_plonky3_pipeline(pipeline);
let pipeline = make_simple_prepared_pipeline::<Mersenne31Field>(f, LinkerMode::Bus);
test_mock_backend(pipeline.clone());
test_plonky3_pipeline(pipeline);
}

#[test]
Expand Down
9 changes: 8 additions & 1 deletion std/field.asm
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ let BN254_PRIME: int = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f59
let GOLDILOCKS_PRIME: int = 0xffffffff00000001;
let KOALABEAR_PRIME: int = 2**31 - 2**24 + 1;
let BABYBEAR_PRIME: int = 0x78000001;
let M31_PRIME: int = 2**31 - 1;

/// All known fields
enum KnownField {
BN254,
Goldilocks,
KoalaBear,
BabyBear,
M31
}

/// Checks whether the function is called in a context where it is operating on
Expand All @@ -29,7 +31,11 @@ let known_field: -> Option<KnownField> = || if modulus() == BABYBEAR_PRIME {
if modulus() == BN254_PRIME {
Option::Some(KnownField::BN254)
} else {
Option::None
if modulus() == M31_PRIME {
Option::Some(KnownField::M31)
} else {
Option::None
}
}
}
}
Expand All @@ -40,5 +46,6 @@ let require_known_field: KnownField, (-> string) -> () = |f, err| match (f, know
(KnownField::Goldilocks, Option::Some(KnownField::Goldilocks)) => (),
(KnownField::KoalaBear, Option::Some(KnownField::KoalaBear)) => (),
(KnownField::BabyBear, Option::Some(KnownField::BabyBear)) => (),
(KnownField::M31, Option::Some(KnownField::M31)) => (),
_ => std::check::panic(err()),
};
1 change: 1 addition & 0 deletions std/math/extension_field.asm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let required_extension_size: -> int = || match known_field() {
Option::Some(KnownField::BN254) => 1,
Option::Some(KnownField::BabyBear) => 4,
Option::Some(KnownField::KoalaBear) => 4,
Option::Some(KnownField::M31) => 4,
None => panic("The permutation/lookup argument is not implemented for the current field!")
};

Expand Down
1 change: 1 addition & 0 deletions std/protocols/bus.asm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ let bus_interaction: expr, expr[], expr, expr -> () = constr |id, tuple, multipl
Option::Some(KnownField::Goldilocks) => true,
Option::Some(KnownField::BabyBear) => true,
Option::Some(KnownField::KoalaBear) => true,
Option::Some(KnownField::M31) => true,
// The case above triggers our hand-written witness generation, but on Bn254, we'd not be
// on the extension field and use the automatic witness generation.
// However, it does not work with a materialized folded tuple. At the same time, Halo2
Expand Down
Loading