The Underlying Logic and Operating Mechanism of Digital Currency | 数字货币的底层逻辑与运行机制

📚 The Underlying Logic and Operating Mechanism of Digital Currency | 数字货币的底层逻辑与运行机制

Digital currency, most notably Bitcoin and Ethereum, has transformed how we think about money and trust. Rather than relying on a central bank, digital currencies use cryptographic algorithms, distributed networks, and consensus protocols to validate transactions. For a computer science student, understanding these mechanisms reveals a beautiful interplay of data structures, networking, and security.

数字货币,尤其是比特币和以太坊,彻底改变了我们对于货币与信任的思考方式。与传统依赖中央银行不同,数字货币借助密码学算法、分布式网络和共识协议来验证交易。对计算机科学学生而言,理解这些机制能揭示数据结构、网络通信与安全防护之间精彩的相互作用。


1. What Is Digital Currency? | 什么是数字货币

Digital currency is a form of money that exists purely in electronic form. It uses cryptographic techniques to secure transactions and to control the creation of new units. Unlike fiat currency issued by governments, most digital currencies operate on decentralised networks, meaning no single entity has ultimate authority.

数字货币是一种纯粹以电子形式存在的货币。它使用密码学技术来保障交易安全,并控制新单位的产生。与政府发行的法定货币不同,大多数数字货币运行在去中心化网络上,这意味着没有任何单一实体拥有最终权力。

There are two broad categories: central bank digital currencies (CBDCs), which are issued and regulated by a central authority, and decentralised cryptocurrencies, which operate through peer-to-peer networks. This article focuses on the latter, because their technical architecture is more relevant to a computer science syllabus.

数字货币可分为两大类:中央银行数字货币(CBDC),由中央权威机构发行和监管;以及去中心化的加密货币,通过点对点网络运行。本文重点讨论后者,因为其技术架构与计算机科学课程内容更加相关。


2. The Blockchain: A Distributed Ledger | 区块链:分布式账本

At the heart of most digital currencies lies the blockchain. A blockchain is a distributed ledger that records every transaction across a network of computers. Each block contains a batch of valid transactions, a timestamp, and a reference to the previous block, forming an unbroken chain.

大多数数字货币的核心是区块链。区块链是一种分布式账本,在由多台计算机组成的网络中记录每一笔交易。每个区块包含一批有效交易、一个时间戳以及对前一个区块的引用,从而形成一条不可断裂的链条。

Because the ledger is replicated on many nodes, no single server can be hacked to alter history. If an attacker wants to modify a past transaction, they would need to rewrite every subsequent block on a majority of nodes — a task that becomes computationally impractical as the chain grows.

由于账本在众多节点上均有副本,没有任何单一服务器被攻破就能篡改历史。如果攻击者想要修改一笔过往交易,就需要在多数节点上重写之后的所有区块——随着链的增长,这在计算上是极不现实的。

Blockₙ = Hash(Blockₙ₋₁ + Timestamp + MerkleRoot + Nonce)

The equation above shows the essence of a block: its header includes the hash of the previous block, a timestamp, the Merkle root of all transactions, and a nonce used in mining. This structure creates tamper-evident, ordered data.

上面的公式展示了区块的本质:其头部包含前一区块的哈希值、时间戳、所有交易的默克尔根以及挖矿中使用的随机数。这种结构创造了可防篡改、有序排列的数据。


3. Cryptographic Hash Functions | 密码学哈希函数

A cryptographic hash function, such as SHA-256, takes an input of arbitrary length and produces a fixed-size output, typically a 256-bit number. For example, SHA-256(“hello”) produces a specific 64-character hexadecimal string. Even a tiny change in the input produces a completely different output.

密码学哈希函数(如SHA-256)接受任意长度的输入,并产生固定大小的输出,通常是256位的数字。例如,SHA-256(“hello”)会产生一个特定的64位十六进制字符串。即使输入发生极微小的变化,输出也会完全不同。

Three properties are essential for digital currency. First, preimage resistance: given a hash, it is infeasible to find the original input. Second, second-preimage resistance: given an input, it is infeasible to find a different input with the same hash. Third, collision resistance: it is infeasible to find any two different inputs that hash to the same value.

数字通证需要哈希函数具备三个关键性质。第一,抗原像性:给定哈希值,无法反推出原始输入。第二,抗第二原像性:给定一个输入,无法找到另一个不同输入与之拥有相同哈希。第三,抗碰撞性:无法找到两个不同输入,使它们哈希到相同值。

These properties guarantee that transaction data cannot be forged, because altering any byte changes the hash, which invalidates all subsequent blocks. Hash functions also provide the “proof of work” puzzle in Bitcoin mining, as miners search for a nonce that produces a hash below a target threshold.

这些性质保证了交易数据无法被伪造,因为修改任何字节都会改变哈希值,进而使后续所有区块失效。哈希函数还为比特币挖矿提供了“工作量证明”难题,矿工需要寻找一个随机数,使哈希值低于目标阈值。


4. Digital Signatures and Wallets | 数字签名与钱包

Digital currencies use asymmetric cryptography, also called public-key cryptography. Each user has a private key (secret) and a public key (shared). The private key is used to sign transactions, while the public key allows others to verify the signature. This scheme is based on elliptic curve cryptography, commonly secp256k1 in Bitcoin.

数字货币使用非对称密码学,也称公钥密码学。每个用户拥有一对密钥:私钥(保密)和公钥(公开)。私钥用于签署交易,公钥用于让他人验证签名。这种方案基于椭圆曲线密码学,比特币中常采用secp256k1曲线。

To send currency, Alice creates a transaction message and computes a digital signature using her private key. The signature proves that Alice, the owner of the funds, authorised the transfer. Miners and other nodes verify the signature using Alice’s public key. If the signature is invalid, the transaction is rejected.

当 Alice 发送货币时,她创建一条交易消息,并使用自己的私钥计算数字签名。该签名证明资金的拥有者 Alice 确实授权了这笔转账。矿工和其他节点使用 Alice 的公钥验证签名。如果签名无效,交易将被拒绝。

A wallet, in practice, is not a physical container of coins, but a software program that stores private keys and calculates associated public addresses. Losing the private key means losing access to the funds forever, because there is no central authority to reset it. This introduces an important security principle: key management is a critical risk in digital currency systems.

实际上,钱包并非存放硬币的物理容器,而是一个存储私钥并计算相应公共地址的软件程序。丢失私钥意味着永久失去对资金的控制权,因为没有中央机构可以重置密码。这引出一个重要的安全原则:密钥管理是数字货币系统中关键的风险点。


5. Transactions and the UTXO Model | 交易与UTXO模型

Bitcoin and many other cryptocurrencies use a model called UTXO (Unspent Transaction Output). In this model, a transaction consumes one or more previous outputs as inputs, and creates new outputs. Each output is a specific amount of currency associated with a locking script that specifies who can spend it.

比特币及许多其他加密货币采用一种名为UTXO(未花费交易输出)的模型。在该模型中,一笔交易消耗一个或多个之前的输出作为输入,并产生新的输出。每个输出都是与锁定脚本关联的特定金额,锁定脚本规定了谁能花费这笔资金。

For example, suppose Alice has a UTXO of 10 BTC. She wants to send 3 BTC to Bob and 6.9 BTC back to herself as change. She creates a transaction with one input (the 10 BTC UTXO) and two outputs: 3 BTC to Bob’s address and 6.9 BTC to her own change address. The remaining 0.1 BTC is the transaction fee paid to miners.

例如,假设 Alice 持有10 BTC的UTXO。她想向 Bob 发送3 BTC,并将6.9 BTC作为找零返还给自己。她创建一笔包含一个输入(10 BTC的UTXO)和两个输出的交易:3 BTC发往 Bob 的地址,6.9 BTC发回她自己的找零地址。剩余的0.1 BTC是支付给矿工的交易费。

The UTXO model enforces a key invariant: the sum of inputs must equal the sum of outputs plus the transaction fee. This prevents double spending because each UTXO can only be spent once. Once spent, it is removed from the unspent set and the new outputs become UTXOs.

UTXO模型强制一个关键恒等式:输入总额必须等于输出总额加交易费。这防止了双重支付,因为每个UTXO只能被花费一次。一旦被花费,它就从未花费集合中移除,新的输出则成为UTXO。

Σ(inputs) = Σ(outputs) + transaction fee

This accounting equation is verified independently by every node, ensuring that no participant can create currency out of thin air without following the protocol’s rules.

这一会计恒等式由每个节点独立验证,确保没有任何参与者可以在不遵循协议规则的情况下凭空制造货币。


6. Consensus Mechanisms: PoW and PoS | 共识机制:工作量证明与权益证明

In a decentralised network, nodes must agree on the order and validity of transactions. A consensus mechanism is the algorithm that achieves this agreement even when some nodes may be dishonest. The two most prominent mechanisms are Proof of Work (PoW) and Proof of Stake (PoS).

在去中心化网络中,节点必须就交易的顺序和有效性达成一致。共识机制就是即使在部分节点不诚实的情况下也能实现这种一致的算法。最著名的两种机制是工作量证明(PoW)和权益证明(PoS)。

In Proof of Work, miners compete to solve a computational puzzle. The puzzle is to find a nonce such that the block’s hash is less than a target value. The difficulty adjusts to maintain a constant average block time. The first miner to find a valid nonce broadcasts the block, and other nodes verify it. The winning miner receives newly minted coins and transaction fees as a reward.

在工作量证明中,矿工竞争解决一个计算难题。该难题是要找到一个随机数,使区块的哈希值小于目标值。难度会调整以维持恒定的平均出块时间。最先找到有效随机数的矿工广播该区块,其他节点进行验证。获胜矿工获得新铸造的币和交易费作为奖励。

Proof of Stake, by contrast, selects validators based on the amount of cryptocurrency they “stake” or lock up as collateral. Validators are chosen pseudo-randomly, with probability proportional to their stake. If a validator proposes an invalid block, their stake is slashed. PoS is far more energy-efficient than PoW because it does not require expensive computation.

相比之下,权益证明根据验证者“质押”或锁定的加密货币数量来选择验证者。验证者的选择是伪随机的,概率与其质押量成正比。如果验证者提出无效区块,其质押将被削减。PoS比PoW节能得多,因为它不需要昂贵的计算资源。


7. Mining and Block Generation | 挖矿与区块生成

Mining is the process of adding new blocks to the blockchain under PoW. Miners collect pending transactions from a memory pool, verify each transaction’s signature and UTXO validity, and assemble them into a candidate block. They then search for a nonce that makes the block hash meet the difficulty target.

挖矿是在PoW机制下向区块链添加新区块的过程。矿工从内存池中收集待处理交易,验证每笔交易的签名和UTXO有效性,并将它们组装成候选区块。然后,他们寻找一个随机数,使区块哈希满足难度目标。

Because SHA-256 is a one-way function, mining requires brute-force searching. The expected number of attempts is approximately 2²⁵⁶ divided by the target value. This probabilistic process means that a miner’s chance of success is proportional to their computational power, commonly measured in hashes per second.

由于SHA-256是单向函数,挖矿需要暴力搜索。预期尝试次数约为2²⁵⁶除以目标值。这个概率过程意味着矿工的成功机会与其计算能力成正比,通常以每秒哈希数来衡量。

Once a miner finds a valid nonce, it broadcasts the block to the network. Other nodes validate the block by checking the proof of work, verifying all transactions, and confirming that the previous block reference is correct. Because the chain with the most cumulative work is considered canonical, any competing block that is not extended quickly becomes orphaned.

一旦矿工找到有效随机数,它将广播区块到网络。其他节点通过检查工作量证明、验证所有交易以及确认前序区块引用是否正确来验证区块。由于累计工作量最多的链被视为权威链,任何未能被迅速扩展的竞争区块最终会成为孤块。


8. Smart Contracts | 智能合约

A smart contract is a self-executing program stored on a blockchain. It runs exactly as coded, with no possibility of censorship, downtime, or fraud. Ethereum popularised this concept by providing a virtual machine, the Ethereum Virtual Machine (EVM), which executes bytecode on every node.

智能合约是存储在区块链上的自动执行程序。它严格按照代码运行,不受审查、停机或欺诈影响。以太坊通过提供虚拟机(EVM)推广了这一概念,该虚拟机在每个节点上执行字节码。

Smart contracts are written in high-level languages such as Solidity, then compiled into bytecode. They can hold funds, define ownership rules, and automate multi-step workflows. For example, a crowdfunding contract might collect funds from many users and only forward them to the creator if a funding target is reached within a deadline.

智能合约通常用Solidity等高级语言编写,然后编译为字节码。它们可以持有资金、定义所有权规则,并自动化多步骤工作流程。例如,众筹合约可以从多个用户处收集资金,并仅在截止日期前达成筹款目标时将其转给发起人。

From a computer science perspective, smart contracts raise interesting questions about determinism, gas limits, and security. Since every node must reach the same result, contracts cannot use randomness or system time directly. Gas is a pricing mechanism that prevents infinite loops and resource abuse by charging fees for each computation step.

从计算机科学角度看,智能合约引发了关于确定性问题、Gas限制和安全性的有趣议题。由于每个节点必须得到相同结果,合约不能直接使用随机数或系统时间。Gas是一种定价机制,通过为每个计算步骤收取费用,防止无限循环和资源滥用。


9. Security and Attacks | 安全与攻击

Digital currencies are not immune to attacks. One classic vulnerability is the double-spending attack, where a user tries to spend the same UTXO twice. The consensus mechanism prevents this in normal operation, but a “51% attack” becomes possible if a single miner or pool controls more than half of the network’s hash power. This attacker could reorder or reverse transactions, although rewriting the entire chain becomes exponentially harder with depth.

数字货币并非不受攻击影响。一个经典漏洞是双重支付攻击,即用户试图花费同一UTXO两次。共识机制在正常情况下可以防止这种情况,但如果单个矿工或矿池控制超过全网一半的算力,就可能发生“51%攻击”。攻击者可以重排或逆转交易,但随着链深度的增加,重写整条链的难度呈指数增长。

Another attack vector is the Sybil attack, where an adversary creates many fake identities to gain undue influence. PoW mitigates this by tying influence to computational work, while PoS ties it to economic stake. Additionally, cryptographic attacks on hash functions or signature algorithms would be catastrophic, but current primitives remain secure against known computational limits.

另一种攻击方式是女巫攻击,即对手创建大量虚假身份以获取不当影响力。PoW通过将影响力与计算工作量绑定来缓解此问题,而PoS则将其与经济质押绑定。此外,对哈希函数或签名算法的密码学攻击将是灾难性的,但当前的密码原语在已知计算限制下仍然是安全的。

Users also face security risks outside the protocol: phishing, malware, and lost private keys account for a majority of real-world losses. Therefore, digital currency education is not complete without emphasising personal security practices, such as using hardware wallets and multi-signature schemes.

用户还面临协议之外的安全风险:网络钓鱼、恶意软件和私钥丢失是现实中大多数损失的主要原因。因此,数字货币教育必须强调个人安全实践,例如使用硬件钱包和多签名方案。


10. Digital Currency and the Computer Science Syllabus | 数字货币与计算机科学考纲

Digital currency technologies map directly onto several topics in the CIE Computer Science syllabus. Data structures such as linked lists and hash tables appear in the blockchain and Merkle trees. Algorithms for hashing and digital signatures reinforce content on cryptographic techniques and data integrity.

数字货币技术与CIE计算机科学考纲中的多个主题直接对应。数据结构中的链表和哈希表体现在区块链和默克尔树中。哈希算法和数字签名强化了密码学技术和数据完整性方面的内容。

Networking concepts, including client-server versus peer-to-peer architectures, are central to understanding how nodes synchronise. Database concepts such as atomicity and consistency appear in transaction validation. The idea of a state machine, where each block transition changes the global state, connects to finite state automata taught in the theory of computation.

网络概念,包括客户端-服务器架构与点对点架构的对比,是理解节点同步的核心。数据库概念如原子性和一致性体现在交易验证中。状态机的思想——每个区块转换改变全局状态——与计算理论中讲授的有限状态自动机相呼应。

Finally, the study of digital currency raises ethical and professional issues, including energy consumption, financial inclusion, and regulatory compliance. These discussions help students connect technical knowledge with broader societal impact, a key goal of the Cambridge curriculum.

最后,数字货币研究还引发了伦理和职业问题,包括能源消耗、金融包容性和监管合规。这些讨论帮助学生将技术知识与更广泛的社会影响联系起来,这正是剑桥课程的重要目标。


In summary, digital currency is more than a financial innovation; it is a profound application of computer science principles. From cryptographic hashing and digital signatures to distributed consensus and smart contracts, every layer of the system demonstrates how algorithms and data structures can create trust without a central authority. For A-Level students, understanding these mechanisms provides a strong foundation for further study in distributed systems, security, and blockchain engineering.

总而言之,数字货币不仅是金融创新,更是计算机科学原理的深刻应用。从密码学哈希和数字签名,到分布式共识与智能合约,系统的每一层都展示了算法和数据结构如何在无中心权威的情况下建立信任。对于A-Level学生来说,理解这些机制将为后续学习分布式系统、安全性和区块链工程奠定坚实基础。

Published by TutorHao | Computer Science Revision Series | aleveler.com

更多咨询请联系16621398022(同微信)

Comments

屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from aleveler.com

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version