pub struct MidnightDataProvider {
pub fetch_mode: FetchMode,
pub base_url: Url,
pub output_mode: OutputMode,
pub expected_data: Vec<(&'static str, [u8; 32], &'static str)>,
pub dir: PathBuf,
}Expand description
Retrieves various static cryptographic artifacts from a data server. This keeps a local file system cache of the parameters, prover keys, verifier keys, and IR, that can also be fetched remotely.
The local cache is located at: $MIDNIGHT_PP / $XDG_CACHE_HOME/midnight/zk-params /
$HOME/.cache/midnight/zk-params in that order of fall-backs.
The provider knows which data is in scope, and the SHA-256 hashes of each of these. When reading one of the values from cache, or fetching them, the SHA-256 hash is verified for integrity.
The data provider can operate in an on-demand, or synchronous mode. In the former, if a datum
is not locally available, it is fetched when requested. In the latter, the datum is only
fetched when explicitly requested via a MidnightDataProvider::fetch call. Key material is
always synchronous.
Fields§
§fetch_mode: FetchModeHow to handle requests to fetch data
base_url: UrlThe base URL of the data store to use.
Fetching an item with name will request it from {base_url}/{name}.
output_mode: OutputModeHow to report status of fetching to the user
expected_data: Vec<(&'static str, [u8; 32], &'static str)>Additional (non-parameter) files allows to be fetched
Triple of file_path, SHA-256 hash, and description
dir: PathBufThe path to the directory where Midnight key material is stored
Implementations§
Source§impl MidnightDataProvider
impl MidnightDataProvider
Sourcepub fn new(
fetch_mode: FetchMode,
output_mode: OutputMode,
expected_data: Vec<(&'static str, [u8; 32], &'static str)>,
) -> Result<MidnightDataProvider, Error>
pub fn new( fetch_mode: FetchMode, output_mode: OutputMode, expected_data: Vec<(&'static str, [u8; 32], &'static str)>, ) -> Result<MidnightDataProvider, Error>
Creates a new data provider with the default base URL.
Examples found in repository?
46async fn async_main() {
47 let engine = Arc::new(ProverEngine::from_env().expect("ProverEngine::from_env"));
48 let uncached_params = MidnightDataProvider::new(
49 moonproof_ledger::base_crypto::data_provider::FetchMode::OnDemand,
50 moonproof_ledger::base_crypto::data_provider::OutputMode::Log,
51 Vec::new(),
52 )
53 .expect("MidnightDataProvider");
54
55 // Warm the cached engine once
56 let warm_p = make_zswap_output_preimage(1);
57 let t0 = Instant::now();
58 let _ = engine
59 .prove_preimage(&warm_p, None, None)
60 .await
61 .expect("warm cached");
62 println!(
63 "zswap/output cached cold (first ever): {:.2} ms",
64 t0.elapsed().as_secs_f64() * 1000.0
65 );
66
67 // Interleaved A/B comparison across 5 pairs
68 let pairs = 5usize;
69 let mut uncached_ms = Vec::with_capacity(pairs);
70 let mut cached_ms = Vec::with_capacity(pairs);
71 for i in 0..pairs {
72 let p = make_zswap_output_preimage(100 + i as u64);
73
74 // A: Uncached legacy path (fresh BuiltinResolver + raw MidnightDataProvider + prove_versioned)
75 let ta = Instant::now();
76 let fresh_builtin = BuiltinResolver::new().expect("fresh builtin");
77 let probe = fresh_builtin
78 .resolve_key(p.key_location.clone())
79 .await
80 .expect("resolve")
81 .expect("some");
82 let (proof_a, _) =
83 prove_versioned(&p, &probe.ir_source, None, &uncached_params, &fresh_builtin)
84 .await
85 .expect("uncached prove");
86 let ms_a = ta.elapsed().as_secs_f64() * 1000.0;
87 assert_ne!(proof_a.0.len(), 0);
88 uncached_ms.push(ms_a);
89
90 // B: Optimized cached ProverEngine path
91 let tb = Instant::now();
92 let res_b = engine
93 .prove_preimage(&p, None, None)
94 .await
95 .expect("cached prove");
96 let ms_b = tb.elapsed().as_secs_f64() * 1000.0;
97 assert_ne!(res_b.proof.len(), 0);
98 cached_ms.push(ms_b);
99
100 println!(
101 "pair {}: uncached={ms_a:>7.2} ms cached={ms_b:>7.2} ms speedup={:.2}x",
102 i + 1,
103 ms_a / ms_b
104 );
105 }
106
107 let pairs_f = f64::from(u32::try_from(pairs).expect("pairs fits u32"));
108 let avg_a: f64 = uncached_ms.iter().sum::<f64>() / pairs_f;
109 let avg_b: f64 = cached_ms.iter().sum::<f64>() / pairs_f;
110 let min_a = uncached_ms.iter().copied().fold(f64::INFINITY, f64::min);
111 let min_b = cached_ms.iter().copied().fold(f64::INFINITY, f64::min);
112 println!(
113 "\n=== zswap/output (v1/v2) A/B SUMMARY ===\n uncached: avg={avg_a:.2} ms min={min_a:.2} ms\n cached: avg={avg_b:.2} ms min={min_b:.2} ms\n speedup: {:.2}x avg ({:.2}x min)",
114 avg_a / avg_b,
115 min_a / min_b,
116 );
117
118 // Interleaved A/B for /check
119 let mut check_body = Vec::new();
120 let payload = (
121 moonproof_prover::ProofPreimageVersioned::V2(Arc::new(warm_p.clone())),
122 None::<moonproof_prover::WrappedIr>,
123 );
124 moonproof_prover::tagged_serialize(&payload, &mut check_body).expect("serialize check");
125 let _ = engine.check_payload(&check_body).await.expect("warm check");
126 let t = Instant::now();
127 let n = 20u32;
128 for _ in 0..n {
129 let _ = engine.check_payload(&check_body).await.expect("check");
130 }
131 println!(
132 "zswap/output cached check_payload: {:.2} ms/iter ({n} iters)",
133 t.elapsed().as_secs_f64() * 1000.0 / f64::from(n)
134 );
135}Trait Implementations§
Source§impl Clone for MidnightDataProvider
impl Clone for MidnightDataProvider
Source§fn clone(&self) -> MidnightDataProvider
fn clone(&self) -> MidnightDataProvider
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl ParamsProverProvider for MidnightDataProvider
impl ParamsProverProvider for MidnightDataProvider
Source§async fn get_params(&self, k: u8) -> Result<ParamsProver, Error>
async fn get_params(&self, k: u8) -> Result<ParamsProver, Error>
k valueSource§impl ParamsProverProvider for MidnightDataProvider
impl ParamsProverProvider for MidnightDataProvider
Source§async fn get_params(&self, k: u8) -> Result<ParamsProver, Error>
async fn get_params(&self, k: u8) -> Result<ParamsProver, Error>
k valueAuto Trait Implementations§
impl Forget for MidnightDataProvider
impl Freeze for MidnightDataProvider
impl Move for MidnightDataProvider
impl RefUnwindSafe for MidnightDataProvider
impl Send for MidnightDataProvider
impl Sync for MidnightDataProvider
impl Unpin for MidnightDataProvider
impl UnsafeUnpin for MidnightDataProviderwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const ArcInner<RwLock<MultiState>> is !null: UnsafeUnpin,
PhantomData<ArcInner<RwLock<MultiState>>>: UnsafeUnpin,
PhantomData<(&'static str, [u8; 32], &'static str)>: UnsafeUnpin,
impl UnwindSafe for MidnightDataProvider
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,
Source§impl<T> Envelope<PhantomData<T>> for T
impl<T> Envelope<PhantomData<T>> for T
Source§fn into_envelope(&self) -> PhantomData<T>
fn into_envelope(&self) -> PhantomData<T>
Source§fn envelope_data(&self) -> Vec<u8> ⓘwhere
T: Serializable + Tagged,
fn envelope_data(&self) -> Vec<u8> ⓘwhere
T: Serializable + Tagged,
Source§fn envelope_write(&self, writer: impl Write) -> Result<(), Error>where
T: Serializable + Tagged,
fn envelope_write(&self, writer: impl Write) -> Result<(), Error>where
T: Serializable + Tagged,
Source§impl<T> Envelope<T> for Twhere
T: Clone,
impl<T> Envelope<T> for Twhere
T: Clone,
Source§fn into_envelope(&self) -> T
fn into_envelope(&self) -> T
Source§fn envelope_data(&self) -> Vec<u8> ⓘwhere
T: Serializable + Tagged,
fn envelope_data(&self) -> Vec<u8> ⓘwhere
T: Serializable + Tagged,
Source§fn envelope_write(&self, writer: impl Write) -> Result<(), Error>where
T: Serializable + Tagged,
fn envelope_write(&self, writer: impl Write) -> Result<(), Error>where
T: Serializable + Tagged,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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 moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> SyncDeps for T
impl<T> SyncDeps for T
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.