Skip to content

Feature/20 rayon parallelism#23

Open
xoredtwice wants to merge 6 commits into
QuipNetwork:mainfrom
xoredtwice:feature/20-rayon-parallelism
Open

Feature/20 rayon parallelism#23
xoredtwice wants to merge 6 commits into
QuipNetwork:mainfrom
xoredtwice:feature/20-rayon-parallelism

Conversation

@xoredtwice

Copy link
Copy Markdown
Contributor

Summary

This MR introduces an optional parallel feature using Rayon to enable parallel computation of WOTS+ chain segments while preserving deterministic ordering and RFC-compatible behavior.

Changes

  • Optional parallel feature (Rayon-based)
  • Refactored chain segment computation to use:
    + par_iter().map().collect()
    • Sequential fallback when parallel is disabled
  • Minor cleanup, removed duplicate code in verify() and verify_with_randomization_elements() and safety assertions
  • Keccak256 function to compare the performace of parallel and sequential flows (Later we should consider proper benchmarking using criterion)

Security & Correctness Notes

  • Parallelization only applied at chain-segment level (outer loop)
  • Internal hash-chain loop remains sequential (cryptographically required)
  • Output ordering preserved (Rayon collect() guarantees order)
  • No shared mutable state in parallel blocks
  • Signature size invariants maintained

Testing

Tested with:

cargo test
cargo test --features parallel
cargo test --no-default-features --features parallel

All tests pass in both sequential and parallel modes.

@augmentcode

augmentcode Bot commented Feb 24, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: Adds an optional Rayon-based parallel execution path for WOTS+ chain-segment computation while keeping outputs deterministic and RFC-compatible.

Changes:

  • Introduced Cargo features: default solana and optional parallel (Rayon).
  • Added a SignatureBuffer helper to build signature/public-key byte buffers with reduced duplication and controlled sizing.
  • Refactored signing to compute per-segment chains in parallel via par_iter().map(...).collect(), with a sequential fallback.
  • Refactored verification to reuse verify_with_randomization_elements() and optionally parallelize per-segment reconstruction.
  • Extracted repeated per-segment logic into compute_chain_segment().
  • Updated tests to include a Keccak256-based hash function (via sha3), plus determinism and SignatureBuffer behavior tests.

Technical Notes: Parallelism is limited to independent outer segments; internal per-chain hashing remains sequential, and ordering is preserved by collecting from Rayon’s indexed iterators.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 4 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread src/lib.rs

#[cfg(feature = "parallel")]
use rayon::prelude::*;
use std::time::Instant;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use std::time::Instant; is in the main library module but only used in the test module, which can break cargo build-sbf/no-std-ish Solana builds (and also creates an unused-import warning in non-test builds). Consider gating it with #[cfg(test)] or moving it into the tests module.

Severity: high

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Comment thread src/lib.rs
{
let Self::Array { buf, len } = self;
let end = *len + data.len();
buf[*len..end].copy_from_slice(data);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the non-solana SignatureBuffer::push_slice branch, an overflow will panic via slice indexing rather than an explicit invariant check, so the failure mode/message is much less clear than the solana branch. Consider adding an explicit length bound check here as well so callers get a predictable panic reason.

Severity: low

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Comment thread Cargo.toml

[dependencies]
rayon = { version = "1.8", optional = true }
sha3 = "0.10"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sha3 is listed under [dependencies] but appears to be used only from #[cfg(test)] code, so it will be pulled into all downstream builds (including the Solana program). Consider moving it to [dev-dependencies] (or gating it) to avoid inflating the dependency graph for library consumers.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Comment thread Cargo.toml
[features]
default = ["solana"]
solana = []
parallel = ["rayon"] No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With default = ["solana"], it’s possible to enable --features parallel alongside solana, but Rayon/threaded parallelism typically won’t work for Solana SBF/BPF targets. Consider documenting or preventing this incompatible feature combination so consumers don’t accidentally break on-chain builds.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Comment thread src/lib.rs

fn keccak256_hash(data: &[u8]) -> [u8; 32] {
let mut hasher = Keccak256::new();
hasher.update(data);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reiterate the init_var for calling upon instantiation of the var

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants