What changed, and why it matters
This commit fixes two test cases in the secp256k1 cryptographic library so they now verify that a public-key sorting function actually succeeds before checking its output. Previously the tests only inspected the sorted result and ignored whether the function returned an error. This is a test-hardening change, not a fix to the sorting function itself, and it does not create or fix a vulnerability in production code.
No action required beyond normal review and merge. Users of the library are not affected because the production API behavior is unchanged.
Security signals we found
Test-only change: modifies src/tests.c only
Adds return-value checks on secp256k1_ec_pubkey_sort
No change to secp256k1_ec_pubkey_sort implementation or public API
No input validation, memory safety, or cryptographic logic changes
Evidence from the diff
In src/tests.c, two call sites of secp256k1_ec_pubkey_sort were wrapped with CHECK(… == 1). The helper test_sort_helper and the main test_sort loop previously called the API without asserting success, then validated the reordered arrays. The patch ensures the test fails if the sort function returns 0 (failure). No implementation code is changed.
Changed components
src/tests.ctest_sort_helpertest_sortInspect captured patch +2 / −2
diff --git a/src/tests.c b/src/tests.c
index c0ab8aa..3fe3b7b 100644
--- a/src/tests.c
+++ b/src/tests.c
@@ -6873,7 +6873,7 @@ static void test_sort_helper(secp256k1_pubkey *pk, size_t *pk_order, size_t n_pk
for (i = 0; i < n_pk; i++) {
pk_test[i] = &pk[pk_order[i]];
}
- secp256k1_ec_pubkey_sort(CTX, pk_test, n_pk);
+ CHECK(secp256k1_ec_pubkey_sort(CTX, pk_test, n_pk) == 1);
for (i = 0; i < n_pk; i++) {
CHECK(secp256k1_memcmp_var(pk_test[i], &pk[i], sizeof(*pk_test[i])) == 0);
}
@@ -6962,7 +6962,7 @@ static void test_sort(void) {
testutil_random_pubkey_test(&pk[j]);
pk_ptr[j] = &pk[j];
}
- secp256k1_ec_pubkey_sort(CTX, pk_ptr, 5);
+ CHECK(secp256k1_ec_pubkey_sort(CTX, pk_ptr, 5) == 1);
for (j = 1; j < 5; j++) {
CHECK(secp256k1_ec_pubkey_sort_cmp(&pk_ptr[j - 1], &pk_ptr[j], CTX) <= 0);
}
Why this scored 16/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.