Skip to main content

InputPair

Struct InputPair 

Source
pub struct InputPair<T, F1, F2> { /* private fields */ }
Expand description

Pre-generated inputs for timing tests.

Both baseline() and sample() call their respective closures to generate values. This symmetric design ensures both classes have identical calling patterns.

§Type Parameters

  • T: The input type (e.g., [u8; 32], Vec<u8>)
  • F1: The baseline closure type
  • F2: The sample closure type

§Example

use tacet::helpers::InputPair;

// Both are closures (symmetric)
let inputs = InputPair::new(
    || [0u8; 32],          // baseline closure
    || rand::random(),     // sample closure
);

// Use in test - both call their closures
let baseline_val = inputs.baseline();
let sample_val = inputs.sample();

Implementations§

Source§

impl<T, F1, F2> InputPair<T, F1, F2>
where T: Clone + Hash, F1: FnMut() -> T, F2: FnMut() -> T,

Source

pub fn new(baseline: F1, sample: F2) -> Self

Create a new input pair with anomaly detection.

Both arguments are closures that generate input values.

§Arguments
  • baseline: Closure that generates the baseline value (typically constant)
  • sample: Closure that generates varied sample values
§Type Requirements
  • T: Clone for internal operations
  • T: Hash for anomaly detection (use new_untracked for non-Hash types)
§Example
let inputs = InputPair::new(
    || [0u8; 32],                // baseline: returns constant value
    || rand::random::<[u8; 32]>() // sample: generates varied values
);
Source

pub fn new_unchecked(baseline: F1, sample: F2) -> Self

Create a new input pair without anomaly detection.

Use this when you intentionally use deterministic inputs (e.g., fixed nonces, pre-generated signatures) and want to suppress the “identical values” warning.

§Example
// Testing with fixed nonces - intentionally deterministic
let nonces = InputPair::new_unchecked(
    || [0x00u8; 12],  // Fixed nonce A
    || [0xFFu8; 12],  // Fixed nonce B
);
Source

pub fn baseline(&self) -> T

Generate a baseline value by calling the baseline closure.

Returns T by calling the baseline closure each time.

let inputs = InputPair::new(|| [0u8; 32], || rand::random());
let val = inputs.baseline();  // Calls || [0u8; 32]
Source

pub fn sample(&self) -> T

Generate a sample value with anomaly tracking.

Calls the sample closure and tracks the hash for anomaly detection (only the first ANOMALY_DETECTION_WINDOW samples are tracked).

Note: This method includes tracking overhead. For timing-critical code, use generate_sample() during pre-generation and check anomalies after.

Source

pub fn generate_sample(&self) -> T

Generate a sample value without anomaly tracking.

Use this for pre-generating inputs before measurement. After pre-generation, call track_value() on each value to enable anomaly detection.

This is used internally by TimingOracle::test() to avoid overhead during the measurement loop.

Source

pub fn generate_baseline(&self) -> T

Generate a baseline value without any overhead.

Identical to baseline() but named for symmetry with generate_sample().

Source

pub fn track_value(&self, value: &T)

Track a sample value for anomaly detection.

Call this on pre-generated sample values to enable anomaly detection without adding overhead during measurement.

Source

pub fn check_anomaly(&self) -> Option<String>

Check if the sample generator appears to be producing constant values.

Returns a warning message if anomaly detected, None otherwise. Should be called after measurement completes.

§Detected Anomalies
ConditionSeverityMessage
All samples identicalErrorLikely captured pre-evaluated value
<50% unique samplesWarningLow entropy, possible mistake
Normal entropyOKNone
§Example
// After running the test
if let Some(warning) = inputs.check_anomaly() {
    eprintln!("[tacet] {}", warning);
}
Source§

impl<T, F1, F2> InputPair<T, F1, F2>
where T: Clone, F1: FnMut() -> T, F2: FnMut() -> T,

Source

pub fn new_untracked(baseline: F1, sample: F2) -> Self

Create without anomaly detection (for non-Hash types).

Use this when T doesn’t implement Hash (e.g., cryptographic scalars, field elements, big integers).

§Example
// Scalar type that doesn't implement Hash
let inputs = InputPair::new_untracked(
    || Scalar::zero(),
    || Scalar::random(&mut rng)
);
Source

pub fn baseline_untracked(&self) -> T

Generate a baseline value (untracked version).

Source

pub fn sample_untracked(&self) -> T

Generate a sample value without tracking (for non-Hash types).

Source

pub fn check_anomaly_untracked(&self) -> Option<String>

Check anomaly - always returns None for untracked InputPairs.

This method exists so code can call check_anomaly() uniformly without knowing whether tracking is enabled.

Auto Trait Implementations§

§

impl<T, F1, F2> !Freeze for InputPair<T, F1, F2>

§

impl<T, F1, F2> !RefUnwindSafe for InputPair<T, F1, F2>

§

impl<T, F1, F2> Send for InputPair<T, F1, F2>
where F1: Send, F2: Send, T: Send,

§

impl<T, F1, F2> !Sync for InputPair<T, F1, F2>

§

impl<T, F1, F2> Unpin for InputPair<T, F1, F2>
where T: Unpin, F1: Unpin, F2: Unpin,

§

impl<T, F1, F2> UnsafeUnpin for InputPair<T, F1, F2>
where F1: UnsafeUnpin, F2: UnsafeUnpin,

§

impl<T, F1, F2> UnwindSafe for InputPair<T, F1, F2>
where T: UnwindSafe, F1: UnwindSafe, F2: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more