hacktricks/blockchain/blockchain-and-crypto-currencies/README.md

217 lines
13 KiB
Markdown
Raw Normal View History

2022-05-01 16:32:23 +00:00
2022-04-28 16:01:33 +00:00
<details>
2024-01-16 22:09:51 +00:00
<summary><strong>Learn AWS hacking from zero to hero with</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
2024-01-16 22:09:51 +00:00
Other ways to support HackTricks:
2022-04-28 16:01:33 +00:00
2024-01-16 22:09:51 +00:00
* If you want to see your **company advertised in HackTricks** or **download HackTricks in PDF** Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
* Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com)
* Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family)
2024-02-04 16:10:29 +00:00
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
2024-01-16 22:09:51 +00:00
* **Share your hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>
2022-05-01 16:32:23 +00:00
2024-02-08 21:36:35 +00:00
## Basic Concepts
2024-02-08 21:36:35 +00:00
- **Smart Contracts** are defined as programs that execute on a blockchain when certain conditions are met, automating agreement executions without intermediaries.
- **Decentralized Applications (dApps)** build upon smart contracts, featuring a user-friendly front-end and a transparent, auditable back-end.
- **Tokens & Coins** differentiate where coins serve as digital money, while tokens represent value or ownership in specific contexts.
- **Utility Tokens** grant access to services, and **Security Tokens** signify asset ownership.
- **DeFi** stands for Decentralized Finance, offering financial services without central authorities.
- **DEX** and **DAOs** refer to Decentralized Exchange Platforms and Decentralized Autonomous Organizations, respectively.
2024-02-08 21:36:35 +00:00
## Consensus Mechanisms
2024-02-08 21:36:35 +00:00
Consensus mechanisms ensure secure and agreed transaction validations on the blockchain:
- **Proof of Work (PoW)** relies on computational power for transaction verification.
- **Proof of Stake (PoS)** demands validators to hold a certain amount of tokens, reducing energy consumption compared to PoW.
2024-02-08 21:36:35 +00:00
## Bitcoin Essentials
2024-02-08 21:36:35 +00:00
### Transactions
2024-02-08 21:36:35 +00:00
Bitcoin transactions involve transferring funds between addresses. Transactions are validated through digital signatures, ensuring only the owner of the private key can initiate transfers.
2024-02-08 21:36:35 +00:00
#### Key Components:
2024-02-08 21:36:35 +00:00
- **Multisignature Transactions** require multiple signatures to authorize a transaction.
- Transactions consist of **inputs** (source of funds), **outputs** (destination), **fees** (paid to miners), and **scripts** (transaction rules).
2024-02-08 21:36:35 +00:00
### Lightning Network
2024-02-08 21:36:35 +00:00
Aims to enhance Bitcoin's scalability by allowing multiple transactions within a channel, only broadcasting the final state to the blockchain.
2024-02-08 21:36:35 +00:00
## Bitcoin Privacy Concerns
2024-02-08 21:36:35 +00:00
Privacy attacks, such as **Common Input Ownership** and **UTXO Change Address Detection**, exploit transaction patterns. Strategies like **Mixers** and **CoinJoin** improve anonymity by obscuring transaction links between users.
2024-02-08 21:36:35 +00:00
## Acquiring Bitcoins Anonymously
2024-02-08 21:36:35 +00:00
Methods include cash trades, mining, and using mixers. **CoinJoin** mixes multiple transactions to complicate traceability, while **PayJoin** disguises CoinJoins as regular transactions for heightened privacy.
2024-02-08 21:36:35 +00:00
# Bitcoin Privacy Atacks
2024-02-08 21:36:35 +00:00
# Summary of Bitcoin Privacy Attacks
2024-02-08 21:36:35 +00:00
In the world of Bitcoin, the privacy of transactions and the anonymity of users are often subjects of concern. Here's a simplified overview of several common methods through which attackers can compromise Bitcoin privacy.
2024-02-08 21:36:35 +00:00
## **Common Input Ownership Assumption**
2024-02-08 21:36:35 +00:00
It is generally rare for inputs from different users to be combined in a single transaction due to the complexity involved. Thus, **two input addresses in the same transaction are often assumed to belong to the same owner**.
2024-02-08 21:36:35 +00:00
## **UTXO Change Address Detection**
2024-02-08 21:36:35 +00:00
A UTXO, or **Unspent Transaction Output**, must be entirely spent in a transaction. If only a part of it is sent to another address, the remainder goes to a new change address. Observers can assume this new address belongs to the sender, compromising privacy.
2024-02-08 21:36:35 +00:00
### Example
To mitigate this, mixing services or using multiple addresses can help obscure ownership.
2024-02-08 21:36:35 +00:00
## **Social Networks & Forums Exposure**
2024-02-08 21:36:35 +00:00
Users sometimes share their Bitcoin addresses online, making it **easy to link the address to its owner**.
2024-02-08 21:36:35 +00:00
## **Transaction Graph Analysis**
2024-02-08 21:36:35 +00:00
Transactions can be visualized as graphs, revealing potential connections between users based on the flow of funds.
2024-02-08 21:36:35 +00:00
## **Unnecessary Input Heuristic (Optimal Change Heuristic)**
2024-02-08 21:36:35 +00:00
This heuristic is based on analyzing transactions with multiple inputs and outputs to guess which output is the change returning to the sender.
2024-02-08 21:36:35 +00:00
### Example
2024-02-08 21:36:35 +00:00
```bash
2 btc --> 4 btc
3 btc 1 btc
```
2024-02-08 21:36:35 +00:00
If adding more inputs makes the change output larger than any single input, it can confuse the heuristic.
2021-08-30 22:37:30 +00:00
2024-02-08 21:36:35 +00:00
## **Forced Address Reuse**
2021-08-30 22:37:30 +00:00
2024-02-08 21:36:35 +00:00
Attackers may send small amounts to previously used addresses, hoping the recipient combines these with other inputs in future transactions, thereby linking addresses together.
2021-08-30 22:37:30 +00:00
2024-02-08 21:36:35 +00:00
### Correct Wallet Behavior
Wallets should avoid using coins received on already used, empty addresses to prevent this privacy leak.
2024-02-08 21:36:35 +00:00
## **Other Blockchain Analysis Techniques**
2024-02-08 21:36:35 +00:00
- **Exact Payment Amounts:** Transactions without change are likely between two addresses owned by the same user.
- **Round Numbers:** A round number in a transaction suggests it's a payment, with the non-round output likely being the change.
- **Wallet Fingerprinting:** Different wallets have unique transaction creation patterns, allowing analysts to identify the software used and potentially the change address.
- **Amount & Timing Correlations:** Disclosing transaction times or amounts can make transactions traceable.
2021-08-31 13:52:31 +00:00
2024-02-08 21:36:35 +00:00
## **Traffic Analysis**
2021-08-31 13:52:31 +00:00
2024-02-08 21:36:35 +00:00
By monitoring network traffic, attackers can potentially link transactions or blocks to IP addresses, compromising user privacy. This is especially true if an entity operates many Bitcoin nodes, enhancing their ability to monitor transactions.
2021-08-31 13:52:31 +00:00
2024-02-08 21:36:35 +00:00
## More
For a comprehensive list of privacy attacks and defenses, visit [Bitcoin Privacy on Bitcoin Wiki](https://en.bitcoin.it/wiki/Privacy).
2021-08-31 13:52:31 +00:00
2024-02-08 21:36:35 +00:00
# Anonymous Bitcoin Transactions
2021-08-31 13:52:31 +00:00
2024-02-08 21:36:35 +00:00
## Ways to Get Bitcoins Anonymously
2021-08-31 13:52:31 +00:00
2024-02-08 21:36:35 +00:00
- **Cash Transactions**: Acquiring bitcoin through cash.
- **Cash Alternatives**: Purchasing gift cards and exchanging them online for bitcoin.
- **Mining**: The most private method to earn bitcoins is through mining, especially when done alone because mining pools may know the miner's IP address. [Mining Pools Information](https://en.bitcoin.it/wiki/Pooled_mining)
- **Theft**: Theoretically, stealing bitcoin could be another method to acquire it anonymously, although it's illegal and not recommended.
2021-08-31 13:52:31 +00:00
2024-02-08 21:36:35 +00:00
## Mixing Services
2021-08-31 13:52:31 +00:00
2024-02-08 21:36:35 +00:00
By using a mixing service, a user can **send bitcoins** and receive **different bitcoins in return**, which makes tracing the original owner difficult. Yet, this requires trust in the service not to keep logs and to actually return the bitcoins. Alternative mixing options include Bitcoin casinos.
2021-08-31 13:52:31 +00:00
2022-05-01 16:32:23 +00:00
## CoinJoin
2021-08-31 13:52:31 +00:00
2024-02-08 21:36:35 +00:00
**CoinJoin** merges multiple transactions from different users into one, complicating the process for anyone trying to match inputs with outputs. Despite its effectiveness, transactions with unique input and output sizes can still potentially be traced.
2021-08-31 13:52:31 +00:00
2024-02-08 21:36:35 +00:00
Example transactions that may have used CoinJoin include `402d3e1df685d1fdf82f36b220079c1bf44db227df2d676625ebcbee3f6cb22a` and `85378815f6ee170aa8c26694ee2df42b99cff7fa9357f073c1192fff1f540238`.
2021-08-31 13:52:31 +00:00
2024-02-08 21:36:35 +00:00
For more information, visit [CoinJoin](https://coinjoin.io/en). For a similar service on Ethereum, check out [Tornado Cash](https://tornado.cash), which anonymizes transactions with funds from miners.
2022-05-01 16:32:23 +00:00
## PayJoin
2021-08-31 13:52:31 +00:00
2024-02-08 21:36:35 +00:00
A variant of CoinJoin, **PayJoin** (or P2EP), disguises the transaction among two parties (e.g., a customer and a merchant) as a regular transaction, without the distinctive equal outputs characteristic of CoinJoin. This makes it extremely hard to detect and could invalidate the common-input-ownership heuristic used by transaction surveillance entities.
2021-08-31 13:52:31 +00:00
2024-02-08 21:36:35 +00:00
```plaintext
2021-08-31 13:52:31 +00:00
2 btc --> 3 btc
5 btc 4 btc
```
2024-02-08 21:36:35 +00:00
Transactions like the above could be PayJoin, enhancing privacy while remaining indistinguishable from standard bitcoin transactions.
2021-08-31 13:52:31 +00:00
2024-02-08 21:36:35 +00:00
**The utilization of PayJoin could significantly disrupt traditional surveillance methods**, making it a promising development in the pursuit of transactional privacy.
2021-08-31 13:52:31 +00:00
2024-02-08 21:36:35 +00:00
# Best Practices for Privacy in Cryptocurrencies
2021-08-31 13:52:31 +00:00
2024-02-08 21:36:35 +00:00
## **Wallet Synchronization Techniques**
2021-08-31 16:48:59 +00:00
2024-02-08 21:36:35 +00:00
To maintain privacy and security, synchronizing wallets with the blockchain is crucial. Two methods stand out:
2021-08-31 16:48:59 +00:00
2024-02-08 21:36:35 +00:00
- **Full node**: By downloading the entire blockchain, a full node ensures maximum privacy. All transactions ever made are stored locally, making it impossible for adversaries to identify which transactions or addresses the user is interested in.
- **Client-side block filtering**: This method involves creating filters for every block in the blockchain, allowing wallets to identify relevant transactions without exposing specific interests to network observers. Lightweight wallets download these filters, only fetching full blocks when a match with the user's addresses is found.
2024-02-08 21:36:35 +00:00
## **Utilizing Tor for Anonymity**
2024-02-08 21:36:35 +00:00
Given that Bitcoin operates on a peer-to-peer network, using Tor is recommended to mask your IP address, enhancing privacy when interacting with the network.
2024-02-08 21:36:35 +00:00
## **Preventing Address Reuse**
2024-02-08 21:36:35 +00:00
To safeguard privacy, it's vital to use a new address for every transaction. Reusing addresses can compromise privacy by linking transactions to the same entity. Modern wallets discourage address reuse through their design.
2024-02-08 21:36:35 +00:00
## **Strategies for Transaction Privacy**
2024-02-08 21:36:35 +00:00
- **Multiple transactions**: Splitting a payment into several transactions can obscure the transaction amount, thwarting privacy attacks.
- **Change avoidance**: Opting for transactions that don't require change outputs enhances privacy by disrupting change detection methods.
- **Multiple change outputs**: If avoiding change isn't feasible, generating multiple change outputs can still improve privacy.
2024-02-08 21:36:35 +00:00
# **Monero: A Beacon of Anonymity**
2024-02-08 21:36:35 +00:00
Monero addresses the need for absolute anonymity in digital transactions, setting a high standard for privacy.
2024-02-08 21:36:35 +00:00
# **Ethereum: Gas and Transactions**
2024-02-08 21:36:35 +00:00
## **Understanding Gas**
2024-02-08 21:36:35 +00:00
Gas measures the computational effort needed to execute operations on Ethereum, priced in **gwei**. For example, a transaction costing 2,310,000 gwei (or 0.00231 ETH) involves a gas limit and a base fee, with a tip to incentivize miners. Users can set a max fee to ensure they don't overpay, with the excess refunded.
2024-02-08 21:36:35 +00:00
## **Executing Transactions**
2024-02-08 21:36:35 +00:00
Transactions in Ethereum involve a sender and a recipient, which can be either user or smart contract addresses. They require a fee and must be mined. Essential information in a transaction includes the recipient, sender's signature, value, optional data, gas limit, and fees. Notably, the sender's address is deduced from the signature, eliminating the need for it in the transaction data.
2024-02-08 21:36:35 +00:00
These practices and mechanisms are foundational for anyone looking to engage with cryptocurrencies while prioritizing privacy and security.
2024-02-08 03:06:37 +00:00
## References
2021-11-30 16:46:07 +00:00
* [https://en.wikipedia.org/wiki/Proof\_of\_stake](https://en.wikipedia.org/wiki/Proof\_of\_stake)
* [https://www.mycryptopedia.com/public-key-private-key-explained/](https://www.mycryptopedia.com/public-key-private-key-explained/)
* [https://bitcoin.stackexchange.com/questions/3718/what-are-multi-signature-transactions](https://bitcoin.stackexchange.com/questions/3718/what-are-multi-signature-transactions)
* [https://ethereum.org/en/developers/docs/transactions/](https://ethereum.org/en/developers/docs/transactions/)
* [https://ethereum.org/en/developers/docs/gas/](https://ethereum.org/en/developers/docs/gas/)
2021-11-30 16:46:07 +00:00
* [https://en.bitcoin.it/wiki/Privacy](https://en.bitcoin.it/wiki/Privacy#Forced\_address\_reuse)
2022-04-28 16:01:33 +00:00
2022-05-01 16:32:23 +00:00
2022-04-28 16:01:33 +00:00
<details>
2024-01-16 22:09:51 +00:00
<summary><strong>Learn AWS hacking from zero to hero with</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
2024-01-16 22:09:51 +00:00
Other ways to support HackTricks:
2022-04-28 16:01:33 +00:00
2024-01-16 22:09:51 +00:00
* If you want to see your **company advertised in HackTricks** or **download HackTricks in PDF** Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
* Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com)
* Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family)
2024-02-04 16:10:29 +00:00
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
2024-01-16 22:09:51 +00:00
* **Share your hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>
2022-05-01 16:32:23 +00:00