Merge BlockstreamResearch/secp256k1-zkp#365: tests: Port hash context tests to zkp modules

72867fd682 tests: Port hash context tests to zkp modules (mllwchrry)

Pull request description:

  Ports the hash context tests from bitcoin-core/secp256k1#1777 to the zkp-specific modules.


ACKs for top commit:
  apoelstra:
    ACK 72867fd682279ff2c79cf13f4f8d8484048d2527; successfully ran local tests


Tree-SHA512: 1714a4c5fd793b32a0f00a92670a48709e4d01917bb81739428601c6e88e89f871cdc1294024e6df7272d6c16e681309d9b3448adcd07ce37bfa2be2dc3f4172
This commit is contained in:
Andrew Poelstra
2026-08-18 15:20:17 +00:00
6 changed files with 177 additions and 1 deletions

View File

@@ -1319,6 +1319,32 @@ static void test_single_value_proof_all(void) {
test_single_value_proof(UINT64_MAX);
}
DEFINE_SHA256_TRANSFORM_PROBE(sha256_rangeproof)
static void test_rangeproof_ctx_sha256(void) {
/* Check ctx-provided SHA256 compression override takes effect */
secp256k1_context *ctx = secp256k1_context_clone(CTX);
unsigned char proof_default[5134], proof_custom[5134];
size_t len = sizeof(proof_default);
unsigned char blind[32] = {1};
secp256k1_pedersen_commitment commit;
CHECK(secp256k1_pedersen_commit(ctx, &commit, blind, 1, secp256k1_generator_h));
/* Default behavior. No ctx-provided SHA256 compression */
CHECK(secp256k1_rangeproof_sign(ctx, proof_default, &len, 0, &commit, blind, commit.data, 0, 0, 1, NULL, 0, NULL, 0, secp256k1_generator_h));
CHECK(!sha256_rangeproof_called);
/* Override SHA256 compression directly, bypassing the ctx setter sanity checks */
ctx->hash_ctx.fn_sha256_compression = sha256_rangeproof;
len = sizeof(proof_custom);
CHECK(secp256k1_rangeproof_sign(ctx, proof_custom, &len, 0, &commit, blind, commit.data, 0, 0, 1, NULL, 0, NULL, 0, secp256k1_generator_h));
CHECK(sha256_rangeproof_called);
/* Outputs must differ if custom compression was used */
CHECK(secp256k1_memcmp_var(proof_default, proof_custom, len) != 0);
secp256k1_context_destroy(ctx);
}
/* --- Test registry --- */
REPEAT_TEST(test_rangeproof_api)
REPEAT_TEST(test_borromean)
@@ -1332,6 +1358,7 @@ static const struct tf_test_entry tests_rangeproof[] = {
CASE1(test_rangeproof),
CASE1(test_rangeproof_null_blinder),
CASE1(test_multiple_generators),
CASE1(test_rangeproof_ctx_sha256),
};
#endif