欢迎光临
我们一直在努力

14.ETH-以太坊概述-北大肖臻老师客堂笔记

北京大学肖臻老师《区块链技术与应用》公开课第 14 讲是以太坊 (Ethereum) 的开篇,主题通常是**“以太坊概述” (Introduction to Ethereum)**。

在告别了比特币章节后,课程正式进入“区块链 2.0”时代。这一讲主要介绍了以太坊的设计理念、与比特币的区别以及核心账户模型。

以下是本课内容的结构化详细总结:

一、 以太坊的定位:区块链 2.0

  • 从去中心化货币到去中心化合约:
    • 比特币 (Bitcoin):主要目标是做一个去中心化的加密货币(Payment Network),被称为“全球账本”。
    • 以太坊 (Ethereum):主要目标是做一个去中心化的智能合约平台 (Smart Contract Platform),被称为“世界计算机”。
  • 可编程性:
    • 比特币的脚本语言(Script)非常简单,功能有限(非图灵完备),很难开发复杂的应用。
    • 以太坊提供了一种图灵完备 (Turing Complete) 的编程语言(Solidity),允许开发者在区块链上编写任意复杂的逻辑(智能合约)。

    二、 以太坊的账户模型 (Account-based Model)

    这是以太坊与比特币最底层的区别。

    1. 比特币:UTXO 模型
    • 特点:没有“账户余额”的概念,你的钱是一堆“未花费的交易输出” (UTXO) 拼凑出来的。
    • 缺点:难以精确控制“状态”。比如你想写一个合约限制“每天只能取 10 块钱”,在 UTXO 模型下很难实现,因为你需要追溯并管理大量零散的 UTXO。
    2. 以太坊:基于账户的模型
    • 特点:系统直接记录每个账户的余额 (Balance)、计数器 (Nonce) 等状态。这就好比银行账户,想转账直接扣款即可。
    • 优点:
    • 直观:符合人们对“账户”的直觉理解。
    • 易于编程:智能合约本质上就是管理状态(State),账户模型天生适合状态管理。
    • 防重放攻击:显式地使用 Nonce(交易计数器)来防止同一笔交易被广播两次。

    三、 两类账户 (Two Types of Accounts)

    在以太坊中,账户分为两类,它们在数据结构上是统一的,但功能不同。

    1. 外部账户 (Externally Owned Account, EOA)
    • 控制者:由私钥控制(即普通用户使用的账户)。
    • 特点:
    • 有余额 (Balance)。
    • 有 Nonce (交易序号)。
    • 没有代码 (No Code)。
    • 主动发起交易:只有 EOA 才能发起交易(Transaction),这是区块链一切活动的源头。
    2. 合约账户 (Contract Account)
    • 控制者:由代码逻辑控制(没有私钥对应)。

    • 特点:

    • 有余额。

    • 有 Nonce。

    • 有代码 (Code):存储了智能合约的编译后字节码。

    • 有存储 (Storage):维护了一棵存储树(Storage Trie),保存合约运行时的状态变量(如投票数、众筹金额等)。

    • 被动执行:合约账户不能自己发起交易,必须被 EOA 或其他合约调用(发送消息)才能触发其代码执行。

    四、 交易与消息 (Transaction & Message)

    • 交易 (Transaction):

    • 指的是从 外部账户 (EOA) 发出的签名数据包。

    • 包含:接收方地址、金额、Nonce、签名、以及可选的数据(Data,用于调用合约函数)。

    • 消息 (Message / Internal Transaction):

    • 指的是合约调用合约时产生的数据传递。

    • 它不直接记录在区块链上,而是作为交易执行过程中的一部分。

    五、 以太坊的数据结构概览

    肖老师在这一讲中也简要铺垫了以太坊复杂的状态树结构(下一讲会深入):

    • 状态树 (State Trie):记录全网所有账户的状态(余额、Nonce、代码哈希、存储根)。
    • 特点:使用 MPT (Merkle Patricia Trie) 结构,既能像 Merkle Tree 一样验证数据完整性,又能高效地进行查找和更新。

    🧠 逻辑流程:以太坊的运行机制

    #mermaid-svg-UrRW8Q5yCcIyTSgJ{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-UrRW8Q5yCcIyTSgJ .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .error-icon{fill:#552222;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .marker{fill:#333333;stroke:#333333;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .marker.cross{stroke:#333333;}#mermaid-svg-UrRW8Q5yCcIyTSgJ svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-UrRW8Q5yCcIyTSgJ p{margin:0;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .cluster-label text{fill:#333;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .cluster-label span{color:#333;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .cluster-label span p{background-color:transparent;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .label text,#mermaid-svg-UrRW8Q5yCcIyTSgJ span{fill:#333;color:#333;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .node rect,#mermaid-svg-UrRW8Q5yCcIyTSgJ .node circle,#mermaid-svg-UrRW8Q5yCcIyTSgJ .node ellipse,#mermaid-svg-UrRW8Q5yCcIyTSgJ .node polygon,#mermaid-svg-UrRW8Q5yCcIyTSgJ .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .rough-node .label text,#mermaid-svg-UrRW8Q5yCcIyTSgJ .node .label text,#mermaid-svg-UrRW8Q5yCcIyTSgJ .image-shape .label,#mermaid-svg-UrRW8Q5yCcIyTSgJ .icon-shape .label{text-anchor:middle;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .rough-node .label,#mermaid-svg-UrRW8Q5yCcIyTSgJ .node .label,#mermaid-svg-UrRW8Q5yCcIyTSgJ .image-shape .label,#mermaid-svg-UrRW8Q5yCcIyTSgJ .icon-shape .label{text-align:center;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .node.clickable{cursor:pointer;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .arrowheadPath{fill:#333333;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-UrRW8Q5yCcIyTSgJ .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-UrRW8Q5yCcIyTSgJ .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-UrRW8Q5yCcIyTSgJ .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .cluster text{fill:#333;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .cluster span{color:#333;}#mermaid-svg-UrRW8Q5yCcIyTSgJ div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-UrRW8Q5yCcIyTSgJ rect.text{fill:none;stroke-width:0;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .icon-shape,#mermaid-svg-UrRW8Q5yCcIyTSgJ .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .icon-shape p,#mermaid-svg-UrRW8Q5yCcIyTSgJ .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .icon-shape rect,#mermaid-svg-UrRW8Q5yCcIyTSgJ .image-shape rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-UrRW8Q5yCcIyTSgJ .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-UrRW8Q5yCcIyTSgJ .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-UrRW8Q5yCcIyTSgJ :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

    执行层

    网络层

    用户层

    1. 发起交易 (带签名)2. 验证签名 & Nonce3. 触发代码 (EVM执行)

    条件满足

    调用其他合约

    用户 EOA

    以太坊网络

    合约账户

    逻辑判断

    4. 修改状态 (余额/存储)

    发送内部消息 Message

    💡 总结

    第 14 讲的核心任务是**“转换思维”**:
    从比特币的 “UTXO + 脚本” 思维,转换到以太坊的 “账户 + 状态 + 智能合约” 思维。这是理解后续去中心化应用 (DApp) 的基石。

    赞(0)
    未经允许不得转载:171主机测评 » 14.ETH-以太坊概述-北大肖臻老师客堂笔记
    分享到: 更多 (0)

    评论 抢沙发

    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址