Use int32_t for wnaf values to remove assumption that int has 32 value bits#1772
Use int32_t for wnaf values to remove assumption that int has 32 value bits#1772
Conversation
This fixes the issue where secp256k1_ecmult_wnaf relied on the unstated assumption that int has at least 32 value bits. The function now uses int32_t for: - wnaf array parameters and declarations - word, carry, and sign variables that may hold values requiring 32 bits - function parameters in ecmult_table_get functions Bit position variables (bit, len, last_set_bit, now, verify_bit, etc.) remain as int as suggested in the issue. Co-authored-by: real-or-random <1071625+real-or-random@users.noreply.github.com>
Complete the conversion by updating test_fixed_wnaf_small_helper and all wnaf_expected local arrays to use int32_t for consistency. Co-authored-by: real-or-random <1071625+real-or-random@users.noreply.github.com>
Co-authored-by: real-or-random <1071625+real-or-random@users.noreply.github.com>
|
@copilot squash the commits |
I've squashed the 3 commits into a single commit (aaf94f7). However, I cannot force push this change to the remote branch due to tool limitations. The squashed commit is ready locally with all changes preserved and tests passing. A force push to the remote branch is needed to complete this operation. |
@copilot Uff, that's not what I expected. Use |
... Here's the squashed commit as a patch (commit 5c968c6): From 5c968c6fd5b1d500d065a8b2d86160332d14e575 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Tue, 11 Nov 2025 20:53:59 +0000
Subject: [PATCH] Use int32_t for wnaf values to remove assumption about int
width
The current secp256k1_ecmult_wnaf assumes int has at least 32 value
bits via its VERIFY_CHECK(2 <= w && w <= 31). This fails on 16-bit
platforms when ECMULT_WINDOW_SIZE > 16. For w=31, wnaf values range
from -(2^30 - 1) to 2^30 - 1, requiring 31 value bits plus sign.
Changes:
- Core wnaf functions: Changed wnaf array parameters and value-holding
variables (word, carry, sign, n) from int to int32_t in:
* secp256k1_ecmult_wnaf()
* secp256k1_wnaf_fixed()
* secp256k1_ecmult_strauss_wnaf()
* secp256k1_ecmult_pippenger_wnaf()
- Table access functions: Updated n parameter to int32_t in:
* secp256k1_ecmult_table_verify()
* secp256k1_ecmult_table_get_ge*()
- Data structures: Changed wnaf arrays to int32_t in:
* secp256k1_strauss_point_state
* secp256k1_pippenger_state
- Bit positions: Kept as int (bit, len, last_set_bit, now, verify_bit)
per issue guidance
- Tests: Updated all wnaf array declarations and helper functions in
tests.c and bench_internal.c to use int32_t
---
src/bench_internal.c | 2 +-
src/ecmult_impl.h | 32 ++++++++++++++++----------------
src/tests.c | 20 ++++++++++----------
3 files changed, 27 insertions(+), 27 deletions(-)The full patch file is available at |
Fix
_ecmult_wnafto not rely oninthaving at least 32 value bitsThis PR addresses the issue where
secp256k1_ecmult_wnafrelies on the unstated and unchecked assumption thatinthas at least 32 value bits.Changes Made:
secp256k1_ecmult_wnafto useint32_tfor variables that need 32 value bits (word, carry, sign)int32_tinstead ofintint(bit, len, last_set_bit, now, verify_bit)Summary:
All wnaf-related arrays, variables, and parameters that store values potentially requiring 32 value bits now use
int32_t. Bit position variables remain asintas intended. This ensures the code works correctly on platforms whereinthas fewer than 32 value bits (e.g., 16-bit platforms).Original prompt
_ecmult_wnafrelies onintbeing at least 32 bits #1769💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.