refactor(stark): uniform Coset trait, fallible LiftedDomain constructors#993
Draft
refactor(stark): uniform Coset trait, fallible LiftedDomain constructors#993
Conversation
Adds a `Coset<F>` trait with required `(log_size, shift, generator)` plus defaults for `size`, `point_at`, `points`, `bit_reversed_points`, `vanishing_at`, `contains`, `generator_inverse`, and a cached `shift_inverse` (`F::ONE` for subgroup; stored field on coset). Both `TwoAdicSubgroup` and `TwoAdicCoset` impl the trait; `LiftedDomain` does not — composing a trace subgroup and an LDE coset, it disambiguates via explicit `trace_subgroup()` / `lde_coset()` accessors rather than silently picking one vanishing polynomial. Drops dead/redundant `LiftedDomain` methods (`points`, `bit_reversed_points`, `point_at`, `lde_subgroup`, `is_in_*`, `is_lifted`, `blowup`, `max_lde_height`, `log_max_lde_height`, `log_lift_ratio` getter, `lifted_trace_vanishing_at`); call sites now go through `domain.lde_coset()`. Selector logic (`selectors`, `selectors_at`) moves from the coset/subgroup types into `LiftedDomain` where the lift-ratio context lives. `log_blowup` returns `u8` to match its sibling `log_*` accessors. Also renames `*coset` bindings/params/fields holding `LiftedDomain` to `*domain` for consistency, and threads `Committed::max_domain` / `FriTranscript<&TwoAdicSubgroup>` to keep the type-driven height metadata flowing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…domains `LiftedDomain::canonical`, `sub_domain`, `evaluation_coset`, and `selectors` now return `Result<_, DomainError>`. Construction success is the validation evidence: holding a `LiftedDomain<F>` means its parameters are bounds-checked. Verifier and prover entry points propagate errors via `?`; downstream sites that derive from validated inputs use `.expect()` with strings documenting the upstream check. Added `LiftedDomain::sub_domains(impl IntoIterator<Item = u8>)` for the common "build per-instance sub-domains from a list of heights" pattern, collapsing a 5-line `iter().map().collect::<Result<_, _>>()` chain to one accessor. `commit_traces` now takes `&[LiftedDomain<F>]` instead of a separate `max_domain` and re-deriving sub-domain shifts internally — the prover already builds the per-instance domains, so threading them through removes a fragile `sub_domain(h).expect().lde_shift()` chain and the `assert_eq!(traces.last().height(), max_domain.trace_height())` check (now per-trace, stronger). Renamed `instance::validate_inputs` to the method `InstanceShapes::validate`, returning the validated max log trace height. AIR/instance-contract checks live there; LDE-bound checks moved to `LiftedDomain::canonical`. Added `LogTraceHeightTooLarge` variant to `InstanceValidationError` to keep `validate` panic-free against adversarial `1usize << log_h` overflow. `DomainError` is wired into both `VerifierError` and `ProverError` via `#[from]`. New tests: `canonical_too_large_returns_error`, `sub_domain_too_large_returns_error`, `evaluation_coset_too_large_returns_error`, and `malformed_log_trace_heights_is_rejected` updated to distinguish the two failure paths. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reshapes the lifted-STARK domain layer (
miden-lifted-stark) into a small hierarchy with explicit fallibility, eliminating ambient panic risk in the verifier path.Coset hierarchy (commit 1,
65b7ef9c7):domain.rsmodule withTwoAdicSubgroup<F>⊂TwoAdicCoset<F>⊂LiftedDomain<F>.Cosettrait owns the shared(log_size, shift, generator)interface and provides default bodies forpoints,bit_reversed_points,vanishing_at,contains,point_at,size,generator_inverse,shift_inverse(cached).LiftedDomaindeliberately does not implementCoset— it composes a trace subgroup and an LDE coset; callers saydomain.trace_subgroup()ordomain.lde_coset()to disambiguate vanishing polynomials.LiftedDomainaccessors that silently picked the LDE side.LiftedDomainwhere the lift ratio lives.Fallible constructors + statically-validated batch domains (commit 2,
29f2584a9):LiftedDomain::canonical,sub_domain,evaluation_coset,selectorsnow returnResult<_, DomainError>. Holding aLiftedDomain<F>is the validation evidence.InstanceShapes::validate(renamed fromvalidate_inputs) returns the validated max log trace height; LDE-bound checks moved toLiftedDomain::canonical.LiftedDomain::sub_domains(impl IntoIterator<Item = u8>)collapses the per-instance sub-domain construction to one accessor.commit_tracestakes&[LiftedDomain<F>]instead of re-deriving sub-domain shifts internally.DomainErrorflows into bothVerifierErrorandProverErrorvia#[from].Test plan
cargo test -p miden-lifted-stark(92 tests pass)cargo check -p miden-lifted-stark --benches --features testingmake docmake lint(clippy + fmt + taplo + typos all clean;cargo shearstep skipped — tool not installed locally)🤖 Generated with Claude Code