Bitcoin 维护的是 UTXO 集:本质是"谁拥有什么"的账本
Ethereum 维护的是全局状态:账户余额 + 合约存储 + 代码 + nonce
每笔交易在 Ethereum 中触发一次确定性的状态转换函数:
σt+1=APPLY(σt,TX)\sigma_{t+1} = \text{APPLY}(\sigma_t, TX) σt+1=APPLY(σt,TX)
状态机范式使 Ethereum 易于表达金融逻辑:
Ethereum 系统由五个基本组件构成,共同支撑可编程区块链的运行:
Ethereum 的"状态"是每个账户的完整快照,全局映射:
σ[address]=(nonce,balance,storageRoot,codeHash)\sigma[\text{address}] = (\text{nonce}, \text{balance}, \text{storageRoot}, \text{codeHash}) σ[address]=(nonce,balance,storageRoot,codeHash)
与 Bitcoin 的关键区别:Bitcoin 状态 = UTXO 集合;Ethereum 状态 = 所有账户的完整数据
智能合约的存储(storage)是状态的一部分,由合约逻辑读写
状态在每笔交易后确定性更新——所有节点最终持有相同状态
Ethereum 本质上是一个基于交易的状态机(Transaction-Based State Machine)
核心转换公式:
σt+1=Υ(σt,T)\sigma_{t+1} = \Upsilon(\sigma_t, T) σt+1=Υ(σt,T)
其中 Υ\UpsilonΥ 是状态转换函数,输入当前状态 σt\sigma_tσt 和交易 TTT,输出新状态 σt+1\sigma_{t+1}σt+1
步骤梳理:
常见操作码及其 Gas 消耗(反映资源成本):
Ethereum 交易的结构:
调用链:EOA 交易 →\rightarrow→ 合约 A →\rightarrow→ 合约 B →\rightarrow→ ...
消息调用(Message Call):合约到合约的调用,可传递数据和 ETH
Gas 消耗的三个层面:
Gas 与费用的区分(教学重点):
Gas limit 验证:交易指定的 gasLimit 必须至少等于实际消耗——否则交易失败
contract SimpleToken { mapping(address => uint256) public balanceOf; event Transfer(address indexed from, address indexed to, uint256 value); constructor(uint256 _supply) { balanceOf[msg.sender] = _supply; } function transfer(address to, uint256 amount) external returns (bool) { require(balanceOf[msg.sender] >= amount, "insufficient balance"); balanceOf[msg.sender] -= amount; balanceOf[to] += amount; emit Transfer(msg.sender, to, amount); return true; } }
DApp(Decentralized Application):至少由以下三层构成:
用户交互层(前端 UI / 移动端) (通过钱包签名) 合约执行层(智能合约逻辑 + 状态) (链上数据索引与查询) 数据层(区块链账本 + 事件日志)
与传统 App 的本质区别:
Transfer(from, to, value)
Approval(owner, spender, value)