Skip to content

Baxos encoding crashes when using PRNG input in parallel threads. #5

Closed

Description

@Ame-ReIori

Hello, I want to encode an OKVS object with baxos.solve. In addition, I want to input a PRNG for randomizing all 0 positions in the OKVS objects and make the encoding phase parallel. However, a segmentation fault always occurs when running the statement like baxos.solve<block>(in, values, okvs, &prng, kThrdNum);

Here is my code, which may reproduce the above error.

int main() {
  uint64_t kItemNum = 1ull << 20;
  int kBinSize = 1 << 14;
  int kCuckooHashNum = 3;
  int kLambda = 40;
  int kThrdNum = 8;

  PRNG prng(sysRandomSeed());
  std::vector<block> in(kItemNum);
  std::vector<block> values(kItemNum);

  prng.get<block>(in);
  prng.get<block>(values);

  volePSI::Baxos baxos;
  baxos.init(kItemNum, kBinSize, kCuckooHashNum, kLambda,
             volePSI::PaxosParam::GF128, AllOneBlock);

  std::vector<block> okvs(baxos.size());
  baxos.solve<block>(in, values, okvs, &prng, kThrdNum);
}

Activity

  1. verdelyi commented on Nov 16, 2026

    @verdelyi

    We hit the same crash and tracked it down; details below in case they help.

    Disclosure: this was found by Claude (Anthropic's AI model) during an audit of code that uses volePSI, and Claude
    drafted this comment. Every number comes from a run that was actually made.

    Cause. In Baxos::implParSolve (volePSI/PaxosImpl.h) every worker thread passes the same PRNG* to
    paxos.encode(values, output, h, prng). PRNG is not thread-safe: two threads advancing its buffer position at
    once can push it past the end of the buffer, after which PRNG::implGet copies out of bounds (the segfault in this
    issue). RsOpprfSender::send passes a PRNG too, so the OPPRF and circuit-PSI senders hit this with more than one
    thread.

    Still present on current main (f46d8bb, pinned dependencies, Release, x86-64, GCC 14.2): upstream's own
    frontend -perf -cpsi -nn 22 segfaults 3 of 3 runs at 8 threads and 5 of 5 at 4 threads. A direct
    Baxos::solve<block>(..., &prng, nt) with the OPPRF parameters crashes in 26 to 50 of 50 runs at 8 threads for
    n = 2^16 to 2^20 (and already 24 of 50 at 2 threads for n = 2^18).

    Fix. Seed one PRNG per worker from the caller's before the threads start (11 lines). With it: 0 crashes in all of
    the above, no decode mismatches, and frontend -u passes (56 tests). One side effect: for a given seed the solved
    table changes, which no test depends on.

    --- a/volePSI/PaxosImpl.h
    +++ b/volePSI/PaxosImpl.h
    @@ -2783,8 +2783,18 @@
     		std::promise<void> hashingDoneProm;
     		auto hashingDoneFu = hashingDoneProm.get_future().share();
     
    +		// PRNG is not thread-safe, so give each worker its own, seeded from the caller's.
    +		std::vector<PRNG> thrdPrngs;
    +		if (prng)
    +		{
    +			thrdPrngs.reserve(numThreads);
    +			for (u64 t = 0; t < numThreads; ++t)
    +				thrdPrngs.emplace_back(prng->get<block>());
    +		}
    +
     		auto processBins = [&](u64 thrdIdx, bool& countedDone)
     		{
    +			PRNG* thrdPrng = prng ? &thrdPrngs[thrdIdx] : nullptr;
     			auto begin = (inputs_.size() * thrdIdx) / numThreads;
     			auto end = (inputs_.size() * (thrdIdx + 1)) / numThreads;
     			auto inputs = inputs_.subspan(begin, end - begin);
    @@ -2986,7 +2996,7 @@
     				}
     
     				paxos.setInput(rows, hashes, cols, colBacking, colWeights);
    -				paxos.encode(values, output, h, prng);
    +				paxos.encode(values, output, h, thrdPrng);
     
     			}
     		};

    Happy to open a pull request with this and a multi-threaded Baxos::solve test with a PRNG.

  2. ladnir commented on Nov 16, 2026

    @ladnir
    Owner

    yeah, working on a fix and a larger update. getting faster and hardening the implementation/cryptography

  3. ladnir commented on Nov 18, 2026

    @ladnir
    Owner

    Fixed in #18: parallel Baxos now uses an independent PRNG per worker. On current main, 50 eight-thread randomized solve/decode runs at 2^20 items and 100 at 2^18 completed without a crash or mismatch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions