From 96c31d93d2b15d88ab83ddcbc12a7a1663ae741f Mon Sep 17 00:00:00 2001 From: topologoanatom Date: Wed, 24 Jun 2026 13:12:05 +0300 Subject: [PATCH] sign_tx: use caller-supplied genesis hash --- main/process/sign_tx.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/main/process/sign_tx.c b/main/process/sign_tx.c index 591c97a4..0030dc82 100644 --- a/main/process/sign_tx.c +++ b/main/process/sign_tx.c @@ -478,6 +478,20 @@ static void sign_tx_impl(jade_process_t* process, const bool for_liquid) goto cleanup; } + // Liquid: Optional caller-supplied genesis hash overrides the hardcoded network default. + // Must be read and copied now while the initial message buffer (params) is still valid. + uint8_t caller_genesis[SHA256_LEN]; + bool has_caller_genesis = false; + if (for_liquid) { + const uint8_t* genesis_ptr = NULL; + size_t genesis_ptr_len = 0; + rpc_get_bytes_ptr("genesis_block_hash", ¶ms, &genesis_ptr, &genesis_ptr_len); + if (genesis_ptr && genesis_ptr_len == SHA256_LEN) { + memcpy(caller_genesis, genesis_ptr, SHA256_LEN); + has_caller_genesis = true; + } + } + // Liquid: Gather the (unblinded) output info for user confirmation, // then validate output and additional_info values if (for_liquid) { @@ -799,9 +813,15 @@ static void sign_tx_impl(jade_process_t* process, const bool for_liquid) uint8_t genesis_buff[SHA256_LEN], *genesis = NULL; size_t genesis_len = 0; if (for_liquid && num_p2tr_to_sign) { - // Liquid: Fetch the genesis blockhash for taproot hash generation + // Liquid: Fetch the genesis blockhash for taproot hash generation. + // Prefer the caller-supplied hash (from sign_liquid_tx params) so that + // non-standard regtest environments (e.g. -initialfreecoins) work correctly. genesis = genesis_buff; - network_to_genesis_hash(network_id, genesis, sizeof(genesis_buff)); + if (has_caller_genesis) { + memcpy(genesis_buff, caller_genesis, SHA256_LEN); + } else { + network_to_genesis_hash(network_id, genesis, sizeof(genesis_buff)); + } genesis_len = sizeof(genesis_buff); } for (size_t index = 0; num_p2tr_to_sign != 0 && index < tx->num_inputs; ++index) {