Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ int main(int argc, char** argv)
<< " -indexSet: output the index set of the intersection instead of the set element itself\n"
<< " -noSort: do not require the output to be in the same order and the input (slightly faster).\n"
<< " -malicious: run the protocol with malicious security\n"
<< " -okvs <baxos|ribbon>: select the same OKVS on both parties (default baxos).\n"
<< " -ssp: Statistical Security parameter, default = 40.\n\n"

<< " -ip <value>: IP address and port of the server = PSI receiver. (Default = localhost:1212)\n"
Expand Down
4 changes: 4 additions & 0 deletions frontend/messagePassingExample.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ void messagePassingExampleRun(oc::CLP& cmd)
set[i] = oc::block(0, i);

sender.setMultType(type);
sender.setOkvsType(volePSI::parseOkvsType(cmd.getOr<std::string>("okvs", "baxos")));
sender.init(ns, nr, ssp, oc::sysRandomSeed(), mal, 1, useReducedRounds);

if (verbose)
Expand All @@ -174,6 +175,7 @@ void messagePassingExampleRun(oc::CLP& cmd)

volePSI::RsPsiReceiver recevier;
recevier.setMultType(type);
recevier.setOkvsType(volePSI::parseOkvsType(cmd.getOr<std::string>("okvs", "baxos")));
recevier.init(ns, nr, ssp, oc::sysRandomSeed(), mal, 1, useReducedRounds);

if (verbose)
Expand Down Expand Up @@ -231,6 +233,7 @@ void messagePassingExampleBoth(oc::CLP& cmd)
senderSet[i] = oc::block(0, i);

sender.setMultType(type);
sender.setOkvsType(volePSI::parseOkvsType(cmd.getOr<std::string>("okvs", "baxos")));
sender.init(ns, nr, ssp, oc::sysRandomSeed(), mal, 1, useReducedRounds);

if (verbose)
Expand All @@ -249,6 +252,7 @@ void messagePassingExampleBoth(oc::CLP& cmd)

volePSI::RsPsiReceiver recevier;
recevier.setMultType(type);
recevier.setOkvsType(volePSI::parseOkvsType(cmd.getOr<std::string>("okvs", "baxos")));
recevier.init(ns, nr, ssp, oc::sysRandomSeed(), mal, 1, useReducedRounds);

if (verbose)
Expand Down
2 changes: 2 additions & 0 deletions frontend/networkSocketExample.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void networkSocketExampleRun(const oc::CLP& cmd)
// configure
volePSI::RsPsiSender sender;
sender.setMultType(type);
sender.setOkvsType(volePSI::parseOkvsType(cmd.getOr<std::string>("okvs", "baxos")));
sender.init(ns, nr, ssp, oc::sysRandomSeed(), mal, 1, useReducedRounds);

std::cout << "sender start\n";
Expand All @@ -121,6 +122,7 @@ void networkSocketExampleRun(const oc::CLP& cmd)
// Configure.
volePSI::RsPsiReceiver recevier;
recevier.setMultType(type);
recevier.setOkvsType(volePSI::parseOkvsType(cmd.getOr<std::string>("okvs", "baxos")));
recevier.init(ns, nr, ssp, oc::sysRandomSeed(), mal, 1, useReducedRounds);

std::cout << "recver start\n";
Expand Down
7 changes: 5 additions & 2 deletions frontend/perf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,11 @@ void perfPSI(oc::CLP& cmd)
recv.init(n, n, 40, ZeroBlock, mal, nt);
send.init(n, n, 40, ZeroBlock, mal, nt);

recv.setMultType(type);
send.setMultType(type);
recv.setMultType(type);
send.setMultType(type);
auto okvs = parseOkvsType(cmd.getOr<std::string>("okvs", "baxos"));
recv.setOkvsType(okvs);
send.setOkvsType(okvs);

if (noCompress)
{
Expand Down
2 changes: 2 additions & 0 deletions research/baxos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__/
*.tgz
110 changes: 110 additions & 0 deletions research/baxos/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
Baxos optimization pass -- 2026-11-15
===================================

Result
------
Peach, one thread, 2^20 entries (final repeat, medians after warmup):
operation preserved baseline optimized reduction
encode 104.71 ms 78.19 ms 25.3%
decode 31.98 ms 21.94 ms 31.4%

An earlier run of the same qualified executable measured 78.17 / 21.90
ms. Recompiling changed code layout and produced 78.44 / 22.95 ms in
an intermediate build; retain the raw data rather than attributing every
small timing difference to a specific optimization.

All 21 registered Paxos/Baxos checks pass natively, with ASan/UBSan
(halt on first undefined behavior), and with AVX2 and forced block
arithmetic backends. Tests include GF128/binary, vector/matrix payloads,
forced gaps, randomized/nonrandomized encoding, multiple threads, tail
batches, scalar nonmember checks, add-to-decode, and parameter failures.
The new arithmetic checks compare all SIMD remainders against C++ % and
Horner results against an independent field-power sum at degrees 1, 2, 3, 7, 17, and 40.

Final single-thread encoded tables plus mixed member/nonmember outputs
are byte-identical to the preserved binary at 2^16 and 2^20 entries,
using different matrix/free-cell seeds. Differential hashes, source
manifests, raw CSVs, profiles, and validation logs are under
results/peach-20261115. Full source/binary snapshots and exploratory logs
are archived in out/baxos-opt-20261115/results.tgz. Each manifest identifies
the exact sources used for that build.

Scope
-----
Production Paxos/Baxos code, with unchanged row hashes, table dimensions,
field polynomial, bin assignment, pivot order, and single-thread PRNG
consumption. The Ribbon prototype is separate and was not changed.

Changes
-------
- Remove the encoder's unused input-index mapping and its scattered writes.
- Keep 32-way remainder calculations in SIMD registers. Power-of-two
divisors use an exact mask; general divisors retain libdivide quotients.
- Evaluate the dense polynomial with Horner's rule: d field multiplies
instead of 2*d-1. Eight rows run together using AVX-512 VPCLMUL, AVX2
VPCLMUL, or the existing block multiplication backend. Custom helpers
and matrix-valued elements retain the original generic implementation.
- Track the XOR of active row indices per column. Weight-one columns can
select their sole row without scanning stale adjacency entries. Keep
the existing weight-set order and gap handling.
- Reuse Paxos's owned arena when its capacity suffices.

Correctness fixes found during validation
----------------------------------------
Parallel randomized encoding previously passed the same mutable PRNG to
all workers. Workers now receive separately seeded PRNGs before launch.
Single-thread consumption is unchanged. Parallel randomized tables and
parent-PRNG consumption change from the previous racy implementation;
for a fixed thread count and seed they are now independent of scheduling.
The regression checks repeated encodes, parent state, and decoded values.

The scalar hash row builder read a u64 at a four-byte offset through a
u64 pointer. Fixed-size memcpy loads retain the same bytes without the
alignment/aliasing violation. Scratch arenas now place pointer-aligned
span objects before narrower index arrays. This removes misalignment
for odd row counts without adding padding or changing table contents.

Benchmark method
----------------
Peach Ryzen 7950X, one thread pinned to CPU 2, GCC 15.2, -O3 -march=native,
2^20 keys, 128-bit values, bin target 2^14, weight 3, SSP 40, GF128 dense
columns. The resulting table has 1,411,712 cells and two dense columns
per bin. Fresh allocation and randomized free cells on every encode;
queries are half members and half independent keys. Eight trials, with
the first excluded from the reported median. All benchmarks, builds,
and tests take the shared volepsi, hypercat, and cat-blst locks.

Timing includes initialization and output allocation for encoding, and
all hashing, binning, arithmetic, scattering, and scratch allocation /
destruction. Verification is outside timed regions. These are standalone
OKVS measurements, not PSI totals. No huge-page advice was added.

Baseline executable and source snapshots are preserved. perf samples
identified dense decode, modular row construction, binning, and sparse
triangulation as the major costs. Raw profiles include setup overhead
and are diagnostic, not the source of reported wall timings.

Reproduction
------------
Working remote directory: /tmp/baxos-opt-20261115
Dependencies: /tmp/volepsi-chosenbaa30-20261115
Copy volePSI/, tests/Paxos_Tests.*, bench.cpp, tests.cpp, and peach.py to
that directory before running the following commands. The build links
the existing dependencies while compiling the edited template headers.

python3 peach.py build --exe qualified
python3 peach.py bench --exe qualified --out qualified-after
python3 peach.py test --exe final-native-tests
python3 peach.py sanitize --exe final-sanitize-tests
python3 peach.py test --exe avx2-tests --isa avx2
python3 peach.py test --exe scalar-tests --isa scalar

The avx2 build disables AVX-512 and exercises two-lane VPCLMUL plus the
AVX2 remainder product. The scalar build forces the eight independent block evaluators
(128-bit PCLMUL on Peach). cryptoTools itself retains its configured
VPCLMUL requirements; the override affects only the new Baxos kernel. These
checks do not substitute for native ARM measurements.

Next step
---------
Rerun single-thread semi-honest PSI on Peach to measure the end-to-end gain.
43 changes: 43 additions & 0 deletions research/baxos/bench.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <volePSI/Paxos.h>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <fstream>
using namespace volePSI;
using Clock=std::chrono::steady_clock;
double ms(Clock::time_point t) {return std::chrono::duration<double,std::milli>(Clock::now()-t).count();}
int main(int argc,char** argv) {
try {
unsigned logn=argc>1?std::stoul(argv[1]):20,trials=argc>2?std::stoul(argv[2]):8;
std::string mode=argc>3?argv[3]:"both";
std::size_t n=std::size_t(1)<<logn;
PRNG input(oc::toBlock(20261115));
std::vector<block> keys(n),values(n),queries(n),out(n);
input.get(keys.data(),n);input.get(values.data(),n);input.get(queries.data(),n);
std::copy_n(keys.data(),n/2,queries.data());
std::cout<<"trial,n,m,dense,encode_ms,decode_ms\n"<<std::fixed<<std::setprecision(5);
for(unsigned trial=0;trial<trials;++trial) {
auto t=Clock::now();
Baxos b;b.init(n,1<<14,3,40,PaxosParam::GF128,oc::toBlock(trial+100));
std::vector<block> cells(b.size());PRNG rng(oc::toBlock(trial+200));
b.solve<block>(keys,values,cells,&rng,1);
double enc=ms(t),dec=0;
if(mode!="encode") {
t=Clock::now();b.decode<block>(queries,out,cells,1);dec=ms(t);
for(std::size_t i=0;i<n/2;++i) if(out[i]!=values[i]) throw std::runtime_error("mixed member mismatch");
if(mode=="decode") for(unsigned j=0;j<20;++j) b.decode<block>(queries,out,cells,1);
}
if(mode=="both") {
b.decode<block>(keys,out,cells,1);
if(out!=values) throw std::runtime_error("member mismatch");
}
std::cout<<trial<<','<<n<<','<<b.size()<<','<<b.mPaxosParam.mDenseSize<<','<<enc<<','<<dec<<'\n'<<std::flush;
if(mode=="dump") {
std::ofstream f(argv[4],std::ios::binary);
f.write(reinterpret_cast<char*>(cells.data()),cells.size()*sizeof(block));
b.decode<block>(queries,out,cells,1);
f.write(reinterpret_cast<char*>(out.data()),out.size()*sizeof(block));
}
}
} catch(const std::exception& e) {std::cerr<<e.what()<<'\n';return 1;}
}
50 changes: 50 additions & 0 deletions research/baxos/peach.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import argparse,fcntl,hashlib,json,os,subprocess,time
from pathlib import Path
p=argparse.ArgumentParser();p.add_argument('action',choices=['build','test','sanitize','bench','profile','dump']);p.add_argument('--exe',default='baseline');p.add_argument('--out',default='baseline');p.add_argument('--root',default='.');p.add_argument('--mode',default='both');p.add_argument('--trials',default=8,type=int);p.add_argument('--logn',default=20,type=int)
p.add_argument('--isa',choices=['native','avx2','scalar'],default='native')
a=p.parse_args();here=Path(__file__).resolve().parent
locks=[]
for name in ['volepsi-benchmark.lock','hypercat-global-benchmark.lock','cat-blst-benchmark.lock']:
f=open('/tmp/'+name,'a');fcntl.flock(f,fcntl.LOCK_EX|fcntl.LOCK_NB);locks.append(f)
base=Path('/tmp/volepsi-chosenbaa30-20261115');env=dict(os.environ,LD_LIBRARY_PATH=str(base/'deps/lib'),UBSAN_OPTIONS='halt_on_error=1:print_stacktrace=1')
exe=here/a.exe
if a.action in ['build','test','sanitize']:
flags=['-std=c++20','-march=native','-O3','-g1','-DNDEBUG','-pthread',
'-DCRYPTOTOOLS_EDWARDS25519_ASM=1','-I'+str((here/a.root).resolve()),
'-I'+str(base/'psi-build'),'-I'+str(base/'psi'),
'-isystem',str(base/'install/include'),'-isystem',str(base/'deps/include')]
libs=[str(base/'psi-build/volePSI/libvolePSI.a')]
libs += [str(base/'install/lib'/x) for x in ['liblibOTe.a','libcryptoTools.a']]
libs += [str(base/'deps/lib'/x) for x in ['libsodium.a','libcoproto.a','libmacoro.a','libbitpolymul.a']]
if a.isa=='avx2': flags+=['-mno-avx512f']
if a.isa=='scalar': flags+=['-mno-avx512f','-DVOLEPSI_PAXOS_FORCE_SCALAR']
sources_to_compile=[str(here/'bench.cpp')]
if a.action in ['test','sanitize']:
sources_to_compile=[str(here/'tests.cpp'),str(here/'tests/Paxos_Tests.cpp')]
flags+=['-UNDEBUG']
if a.action=='sanitize': flags+=['-O1','-fsanitize=address,undefined','-fno-omit-frame-pointer']
command=['g++',*flags,*sources_to_compile,*libs,'-o',str(exe)]
subprocess.run(command,env=env,check=True)
sources={}
snap=here/(a.exe+'-sources');snap.mkdir(exist_ok=True)
for name in ['Paxos.h','PaxosImpl.h','PxUtil.h','PaxosGf128.h']:
data=(here/a.root/'volePSI'/name).read_bytes();sources[name]=hashlib.sha256(data).hexdigest();(snap/name).write_bytes(data)
for source in sources_to_compile:
path=Path(source);data=path.read_bytes();sources[str(path.relative_to(here))]=hashlib.sha256(data).hexdigest();(snap/path.name).write_bytes(data)
(here/(a.exe+'-build.json')).write_text(json.dumps(dict(command=command,sources=sources),indent=2))
if a.action in ['test','sanitize']:
r=subprocess.run([str(exe)],env=env,text=True,capture_output=True)
(here/(a.exe+'-tests.txt')).write_text(r.stdout+r.stderr)
print(r.stdout+r.stderr);r.check_returncode()
else:
out=here/'results';out.mkdir(exist_ok=True)
command=['taskset','-c','2',str(exe),str(a.logn),str(a.trials),a.mode]
if a.action=='profile': command=['perf','record','-o',str(out/(a.out+'.data')),'--',*command]
if a.action=='dump': command+= [str(out/(a.out+'.bin'))]
r=subprocess.run(command,env=env,text=True,capture_output=True,check=True)
(out/(a.out+'.csv')).write_text(r.stdout);(out/(a.out+'.stderr')).write_text(r.stderr)
meta=dict(cpu=subprocess.check_output(['lscpu'],text=True),compiler=subprocess.check_output(['g++','--version'],text=True).splitlines()[0],frequency={name:Path('/sys/devices/system/cpu/cpu2/cpufreq',name).read_text().strip() for name in ['scaling_governor','scaling_min_freq','scaling_max_freq']},command=command,time_utc=time.strftime('%Y-%m-%dT%H:%M:%SZ',time.gmtime()),binary_sha256=hashlib.sha256(exe.read_bytes()).hexdigest(),build=json.loads((here/(a.exe+'-build.json')).read_text()))
(out/(a.out+'.json')).write_text(json.dumps(meta,indent=2));print(r.stdout)
if a.action=='profile':
report=subprocess.check_output(['perf','report','-i',str(out/(a.out+'.data')),'--stdio','--no-children','--percent-limit','1'],text=True)
(out/(a.out+'-profile.txt')).write_text(report);print(report[:14000])
25 changes: 25 additions & 0 deletions research/baxos/tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "tests/Paxos_Tests.h"
#include <iostream>
int main(int argc,char** argv) {try {oc::CLP cmd; cmd.parse(argc,argv);
Baxos_randomized_parallel_determinism_Test(cmd);std::cout<<"PASS Baxos_randomized_parallel_determinism_Test\n"<<std::flush;
Paxos_dense_kernel_Test(cmd);std::cout<<"PASS Paxos_dense_kernel_Test\n"<<std::flush;
Paxos_mod32_Test(cmd);std::cout<<"PASS Paxos_mod32_Test\n"<<std::flush;
Baxos_dense_reference_Test(cmd);std::cout<<"PASS Baxos_dense_reference_Test\n"<<std::flush;
Paxos_buildRow_Test(cmd);std::cout<<"PASS Paxos_buildRow_Test\n"<<std::flush;
Paxos_solve_Test(cmd);std::cout<<"PASS Paxos_solve_Test\n"<<std::flush;
Paxos_solve_u8_Test(cmd);std::cout<<"PASS Paxos_solve_u8_Test\n"<<std::flush;
Paxos_solve_mtx_Test(cmd);std::cout<<"PASS Paxos_solve_mtx_Test\n"<<std::flush;
Paxos_invE_Test(cmd);std::cout<<"PASS Paxos_invE_Test\n"<<std::flush;
Paxos_invE_g3_Test(cmd);std::cout<<"PASS Paxos_invE_g3_Test\n"<<std::flush;
Paxos_solve_gap_Test(cmd);std::cout<<"PASS Paxos_solve_gap_Test\n"<<std::flush;
Paxos_solve_rand_Test(cmd);std::cout<<"PASS Paxos_solve_rand_Test\n"<<std::flush;
Paxos_solve_rand_gap_Test(cmd);std::cout<<"PASS Paxos_solve_rand_gap_Test\n"<<std::flush;
Baxos_solve_Test(cmd);std::cout<<"PASS Baxos_solve_Test\n"<<std::flush;
Baxos_solve_mtx_Test(cmd);std::cout<<"PASS Baxos_solve_mtx_Test\n"<<std::flush;
Baxos_solve_par_Test(cmd);std::cout<<"PASS Baxos_solve_par_Test\n"<<std::flush;
Baxos_solve_rand_Test(cmd);std::cout<<"PASS Baxos_solve_rand_Test\n"<<std::flush;
Baxos_bin_overflow_Test(cmd);std::cout<<"PASS Baxos_bin_overflow_Test\n"<<std::flush;
Baxos_bin_size_Test(cmd);std::cout<<"PASS Baxos_bin_size_Test\n"<<std::flush;
Baxos_decode_weight_overflow_Test(cmd);std::cout<<"PASS Baxos_decode_weight_overflow_Test\n"<<std::flush;
Baxos_idxtype_sentinel_and_params_Test(cmd);std::cout<<"PASS Baxos_idxtype_sentinel_and_params_Test\n"<<std::flush;
}catch(const std::exception& e){std::cerr<<e.what()<<"\n";return 1;}}
8 changes: 8 additions & 0 deletions research/ribbon/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
__pycache__/
bench
bench-sanitize
*-command.json
*.log
BaselineRibbon.h
differential
differential-sanitize
Loading
Loading