prism_numerics/polynomial.rs
1//! `PolynomialShape<MAX_DEGREE, COEFF_BYTES>` — ADR-031 named
2//! numerics shape carrier.
3//!
4//! Per [Wiki ADR-031][09-adr-031], prism-numerics ships
5//! `Polynomial<MaxDegree, Coeff>` as one of its canonical shape
6//! declarations alongside `BigInt<MaxBits>`, `FixedPoint<I, F>`, and
7//! `FieldElement<P>`.
8//!
9//! This carrier is `MAX_DEGREE + 1` coefficient slots of `COEFF_BYTES`
10//! each, packed big-endian — coefficient `c_i` lives at byte offset
11//! `i * COEFF_BYTES`. Total site count: `(MAX_DEGREE + 1) * COEFF_BYTES`.
12//!
13//! Per ADR-017's closure rule the IRI is the foundation's shared
14//! `ConstrainedType` class; instance identity flows through
15//! `(SITE_COUNT, CONSTRAINTS)`. The shape carries no admission
16//! constraints; application authors that need degree-bound, sparsity,
17//! or coefficient-range admission discipline declare additional
18//! `ConstraintRef` predicates in a newtype wrapper.
19//!
20//! Horner evaluation (`prism::numerics`'s `horner` verb in the ADR-031
21//! roster) and polynomial multiplication compose this shape with
22//! substrate `PrimitiveOp::{Add, Mul}` per ADR-050's width-parametric
23//! evaluation discipline.
24//!
25//! [09-adr-031]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
26
27use uor_foundation::enforcement::GroundedShape;
28use uor_foundation::pipeline::{ConstrainedTypeShape, ConstraintRef, IntoBindingValue, TermValue};
29
30/// Parametric `ConstrainedTypeShape` for a degree-`MAX_DEGREE` polynomial
31/// with `COEFF_BYTES`-wide coefficients (big-endian).
32///
33/// Carries `MAX_DEGREE + 1` coefficient slots — index `i` holds the
34/// `x^i` coefficient. The shape's identity flows through its byte-site
35/// count per ADR-017.
36#[derive(Debug, Clone, Copy)]
37pub struct PolynomialShape<const MAX_DEGREE: usize, const COEFF_BYTES: usize>;
38
39impl<const MAX_DEGREE: usize, const COEFF_BYTES: usize> Default
40 for PolynomialShape<MAX_DEGREE, COEFF_BYTES>
41{
42 fn default() -> Self {
43 Self
44 }
45}
46
47impl<const MAX_DEGREE: usize, const COEFF_BYTES: usize> ConstrainedTypeShape
48 for PolynomialShape<MAX_DEGREE, COEFF_BYTES>
49{
50 const IRI: &'static str = "https://uor.foundation/type/ConstrainedType";
51 const SITE_COUNT: usize = (MAX_DEGREE + 1) * COEFF_BYTES;
52 const CONSTRAINTS: &'static [ConstraintRef] = &[];
53 #[allow(clippy::cast_possible_truncation)]
54 const CYCLE_SIZE: u64 = 256u64.saturating_pow(((MAX_DEGREE + 1) * COEFF_BYTES) as u32);
55}
56
57impl<const MAX_DEGREE: usize, const COEFF_BYTES: usize> uor_foundation::pipeline::__sdk_seal::Sealed
58 for PolynomialShape<MAX_DEGREE, COEFF_BYTES>
59{
60}
61impl<const MAX_DEGREE: usize, const COEFF_BYTES: usize> GroundedShape
62 for PolynomialShape<MAX_DEGREE, COEFF_BYTES>
63{
64}
65impl<'a, const MAX_DEGREE: usize, const COEFF_BYTES: usize> IntoBindingValue<'a>
66 for PolynomialShape<MAX_DEGREE, COEFF_BYTES>
67{
68 fn as_binding_value<const INLINE_BYTES: usize>(&self) -> TermValue<'a, INLINE_BYTES> {
69 TermValue::empty()
70 }
71}
72
73/// Degree-7 polynomial with 32-byte (256-bit) coefficients — canonical
74/// shape for cryptographic polynomial commitments operating in a
75/// `Z/(2^256)Z` coefficient ring.
76pub type Polynomial7Mod256 = PolynomialShape<7, 32>;
77
78/// Degree-15 polynomial with 32-byte coefficients — the depth-4
79/// Merkle / KZG canonical commitment width.
80pub type Polynomial15Mod256 = PolynomialShape<15, 32>;