From fd0332b9ea7d8f74bfeec250cdfef1c866131bde Mon Sep 17 00:00:00 2001 From: Eli Baum Date: Wed, 2 Sep 2026 21:23:32 -0400 Subject: [PATCH 1/3] Batch verifier consistent-input into two exchange rounds. Collapse the 24 serial F_ConsistentShare calls in CheckEqs into a single public-schedule batch so Phase A needs two network rounds instead of ~48. Co-authored-by: Cursor --- include/core/protocols/verifier_4pc.h | 278 +++++++++++++++++++++----- 1 file changed, 225 insertions(+), 53 deletions(-) diff --git a/include/core/protocols/verifier_4pc.h b/include/core/protocols/verifier_4pc.h index 0ae0ea2d..1103061a 100644 --- a/include/core/protocols/verifier_4pc.h +++ b/include/core/protocols/verifier_4pc.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -109,58 +110,203 @@ class Verifier_4PC : public VerifierBase { const int num_threads; /** - * @brief Party Pi shares GF2E element x with two other parties, who then gossip to confirm - * consistency. Fourth party only uses a common PRG to set its shares, and does not communicate. - * Share xi (not held by the sending party) is kept at zero. + * @brief Batched F_ConsistentShare for many (Pi, x) pairs. * - * @param Pi - * @param x - * @return EVector + * Public schedule: slot k is dealt by dealers[k]. The plaintext values[k] is + * consumed only if me == dealers[k]; otherwise it is ignored (never sent). + * + * Round structure (2 network rounds): + * R1: every dealer sends share[Pg] to {Pj, Ph} (multi-exchange) + * R2: Pj <-> Ph gossip share[Pg] and compare (multi-exchange) + * + * PRG advance order matches the old per-call loop (lockstep over slots). */ - EVector consistent_input_from(PartyID Pi, NTL::GF2E& x) { - Vector shares(4); + EVector consistent_input_batch(const std::vector& dealers, const Vector& values) { + const size_t n = dealers.size(); + assert(values.size() == n); + + // Per-slot absolute shares; share[Pi] stays 0 by public convention. + // IMPORTANT: Vector's copy ctor is shallow — do not use vector(n, Vector(4)). + std::vector shares; + shares.reserve(n); + for (size_t k = 0; k < n; k++) { + shares.emplace_back(4); + } + + // Outbound distribute buffers keyed by absolute peer. + std::vector> dist_send(4); - // arbitrary - PartyID Pj = (Pi + 1) % 4; - PartyID Pg = (Pi + 2) % 4; - PartyID Ph = (Pi + 3) % 4; + // Expected receive: for slots where we are Pj/Ph, one share from Pi. + std::vector dist_from(n, -1); - // Let share Pi be zero: everyone knows it, so no use generating. + for (size_t k = 0; k < n; k++) { + PartyID Pi = dealers[k]; + PartyID Pj = (Pi + 1) % 4; + PartyID Pg = (Pi + 2) % 4; + PartyID Ph = (Pi + 3) % 4; - if (me != Pj) { - this->randomnessManager->commonPRGManager->get({Pi, Pg, Ph})->getNext(shares[Pj]); + // Same PRG calls / groups as consistent_input_from — all parties + // advance in public slot order (roles decide who calls which PRG). + if (me != Pj) { + this->randomnessManager->commonPRGManager->get({Pi, Pg, Ph}) + ->getNext(shares[k][Pj]); + } + if (me != Ph) { + this->randomnessManager->commonPRGManager->get({Pi, Pj, Pg}) + ->getNext(shares[k][Ph]); + } + + if (me == Pi) { + shares[k][Pg] = values[k] - shares[k][Pi] - shares[k][Pj] - shares[k][Ph]; + dist_send[Pj].push_back(shares[k][Pg]); + dist_send[Ph].push_back(shares[k][Pg]); + } else if (me == Pj || me == Ph) { + dist_from[k] = Pi; + } } - if (me != Ph) { - this->randomnessManager->commonPRGManager->get({Pi, Pj, Pg})->getNext(shares[Ph]); + // ---- R1: distribute Pi -> {Pj, Ph} via one multi-exchange ---- + // Lengths are a function of the public dealer schedule only. + std::vector> send_bufs, recv_bufs; + std::vector to_ids, from_ids; + std::vector peer_order; + + for (PartyID p = 0; p < 4; p++) { + if (p == me) { + continue; + } + // Always include all 3 peers so the round shape is identical for + // every party (empty payload if this edge is unused). Empty ≠ trusted + // zero share: we never read recv data on unused edges. + peer_order.push_back(p); + to_ids.push_back(abs2rel(p)); + from_ids.push_back(abs2rel(p)); + + // Recv element count must match peer's send count — publicly computable: + size_t expect = 0; + for (size_t k = 0; k < n; k++) { + PartyID Pi = dealers[k]; + if (Pi != p) { + continue; + } + PartyID Pj = (Pi + 1) % 4; + PartyID Ph = (Pi + 3) % 4; + if (me == Pj || me == Ph) { + expect++; + } + } + + // MPI exchangeShares requires equal send/recv sizes on each edge. + // Pad both directions to max(...); only the real prefix is used. + const size_t nbytes = math::gf2e_num_bytes(); + const size_t send_elms = dist_send[p].size(); + const size_t edge_elms = std::max(send_elms, expect); + + orq::Vector send_buf(edge_elms * nbytes); + if (send_elms > 0) { + auto packed = serializeGF2E(std::span(dist_send[p])); + std::copy(packed.begin(), packed.end(), send_buf.begin()); + } + send_bufs.push_back(std::move(send_buf)); + recv_bufs.push_back(orq::Vector(edge_elms * nbytes)); + } + + this->communicator->exchangeShares(send_bufs, recv_bufs, to_ids, from_ids); + + // Unpack only on edges where dist_from[k] == peer (designated Pi). + // Recv buffers may be padded; only the real prefix (expect elms) is valid. + for (size_t i = 0; i < peer_order.size(); i++) { + PartyID p = peer_order[i]; + + size_t expect = 0; + for (size_t k = 0; k < n; k++) { + if (dist_from[k] == p) { + expect++; + } + } + if (expect == 0) { + continue; + } + + Vector recv = deserializeGF2E(recv_bufs[i].data(), expect); + size_t t = 0; + for (size_t k = 0; k < n; k++) { + if (dist_from[k] != p) { + continue; + } + PartyID Pg = (dealers[k] + 2) % 4; + shares[k][Pg] = recv[t++]; + } + assert(t == recv.size()); } - if (me == Pi) { - shares[Pg] = x - shares[Pi] - shares[Pj] - shares[Ph]; - // These could happen in parallel... maybe using multi-send? + // ---- R2: Pj <-> Ph gossip + equality check ---- + std::vector> gossip_send(4); + std::vector gossip_peer(n, -1); + + for (size_t k = 0; k < n; k++) { + PartyID Pi = dealers[k]; + PartyID Pj = (Pi + 1) % 4; + PartyID Pg = (Pi + 2) % 4; + PartyID Ph = (Pi + 3) % 4; + if (me == Pj || me == Ph) { + PartyID other = (me == Pj) ? Ph : Pj; + gossip_peer[k] = other; + gossip_send[other].push_back(shares[k][Pg]); + } + } - this->communicator->sendShare(shares[Pg], abs2rel(Pj)); - this->communicator->sendShare(shares[Pg], abs2rel(Ph)); - } else if (me == Pj || me == Ph) { - // Pj or Ph receive x_g from Pi - this->communicator->receiveShare(shares[Pg], abs2rel(Pi)); + send_bufs.clear(); + recv_bufs.clear(); + to_ids.clear(); + from_ids.clear(); + peer_order.clear(); - PartyID other = (me == Pj) ? Ph : Pj; + for (PartyID p = 0; p < 4; p++) { + if (p == me) { + continue; + } + peer_order.push_back(p); + to_ids.push_back(abs2rel(p)); + from_ids.push_back(abs2rel(p)); - this->communicator->sendShare(shares[Pg], abs2rel(other)); + send_bufs.push_back(serializeGF2E(std::span(gossip_send[p]))); + // Symmetric: peer sends us one element per slot where we gossip with them. + recv_bufs.push_back(orq::Vector(send_bufs.back().size())); + } - NTL::GF2E check; - this->communicator->receiveShare(check, abs2rel(other)); + this->communicator->exchangeShares(send_bufs, recv_bufs, to_ids, from_ids); - if (check != shares[Pg]) { - std::cout << "P" << me << ": Inconsistent share with P" << other << " via sender P" - << Pi << "\n"; - malicious_check_ok.clear(); + for (size_t i = 0; i < peer_order.size(); i++) { + PartyID p = peer_order[i]; + if (recv_bufs[i].size() == 0) { + continue; + } + size_t elms = recv_bufs[i].size() / math::gf2e_num_bytes(); + Vector check = deserializeGF2E(recv_bufs[i].data(), elms); + size_t t = 0; + for (size_t k = 0; k < n; k++) { + if (gossip_peer[k] != p) { + continue; + } + PartyID Pg = (dealers[k] + 2) % 4; + if (check[t++] != shares[k][Pg]) { + std::cout << "P" << me << ": Inconsistent share with P" << p << " via sender P" + << dealers[k] << "\n"; + malicious_check_ok.clear(); + } } + assert(t == check.size()); } - return {shares.singleton((me + 1) % 4), shares.singleton((me + 2) % 4), - shares.singleton((me + 3) % 4)}; + // Build EVector result: my three held shares per slot. + Vector s0(n), s1(n), s2(n); + for (size_t k = 0; k < n; k++) { + s0[k] = shares[k][(me + 1) % 4]; + s1[k] = shares[k][(me + 2) % 4]; + s2[k] = shares[k][(me + 3) % 4]; + } + return EVector({s0, s1, s2}); } /** @@ -210,34 +356,60 @@ class Verifier_4PC : public VerifierBase { // Create a length-12 Vector of hashes in canonical order (4 parties * 3 roles) EVector hashes(hash_size); - auto idx = -1; + // Public canonical PA order (same as before). + std::vector pas; + pas.reserve(hash_size); for (int i = 0; i < 4; i++) { for (int j = i + 1; j < 4; j++) { for (int r = 0; r < 4; r++) { if (i == r || j == r) { continue; } - - idx++; - - auto pa = _jmp_assignments(i, j, r); - auto hash = aggregate_hashes_by_pa[pa]; - - // These are each 2 rounds - // TODO: consolidate into one function call? - // Maybe add hashing, then check after the loop - // There really could just be a SINGLE check outside this loop. - auto sr = consistent_input_from(pa.receiver, hash); - auto sh = consistent_input_from(pa.hasher, hash); - - // Insert both into the hashes vec - hashes.slice(idx, idx + 1) = sh + sr; + pas.push_back(_jmp_assignments(i, j, r)); + } + } + } + assert(pas.size() == hash_size); + + // Slot layout (public), interleaved like the original loop: + // for each PA k: dealers[2k]=receiver, dealers[2k+1]=hasher. + // values[i] is only read when me == dealers[i]. + std::vector dealers(2 * hash_size); + Vector values(2 * hash_size); + for (size_t k = 0; k < hash_size; k++) { + dealers[2 * k] = pas[k].receiver; + dealers[2 * k + 1] = pas[k].hasher; + + auto it = aggregate_hashes_by_pa.find(pas[k]); + const bool have = (it != aggregate_hashes_by_pa.end()); + + // Only the designated dealer may supply a digest for this PA. + // Missing digest while being dealer => check fails (do not treat as valid share of 0). + if (me == pas[k].receiver) { + if (!have) { + malicious_check_ok.clear(); + } else { + values[2 * k] = it->second; + } + } + if (me == pas[k].hasher) { + if (!have) { + malicious_check_ok.clear(); + } else { + values[2 * k + 1] = it->second; } } + // else: values left default; ignored because me != dealers[i] } - // 12 * 4 = 48 rounds overall... - // Could be two rounds (send, confirm), or one if we combine with next + // 2 rounds total (was ~48 sequential send/recv pairs) + EVector shared = consistent_input_batch(dealers, values); + + // hashes[k] = share(d^H) + share(d^R) for PA k (char-2 field: equal digests => 0) + for (size_t k = 0; k < hash_size; k++) { + hashes.slice(k, k + 1) = + shared.slice(2 * k + 1, 2 * k + 2) + shared.slice(2 * k, 2 * k + 1); + } // Can do a single unified hash check at the end (per share) if (this->randomnessManager->csq->commitmentsAvailable() < 16) { // TODO: this may not be synchronized! From b99206cbe2ef56c32c8eb101013aeb553a130fcf Mon Sep 17 00:00:00 2001 From: Eli Baum Date: Wed, 2 Sep 2026 22:12:33 -0400 Subject: [PATCH 2/3] update some scripts for testing --- bench/micro/micro_sorting.cpp | 8 ++++---- scripts/comm/wan-sim.py | 4 ++-- scripts/profiling/4pc-prof.sh | 37 +++++++++++++++++++++++------------ 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/bench/micro/micro_sorting.cpp b/bench/micro/micro_sorting.cpp index 02653306..1693ce34 100644 --- a/bench/micro/micro_sorting.cpp +++ b/bench/micro/micro_sorting.cpp @@ -28,10 +28,10 @@ int main(int argc, char** argv) { stopwatch::timepoint("Quicksort"); stopwatch::profile_done(); - runTime->mark_statistics(); - orq::operators::bitonic_sort(b); - stopwatch::timepoint("Bitonic"); - runTime->print_statistics(); + // runTime->mark_statistics(); + // orq::operators::bitonic_sort(b); + // stopwatch::timepoint("Bitonic"); + // runTime->print_statistics(); runTime->mark_statistics(); orq::operators::pairwise_sort(b); diff --git a/scripts/comm/wan-sim.py b/scripts/comm/wan-sim.py index 596c49bc..678ea640 100755 --- a/scripts/comm/wan-sim.py +++ b/scripts/comm/wan-sim.py @@ -5,11 +5,11 @@ import sys # Simulated WAN (modeling AWS-GCP interconnect) uses 12Gbps and 13 ms RTT. -BANDWIDTH_LIMIT = "12Gbit" +BANDWIDTH_LIMIT = "1Gbit" # this is the PER LINK latency; actual RTT will be double. # e.g. 40ms => 80ms RTT. -LATENCY = "6.5ms" +LATENCY = "10ms" def get_interface_for_host(host): try: diff --git a/scripts/profiling/4pc-prof.sh b/scripts/profiling/4pc-prof.sh index 891a89eb..13f92327 100755 --- a/scripts/profiling/4pc-prof.sh +++ b/scripts/profiling/4pc-prof.sh @@ -3,23 +3,34 @@ mkdir json-out THR=16 -REP=3 +REP=5 +SETTING=lan +# run_4pc_exp [size_arg] +# size_arg is passed through to run_experiment.py (e.g. "-f 1" or "-r 2^10"). +# If omitted: queries (q*) default to "-f 1"; others use run_experiment defaults. run_4pc_exp() { exp=$1 - path=json-out/$exp - mkdir $path + size_arg=${2:-} + explicit_size=0 + if [[ -n "${2:-}" ]]; then + explicit_size=1 + fi - # for queries, run SF 1. Otherwise, use defaults - if [[ $exp == q* ]]; then + if [[ -z "$size_arg" && $exp == q* ]]; then size_arg="-f 1" - else - size_arg="" fi + path=json-out/$exp + # Nest by size only when the caller passed an explicit size (e.g. sorting sweep) + if [[ $explicit_size -eq 1 ]]; then + size_tag=$(echo "$size_arg" | tr -d ' -') + path=json-out/$exp/$size_tag + fi + mkdir -p $path # Dalskov without check - baseline - ../scripts/run_experiment.py -s lan -o 3 -p 4 -T $THR -n 4 -e $REP \ + ../scripts/run_experiment.py -s $SETTING -o 3 -p 4 -T $THR -n 4 -e $REP \ -m=-DEXTRA=-DSKIP_MALICIOUS_CHECK=1 \ -m=-DUSE_DALSKOV_FANTASTIC_FOUR=ON \ $size_arg $exp @@ -27,23 +38,23 @@ run_4pc_exp() { mv output.json $path/baseline.json # Standard 4PC - Dalskov with check - ../scripts/run_experiment.py -s lan -o 3 -p 4 -T $THR -n 4 -e $REP \ + ../scripts/run_experiment.py -s $SETTING -o 3 -p 4 -T $THR -n 4 -e $REP \ -m=-DEXTRA= \ $size_arg $exp mv output.json $path/fixed.json - ../scripts/run_experiment.py -s lan -o 3 -p 4 -T $THR -n 4 -e $REP \ + ../scripts/run_experiment.py -s $SETTING -o 3 -p 4 -T $THR -n 4 -e $REP \ -m=-DUSE_DALSKOV_FANTASTIC_FOUR=OFF \ $size_arg $exp mv output.json $path/custom.json } -# TODO: figure out sizes. -run_4pc_exp micro_sorting +run_4pc_exp micro_sorting "-r 2^10,2^12,2^14,2^16,2^18,2^20,2^22,2^24,2^26,2^28" + run_4pc_exp q11 run_4pc_exp q22 run_4pc_exp q12 run_4pc_exp q8 -run_4pc_exp q21 \ No newline at end of file +run_4pc_exp q21 From bf1bc8065e32b4e94b11de0a5e272be75de76ffc Mon Sep 17 00:00:00 2001 From: Eli Baum Date: Wed, 2 Sep 2026 22:20:41 -0400 Subject: [PATCH 3/3] only 3 reps for now --- scripts/profiling/4pc-prof.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/profiling/4pc-prof.sh b/scripts/profiling/4pc-prof.sh index 13f92327..37f8b298 100755 --- a/scripts/profiling/4pc-prof.sh +++ b/scripts/profiling/4pc-prof.sh @@ -3,7 +3,7 @@ mkdir json-out THR=16 -REP=5 +REP=3 SETTING=lan # run_4pc_exp [size_arg]