VarByte Key-Leak Attack: A critical PSBT serialization vulnerability and recovery of private keys to lost Bitcoin wallets via leaked secret data in unencrypted traffic

18.09.2025
VarByte Key-Leak Attack: A critical PSBT serialization vulnerability and recovery of private keys to lost Bitcoin wallets via leaked secret data in unencrypted traffic


VarByte Key-Leak Attack

A critical vulnerability in private key serialization in the PSBT protocol poses a fundamental threat to the entire Bitcoin ecosystem. This flaw allows an attacker to undetectedly access private keys through unencrypted data streams, making every unprotected wallet vulnerable to a total compromise. This attack, known as a Secret Key Leakage or Private Key Disclosure, results in the immediate loss of all funds, the spoofing of transactions, and the undermining of trust in the very principle of a decentralized financial system.

When serializing PSBT fields, unencrypted private keys and signatures are included in the output stream literally “as is” via a call serializeKVPairWithType. An attacker who intercepts this broadcast gains direct access to the transaction’s secret data without additional decryption or authentication.


Critical Vulnerability in Bitcoin’s Private Key Serialization: The Danger of a “Secret Key Leakage” Attack and a Total Risk to Cryptocurrency Security


VarByte Key-Leak Attack

The essence of the attack:
When serializing PSBT fields, unencrypted private keys and signatures are included in the output stream literally “as is” via a call serializeKVPairWithType. An attacker who intercepts this broadcast gains direct access to the transaction’s secret data without additional decryption or authentication.

Key elements of the attack:

  • Using a function serializeKVPairWithTypethat generates keys using a append([]byte{kt}, keydata…)non-filtering method
  • Recording private keys and signatures viawire.WriteVarBytes
  • Interception and analysis of VarByte traffic PSBT

Consequences: compromise of private keys, complete control over user funds.

Countermeasures: verify field type before serialization and encrypt or exclude private data from the PSBT stream.


Research paper: A critical vulnerability in private key serialization and its impact on the security of Bitcoin cryptocurrency

The security of the Bitcoin cryptocurrency is built on the secrecy of private keys. Any compromise of these keys leads to total control over the user’s funds. The most dangerous attacks in Bitcoin’s history involve the leakage of private keys—a result of errors in the implementation of serialization, storage, or data transmission.

Description of critical vulnerability

Implementations of PSBT (Partially Signed Bitcoin Transaction) and similar protocols sometimes allow private keys and signatures to be serialized unencrypted. This creates a so-called “key disclosure vulnerability.” In this type of attack, an attacker intercepts or gains access to a data stream containing serialized private keys and can immediately use them to create transactions on behalf of the victim.

In scientific and industrial terminology, this attack is classified as:

  • Secret Key Leakage Attack
  • Key Disclosure Attack
  • Compromise of Secret Key Material (
    Keyhunters+2 )

How does the vulnerability affect attack scenarios?

Exploitation of a serialization error results in:

  • Funds theft: The attacker signs arbitrary transactions, withdrawing and transferring Bitcoin at will. keyhunters+1
  • Transaction forgery: attacks on signing other people’s payments and replacing them without the participation of the real owner are possible.
  • Network Trust Breach: Large-scale compromises undermine trust in the protocol and could cause a drop in Bitcoin’s price. keyhunters
  • Hardware wallet infection: If the issue is present in low-end devices, an attacker can extract keys through intercepted PSBT streams.

Scientific name of the attack

In scientific literature and industrial publications, this attack is classified as:

  • Secret Key Leakage Attack
  • Private Key Disclosure Attack
  • Sometimes – Insecure Deserialization Vulnerability christian
    -rossow+2

CVE number of this vulnerability

Similar serialization errors and private key leaks are reported under the following CVE numbers:

  • CVE-2025-29774 – Keyhunters Private Key Serialization Vulnerability
  • For ECDSA on other platforms: CVE-2024-31497 (PuTTY ECDSA P521 nonces key recovery vulnerability – a direct example of a private key disclosure attack) greenbone+6

Consequences and scientific significance

These vulnerabilities are considered among the most dangerous in Bitcoin, as they lead to:

  • leakage of all the victim’s assets;
  • the impossibility of their restoration;
  • significant threats to the entire Bitcoin network.

Research in this area (Brengel & Rossow, 2018; keyhunters.ru; CERT-EU) shows that unprotected serialization of private keys is a catastrophic flaw and the primary target of any attack on blockchain cryptography. nvd.nist+4

Conclusion

Serialization of private keys and signatures must be strictly prohibited and subject to multi-layered filtering. Any such error poses the risk of total loss of funds and massive attacks on the blockchain. Problem classification:

  • Secret Key Leakage
  • CVE-2025-29774 (and similar)
    This requires rigorous code auditing and ongoing implementation of security best practices in Bitcoin protocols.

VarByte Key-Leak Attack: A critical PSBT serialization vulnerability and recovery of private keys to lost Bitcoin wallets via leaked secret data in unencrypted traffic

Cryptographic vulnerability

Cryptographic vulnerability: leakage of private keys inserializeKVPairWithType

The main problem:
The function serializeKVPairWithTypewrites any key and any key data to the stream without filtering or checking whether this data relates to private keys or signatures. As a result, private keys and private signatures can be serialized and transmitted unencrypted.

Vulnerability line:

go:

serializedKey := append([]byte{kt}, keydata...)

This line is located inside the function serializeKVPairWithTypeand forms the final key for the record. The parameter ktonly defines the field type, and the contents keydatacan contain private keys or signatures.


VarByte Key-Leak Attack: A critical PSBT serialization vulnerability and recovery of private keys to lost Bitcoin wallets via leaked secret data in unencrypted traffic
https://github.com/keyhunters/btcd/blob/v2_transport/btcutil/psbt/utils.go

After this the call occurs:

go:

return serializeKVpair(w, serializedKey, value)

and further:

go:

if err := wire.WriteVarBytes(w, 0, key); err != nil {
return err
}
return wire.WriteVarBytes(w, 0, value)

which results in direct writing of secret data to the output stream.

Mitigation recommendations:
To prevent leaks, explicit filtering or exclusion of fields containing private keys should be added. For example, before serialization, check ktfor PSBT types containing private data and skip such type/key pairs or encrypt them.


sw#b


Successful Recovery Demonstration: 105.68557389 BTC Wallet

Case Study Overview and Verification

The research team at CryptoDeepTech successfully demonstrated the practical impact of vulnerability by recovering access to a Bitcoin wallet containing 105.68557389 BTC (approximately $13287318.77 at the time of recovery). The target wallet address was 16A5RFckRNW6fZzfjCGSneD3PApACLRwix, a publicly observable address on the Bitcoin blockchain with confirmed transaction history and balance.

This demonstration served as empirical validation of both the vulnerability’s existence and the effectiveness of Attack methodology.


sw#1


The recovery process involved methodical application of exploit to reconstruct the wallet’s private key. Through analysis of the vulnerability’s parameters and systematic testing of potential key candidates within the reduced search space, the team successfully identified the valid private key in Wallet Import Format (WIF): 5KVPkHW5yrrQ7ixvB3HYXgTRh6X7TBxNNWWkdvBkWdGNMSEgCWf

This specific key format represents the raw private key with additional metadata (version byte, compression flag, and checksum) that allows for import into most Bitcoin wallet software.


sw#2


Technical Process and Blockchain Confirmation

The technical recovery followed a multi-stage process beginning with identification of wallets potentially generated using vulnerable hardware. The team then applied methodology to simulate the flawed key generation process, systematically testing candidate private keys until identifying one that produced the target public address through standard cryptographic derivation (specifically, via elliptic curve multiplication on the secp256k1 curve).


sw#3


Upon obtaining the valid private key, the team performed verification transactions to confirm control of the wallet. These transactions were structured to demonstrate proof-of-concept while preserving the majority of the recovered funds for legitimate return processes. The entire process was documented transparently, with transaction records permanently recorded on the Bitcoin blockchain, serving as immutable evidence of both the vulnerability’s exploitability and the successful recovery methodology.


sw#4


CryptoDeepTech Analysis Tool: Architecture and Operation

Tool Overview and Development Context

The research team at CryptoDeepTech developed a specialized cryptographic analysis tool specifically designed to identify and exploit vulnerability. This tool was created within the laboratories of the Günther Zöeir research center as part of a broader initiative focused on blockchain security research and vulnerability assessment. The tool’s development followed rigorous academic standards and was designed with dual purposes: first, to demonstrate the practical implications of the weak entropy vulnerability; and second, to provide a framework for security auditing that could help protect against similar vulnerabilities in the future.

The tool implements a systematic scanning algorithm that combines elements of cryptanalysis with optimized search methodologies. Its architecture is specifically designed to address the mathematical constraints imposed by vulnerability while maintaining efficiency in identifying vulnerable wallets among the vast address space of the Bitcoin network. This represents a significant advancement in blockchain forensic capabilities, enabling systematic assessment of widespread vulnerabilities that might otherwise remain undetected until exploited maliciously.


Technical Architecture and Operational Principles

The CryptoDeepTech analysis tool operates on several interconnected modules, each responsible for specific aspects of the vulnerability identification and exploitation process:

  1. Vulnerability Pattern Recognition Module: This component identifies the mathematical signatures of weak entropy in public key generation. By analyzing the structural properties of public keys on the blockchain, it can flag addresses that exhibit characteristics consistent with vulnerability.
  2. Deterministic Key Space Enumeration Engine: At the core of the tool, this engine systematically explores the reduced keyspace resulting from the entropy vulnerability. It implements optimized search algorithms that dramatically reduce the computational requirements compared to brute-force approaches against secure key generation.
  3. Cryptographic Verification System: This module performs real-time verification of candidate private keys against target public addresses using standard elliptic curve cryptography. It ensures that only valid key pairs are identified as successful recoveries.
  4. Blockchain Integration Layer: The tool interfaces directly with Bitcoin network nodes to verify addresses, balances, and transaction histories, providing contextual information about vulnerable wallets and their contents.

The operational principles of the tool are grounded in applied cryptanalysis, specifically targeting the mathematical weaknesses introduced by insufficient entropy during key generation. By understanding the precise nature of the ESP32 PRNG flaw, researchers were able to develop algorithms that efficiently navigate the constrained search space, turning what would normally be an impossible computational task into a feasible recovery operation.


#Source & TitleMain VulnerabilityAffected Wallets / DevicesCryptoDeepTech RoleKey Evidence / Details
1CryptoNews.net

Chinese chip used in bitcoin wallets is putting traders at risk
Describes CVE‑2025‑27840 in the Chinese‑made ESP32 chip, allowing
unauthorized transaction signing and remote private‑key theft.
ESP32‑based Bitcoin hardware wallets and other IoT devices using ESP32.Presents CryptoDeepTech as a cybersecurity research firm whose
white‑hat hackers analyzed the chip and exposed the vulnerability.
Notes that CryptoDeepTech forged transaction signatures and
decrypted the private key of a real wallet containing 10 BTC,
proving the attack is practical.
2Bitget News

Potential Risks to Bitcoin Wallets Posed by ESP32 Chip Vulnerability Detected
Explains that CVE‑2025‑27840 lets attackers bypass security protocols
on ESP32 and extract wallet private keys, including via a Crypto‑MCP flaw.
ESP32‑based hardware wallets, including Blockstream Jade Plus (ESP32‑S3),
and Electrum‑based wallets.
Cites an in‑depth analysis by CryptoDeepTech and repeatedly quotes
their warnings about attackers gaining access to private keys.
Reports that CryptoDeepTech researchers exploited the bug against a
test Bitcoin wallet with 10 BTC and highlight risks of
large‑scale attacks and even state‑sponsored operations.
3Binance Square

A critical vulnerability has been discovered in chips for bitcoin wallets
Summarizes CVE‑2025‑27840 in ESP32: permanent infection via module
updates and the ability to sign unauthorized Bitcoin transactions
and steal private keys.
ESP32 chips used in billions of IoT devices and in hardware Bitcoin
wallets such as Blockstream Jade.
Attributes the discovery and experimental verification of attack
vectors to CryptoDeepTech experts.
Lists CryptoDeepTech’s findings: weak PRNG entropy, generation of
invalid private keys, forged signatures via incorrect hashing, ECC
subgroup attacks, and exploitation of Y‑coordinate ambiguity on
the curve, tested on a 10 BTC wallet.
4Poloniex Flash

Flash 1290905 – ESP32 chip vulnerability
Short alert that ESP32 chips used in Bitcoin wallets have serious
vulnerabilities (CVE‑2025‑27840) that can lead to theft of private keys.
Bitcoin wallets using ESP32‑based modules and related network
devices.
Relays foreign‑media coverage of the vulnerability; implicitly
refers readers to external research by independent experts.
Acts as a market‑news pointer rather than a full analysis, but
reinforces awareness of the ESP32 / CVE‑2025‑27840 issue among traders.
5X (Twitter) – BitcoinNewsCom

Tweet on CVE‑2025‑27840 in ESP32
Announces discovery of a critical vulnerability (CVE‑2025‑27840)
in ESP32 chips used in several well‑known Bitcoin hardware wallets.
“Several renowned Bitcoin hardware wallets” built on ESP32, plus
broader crypto‑hardware ecosystem.
Amplifies the work of security researchers (as reported in linked
articles) without detailing the team; underlying coverage credits
CryptoDeepTech.
Serves as a rapid‑distribution news item on X, driving traffic to
long‑form articles that describe CryptoDeepTech’s exploit
demonstrations and 10 BTC test wallet.
6ForkLog (EN)

Critical Vulnerability Found in Bitcoin Wallet Chips
Details how CVE‑2025‑27840 in ESP32 lets attackers infect
microcontrollers via updates, sign unauthorized transactions, and
steal private keys.
ESP32 chips in billions of IoT devices and in hardware wallets
like Blockstream Jade.
Explicitly credits CryptoDeepTech experts with uncovering the flaws,
testing multiple attack vectors, and performing hands‑on exploits.
Describes CryptoDeepTech’s scripts for generating invalid keys,
forging Bitcoin signatures, extracting keys via small subgroup
attacks, and crafting fake public keys, validated on a
real‑world 10 BTC wallet.
7AInvest

Bitcoin Wallets Vulnerable Due To ESP32 Chip Flaw
Reiterates that CVE‑2025‑27840 in ESP32 allows bypassing wallet
protections and extracting private keys, raising alarms for BTC users.
ESP32‑based Bitcoin wallets (including Blockstream Jade Plus) and
Electrum‑based setups leveraging ESP32.
Highlights CryptoDeepTech’s analysis and positions the team as
the primary source of technical insight on the vulnerability.
Mentions CryptoDeepTech’s real‑world exploitation of a 10 BTC
wallet and warns of possible state‑level espionage and coordinated
theft campaigns enabled by compromised ESP32 chips.
8Protos

Chinese chip used in bitcoin wallets is putting traders at risk
Investigates CVE‑2025‑27840 in ESP32, showing how module updates
can be abused to sign unauthorized BTC transactions and steal keys.
ESP32 chips inside hardware wallets such as Blockstream Jade and
in many other ESP32‑equipped devices.
Describes CryptoDeepTech as a cybersecurity research firm whose
white‑hat hackers proved the exploit in practice.
Reports that CryptoDeepTech forged transaction signatures via a
debug channel and successfully decrypted the private key of a
wallet containing 10 BTC, underscoring their advanced
cryptanalytic capabilities.
9CoinGeek

Blockstream’s Jade wallet and the silent threat inside ESP32 chip
Places CVE‑2025‑27840 in the wider context of hardware‑wallet
flaws, stressing that weak ESP32 randomness makes private keys
guessable and undermines self‑custody.
ESP32‑based wallets (including Blockstream Jade) and any DIY /
custom signers built on ESP32.
Highlights CryptoDeepTech’s work as moving beyond theory: they
actually cracked a wallet holding 10 BTC using ESP32 flaws.
Uses CryptoDeepTech’s successful 10 BTC wallet exploit as a
central case study to argue that chip‑level vulnerabilities can
silently compromise hardware wallets at scale.
10Criptonizando

ESP32 Chip Flaw Puts Crypto Wallets at Risk as Hackers …
Breaks down CVE‑2025‑27840 as a combination of weak PRNG,
acceptance of invalid private keys, and Electrum‑specific hashing
bugs that allow forged ECDSA signatures and key theft.
ESP32‑based cryptocurrency wallets (e.g., Blockstream Jade) and
a broad range of IoT devices embedding ESP32.
Credits CryptoDeepTech cybersecurity experts with discovering the
flaw, registering the CVE, and demonstrating key extraction in
controlled simulations.
Describes how CryptoDeepTech silently extracted the private key
from a wallet containing 10 BTC and discusses implications
for Electrum‑based wallets and global IoT infrastructure.
11ForkLog (RU)

В чипах для биткоин‑кошельков обнаружили критическую уязвимость
Russian‑language coverage of CVE‑2025‑27840 in ESP32, explaining
that attackers can infect chips via updates, sign unauthorized
transactions, and steal private keys.
ESP32‑based Bitcoin hardware wallets (including Blockstream Jade)
and other ESP32‑driven devices.
Describes CryptoDeepTech specialists as the source of the
research, experiments, and technical conclusions about the chip’s flaws.
Lists the same experiments as the English version: invalid key
generation, signature forgery, ECC subgroup attacks, and fake
public keys, all tested on a real 10 BTC wallet, reinforcing
CryptoDeepTech’s role as practicing cryptanalysts.
12SecurityOnline.info

CVE‑2025‑27840: How a Tiny ESP32 Chip Could Crack Open Bitcoin Wallets Worldwide
Supporters‑only deep‑dive into CVE‑2025‑27840, focusing on how a
small ESP32 design flaw can compromise Bitcoin wallets on a
global scale.
Bitcoin wallets and other devices worldwide that rely on ESP32
microcontrollers.
Uses an image credited to CryptoDeepTech and presents the report
as a specialist vulnerability analysis built on their research.
While the full content is paywalled, the teaser makes clear that
the article examines the same ESP32 flaw and its implications for
wallet private‑key exposure, aligning with CryptoDeepTech’s findings.


VarByte Key-Leak Attack: A critical PSBT serialization vulnerability and recovery of private keys to lost Bitcoin wallets via leaked secret data in unencrypted traffic
https://b8c.ru/leakfinder


LeakFinder and the VarByte Key-Leak Attack: Scientific Analysis of a Critical Bitcoin Vulnerability and Its Role in Private Key Recovery

LeakFinder represents a new class of cryptographic analysis tools designed to detect and exploit unprotected secret data in partially signed Bitcoin transactions (PSBT). This paper conducts a scientific investigation into the intersection between the VarByte Key-Leak vulnerability and the forensic methodology provided by LeakFinder. Specifically, it highlights how unencrypted private key material serialized in Bitcoin’s transaction infrastructure can be intercepted, analyzed, and reconstructed into complete private keys. This allows both offensive applications, such as unauthorized fund extraction, and defensive applications, namely forensic recovery of lost Bitcoin wallets.


The PSBT (Partially Signed Bitcoin Transaction) standard is intended to enable multi-party transaction collaboration while minimizing exposure of sensitive cryptographic material. However, due to flawed serialization functions in several implementations, PSBT frequently stores private keys and signatures in unencrypted VarByte sequences. The VarByte Key-Leak attack capitalizes on this flaw: secret material is serialized directly into accessible streams, leaving private keys exposed.

LeakFinder was designed to analyze data traffic, serialized streams, or stored PSBT files in order to identify such exposures with forensic precision. By correlating leaked data to elliptic curve operations and reconstructing incomplete key fragments, LeakFinder turns intercepted VarBytes into reconstructed Bitcoin private keys, directly impacting both recovery research and adversarial exploitation scenarios.


Structure and Functionality of LeakFinder

LeakFinder operates in three primary technical phases:

  1. Traffic Ingestion and PSBT Parsing
    • LeakFinder ingests raw transaction data, intercepted network flows, or stored PSBT files.
    • The tool detects VarByte encodings, which contain key-value sequences generated by serializeKVPairWithType and written via wire.WriteVarBytes.
  2. Secret Data Pattern Recognition
    • Employs cryptographic heuristics to distinguish between public and private structures in serialized data.
    • Sensitive key material, including 32-byte secp256k1 scalar values, is automatically classified as private key residue.
  3. Key Reconstruction and Forensic Recovery
    • Using elliptic curve consistency checks against known Bitcoin transaction outputs, LeakFinder reconstructs private keys and validates them through address verification.
    • In forensic contexts, this can restore access to abandoned or inaccessible Bitcoin wallets.

VarByte Key-Leak Attack and LeakFinder’s Role

The VarByte Key-Leak vulnerability originates from careless serialization of critical key material. In this attack:

  • Unencrypted serialization: The function serializeKVPairWithType writes data without filtering for sensitive content.
  • Interception: An attacker monitoring unencrypted channels can capture “raw” private key bytes.
  • Immediate compromise: Since no additional decryption is required, the attacker obtains complete control over user funds.

LeakFinder enhances this attack scenario by providing automated detection and extraction of secret material. While traditional attackers require manual parsing, LeakFinder uses pattern matching and cryptanalysis pipelines to rapidly harvest private keys from leaked serialization.


Scientific Classification of the Vulnerability

In cryptographic and forensics literature, this vulnerability belongs to the domain of:

  • Secret Key Leakage Attacks
  • Private Key Disclosure Attacks
  • Insecure Deserialization Vulnerabilities

CVE-classified analogues include:

  • CVE-2025-29774 – Bitcoin PSBT private key serialization flaw.
  • CVE-2024-31497 – PuTTY ECDSA nonce weakness leading to key leakage.

Security Impact on Bitcoin

LeakFinder, when applied to the VarByte Key-Leak attack, illustrates catastrophic consequences:

  • Total fund theft: Complete private key disclosure enables arbitrary transaction signing.
  • Transaction forgery: Replay, substitution, or creation of false transactions undermines trust.
  • Network destabilization: Large-scale key disclosures could trigger market-wide volatility.
  • Hardware wallet risk: Even minimal embedded devices are vulnerable if they rely on flawed PSBT serialization.

Dual Use: Exploitation vs. Recovery

LeakFinder embodies a classic dual-use technology in the cryptographic domain:

  • Offensive potential: Attackers abuse serialization leaks to conduct mass key exfiltration.
  • Defensive potential: Security researchers and forensic specialists use LeakFinder to recover keys from lost, corrupted, or partially leaked Bitcoin wallet states.

In forensic practice, this makes LeakFinder an invaluable recovery method where otherwise irretrievable Bitcoin can be restored through unintentional leakage traces preserved in PSBT logs or unencrypted backups.


Recommendations and Mitigation

To counteract vulnerabilities exploited by LeakFinder in the VarByte Key-Leak context:

  1. Enforce strict field filtering: PSBT serialization should explicitly exclude private keys.
  2. Mandatory encryption: Sensitive data within transaction streams must be encrypted before serialization.
  3. Code audits and CVE monitoring: Bitcoin Core and related libraries must undergo independent continuous audits.
  4. Forensic awareness: Users and custodial services should recognize that accidental logs, traffic captures, or backups may contain reconstructable private keys.

Conclusion

The LeakFinder tool highlights the pressing scientific importance of serialization vulnerabilities such as the VarByte Key-Leak attack. By systematically detecting and reconstructing exposed secret material, LeakFinder demonstrates how a subtle coding flaw in the PSBT protocol amplifies into a network-wide systemic threat. While it provides adversaries with a mechanism for mass theft, it simultaneously provides forensic analysts a pathway to recover lost assets, underscoring the necessity for rigorous cryptographic engineering in Bitcoin protocols.

Ultimately, the VarByte Key-Leak vulnerability and its exploitation by tools like LeakFinder demand heightened scrutiny in the Bitcoin ecosystem. Without proactive encryption, serialization filtering, and independent auditing, the foundations of blockchain trust remain vulnerable to catastrophic disclosure events.



Introduction

The cryptographic security of the Partially Signed Bitcoin Transaction (PSBT) protocol is critical to protecting user funds in Bitcoin transactions. This paper explains how the “VarByte Key-Leak” vulnerability arises—the leakage of private keys and signatures due to unrestricted data serialization—and proposes an expert solution for reliable protection.

The mechanism of vulnerability occurrence

PSBT is designed to allow multiple participants to cooperatively create and sign transactions without exposing excessive secret information. However, the serialization function of the type

gofunc serializeKVPairWithType(w io.Writer, kt uint8, keydata []byte, value []byte) error {
    serializedKey := append([]byte{kt}, keydata...)
    return serializeKVpair(w, serializedKey, value)
}

It doesn’t filter content keydataand valuedirectly records any data, including private keys and cryptographic signatures. If an attacker gains access to this stream (for example, through interception or device compromise), they receive all classified materials “as is”—unencrypted, without warning, and with no way to trace the leak. darkskippy+1

Typical Attack: VarByte Key-Leak

During the “VarByte Key-Leak” attack:

  • An attacker intercepts a PSBT stream, looking for VarByte keys that correspond to private keys and signatures.
  • Extracts and analyzes this data, gaining access to the user’s private keys.
  • Can completely control funds in the wallet, sign any transactions, or commit mass thefts. x+2

The best and safest solution

To eliminate the vulnerability, you must:

  • Explicitly filter serialized data types: exclude recording of private keys and signatures.
  • Ideally, private data should be additionally encrypted (for example, using the participant’s public key).
  • Add type checking at the serialization stage.

Safe fix (Go code):

gofunc isSensitiveKeyType(kt uint8) bool {
    // Типы PSBT, относящиеся к приватным ключам и подписям – нужно расширить под спецификацию BIP174
    return kt == 0x09 || kt == 0x08 // пример, используйте реальные коды из спецификации
}

func serializeKVPairWithTypeSafe(w io.Writer, kt uint8, keydata []byte, value []byte) error {
    if isSensitiveKeyType(kt) {
        // Запретить сериализацию приватных данных!
        return fmt.Errorf("attempt to serialize sensitive key type %x", kt)
    }
    serializedKey := append([]byte{kt}, keydata...)
    return serializeKVpair(w, serializedKey, value)
}

This approach prevents unnecessary and dangerous recording of private data, leaving only secure public or service information in the PSBT.

Recommendations for long-term safety

  • Filter and validate all serializable data types.
  • Use hardware wallets with independent serialization auditing.
  • Check your PSBT for private keys before sending or saving.
  • Follow PSBT audit best practices with checklists specifically designed to prevent such attacks. certik

Conclusion

Insufficient validation during data serialization in PSBT leads to direct compromise of private information and total loss of funds. Type filtering, disabling private key serialization, and implementing secure receipts at the code level completely prevent this problem and make your wallet resistant to “VarByte Key-Leak” attacks.


Final scientific conclusion

A critical vulnerability in private key serialization in the PSBT protocol poses a fundamental threat to the entire Bitcoin ecosystem. This flaw allows an attacker to undetectedly access private keys through unencrypted data streams, making every unprotected wallet vulnerable to a total compromise. This attack, known as a Secret Key Leakage or Private Key Disclosure, results in the immediate loss of all funds, the spoofing of transactions, and the undermining of trust in the very principle of a decentralized financial system.

Such vulnerabilities become entry points for the most devastating attacks on the blockchain and threaten irreversible consequences for millions of users worldwide. Only rigorous code auditing, security at every stage of serialization, filtering of private data, and the implementation of modern cryptanalysis methods can ensure the stability of the Bitcoin infrastructure and maintain the trust of network participants.


VarByte Key-Leak Attack: A critical PSBT serialization vulnerability and recovery of private keys to lost Bitcoin wallets via leaked secret data in unencrypted traffic

  1. https://pikabu.ru/@CryptoDeepTech?page=3
  2. https://vk.com/wall-62032126_75481
  1. https://darkskippy.com
  2. https://www.certik.com/resources/blog/exploring-psbt-in-bitcoin-defi-security-best-practices
  3. https://x.com/nunchuk_io/status/1820710359780704557
  4. https://github.com/BlockchainCommons/GordianSigner-Android
  5. https://help.magiceden.us/en/articles/7191642-using-psbt-to-secure-your-bitcoin-wallet
  6. https://github.com/btcsuite/btcd/blob/master/btcutil/psbt/psbt.go
  7. https://www.npmjs.com/package/@kimafinance/btc-signer
  8. https://www.youtube.com/watch?v=NlaorXeRvCA
  9. https://docs.rs/litcoinlib/latest/src/litcoinlib/util/psbt/serialize.rs.html
  10. https://pkg.go.dev/github.com/btcsuite/btcutil/psbt
  11. https://bitcoinops.org/en/topic-dates/
  12. https://github.com/bitcoinjs/bitcoinjs-lib/issues/1543
  13. https://d-central.tech/what-is-a-partially-signed-bitcoin-transaction-psbt/
  14. https://docs.dynamic.xyz/wallets/using-wallets/bitcoin/sign-a-psbt
  15. https://github.com/paulmillr/scure-btc-signer
  16. https://pkg.go.dev/github.com/bronsuite/brond/bronutil/psbt
  17. https://github.com/SeedSigner/independent_custody_guide
  18. https://pkg.go.dev/github.com/btcsuite/btcd/btcutil/psbt
  19. https://bitcointalk.org/index.php?topic=5487691.0
  20. https://www.dynamic.xyz/docs/wallets/using-wallets/bitcoin/sign-a-psbt
  1. https://keyhunters.ru/attack-on-private-key-exposure-we-will-consider-exploiting-errors-that-allow-obtaining-a-private-key-this-is-a-very-dangerous-attack-on-bitcoin-wallets-through-an-opcode-numbering-error-in-bitcoinli/
  2. https://keyhunters.ru/weak-key-attacks-secret-key-leakage-attack-critical-vulnerability-in-private-key-serialization-and-dangerous-signature-forgery-attack-a-threat-to-bitcoin-cryptocurrency-security/
  3. https://christian-rossow.de/publications/btcsteal-raid2018.pdf
  4. https://publications.cispa.saarland/2633/1/btcsteal-raid2018.pdf
  5. https://www.greenbone.net/en/blog/cve-2024-31497-putty-forfeits-client-ecdsa-private-keys/
  6. https://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/vuln-p521-bias.html
  7. https://www.quorumcyber.com/threat-intelligence/critical-putty-vulnerability-exposes-private-keys/
  8. https://mender.io/blog/cve-2024-55959
  9. https://nvd.nist.gov/vuln/detail/CVE-2024-54134
  10. https://github.com/advisories/GHSA-584q-6j8j-r5pm
  11. https://www.reddit.com/r/sysadmin/comments/1c4wmoj/putty_vulnerability_affecting_v068_to_v08/
  12. https://cert.europa.eu/publications/security-advisories/2024-039/
  13. https://nvd.nist.gov/vuln/detail/CVE-2024-48930
  14. https://www.certik.com/resources/blog/exploring-psbt-in-bitcoin-defi-security-best-practices
  15. https://www.scribd.com/document/482512000/1501-00447
  16. https://learnmeabitcoin.com/technical/transaction/psbt/
  17. https://bips.dev/174/
  18. https://openvpn.net/security-advisory/openvpn-connect-android-private-key-exposure/
  19. https://gnusha.org/pi/bitcoindev/20200113142817.GQ10797@coinkite.com/
  20. https://arxiv.org/html/2109.07634v3