Skip to content

Solana-safe buffer abstraction to avoid large stack allocations#21

Open
xoredtwice wants to merge 4 commits into
QuipNetwork:mainfrom
xoredtwice:fix/11-memory-allocation-feature
Open

Solana-safe buffer abstraction to avoid large stack allocations#21
xoredtwice wants to merge 4 commits into
QuipNetwork:mainfrom
xoredtwice:fix/11-memory-allocation-feature

Conversation

@xoredtwice

Copy link
Copy Markdown
Contributor

This MR introduces a small buffer abstraction to avoid large fixed-size stack allocations that can cause runtime failures in Solana BPF programs due to strict stack frame limits (~4KB).

A new internal SignatureBuffer abstraction unifies two execution paths:

  1. Solana builds (default feature) use heap-backed buffers to remain BPF-safe
  2. Non-Solana builds use fixed-capacity buffers for maximum performance

This removes manual offset arithmetic, keeps cryptographic behavior unchanged, and makes platform constraints explicit without duplicating logic.

No WOTS+ logic or parameters were modified.

Summary of changes

  • Added SignatureBuffer abstraction with a minimal, uniform API.
  • Replaced offset-based writes with sequential appends
  • Introduced solana feature (default) for Solana-safe behavior
  • Updated and added tests to cover both feature paths

Testing

cargo test
cargo test --no-default-features
cargo test --features solana

Related issue

Closes / Related to: #11

@augmentcode

augmentcode Bot commented Jan 12, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: Introduces an internal SignatureBuffer helper to avoid manual offset arithmetic when concatenating WOTS+ public-key segments, motivated by Solana BPF stack-frame limits.
Changes:

  • Adds a solana feature (default) to select the buffer backing implementation.
  • Replaces segment accumulation in key generation and verification with push_slice()/as_slice().
  • Updates hashing call sites to consume the unified buffer view.
  • Adds tests for deterministic signatures and SignatureBuffer behavior under both feature configurations.

🤖 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. 1 suggestions posted.

Fix All in Augment

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

Comment thread src/lib.rs


enum SignatureBuffer {
#[cfg(feature = "solana")]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SignatureBuffer’s #[cfg(feature = "solana")] variant stores [u8; constants::SIGNATURE_SIZE] inline, which is a stack allocation and seems to contradict the PR description/goal of avoiding large Solana stack frames (and it replaces prior Vec usages with stack storage). Was the cfg intended to be inverted (heap-backed on solana, fixed-capacity on non-Solana)?

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

@maekwae

maekwae commented Feb 19, 2026

Copy link
Copy Markdown

Best way to get

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