pub struct PixParams {
polys_per_ssa: u16,
shares_per_poly: u8,
surplus_shares: u8,
suite: PixSuite,
}Expand description
Everything about PIX two nodes must agree on for a Session, and the only encoding of it: three dimensions and the curve suite they are dimensions of.
The same quadruple is packed into two different wire fields — the SsaRequest params word and
the upper half of StartInitiation::additional_data — and both go through this type. Every
earlier version of this had the shifts written out by hand at each site, in two mutually
inconsistent shapes, which is why the packing lives behind a constructor rather than in the
callers.
Named fields rather than a (u16, u8, u8, PixSuite) tuple: polys_per_ssa and shares_per_poly
are interchangeable to the type system and not interchangeable to the protocol, while their
product — which is all the Exit compares — is identical either way. A transposition therefore
announced valid-looking dimensions against a correct quota, and the only thing that caught it was
SessionManager::new_session requiring both to match the locally installed generator exactly,
which is a check about something else entirely.
The fields are private because try_new is what enforces the ranges; holding a
PixParams is what makes to_u32 infallible.
The suite is here for the same reason the dimensions are: it is something both
nodes must agree on, and equality of this type is what the Entry already checks against the
Exit’s echo, so carrying it here gets that direction for free. Note that it is not a dimension —
it does not enter the quota — so code that speaks about what the deposit buys is right to name
only the other three.
Fields§
§polys_per_ssa: u16§suite: PixSuiteImplementations§
Source§impl PixParams
impl PixParams
Sourcepub const fn try_new(
polys_per_ssa: u16,
shares_per_poly: u8,
surplus_shares: u8,
suite: PixSuite,
) -> Result<Self, InvalidPixParams>
pub const fn try_new( polys_per_ssa: u16, shares_per_poly: u8, surplus_shares: u8, suite: PixSuite, ) -> Result<Self, InvalidPixParams>
Validates and assembles the quadruple.
Sourcepub fn try_new_for<S: PixSpec>(
polys_per_ssa: u16,
shares_per_poly: u8,
surplus_shares: u8,
) -> Result<Self, InvalidPixParams>
pub fn try_new_for<S: PixSpec>( polys_per_ssa: u16, shares_per_poly: u8, surplus_shares: u8, ) -> Result<Self, InvalidPixParams>
Validates and assembles the dimensions under the curve suite of S.
The constructor to prefer wherever a concrete spec is in scope, because it makes the suite impossible to state wrongly: the shares a node produces and the suite it announces then come from the same place.
Sourcepub fn try_from_config<S: PixSpec>(
cfg: &SsaGeneratorConfig,
) -> Result<Self, InvalidPixParams>
pub fn try_from_config<S: PixSpec>( cfg: &SsaGeneratorConfig, ) -> Result<Self, InvalidPixParams>
The SsaGeneratorConfig’s dimensions under the curve suite of S.
The Entry’s only source of a PixParams: the dimensions and the surplus are properties of
the installed generator, and the suite is a property of the spec that generator is
instantiated over — neither is something a Session caller gets to pick.
Fallible because SsaGeneratorConfig’s fields are public and its ranges are enforced by
validator rather than by construction.
Sourcepub const fn polys_per_ssa(&self) -> u16
pub const fn polys_per_ssa(&self) -> u16
Number of polynomials the SSA secret is split across.
Shares required to reconstruct one polynomial.
Shares emitted per polynomial beyond shares_per_poly, to absorb
losses.
Total shares the Entry emits per polynomial, i.e. threshold plus surplus.
Widened to u16 because the sum of two u8s does not fit one.
Sourcepub const fn suite(&self) -> PixSuite
pub const fn suite(&self) -> PixSuite
The elliptic curve suite these parameters were produced under.
Sourcepub const fn to_u32(&self) -> u32
pub const fn to_u32(&self) -> u32
Packs into 32 bits: suite in bits 31..30, polys_per_ssa in bits 29..16,
shares_per_poly in bits 15..8, and surplus_shares in bits 7..0.
Sourcepub const fn try_from_u32(packed: u32) -> Result<Self, InvalidPixParams>
pub const fn try_from_u32(packed: u32) -> Result<Self, InvalidPixParams>
Inverse of to_u32, rejecting out-of-range values and unknown suites.
§Compatibility with words packed before the suite existed
Those words carried the polynomial count in the full top 16 bits, but the count is bounded by
MAX_POLYS_PER_SSA and so never set the two the suite now occupies. Reading such a word
therefore yields PixSuite::BabyJubJub, which is what those builds ran by default. In the
other direction a peer that predates this field rejects a Secp256k1 word outright: the
suite bit reads to it as a polynomial count of at least 16 384, above the maximum it already
enforced. Neither side mis-parses the other; both refuse.
Sourcepub const fn into_additional_data(self, surb_target: u32) -> u64
pub const fn into_additional_data(self, surb_target: u32) -> u64
Packs into the upper half of a StartInitiation::additional_data word, leaving surb_target
in the lower half.
The two halves are the whole of that field: there is no room left in it to negotiate anything further.
Sourcepub const fn try_from_additional_data(
additional_data: u64,
) -> Result<Self, InvalidPixParams>
pub const fn try_from_additional_data( additional_data: u64, ) -> Result<Self, InvalidPixParams>
Inverse of into_additional_data, ignoring the SURB target in
the lower half.
Trait Implementations§
impl Copy for PixParams
impl Eq for PixParams
impl StructuralPartialEq for PixParams
Auto Trait Implementations§
impl Freeze for PixParams
impl RefUnwindSafe for PixParams
impl Send for PixParams
impl Sync for PixParams
impl Unpin for PixParams
impl UnsafeUnpin for PixParams
impl UnwindSafe for PixParams
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more