60 |
61 | 每个区块的奖励由创世账号从国库中提取出来,发送给出块的矿工,延迟 N 个块到帐,初始值是 7 个块。如果国库中余额为 0 ,则该区块没有区块奖励。
62 |
63 | ## 链上治理
64 |
65 | Starcoin 内置了一套 DAO 合约,创世交易中,创世账号会初始化一个 DAO,并将 STC 设置为治理 Token。STC 的持有者可以参与以下治理项的治理:
66 |
67 | 1. 链上配置变更,比如上面的区块奖励参数。
68 | 2. DAO 相关参数的变更。
69 | 3. Stdlib 中的系统合约升级。
70 | 4. 从国库中申请提款权。
71 |
72 | 投票方式为 1 个 STC 1 票,当同意的票数大于反对的票数,并且超过 DAO 的最低票数阈值,则该提案通过。最低票数阈值由 STC 的真实流通量乘 DAO 的阈值比例得出,初始化的阈值比例是 4%。初始化的投票周期为 7 天,投票周期内参与投票的 STC 会锁定到提案中,直到投票结束。
73 |
74 | 注:STC 真实流通量 = STC 铸币总量 - 国库中的余额。也就是说,如果线性提款权未被使用,不会算在真实流通中。
75 |
76 | ## 国库提款权
77 |
78 | 国库提款权是一种矿工奖励之外的 STC 分发机制,如果有生态项目建设方,可发起提案,申请提款权。以下是发起流程:
79 |
80 | 1. 任何人都可以发起提案。提案中需指定线性提款权的接收方,需要的总数,线性释放的周期。
81 | 2. 社区成员通过 STC 投票支持或者反对该提案。
82 | 3. 提案通过后,接收方需要在链上执行提案,获取到线性提款权。
83 | 4. 接收方通过线性提款权定期从国库中提款。
84 |
85 | ## 经济模型自举
86 |
87 |
88 |
89 | 当前的 PoW 公链,PoW 既是保证安全的一种共识机制,也是 Token 的分发策略。PoW 链的经济模型中,Token 先分发给矿工,然后再流转到其他生态。
90 |
91 | 但这种模型对于 BTC 这样的以价值存储为目标的链来说,是可以形成生态闭环的,但对于智能合约链来说,Token 的价值依赖于链上的生态的繁荣,所以 Token 分发策略中应该向上层的生态应用倾斜,同时需要通过生态建设分发 Token,而不单纯通过矿工分发。
92 |
93 | 从长远来看,链上的基础生态收益,最后归入到国库中,国库资金如果最后可以覆盖未来的研发投入以及矿工奖励,说明链的经济模型实现了自举。
--------------------------------------------------------------------------------
/sip-5/index.zh.md:
--------------------------------------------------------------------------------
1 | ---
2 | sip: 5
3 | title: "[SIP5] 引入国库机制,让链的发展可持续"
4 | author: "@jolestar"
5 | sip_type: paper
6 | category: Core
7 | status: Draft
8 | created: 2021-04-13
9 | weight: 5
10 | ---
11 |
12 | # 引入国库机制,让链的发展可持续
13 |
14 | ## 背景与动机
15 |
16 | 国库是一个和 DAO 关联起来的资金库,可以通过治理机制支配其中的资金。当前 Starcoin 的经济模型中,预留了一部分固定的生态基金的 Token 额度,用于发展生态,但固定额度的生态基金有可持续问题。另外通过 PoW 分发的 Token,如果分发完之后,链如何运转,也尚未有明确答案。
17 |
18 | 所以这个提案中建议引入国库 (Treasury) 机制,为链的可持续的生态系统打好基础,同时也给 DAO 系统补上了不可或缺的一环。
19 |
20 | ## 方案
21 |
22 | 1. STC 总量恒定,在创世块中一次性铸造出来锁到国库中,并销毁铸造能力。
23 | 2. 国库中的的 STC 支取需要通过链上的治理机制进行决策。
24 | 3. PoW 矿工奖励也从国库中提取,出块奖励的基础额度通过链上治理机进行调整。
25 | 4. 如果 STC 国库没有余额,则出块无奖励。
26 | 5. 链的生态k可以创造一些收益,并注入国库。
27 |
28 |
29 | ## 经济模型解释
30 |
31 | 当前的 PoW 公链,PoW 既是保证安全的一种共识机制,也是 Token 的分发策略。PoW 链的经济模型中,Token 先分发给矿工,然后再流转到其他生态。
32 |
33 | 但这种模型对于 BTC 这样的以价值存储为目标的链来说,是可以形成生态闭环的,但对于智能合约链来说,Token 的价值依赖于链上的生态的繁荣,所以 Token 分发策略中应该向上层的生态应用倾斜,同时需要通过生态应用分发 Token,而不单纯通过矿工分发。
34 |
35 | 从长远来看,链上的基础生态收益,最后归入到国库中,国库资金如果最后可以覆盖未来的研发投入以及矿工奖励,说明链的经济模型实现了自举。
36 |
37 |
38 | ## 技术方案
39 |
40 | 定义一个链上的 Treasury, 这个 Treasury 是一个通用的模块,支持任意 Token,所以第三方 Token 也可以使用国库机制。 只有 Token 但 issuer 可以创造 Treasury.
41 |
42 |
43 | ```rust
44 | module Treasury{
45 |
46 | struct Treasury
60 |
61 | The reward of each block is extracted from the Treasury by the genesis account, and sent to the miner who offered the block, delayed by N blocks to the account, and the initial value is 7 blocks. If the balance in the Treasury is 0, there is no block reward for this block.
62 |
63 | ## On-chain Governance
64 |
65 | Starcoin has a built-in DAO contract. In the generation transaction, the genesis account will initialize a DAO and set the STC as the governance Token. STC holders can participate in the governance of the following governance items:
66 |
67 |
68 | 1. On-chain configuration changes, such as the aforementioned block reward parameters.
69 | 2. The changes of DAO-related parameters.
70 | 3. System contract upgrade in Stdlib.
71 | 4. Application for withdrawal rights from the Treasury.
72 |
73 | For voting, one STC accounts for one vote. When the number of affirmative votes exceeds the minimum number of votes in the DAO and is greater than the number of negative votes, the proposal is accepted. The minimum number of votes is calculated by the multiplication of both the circulating STC amount and the DAO threshold ratio (the initial threshold is 4%). The initial voting period is 7 days. All participating STCs in the voting period will remain locked in the proposal until the end of the voting.
74 |
75 | Note: the circulating STC amount = total minted STC amount - Treasury balance. In other words, if the linear withdrawal right is not used, it will not be counted towards actual circulation.
76 |
77 | ## Treasury Withdrawal Rights
78 |
79 | Treasury withdrawal rights are an STC distribution mechanism in addition to miner rewards. Any one can initiate proposals and submit it to the ecological project construction party to apply for withdrawal rights. The following is the initiation process:
80 |
81 | 1. Anyone can initiate a proposal. The proposal needs to specify the recipient of linear withdrawal rights, the total number of Tokens in the application, and the period of linear release.
82 | 2. Community members may support or oppose the proposal via STC voting.
83 | 3. After the proposal is passed, the receiver needs to execute the proposal on the chain to obtain linear withdrawal rights.
84 | 4. The recipient periodically withdraws funds from the treasury through linear withdrawal rights.
85 |
86 | ## Economic Model Bootstrapping
87 |
88 |
89 |
90 | In the current PoW-based public chain, PoW is not only a security-wise consensus mechanism, but also a Token distribution strategy. In the economic model of the PoW chain, Tokens are firstly distributed to miners and then transferred to other ecosystems.
91 |
92 | However, for chains such as BTC that target value storage, this model can form an ecological closed loop. But for smart contract chains, the value of Tokens depends on the prosperity of the on-chain ecology, so the Token distribution strategy should be leaning toward the upper-level ecological applications, and at the same time, Tokens need to be distributed through ecological construction, not simply through miners.
93 |
94 | In the long run, the basic on-chain ecological benefits are finally included in the Treasury. If the funds in the Treasury can finally cover future R&D investment and miner rewards, it means that the economic model of the chain has bootstrapped itself up.
95 |
--------------------------------------------------------------------------------
/sip-22/index.zh.md:
--------------------------------------------------------------------------------
1 | ---
2 | sip: 22
3 | title: "[SIP22] NFT"
4 | author: "@jolestar"
5 | sip_type: Standard
6 | category: Contract
7 | status: Alpha
8 | created: 2021-08-10
9 | weight: 22
10 | ---
11 |
12 | ## NFT
13 |
14 | NFT 的实现和扩展协议
15 |
16 |
17 |
18 | ## 动机
19 |
20 | 在智能合约中,Token 用来表达可拆分的数字资源,而要表达不可拆分的资源,就需要 NFT。在 Move 中,任何一个不可 copy 和 drop 的类型实例,都可以认为是一个不可拆分的资源,是一个 NFT。但 NFT 需要一种统一展示的标准,以及 NFT 的收集和转移方法,所以设计本标准。
21 |
22 | ## 目标
23 |
24 | 提供一种通用的,可扩展的标准,同时提供 NFT 相关的基本操作实现。
25 |
26 | ## 类型定义
27 |
28 | ```rust
29 | struct NFT
66 |
67 |
68 | ### 动态出块时间调整
69 |
70 | 为了将叔块维持在一个合适的阈值内,在每个 Epoch 末,都会重新调整下一个周期的出块时间。
71 |
72 | 如果叔块率较高,则说当前的出块时间间隔下,网络中存在较多的分叉和孤块,我们需要调大出块的时间,缓解此问题。反之,则说明全网出块情况良好,还能进一步缩短出块时间,进一步提高全网吞吐。
73 |
74 | 算法引入以下参数:
75 |
76 | | 名称 | 描述 |
77 | | ------------------ | ------------------------------ |
78 | | epoch_avg_time | 上一个周期内的算数平均出块时间 |
79 | | epoch_uncles_rate | 上一个周期的叔块率 |
80 | | uncles_rate_target | 目标叔块率 |
81 | | next_time_target | 下一个周期的出块时间 |
82 |
83 |
84 | 计算方式:
85 |
86 | ```rust
87 | next_time_target = epoch_avg_time * epoch_uncles_rate / uncles_rate_target
88 | ```
89 |
90 | ### 动态调整区块大小
91 |
92 | 我们希望区块的大小限制能根据网络情况来动态调节,而区块的大小和区块中所有交易使用掉的 Gas 成正比,所以我们通过调整区块的 Gas 限制来调整区块大小。
93 |
94 | 针对一个 Epoch 内的所有区块 Gas 消耗统计,并结合出块速度,动态的调整区块 Gas 限制。当出块速度达到系统设置的最小值,全网拥塞情况处于良好,因此可以调大区块的 Gas 限制,增加区块大小;反之,当出块速度达到系统设置的最大值时,全网较为拥塞,因此需要降低区块的 Gas 限制,降低区块大小。
95 |
96 |
97 | ### 动态难度调整机制
98 |
99 | Starcoin 改进了中本聪共识的难度调整算法,使得:
100 |
101 | 1. 反应更快速:当全网算力发生变化时,难度值能够快速做出反应。
102 | 2. 出块时间更稳定:在全网算力不变时,有的块偶发性的出快或者出慢,难度不应该剧烈的波动。
103 |
104 |
105 | 通过以下办法进行改进:
106 |
107 | 1. 根据叔块率调整出块时间从而调整下一个 Epoch 的难度。
108 | 2. 难度计算中引入区块高度做为权重,对平均出块时间的计算为高度加权的算术平均。
109 | 3. 使用更短的难度周期。
110 |
111 |
112 | 算法引入以下参数:
113 |
114 | | 名称 | 描述 |
115 | | ------------------ | ------------------------------ |
116 | | block_time_target | 下一 Epoch 的出块时间 |
117 | | n | 难度调整周期内的区块数(小于 Epoch 内的区块数,初始值为 Epoch 区块数的十分之一)|
118 | | next_target | 下一周期的难度目标 |
119 | | block_target_i | 高度为 i 的区块难度 |
120 | | block_time_i | 高度为 i 的区块出块时间 |
121 |
122 |
123 | 计算方法:
124 |
125 | ```rust
126 | next_target = avg_target * avg_time / block_time_target
127 | ```
128 |
129 | 其中:
130 |
131 | ```rust
132 | Arithmetic Mean avg_target
133 | avg_target = (block_target_cur-n+1 + block_target_cur-n +...+ block_target_cur) / n
134 |
135 | Weighted Arithmetic Mean avg_time
136 | avg_time = block_time_cur-n+1 * 1 + block_time_cur-n * 2 +...+ block_time_cur * n / ((n) * (n+1) / 2)
137 | ```
138 |
139 | ### 动态出块奖励调整
140 |
141 | Starcoin 出块奖励的调整遵循如下原则:
142 |
143 | 1. 奖励为难度 / 时间线性。根据下一个周期的出块时间,来动态调整出块奖励。
144 | 2. 分配一定比例的奖励给汇报叔块的区块。
145 |
146 | Starcoin 的动态调整的算法依赖叔块率的数据,而叔块信息需要矿工额外的付出成本去收集,为了奖励矿工在区块中汇报叔块信息,会分配一定的奖励给当前汇报叔块的矿工。
147 |
148 | 叔块奖励计算方式:
149 |
150 | ```rust
151 | reward = next_epoch_block_reward * (1 + reward_per_uncle_percent * uncles)
152 | next_epoch_reward_block = base_reward_per_block * block_next_time_target / base_time_target
153 | ```
154 |
155 | ## 2. 所有权明晰的状态存储
156 |
157 | 区块链的状态存储机制是区块链系统设计中的关键点之一,对链的性能以及安全性都有很大的影响。Starcoin 的状态存储,采用类似以太坊的账户模型,所有用户的状态构成了一个通过地址映射的状态树。 从创世状态开始,随着将交易作为输入信息,将状态推进到下一个新的状态中,生成新的状态树。
158 |
159 | 以太坊将账号分为合约账号和用户账号。合约账号用于部署合约的代码以及存储合约的状态,用户在某个合约中的状态都保存到该合约账号下,读写权限也由合约自己控制。这样的设计自由度很高,但导致合约状态的所有权不明确,从而容易带来安全上的问题以及很难解决"状态爆炸"问题。
160 |
161 | Starcoin 以太坊账户模型基础上做了以下改进:
162 |
163 | 1. 废弃了合约账号,任意账号都可以部署智能合约,部署的智能合约在当前账号下。
164 | 2. 通过对合约编程语言中状态存储机制的改变,让智能合约的开发者很容易的把合约的状态分散保存到该状态所属的用户地址下,从而明确状态的所有权。
165 |
166 | 通过这样的改造,一方面增强了链对用户状态的安全保护能力,另外一方面也为状态计费提供了可能。
167 |
168 | ### 两级状态模型
169 |
170 | 我们在 Diem 的 Jellyfish-Merkle 树的基础上,增加了可分叉功能作为状态存储的基础组件,封装成两级状态树结构。Jellyfish-Merkle 是一种前缀查询树结构。整个链的状态是一个全局树,叶子节点是每个用户的状态 AccountState,查询路径是账号地址;AccountState 里存的便是用户的 Resource 和 Code 的二级 Merkle 树的根哈希值。如下图所示:
171 |
172 |
173 |
174 | Code 树的叶节点是每个合约 Module 的代码,查询路径是 Module 名称。Resource 树的叶节点是合约中的状态,查询路径是状态类型 StructTag。这样合约中即可通过 `borrow_global
307 |
308 | ### 基础层安全
309 |
310 | Starcoin 使用 Rust 语言开发,保障基础组件的内存安全与高效。众所周知,使用 C/C++ 语言经常有内存安全方面的问题,而其他一些高级语言如 Java/Go/Python 等,受 Runtime 和垃圾回收机制等方面的影响,执行效率通常会比 C/C++ 略逊一筹。Rust 语言集二者长处于一身,在保证了内存安全的同时,又兼顾了极致的执行效率。Starcoin 在选择开发语言的时候充分考虑到了安全性和运行效率等因素,选择 Rust 语言开发,最大程度上保障 Starcoin 的安全与高效。
311 |
312 | 在 Starcoin 的整体设计中,提供了四个层面的数据校验机制:
313 |
314 | 1. 交易可校验:BlockHeader 包含一个全局交易累加器的根哈希,任何上链的交易都有对应的全局证明。
315 | 2. 状态可校验:BlockHeader 包含一个全局状态状态树的根哈希,保障了状态可验证。
316 | 3. 区块可校验:BlockHeader 包含一个 BlockBody 的哈希,用于校验 BlockBody 中的数据。
317 | 4. 链可校验:BlockHeader 包含一个全局区块累加器的根哈希。任何一个区块可以提供一个和当前区块的关系证明,不需要遍历区块即可验证某个区块是否是当前区块的祖先区块。参考下图
318 |
319 |
320 |
321 | 以上是 Starcoin 安全性的基石。其中,「交易累加器」和「区块累积器」组成了 Starcoin 独特的「双累加器」模型,为数据安全提供坚实的基础。
322 |
323 |
324 | ### 共识层安全
325 |
326 | Starcoin 共识针对中本聪共识做了一些改良,在继承中本聪共识安全、完全去中心化和防篡改等特性的同时,在安全方面的改进体现在:
327 |
328 | 1. 更加敏锐的感知和适应算力波动
329 | 4. 可通过链上治理调整共识参数,降低硬分叉带来的安全风险的可能
330 |
331 | ### 协议层安全
332 |
333 | Starcoin 协议在数据安全和共识层安全的基础上进行设计,充分保障了链在非可信网络中的安全性。Starcoin 协议本着数据可验证的原则,对接收到的网络数据进行严格的校验,迅速甄别作恶节点,从而起到保护节点安全的作用。
334 |
335 | ### 扩展层安全
336 |
337 | 为了更好地扩展区块链的能力,Starcoin 将智能合约的安全作为重要设计目标。Starcoin 使用 Move 语言作为智能合约语言。Move 语言的设计理念是让针对数字资产的编程更加安全、简单,所以在语言的设计过程中首先考虑了安全性和可靠性。Move 语言的设计者们从以往的智能合约安全事件中充分吸取经验教训,最大可能的降低 Move 合约出现意外漏洞或安全事件的风险,其安全性主要由以下几个方面保证:
338 |
339 | 1. 自底向上的静态类型系统;
340 | 2. 资源不可复制或者隐式丢弃;
341 | 3. 资源按用户存储,重新定义链,合约,用户三方的数据操作权限;
342 | 4. 引入形式化验证技术,通过数学原理来证明合约的安全性;
343 |
344 | ### 应用层安全
345 |
346 | Starcoin 主要在以下层面支撑应用层的安全性:
347 |
348 | 1. 提供多签交易,方便通过多签来管理数字资产。
349 | 2. 提供私钥重置功能,在账号地址不变的情况下,可变更私钥。
350 | 3. 应用层可通过前面提到的数据校验机制,方便地确定交易是否上链、验证状态以及区块是否合法,从而保证应用的安全与可靠。
351 |
352 |
353 | ## 6. 分层网络
354 |
355 | **背景**
356 |
357 | 当前区块链面临的可扩展性问题的解决思路主要有两种,一种是一层(layer1)扩展,另外一种是二层(layer2)扩展。一层的扩展受不可能三角限制,很难平衡安全和可扩展性,所以 Starcoin 的设计中,一层主要负责安全,二层负责扩展,一二层有机结合起来,解决区块链面临的可扩展性问题。这种思路,已经是公链领域在一层扩展遇到困难后,基本达成的共识,比如以太坊的 Rollup 发展路线 [4],Nervos 的 CKB [7]。
358 |
359 | 一层在分层网络中的职能:
360 |
361 | 1. 通过增强的中本聪共识机制来尽可能的在保证安全的基础上在一层扩容,最大化一层网络的利用率(出块时间以及区块大小的动态调整机制,参看共识部分)。
362 | 2. 提供资产的定义,发行,以及流转,以及一二层之间的流转能力。
363 | 3. 给二层提供仲裁能力,二层可以利用一层的安全机制来保证自己的安全。
364 |
365 | 二层在分层网络中的职能:
366 |
367 | 1. 将一层的交易分流到二层,一层不再关心二层交易的细节以状态的变更。
368 | 2. 提供一套监督机制,二层的不同角色之间可以互相监督。
369 | 3. 提供证据保全能力,用户如果对二层的交易有争议,可以到一层仲裁。
370 |
371 | ### 二层方案概览
372 |
373 | **状态通道**
374 |
375 | 通用的状态通道包含支付通道,只是后者的状态只能是资产,而通用的状态通道试图把状态扩展到应用的任意状态。状态通道的根本思路是通过通道双方的互相监督,让双方之前的状态变化从链上迁移到链下,等通道关闭时再进行链上清算(也可以优化为定时清算),相当于把多次交易的状态变更合并为一次,从而降低交易成本,提升整体的交易容量。通道内的状态变化成本极其低廉,所以可以支持高频交易或者双方交互频繁的互联网应用(比如游戏)。虽然理论上状态通道的参与者可以是多方,但由于状态通道上的任何变更都需要所有参与方共同确认,所以很难扩展到两个以上的参与方,也因此限制了它的应用场景。
376 |
377 | **侧链**
378 |
379 | 侧链或者子链,业界并没有非常准确的定义,很多人也不认为侧链是二层方案的一种。但我们这里限定一个条件,当侧链的共识机制依赖于一层的共识机制,提供了一种仲裁机制,允许侧链的用户或者节点运营方对侧链共识达成的状态在一层进行挑战,并可以通过一层的仲裁机制,推翻侧链共识状态,我们就认为这种侧链方案属于一种二层的解决方案,否则侧链是一个独立的链,本质上和多个链之间的跨链没有区别。侧链作为二层解决方案的好处是可以扩展到任意多方,并且侧链有了一层的仲裁约束,可以做到只要有一个侧链节点是诚实节点即可保证网络安全。
380 |
381 | **RollupChain**
382 |
383 | RollupChain 是区块链社区新兴的一种二层解决方案,本质上可以理解成是对原来 Commit-Chain 方案(如 Plasma )的改进。在 Commit-Chain 方案中,二层链的运营方需要定时向一层提交二层链的状态根或者区块头证明,而用户可以通过自己状态的证明直接在一层退出二层的资产,如果运营方提供了错误的证明,用户也可以对运营方提交的证明进行挑战,从而保证二层的安全。但 Plasma 的方案中,数据可用性一直是一个难题,用户没有全量的数据,二层链的运营方可能通过隐藏数据或者拒绝服务等方式阻止用户构造出挑战自己的证明。而 RollupChain 的关键改进就是将二层的数据直接提交到一层区块中,一层的区块只是『记录』了二层的交易数据,但并不执行。但当用户需要挑战运营方时,总能在一层找到数据并构造证明,从而解决了数据可用性问题。虽然 RollupChain 也会受限于一层的容量(因为它的交易也需要占用一层区块的容量),但它简化了 Plasma 等方案的挑战机制设计的复杂度,是当前更容易落地实现的方案。
384 |
385 | **可验证的链下计算**
386 |
387 | 可验证的链下计算入 zk-rollup 等方案,思路和 RollupChain 的机制一样。但它引入了零知识证明,避免了二层的交易如果需要挑战,依然需要在一层执行的难题,一层只需要提供校验零知识证明的能力即可。
388 |
389 | **统一的二层方案模型**
390 |
391 | 总结当前的各种二层方案,可以发现并没有『银弹』可以一次性解决区块链的可扩展性问题,区块链的扩展性问题的解决,需要在实践中不断的演进。但同时,二层各种方案之间本质上是有共同之处的,因此我们可以抽象出一种通用的二层方案模型,以适应二层方案的不断演进。当前各种二层网络中的几个关键问题:
392 |
393 | 1. 应用的状态(包括资产)如何在一层和二层之间安全的转移。
394 | 2. 如何保证二层的数据可用性。
395 | 3. 如何证明和提供仲裁机制。
396 |
397 | 这几个关键问题的解决,都和二层交易和状态的存储机制有关系。任何二层的方案,都是将一层的状态锁定并在二层重建,这些状态的变更可以表达为一个状态树,只需要定时或者最终(取决于证明以及挑战机制的设置)将状态树的根提交到一层,作为一层状态树的一个外部子树节点。这样状态的迁移以及证明可以和一层使用同样一套机制。而在 Starcoin 的一层设计中,更容易实现这样的统一模型,主要体现在:
398 |
399 | 1. 所有合约的状态抽象为统一的资源模型,方便一层和二层之间的状态迁移。
400 | 2. 合约的无状态设计,使得合约本身不维护状态,状态由底层的状态存储模型提供,方便合约在一层二层之间迁移。
401 | 3. 交易的累加器以及状态存储的模型,可以更好的提供状态证明机制,一二层复用。
402 |
403 | 关于 Starcoin 的二层设计的具体方案,会在未来发布的 Starcoin 二层设计白皮书中详述,这里只阐述了一层设计中对二层的考量。
404 |
405 | ## 总结
406 |
407 | 综上所述,Starcoin 通过在共识机制,状态存储以及智能合约编程语言方面的改进,一方面增强了安全性,使其更适合当前去中心化金融的应用场景,另外一方面也为分层架构奠定了基础,不同的层做出不同的取舍,未来可支撑高性能 DApp 运行的需求。同时通过链上治理机制,保证了链的持续演进能力和生态构建能力。
408 |
409 | **参考资源**
410 |
411 | 1. S. Nakamoto, “Bitcoin: A Peer-to-Peer Electronic Cash System,” https://bitcoin.org/bitcoin.pdf, 2008.
412 | 2. V. Buterin, "Ethereum A Next-Generation Smart Contract and Decentralized Application Platform", 2014.
413 | 3. Z. Amsden et al., “The Libra Blockchain.” https://developers.libra.org/docs/the-libra-blockchainpaper.
414 | 4. V. Buterin, “A rollup-centric ethereum roadmap" https://ethereum-magicians.org/t/a-rollup-centric-ethereum-roadmap/4698.
415 | 5. S. Blackshear et al., “Move: A language with programmable resources,” https://developers.diem.com/docs/technical-papers/move-paper .
416 | 6. EOS IO. Eos.io technical white paper. https://github.com/EOSIO/Documentation, 2017.
417 | 7. “Nervos CKB: A Common Knowledge Base for Crypto-Economy” https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0002-ckb/0002-ckb.md.
418 |
--------------------------------------------------------------------------------
/sip-6/images/stargate_layers_arch.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/sip-6/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | sip: 6
3 | title: "[SIP6] Stargate: Universal Layers Protocol Framework"
4 | author: "Starcoin Core Dev"
5 | sip_type: paper
6 | category: Core
7 | status: Draft
8 | created: 2022-01-26
9 | weight: 6
10 | ---
11 |
12 | ## Preface
13 |
14 | Currently, the prototypes of various applications on top of blockchain are already available. However, a question that all public chains need to answer remains: How to make blockchain technology adopted on a large scale?
15 |
16 | This question can be broken down into two questions:
17 |
18 | 1. How does the blockchain support massive users? That is, the blockchain's scaling problem.
19 | 2. In what way should applications be combined with the chain? That is, the relationship between the chain and Web3 applications.
20 |
21 | Regarding the issue of scaling, there are three main approaches in the current blockchain world.
22 |
23 | 1. Scaling by improving the consensus mechanism, or by reducing the number of validation nodes, etc.
24 | 2. Scaling through sharding or parallel chains.
25 | 3. Scaling through layering.
26 |
27 |
28 | Starcoin has chosen the third approach for the following reasons:
29 |
30 | 1. Layering is a customary approach to solve the scaling problem in human societies. For example, judicial systems and political institutions, all solve the scaling problem by layering. The constraint mechanism between different layers can ensure security.
31 | 2. In the impossible triangle of blockchain, Layer1 should focus more on security.
32 | 3. The requirements for decentralization, security, and throughput differs for different applications and different stages of applications. It is easier to achieve a gradual application-oriented evolutionary solution through a layered approach.
33 |
34 | Stargate is a layered protocol framework on the Starcoin blockchain network. It supports different layering solutions through a universal abstraction.
35 |
36 | 1. Layer1 ensures Security and Permissionless.
37 | 2. Layer2 enables Finality, migrating state and computation from Layer1 to Layer2, enabling global scaling and instant confirmation of transactions.
38 | 3. Layer3 supports Web3 applications through application-oriented consensus solutions.
39 |
40 |
41 |
42 | ## Key Solutions
43 |
44 | There are three main technical challenges in all the layering solutions:
45 |
46 | 1. How to verify and arbitrate the transaction execution results of Layer2 at Layer1 (and that of Layer3 at Layer2)?
47 | 2. Can Layer2 and Layer3 depend on Layer1's smart contracts? This affects the interlayer composability of smart contracts.
48 | 3. How does the state of a smart contract move between layers?
49 |
50 | ### Transaction verification
51 |
52 | The execution of a transaction on the blockchain, while to be executed based on the historical state, will not actually read the entire historical state. A new state can also be calculated if only the state that the transaction depends on is provided.
53 |
54 | The blockchain state transition can be represented by the following formula (from Ethereum Yellow Paper).
55 |
56 | σt+1 ≡ Υ(σt, T)
57 |
58 | - σ𝑡+1 represents the next world state
59 | - Υ represents the state transition function
60 | - σ𝑡 represents the current state of the world
61 | - T represents a transaction
62 |
63 | Y relies on the current state σ𝑡 to execute T, but Y does not read all σ𝑡 states. If a subset of the states required by Y, denoted by σ`𝑡, is extracted, and the proof that σ`𝑡 σ𝑡 is also provided, the state transition can also be achieved.
64 |
65 | 
66 |
67 | We call
68 | - the subset of states on which the execution of the transaction depends as ReadSet
69 | - the proof of the states as ReadSetProof
70 | - the package of ReadSet, ReadSetProof, the transaction, and the root hash of the state tree after execution as StateFullTransaction.
71 |
72 | The data structure is represented as follows:
73 |
74 | ```rust
75 | pub struct ReadSet {
76 | state:Vec<(AccessPath,Vec