Skip to content

Fix zero-bit left shift and preserve caller stacks - #418

Merged
RobinLinus merged 2 commits into
mainfrom
fix/zero-bit-left-shift-399
Oct 22, 2026
Merged

RobinLinus merged 2 commits into
mainfrom
fix/zero-bit-left-shift-399

Conversation

@RobinLinus

Copy link
Copy Markdown
Contributor

A zero-bit lshift_prevent_overflow must leave the integer and both caller stacks unchanged. The existing implementation reads intermediate limbs from the altstack even though the zero-iteration helpers never put them there.

Integrates trackoor's existing fix from #400, preserving that commit as a merge parent, and adds regressions for U64 and U254 with an empty or populated altstack, zero/one/high-bit/maximum values, and nonzero shifts at 1 and LIMB_SIZE. Caller-owned main-stack and altstack items are checked explicitly.

Validation: both zero-shift regressions fail before the fix; all six bigint::add::test tests pass after it, including existing addition/doubling tests. Tests used an isolated workspace containing only the unchanged bitvm package and the original locked dependency versions, avoiding unrelated zkVM workspace dependencies. No field or full-workspace tests were run. Formatting and diff checks pass.

Fixes #399.

trackoor and others added 2 commits October 18, 2025 12:45
…to prevent unnecessary altstack usage and added assertion for bits limit.
Integrate trackoor's fix from #400 and add zero/nonzero boundary regressions.

Fixes #399
@RobinLinus
RobinLinus merged commit c620dbf into main Oct 22, 2026
0 of 2 checks passed
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.

lshift_prevent_overflow(bits = 0) empties/underflows altstack due to missing OP_TOALTSTACK pushes in limb shifters

2 participants