-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb12e4d
commit 92703ce
Showing
9 changed files
with
274 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
## DA 数据可用性 | ||
|
||
[DA](https://learnblockchain.cn/tags/DA?map=EVM)(Data Availability 数据可用性)在 [Layer2](https://learnblockchain.cn/tags/Layer2?map=EVM) 扩展方案中扮演重要角色,确保交易数据在网络中是可以访问和验证的,这对于保持网络的去中心化和抗审查性至关重要。 | ||
|
||
|
||
|
||
### 数据可用性方案 | ||
|
||
1. **链上数据可用性**:所有交易数据都存储在主链上。这是最简单的方案,确保所有节点都可以访问数据,但会导致主链的存储压力增加。 | ||
|
||
2. **数据可用性证明**:使用数据可用性证明(DA Proofs),通过数学证明的方式来确保数据是可访问的。即使数据不在主链上,节点也可以通过这些证明来验证数据的存在和完整性。 | ||
|
||
3. **数据分片**:将数据分成多个分片,分散存储在多个节点上。通过纠删码技术和数据恢复算法,可以确保即使部分节点故障或恶意行为,数据仍然是可用的。 | ||
|
||
4. **链下数据存储**:部分扩展方案将交易数据存储在链下,只有数据的哈希值或摘要存储在主链上。这种方式需要额外的机制来确保数据的可用性和完整性,如定期验证和数据重传。 | ||
|
||
|
||
|
||
|
||
|
||
4. | ||
|
||
### 数据可用性的应用 | ||
|
||
- **[Rollup](https://learnblockchain.cn/tags/Rollup?map=EVM)**:在 Optimistic Rollup 和 ZK Rollup 中,数据可用性问题尤为重要。交易数据通常存储在链下,但其可用性对于 Rollup 的安全性至关重要。 | ||
|
||
- **去中心化存储**:一些去中心化存储解决方案,如 IPFS 和 Filecoin,通过分布式网络存储和数据可用性证明来确保数据的可访问性和安全性。 | ||
|
||
- **[Layer2](https://learnblockchain.cn/tags/Layer2?map=EVM) 扩展**:在各种 Layer2 方案中,确保数据的可用性是提高扩展性和降低费用的关键。 | ||
|
||
### 结论 | ||
|
||
[DA](https://learnblockchain.cn/tags/DataAvailability?map=EVM) 是保障区块链网络安全性和可靠性的核心概念。在扩展解决方案中,采用有效的数据可用性机制能够在提高系统性能的同时,确保数据的完整性和可验证性,从而维持去中心化网络的高效运作。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
## EIP 4844 | ||
|
||
以太坊提案的 [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844)(Shard Blob Transactions)是为了解决 [数据可用性(DA)](https://learnblockchain.cn/tags/DA?map=EVM) 问题的一项提案。这项提案通过引入一种新的交易类型,即“Blob Carrying Transactions”,来提高 [以太坊](https://learnblockchain.cn/tags/以太坊?map=EVM) 网络的数据可用性。 | ||
|
||
下面详细介绍 EIP-4844 的背景、基础原理: | ||
|
||
### EIP-4844 背景 | ||
|
||
随着以太坊网络的发展和 [Layer2](https://learnblockchain.cn/tags/Layer2?map=EVM) 解决方案的普及,数据可用性问题变得越来越重要。现有的扩展方案,如 [Rollup](https://learnblockchain.cn/tags/Rollup?map=EVM),依赖于数据可用性来确保安全性和有效性。然而,将所有数据直接存储在链上会导致高昂的存储成本和网络负担。 | ||
|
||
EIP-4844 提议引入“Blob Carrying Transactions”来解决这个问题,通过在链上存储数据的证明而不是数据本身,从而提高数据可用性,同时减少存储需求。 | ||
|
||
### EIP-4844 原理 | ||
|
||
EIP-4844 主要引入了一种新的交易类型,称为“Blob Carrying Transactions”。这种交易类型包含一个或多个“Blob”(大块数据),这些 Blob 的数据本身并不存储在执行层区块链上,而是通过作为信标链的一部分(sidecar),所有共识节点完全下载(可在相对较短的延迟后即可删除,从而提供一种高效的方法来处理大规模数据,提高数据可用性而不增加链上存储负担。 | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
## OP Stack | ||
|
||
|
||
|
||
[Op Stack](https://learnblockchain.cn/tags/OpStack?map=EVM) 是由 Optimism 团队开发的一套用于构建 [Layer2](https://learnblockchain.cn/tags/Layer2?map=EVM) 解决方案的模块化框架。它旨在提供一组可重用的工具和组件,帮助开发者更容易地创建和部署高效的扩展解决方案。 | ||
|
||
以下是 [Op Stack](https://learnblockchain.cn/tags/OpStack?map=EVM) 的主要组成部分和功能: | ||
|
||
### 主要组成部分 | ||
|
||
1. **Optimistic Rollup**:这是 [Op Stack](https://learnblockchain.cn/tags/OpStack?map=EVM) 的核心组件之一,利用乐观验证机制来实现扩展性。通过假设大多数交易是有效的,仅在有争议时才进行完整的计算验证,从而提高交易处理速度。 | ||
|
||
2. **Sequencer(排序器)**:这是一个特殊的节点,负责收集和排序交易,生成批量交易,并将其提交到 [Layer1](https://learnblockchain.cn/tags/Layer1?map=EVM) 区块链上。Sequencer 提供快速的交易确认,同时确保数据可用性和最终性。 | ||
|
||
3. **Fraud Proofs**:这是用于检测和纠正无效交易的机制。当有用户质疑交易的有效性时,Fraud Proofs 会执行完整的交易验证,以确保所有提交的交易都是正确的。 | ||
|
||
4. **Data Availability**:[Op Stack](https://learnblockchain.cn/tags/OpStack?map=EVM) 提供以太坊 [4844](https://learnblockchain.cn/tags/EIP4844?map=EVM) Blob 作为[数据可用性(DA)](https://learnblockchain.cn/tags/DA?map=EVM)方案(也可以根据需要定制其他 DA),确保在链上或链下存储的数据能够随时访问和验证。 | ||
|
||
5. **Bridges**:这些组件用于连接不同的区块链,允许资产和信息在 [Layer1](https://learnblockchain.cn/tags/Layer2?map=EVM) 和 [Layer2](https://learnblockchain.cn/tags/Layer2?map=EVM) 之间自由转移。 | ||
|
||
### 功能与优势 | ||
|
||
1. **模块化设计**:开发者可以根据需要选择和组合不同的模块,从而构建定制化的扩展解决方案。 | ||
|
||
2. **高扩展性**:通过利用 [Optimistic Rollup](https://learnblockchain.cn/tags/Layer2?map=EVM) 技术,[Op Stack](https://learnblockchain.cn/tags/OpStack?map=EVM) 能够显著提高交易吞吐量,同时保持低成本。 | ||
|
||
3. **兼容性**:[Op Stack](https://learnblockchain.cn/tags/OpStack?map=EVM) 与 [以太坊](https://learnblockchain.cn/tags/以太坊?map=EVM) 完全兼容,开发者可以使用现有的 [Solidity](https://learnblockchain.cn/tags/Solidity?map=EVM) 智能合约和工具进行开发。 | ||
|
||
4. **去中心化和安全性**:通过使用 Fraud Proofs 和去中心化的 Sequencer,确保系统的安全性和抗审查性。 | ||
|
||
5. **开放生态**:[Op Stack](https://learnblockchain.cn/tags/OpStack?map=EVM) 致力于构建开放和包容的开发者社区,提供丰富的文档和支持,鼓励更多项目和开发者参与其中。 | ||
|
||
|
||
|
||
通过这些功能和特性,[Op Stack](https://learnblockchain.cn/tags/OpStack?map=EVM) 为开发者提供了一个强大而灵活的工具箱,使其能够更容易地创建和部署扩展性强的区块链应用。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
## ABI | ||
|
||
[ABI](https://learnblockchain.cn/tags/ABI?map=EVM)(Application Binary Interface,应用程序二进制接口)是 [以太坊](https://learnblockchain.cn/tags/以太坊?map=EVM) 智能合约的重要组成部分,它定义了智能合约中的函数和事件的接口。ABI 是智能合约和外部应用程序(如前端应用)之间通信的桥梁。 | ||
|
||
|
||
|
||
## ABI 描述 与 ABI 编码 | ||
|
||
使用 ABI 时,经常会接触到两个概念: ABI 描述格式和 ABI 编码,下面我将通过一个简单的智能合约来解释 ABI 格式和 ABI 编码: | ||
|
||
```solidity | ||
pragma solidity ^0.8.0; | ||
contract Example { | ||
uint256 public value; | ||
event ValueChanged(uint256 newValue); | ||
function setValue(uint256 newValue) public { | ||
value = newValue; | ||
emit ValueChanged(newValue); | ||
} | ||
function getValue() public view returns (uint256) { | ||
return value; | ||
} | ||
} | ||
``` | ||
|
||
|
||
|
||
### ABI 格式 | ||
|
||
编译上述智能合约后,会生成如下的 ABI 描述(JSON 格式): | ||
|
||
```json | ||
[ | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "getValue", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ | ||
"name": "newValue", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "setValue", | ||
"outputs": [], | ||
"payable": false, | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": false, | ||
"name": "newValue", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "ValueChanged", | ||
"type": "event" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "value", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
] | ||
|
||
``` | ||
|
||
|
||
|
||
### ABI 编码示例 | ||
|
||
#### 调用 `setValue` 函数 | ||
|
||
假设我们要调用 `setValue` 函数,将 `newValue` 设置为 `42`。需要进行以下步骤: | ||
|
||
1. 获取函数签名:`setValue(uint256)` | ||
2. 计算函数选择器:`keccak256("setValue(uint256)")` 的前 4 字节 | ||
3. 编码参数:将 `42` 编码为 32 字节 | ||
|
||
**函数选择器计算:** | ||
|
||
``` | ||
keccak256("setValue(uint256)") = 0x55241077da72b49e97926b4dd0cf5bc54426914c9124d1b8e4f58b3ad3c96c3b | ||
``` | ||
|
||
前 4 字节(函数选择器)为:`0x55241077` | ||
|
||
**参数编码:** | ||
|
||
``` | ||
`42` 编码为 32 字节:`000000000000000000000000000000000000000000000000000000000000002a` | ||
``` | ||
|
||
**最终编码:** | ||
|
||
将函数选择器和参数编码组合在一起: | ||
|
||
``` | ||
0x55241077000000000000000000000000000000000000000000000000000000000000002a | ||
``` | ||
|
||
|
||
|
||
当调用智能合约中的`setValue`函数时, 这个最终编码就是发送到 [以太坊](https://learnblockchain.cn/tags/以太坊?map=EVM) 网络的 payload 数据。智能合约接收到调用数据后,会根据 ABI 解析并执行相应的函数。 | ||
|
||
## ABI 工具支持 | ||
|
||
很多 [以太坊](https://learnblockchain.cn/tags/以太坊?map=EVM) 交互库,如 [ethers.js](https://learnblockchain.cn/tags/ethers.js?map=EVM) 和 [Web3.js](https://learnblockchain.cn/tags/ethers.js?map=EVM),都提供了对 ABI 的支持,简化了智能合约的调用和事件监听过程。 | ||
|
||
有一些工具(如: [Viem](https://learnblockchain.cn/tags/Viem?map=EVM))会根据 ABI 中定义的变量类型,使用静态类型检查,让函数参数和返回值的类型在编译时就已经确定。这样可以避免许多潜在的错误,确保数据的一致性和可靠性。 | ||
|
||
|
||
|
||
有一些方便开发者的编解码工具: | ||
|
||
* 函数名 和 函数选择器相互转换(查询): https://chaintool.tech/querySelector | ||
|
||
* 调用数据(Calldata)编解码: https://chaintool.tech/calldata | ||
|
||
* ABI 可视化调用:https://chaintool.tech/abi | ||
|
||
* OpenChain 工具,提供 ABI 编解码、调用堆栈:https://openchain.xyz | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
## Remix | ||
|
||
Remix 是一个功能强大的开源开发环境,用于编写、测试、调试和部署智能合约,特别是基于 [Solidity](https://learnblockchain.cn/tags/Solidity?map=EVM) 语言的智能合约。它在 [以太坊](https://learnblockchain.cn/tags/以太坊?map=EVM) 社区中非常流行,并且对新手和经验丰富的开发者都很友好。 | ||
|
||
Remix IDE 网址:https://remix.ethereum.org/ | ||
|
||
中文镜像网址:https://remix.learnblockchain.cn/ | ||
|
||
|
||
|
||
以下是 Remix 的一些主要功能: | ||
|
||
1. **代码编辑器**:Remix 提供了一个强大的代码编辑器,支持语法高亮、自动补全和代码格式化,帮助开发者更高效地编写 [Solidity](https://learnblockchain.cn/tags/Solidity?map=EVM) 代码。 | ||
|
||
2. **实时编译**:在 Remix 中,代码会被实时编译,开发者可以立即看到编译错误和警告,有助于快速迭代和调试。 | ||
|
||
3. **调试器**:Remix 内置了一个调试工具,可以逐步执行智能合约,检查变量状态和调用栈,帮助开发者找到和修复代码中的问题。 | ||
|
||
4. **测试**:Remix 支持通过 JavaScript 测试框架来编写和运行单元测试,确保智能合约的正确性和可靠性。 | ||
|
||
5. **插件系统**:Remix 有一个灵活的插件系统,开发者可以根据需要安装和配置各种插件,以扩展 IDE 的功能。这些插件包括 Solidity 语言服务器、分析工具和部署工具等。 | ||
|
||
6. **多环境支持**:Remix 支持连接到多个以太坊网络,包括主网、测试网和本地开发网络,方便开发者在不同环境中进行开发和测试。 | ||
|
||
7. **文件管理**:Remix 提供了一个文件管理系统,开发者可以轻松管理项目中的多个文件和目录,并支持从本地导入和导出文件。 | ||
|
||
8. **部署和交互**:通过 Remix,开发者可以将智能合约部署到以太坊网络上,并与已部署的合约进行交互。它还提供了一个用户友好的界面来发送交易和调用合约函数。 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters