fix(prf): set correct default logic (#873)

This commit is contained in:
th4s
2025-05-20 15:22:34 +02:00
committed by GitHub
parent d924bd6deb
commit db53814ee7
6 changed files with 16 additions and 19 deletions

View File

@@ -238,7 +238,7 @@ pub enum NetworkSetting {
impl Default for NetworkSetting {
fn default() -> Self {
Self::Bandwidth
Self::Latency
}
}

View File

@@ -19,13 +19,16 @@ fn criterion_benchmark(c: &mut Criterion) {
group.sample_size(10);
let rt = tokio::runtime::Runtime::new().unwrap();
group.bench_function("prf", |b| b.to_async(&rt).iter(prf));
group.bench_function("prf_normal", |b| b.to_async(&rt).iter(|| prf(Mode::Normal)));
group.bench_function("prf_reduced", |b| {
b.to_async(&rt).iter(|| prf(Mode::Reduced))
});
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
async fn prf() {
async fn prf(mode: Mode) {
let mut rng = StdRng::seed_from_u64(0);
let pms = [42u8; 32];
@@ -52,8 +55,8 @@ async fn prf() {
follower_vm.assign(follower_pms, pms).unwrap();
follower_vm.commit(follower_pms).unwrap();
let mut leader = MpcPrf::new(Mode::default());
let mut follower = MpcPrf::new(Mode::default());
let mut leader = MpcPrf::new(mode);
let mut follower = MpcPrf::new(mode);
let leader_output = leader.alloc(&mut leader_vm, leader_pms).unwrap();
let follower_output = follower.alloc(&mut follower_vm, follower_pms).unwrap();

View File

@@ -8,9 +8,3 @@ pub enum Mode {
/// Computes the whole PRF in MPC.
Normal,
}
impl Default for Mode {
fn default() -> Self {
Self::Reduced
}
}

View File

@@ -69,9 +69,9 @@ impl Config {
}
impl ConfigBuilder {
/// Optimizes the protocol for low bandwidth networks.
pub fn low_bandwidth(&mut self) -> &mut Self {
self.prf = Some(PrfMode::Reduced);
/// Optimizes the protocol for high bandwidth networks.
pub fn high_bandwidth(&mut self) -> &mut Self {
self.prf = Some(PrfMode::Normal);
self
}
@@ -105,7 +105,7 @@ impl ConfigBuilder {
.max_recv_records
.unwrap_or_else(|| PROTOCOL_RECORD_COUNT_RECV + default_record_count(max_recv));
let prf = self.prf.unwrap_or_default();
let prf = self.prf.unwrap_or(PrfMode::Reduced);
Ok(Config {
defer_decryption,

View File

@@ -55,8 +55,8 @@ impl ProverConfig {
builder.max_recv_records(max_recv_records);
}
if let NetworkSetting::Latency = self.protocol_config.network() {
builder.low_bandwidth();
if let NetworkSetting::Bandwidth = self.protocol_config.network() {
builder.high_bandwidth();
}
builder.build().unwrap()

View File

@@ -58,8 +58,8 @@ impl VerifierConfig {
builder.max_recv_records(max_recv_records);
}
if let NetworkSetting::Latency = protocol_config.network() {
builder.low_bandwidth();
if let NetworkSetting::Bandwidth = protocol_config.network() {
builder.high_bandwidth();
}
builder.build().unwrap()