* chore: remove dead SIMD/FE52-ARM64 code, add edge-case tests Remove 4 dead-code files that are never compiled on any active platform: - cpu/include/secp256k1/field_simd.hpp (169 lines) - cpu/src/field_asm52_arm64.cpp (254 lines) - cpu/src/field_simd.cpp (130 lines) - cpu/tests/test_simd_batch.cpp (220 lines) Replace test_simd_batch with test_edge_cases (60 tests covering scalar zero, infinity arithmetic, BIP-32 IL>=n, cache corruption, and other coverage gaps identified in CT Hardening Gap analysis). Update CMakeLists.txt for cpu, audit, and esp32_audit to reflect removal and replacement. All 31 ctest targets pass. * fix(opencl): fix 6 bugs in OpenCL kernels -- 27/27 audit PASS Root cause: NC constant typo in secp256k1_extended.cl -- 0x402DA1732FC9BEEF should be 0x402DA1732FC9BEBF (off by 0x30). This single hex digit error corrupted ALL scalar mod-n operations, causing scalar_inverse to fail, which broke ECDSA and Schnorr verify. Bug #1: Kernel name mismatch in opencl_context.cpp -- batch_jacobian_to_affine vs batch_jacobian_to_affine_kernel. Bug #2: Cross-program pubkey inconsistency -- host computed pubkey via embedded kernel (PTX, correct) but verify ran in extended kernel (different field arithmetic). Added ext_generator_mul() helper using extended kernel's generator_mul_windowed for consistency. Bug #3: Schnorr pubkey -- get_schnorr_pubkey_x() now uses ext_generator_mul(). Bug #4: scalar_mul_mod_n_impl -- Barrett reduction completely broken. Rewritten with 2^256 = NC (mod n) reduction: 3 passes + scalar_cond_sub_n x3. Bug #5: field_mul_impl/field_sqr_impl -- carry overflow in schoolbook multiply. Rewritten with column-based muladd/muladd2 3-register accumulator. Bug #6: NC constant typo (THE ROOT CAUSE) -- BEEF vs BEBF. OpenCL audit result: 27/27 PASS, AUDIT-READY (0.7s on RTX 5060 Ti). * ci(scorecard): rename cosign .bundle to .sigstore for OSSF recognition OSSF Scorecard Signed-Releases check does not recognize .bundle extension. Rename all cosign output from .bundle to .sigstore (standard Sigstore extension) so Scorecard can detect signed artifacts. Also extend attest-build-provenance subject-path to include .gem, .jar, .deb, and .rpm package formats for complete SLSA provenance coverage. * fix(ci): pass -T to docker-compose run in non-interactive contexts The pre-push hook runs ci-local.sh branch-gate without a TTY, causing docker-compose run to fail with 'the input device is not a TTY'. Detect non-interactive stdin and pass -T flag automatically. --------- Co-authored-by: shrec <shrec@users.noreply.github.com>
140 lines
5.6 KiB
C++
140 lines
5.6 KiB
C++
// ============================================================================
|
|
// Unified Test Runner -- UltrafastSecp256k1
|
|
// ============================================================================
|
|
// Single binary that runs the library selftest + all test modules.
|
|
// Build once, run everywhere. Registers as a single ctest target.
|
|
//
|
|
// Usage:
|
|
// run_selftest # ci mode (default)
|
|
// run_selftest smoke # fast startup check
|
|
// run_selftest stress # extended nightly suite
|
|
// run_selftest ci <seed> # explicit seed (hex)
|
|
// ============================================================================
|
|
|
|
#include "secp256k1/selftest.hpp"
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
|
|
using namespace secp256k1::fast;
|
|
|
|
// -- Forward declarations -- each test module exports a run function -----------
|
|
// Returns 0 on success, non-zero on failure.
|
|
int test_large_scalar_multiplication_run();
|
|
int test_mul_run();
|
|
int test_arithmetic_correctness_run();
|
|
int test_ct_run();
|
|
int test_ct_equivalence_run();
|
|
int test_ecdsa_schnorr_run();
|
|
int test_multiscalar_batch_run();
|
|
int test_bip32_run();
|
|
int test_bip32_vectors_run();
|
|
int test_musig2_run();
|
|
int test_ecdh_recovery_taproot_run();
|
|
int test_edge_cases_run();
|
|
int test_v4_features_run();
|
|
int test_coins_run();
|
|
int test_batch_add_affine_run();
|
|
int test_hash_accel_run();
|
|
int run_exhaustive_tests();
|
|
int test_comprehensive_run();
|
|
int test_bip340_vectors_run();
|
|
int test_rfc6979_vectors_run();
|
|
int test_ecc_properties_run();
|
|
|
|
// -- Module descriptor --------------------------------------------------------
|
|
struct TestModule {
|
|
const char* name;
|
|
int (*run)();
|
|
};
|
|
|
|
static const TestModule MODULES[] = {
|
|
{ "field & scalar arithmetic", test_mul_run },
|
|
{ "arithmetic correctness", test_arithmetic_correctness_run },
|
|
{ "scalar multiplication", test_large_scalar_multiplication_run },
|
|
{ "constant-time layer", test_ct_run },
|
|
{ "FAST\u2261CT equivalence", test_ct_equivalence_run },
|
|
{ "ECDSA + Schnorr", test_ecdsa_schnorr_run },
|
|
{ "multi-scalar & batch verify", test_multiscalar_batch_run },
|
|
{ "BIP-32 HD derivation", test_bip32_run },
|
|
{ "BIP-32 official test vectors TV1-5", test_bip32_vectors_run },
|
|
{ "MuSig2", test_musig2_run },
|
|
{ "ECDH + recovery + taproot", test_ecdh_recovery_taproot_run },
|
|
{ "edge cases & coverage gaps", test_edge_cases_run },
|
|
{ "v4 features (Pedersen/FROST/etc)", test_v4_features_run },
|
|
{ "coins layer", test_coins_run },
|
|
{ "affine batch addition", test_batch_add_affine_run },
|
|
{ "accelerated hashing", test_hash_accel_run },
|
|
{ "exhaustive algebraic verification", run_exhaustive_tests },
|
|
{ "comprehensive 500+ test suite", test_comprehensive_run },
|
|
{ "BIP-340 official test vectors", test_bip340_vectors_run },
|
|
{ "RFC 6979 ECDSA test vectors", test_rfc6979_vectors_run },
|
|
{ "ECC property-based invariants", test_ecc_properties_run },
|
|
};
|
|
|
|
static constexpr int NUM_MODULES = sizeof(MODULES) / sizeof(MODULES[0]);
|
|
|
|
// -- Main ---------------------------------------------------------------------
|
|
int main(int argc, char* argv[]) {
|
|
// Parse mode
|
|
SelftestMode mode = SelftestMode::ci;
|
|
uint64_t seed = 0;
|
|
|
|
if (argc >= 2) {
|
|
if (std::strcmp(argv[1], "smoke") == 0) { mode = SelftestMode::smoke;
|
|
} else if (std::strcmp(argv[1], "stress") == 0) { mode = SelftestMode::stress;
|
|
} else if (std::strcmp(argv[1], "ci") == 0) { mode = SelftestMode::ci;
|
|
}
|
|
}
|
|
if (argc >= 3) {
|
|
seed = std::strtoull(argv[2], nullptr, 16);
|
|
}
|
|
|
|
const char* mode_name = (mode == SelftestMode::smoke) ? "smoke"
|
|
: (mode == SelftestMode::stress) ? "stress"
|
|
: "ci";
|
|
|
|
std::printf("===============================================================\n");
|
|
std::printf(" UltrafastSecp256k1 -- Unified Test Runner (%s)\n", mode_name);
|
|
std::printf("===============================================================\n\n");
|
|
|
|
// -- Phase 1: Library selftest (core arithmetic KAT) ----------------------
|
|
std::printf("[Phase 1] Library selftest (%s)...\n", mode_name);
|
|
if (!Selftest(true, mode, seed)) {
|
|
std::printf("\n*** SELFTEST FAILED -- aborting ***\n");
|
|
return 1;
|
|
}
|
|
std::printf("[Phase 1] Selftest PASSED\n\n");
|
|
|
|
// -- Phase 2: Test modules ------------------------------------------------
|
|
std::printf("[Phase 2] Running %d test modules...\n\n", NUM_MODULES);
|
|
|
|
int modules_passed = 0;
|
|
int modules_failed = 0;
|
|
|
|
for (int i = 0; i < NUM_MODULES; ++i) {
|
|
std::printf("-- Module %d/%d: %s --\n", i + 1, NUM_MODULES, MODULES[i].name);
|
|
int const rc = MODULES[i].run();
|
|
if (rc == 0) {
|
|
++modules_passed;
|
|
std::printf("-- PASSED --\n\n");
|
|
} else {
|
|
++modules_failed;
|
|
std::printf("-- FAILED --\n\n");
|
|
}
|
|
}
|
|
|
|
// -- Summary --------------------------------------------------------------
|
|
std::printf("===============================================================\n");
|
|
std::printf(" Results: %d/%d modules passed (selftest + %d modules)\n",
|
|
modules_passed, NUM_MODULES, NUM_MODULES);
|
|
if (modules_failed == 0) {
|
|
std::printf(" ALL TESTS PASSED\n");
|
|
} else {
|
|
std::printf(" *** %d MODULE(S) FAILED ***\n", modules_failed);
|
|
}
|
|
std::printf("===============================================================\n");
|
|
|
|
return modules_failed > 0 ? 1 : 0;
|
|
}
|