<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Specter</title>
    <description>Stay Foolish, Stay Hungry</description>
    <link>/</link>
    <atom:link href="/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Mon, 05 Jun 2023 02:31:01 -0500</pubDate>
    <lastBuildDate>Mon, 05 Jun 2023 02:31:01 -0500</lastBuildDate>
    <generator>Jekyll v3.8.5</generator>
    
      <item>
        <title>分布式密钥生成</title>
        <description>&lt;p&gt;[TOC]&lt;/p&gt;

&lt;h2 id=&quot;asynchronous-distributed-key-generation-protocol&quot;&gt;&lt;a href=&quot;https://eprint.iacr.org/2021/1591&quot;&gt;Asynchronous Distributed Key Generation protocol&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;为基于离散对数的门槛密码系统设计了一个新的简单和具体有效的ADKG 协 议。在一个由n≥3t+1 个节点组成的异步网络中，最多只有t个节点可能是恶意的，我们的ADKG协议实现了O(κn3 ) 的预期通信成本，并且在预期的O(log n)轮。因此，我们的协议改进了 先前已知的通用ADKG协议的Kokoris-
Kogias 等人[43] 的通信量增加了n 倍，预期运行时间增 加了n/log n 倍。对于设置假设，Kokoris-Kogias 等人 [43] 假设了随机Oracle (RO )，而我们的协议假设了 RO和PKI(PKI只需要用于我们的ACSS构建)。
在我们的协议结束时，每个节点收到一个随机选择的 秘密z∈Zq 的阈值秘密份额，其中Zq 是一个大小为q 的字 段。因此，我们的协议与现成的基于离散对数的阈值密 码系统[21], [9], [31]兼容。
我们的协议还支持任何重建阈值l∈[t+1 ，n-t] ，即要 求l个节点使用秘钥z(例如，产生一个阈值签名或解密 一个阈值加密)。为了有效地获得这一特性，我们&lt;code class=&quot;highlighter-rouge&quot;&gt;设计了一个新的加法同态的高门槛&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/sourav1547/adkg&quot;&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;论文思路架构&quot;&gt;论文思路架构&lt;/h2&gt;
&lt;h3 id=&quot;dkg-分布式密钥生成&quot;&gt;DKG 分布式密钥生成&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;参与方选择一个共享参数集：所有参与方必须就共享参数集达成一致，这些参数可以包括系统参数、安全参数等。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;随机数生成：每个参与方生成自己的随机数，并将其发送给其他参与方。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;消息交换：参与方之间进行消息交换，以便收集其他参与方的随机数。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;验证：参与方使用收集到的随机数进行验证，以确保其他参与方没有作弊。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;分享密钥部分：每个参与方根据协议的规则将自己的密钥部分分享给其他参与方。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;密钥重构：一旦所有参与方都分享了他们的密钥部分，他们可以通过将这些部分组合在一起来重构完整的密钥。&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;在分布式密钥生成（DKG）协议中，椭圆曲线可以被用来实现密钥生成和共享过程的安全性。椭圆曲线密码学提供了一种强大的加密和密钥交换方案，其安全性基于椭圆曲线离散对数问题的难解性。

ABE的密钥生成部分主要是椭圆曲线

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;密钥共享&quot;&gt;密钥共享&lt;/h4&gt;
&lt;p&gt;CSS的同步与异步&lt;/p&gt;
&lt;h4 id=&quot;广播协议&quot;&gt;广播协议&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Reliable Broadcast(RBC)&lt;/li&gt;
  &lt;li&gt;reedsolomon的可靠性
    &lt;h4 id=&quot;reedsolomon的融入可能性&quot;&gt;ReedSolomon的融入可能性&lt;/h4&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;拜占庭安全&quot;&gt;拜占庭安全&lt;/h3&gt;
&lt;h4 id=&quot;flp不可能性定理&quot;&gt;FLP不可能性定理&lt;/h4&gt;
&lt;p&gt;分布式系统都需要考虑FLP不可能性定理&lt;/p&gt;

&lt;h4 id=&quot;拜占庭错误的解决&quot;&gt;拜占庭错误的解决&lt;/h4&gt;
&lt;p&gt;异步拜占庭二元协议（Asynchronous Binary Agreement，ABA）是一种协议，用于解决在分布式系统中存在拜占庭错误的情况下，如何使一组节点就一个二进制值达成一致。ABA协议需要满足以下三个属性：1）一致性：没有两个诚实的节点输出不同的值；2）有效性：如果所有诚实的节点具有相同的输入值，则没有诚实的节点输出不同的值；3）终止性：每个诚实的节点最终都会输出一个值。由于FLP不可能性定理，所有ABA协议都依赖于随机化来解决异步环境下达成共识的问题。通常使用共同硬币协议提供共享随机数来实现ABA协议。&lt;/p&gt;

&lt;h3 id=&quot;多项式承诺&quot;&gt;多项式承诺&lt;/h3&gt;
&lt;p&gt;https://blog.csdn.net/mutourend/article/details/125922653&lt;/p&gt;
&lt;h4 id=&quot;kate&quot;&gt;Kate&lt;/h4&gt;
&lt;h4 id=&quot;bulletproofs&quot;&gt;Bulletproofs&lt;/h4&gt;
&lt;h4 id=&quot;fri&quot;&gt;FRI&lt;/h4&gt;
&lt;h4 id=&quot;feldman&quot;&gt;Feldman&lt;/h4&gt;
&lt;h4 id=&quot;pedersen&quot;&gt;Pedersen&lt;/h4&gt;

&lt;h3 id=&quot;权限控制&quot;&gt;权限控制&lt;/h3&gt;
&lt;p&gt;融入ABE&lt;/p&gt;

&lt;h3 id=&quot;tips&quot;&gt;Tips&lt;/h3&gt;
&lt;p&gt;ReedSolomon可以同时实现纠错、门限和承诺&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;- 容错性
- 通信成本
- 计算成本
- 密码学假设
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;ss综述&quot;&gt;SS综述&lt;/h2&gt;
&lt;p&gt;秘密共享是指将一个秘密分解成多个份额，并将份额分配给多方，只有各方将各自的份额聚集在一起才能重构秘密的密码学方法。更具体地说，秘密的持有者（有时称为经销商）创建 n 份秘密，并为重构秘密所需的份额数定义阈值 t。然后交易商继续分配股票，使它们由不同的各方控制。&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.cs.bgu.ac.il/~beimel/Papers/Survey.pdf&quot;&gt;在这项调查中&lt;/a&gt;，将描述秘密分享方案的最重要的构造，解释秘密分享 方案与单调公式和单调跨度程序之间的联系。已知的秘密共享方案的主要 问题是共享规模大:它是各方数量的指数级。猜想这是不可能避免的 。将讨论已知的份额大小的下限。这些下限是相当弱的，在下限和上 限之间有很大的差距。对于线性秘密共享方案，这是一类基于线性代数的 方案，包含大多数已知的方案，关于共享大小的超多项式下限是已知的。 将对这些下限的证明进行描述。还将提出两个结果，将汉密尔顿 访问结构的秘密共享方案与NP与coNP问题以及密码学中的一个主要开放 问题–从单向函数构建遗忘传输协议联系起来。&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;秘密共享方案的一个主要问题是，在实现一般访问结构的最佳已知秘密共享方案中，份额的大小与访问结构中的各方数量成指数关系。因此，已知的一般访问结构的构架是不切实际的。即使是隐式访问结构也是如此( 例如，其特征函数可由小型统一电路计算的访问结构)。另一方面，就接入结构而言，共享秘密的最佳已知下限(例如，在[23，29]中)与上述上限相差甚远。
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;for every n, there is an access structure with n parties such that sharing l-bit secrets requires shares of length Ω(ln/ log n).&lt;/p&gt;

&lt;p&gt;https://www.cs.umd.edu/~gasarch/TOPICS/secretsharing/sizelarge.pdf&lt;/p&gt;

&lt;h3 id=&quot;猜想&quot;&gt;猜想&lt;/h3&gt;
&lt;p&gt;Conjecture 1. There exists an ε &amp;gt; 0 such that for every integer n there is an access structure with n parties, for which every secret-sharing scheme distributes shares of length exponential in the number of parties, that is, 2&lt;sup&gt;εn&lt;/sup&gt;.&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;线性秘密共享方案的信息比率可以通过以下公式计算：

IR = (n - k) / k

其中，n是秘密的总数，k是需要访问秘密的最小阈值。信息比率表示为一个实数，通常在0到1之间。它越接近1，表示方案越高效，因为共享的信息量越少。当信息比率等于1时，方案被称为完美秘密共享方案。
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;基于属性的共享&quot;&gt;基于属性的共享&lt;/h3&gt;
&lt;p&gt;根据一些基于用户凭证的策略，对数据进行加密。在Sahai和Waters[Fuzzy identity-based encryption]提出的基于属性的加密系统中，每个用户都有一组属性(即证书)，如果属性 的某些词成立，提供者将授予解密信息的权限(例如，如果一个用户是 “ 朋友 “和 “重要”，她可以解密电子邮件)。&lt;/p&gt;

&lt;h3 id=&quot;阈值共享&quot;&gt;阈值共享&lt;/h3&gt;
&lt;p&gt;http://blog.nsfocus.net/secret-gdpr/&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;基于超平面几何的秘密共享，包括Blakley方案和Brickell方案；
    &lt;ul&gt;
      &lt;li&gt;Brickell的秘密共享方案采用向量方法，一个秘密拥有者Dealer把秘密s嵌入到一个向量中，在通过一个矩阵把秘密共享为n个子秘密分发给n个参与者，具体方法如下：
选择秘密s，和随机向量(y2,y3, …… ，yt), 生成一个n&lt;em&gt;t矩阵M，M有n行，每行记为Mi,任意t个行向量都是线性无关的。秘密份额为(s1，s2，……，sn).每个份额是行向量Mi和列向量(s,y2,y3, …… ，yt),的乘积。即si = Mi&lt;/em&gt; (s,y2,y3, …… ，yt)
&lt;img src=&quot;/images/posts/Blakley和Brickell的超平面几何方案.png&quot; alt=&quot;包括Blakley方案和Brickell方案&quot; /&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;基于插值多项式的秘密共享，包括经典的Shamir阈值秘密共享方案；
Shamir秘密共享是Blakley &amp;amp; Brickell方案中的特例。正因为范德蒙德矩阵的特殊性，线性无关性（xi不相等的任意t阶方阵都是满秩的）和构造简单（并且分布式节点很容易统一这个矩阵），所以大多数方案应用Shamir秘密共享。如果需要把Shamir秘密秘密共享应用到一般模式可以考虑把范德蒙德矩阵用一般矩阵替代。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;Mignotte，Asmuth &amp;amp; Bloom提出的基于中国剩余定理的秘密共享；
基于中国剩余定理（CRT）的秘密共享方案相对于Shamir秘密共享方案在以下场景中更适用：&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;大规模秘密共享：当需要进行大规模的秘密共享，涉及到大量的参与者和大量的秘密信息时，基于CRT的秘密共享方案可以更高效地处理。它可以通过将秘密信息分解为多个模数，利用CRT的并行计算特性，实现快速的秘密信息重构。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;快速秘密恢复：基于CRT的秘密共享方案具有较快的秘密恢复速度。通过利用CRT的运算，可以通过简单的模数和余数计算快速重构秘密信息。这在一些需要迅速恢复秘密信息的场景中很有优势。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;分布式计算：基于CRT的秘密共享方案适用于分布式计算环境。它允许将秘密信息分解为多个模数，并在不同的计算节点上进行并行计算。这样可以利用分布式计算的优势，提高计算效率和系统的可扩展性。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;低安全性要求：相对于某些复杂的秘密共享方案，基于CRT的秘密共享方案在安全性要求较低的场景中更适用。它可以提供一定程度的安全性，但可能在某些高安全性要求的场景下需要额外的安全增强措施。&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;sss-vss&quot;&gt;sss-vss&lt;/h3&gt;
&lt;p&gt;http://aandds.com/blog/sss-vss.html&lt;/p&gt;

&lt;h3 id=&quot;hbacss&quot;&gt;hbacss&lt;/h3&gt;
&lt;p&gt;观察到MPC理论与实践之间存在这种差距的主要原因是缺乏有效的可验证/完全秘密共享 (VSS/CSS) 结构；现有的CSS协议要么需要 a) 在实践中具有挑战性的广播频道，要么 b) 引入至少是玩家数量的二次方的计算和通信开销。这项工作介绍了 hbACSS，这是一套最佳弹性异步完整秘密共享协议，在计算和通信开销方面都是（准）线性的。为了开发 hbACSS，论文开发了 hbPolyCommit，一种高效的多项式承诺方案，它在计算和通信开销方面是（准）线性（多项式），不需要可信设置。hbACSS 协议随着参与方数量的增加而扩展得很好，特别是，在使用 hbACSS 来生成 MPC 输入掩码：一个有用的原语的时候。&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;主要流程&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;经销商阶段：经销商从多项式中计算每个B项，并广播相应的多项式承诺。然后，她使用公钥加密各方的共享和评估证明，并通过 AVID 方案可验证地发送它们。&lt;/li&gt;
  &lt;li&gt;共享验证：每一方检索其加密的有效负载，并尝试根据多项式承诺解密和验证其共享。如果足够多的各方成功接收有效份额，则输出份额。&lt;/li&gt;
  &lt;li&gt;牵连有问题的经销商：如果任何一方发现他们收到的股票无效或解密失败，他们会泄露他们的密钥，使另一方能够在从分散计划中检索到该方的有效载荷后确认交易商有问题。&lt;/li&gt;
  &lt;li&gt;份额回收：一旦交易商被牵连为有问题，收到有效份额的各方将份额进行分配，使其余各方能够重建份额。&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We now explain hbACSS0 in more detail, following along with the protocol pseudocode given in Algorithm 1. Security analysis and the other variants follow in this section.
1) Sharing and Committing: The protocol shares a batch of B inputs at a time, {s1 , …, sB }. The dealer creates a degree-t Shamir sharing φk(·) for each input such that φk(0) = sk, and each party Pi’s share of sk is φk(i).
The dealer then uses the PolyCommit procedure to create a commitment Ck to each polynomial φk(·). The commitments are then broadcasted, ensuring all the parties can validate their shares against the same set of commitments.
Next, for each party Pi, the dealer creates an encrypted payload zi, consisting of the shares {φk(i)}k∈[1,B] and the polynomial evaluation proof πi, encrypted under Pi’s public key PKi. The dealer then Disperses these encrypted payloads. With the broadcast and dispersal complete, the dealer’s role in the protocol is complete—since information dispersal itself requires only one initial round of messages from the dealer, the dealer’s entire role is sending messages in the first round.
2) Share Verification: Each party Pi waits for ReliableBroadcast and Disperse to complete, and then retrieves their payload {zi}. The party then attempts to decrypt and validate its shares. If decryption is successful and all the shares are valid, then Pi signals this by sending an OK message to the other recipients. The goal of the OK and READY messages (lines 302-307) is to ensure that if any party outputs a share, then enough correct parties have shares for share recovery to succeed if necessary.
3) Implicating a faulty dealer: If any honest party Pi receives a share that either fails to decrypt or fails verification, they reveal their secret key by sending (IMPLICATE,SKi,k) to all, which other parties can use to repeat the decryption and confirm that the dealer dispersed invalid data.
4) Share Recovery: If an honest party discovers their shares are faulty after other honest parties have already output, the protocol must enter Share Recovery. In this phase, parties with valid shares are presented with evidence that the dealer is faulty. If convinced, these parties will divulge the keys needed to decrypt their own shares. To avoid the need for constant re-keying, we present a practical modification for long-term keys in Section V-C.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;来自deepl翻译&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1）共享和提交： 该协议每次分享一批B的输入，{s1, ..., sB }。庄家为每个输入创建一个degree-t Shamir共享φk(-)，这样φk(0)=sk，每一方Pi的sk份额是φk(i)。
然后庄家使用PolyCommit程序为每个多项式φk(-)创建一个承诺Ck。然后，这些承诺被广播出去，确保所有各方都能根据同一组承诺来验证他们的份额。
接下来，对于每一方Pi，庄家创建一个加密的有效载荷zi，由股份{φk(i)}k∈[1,B]和多项式评估证明πi组成，在Pi的公钥PKi下进行加密。然后，庄家将这些加密的有效载荷散布出去。随着广播和散布的完成，庄家在协议中的作用也就完成了--因为信息散布本身只需要庄家的一轮初始信息，庄家的全部作用就是在第一轮中发送信息。
2) 分享验证： 每一方Pi等待ReliableBroadcast和Disperse完成，然后检索其有效载荷{zi}。然后，该方试图解密并验证其份额。如果解密成功并且所有的份额都是有效的，那么Pi通过向其他接收者发送一个OK消息来表示这一点。OK和READY消息（第302-307行）的目的是确保如果任何一方输出一个份额，那么足够多的正确方拥有份额，以便在必要时成功恢复份额。
3) 暗示一个有问题的经销商： 如果任何诚实的一方Pi收到一个解密失败或验证失败的份额，他们通过向所有人发送(IMPLICATE,Ski,k)来揭示他们的秘密密钥，其他各方可以用它来重复解密并确认经销商散布无效数据。
4）份额恢复： 如果一个诚实的一方在其他诚实的一方已经输出后发现他们的份额有问题，协议必须进入份额恢复阶段。在这个阶段，拥有有效股份的各方会被告知庄家有问题的证据。如果被说服，这些当事方将泄露解密他们自己股份所需的密钥。为了避免不断地重新配钥匙，我们在第五章C节提出了一个针对长期钥匙的实际修改。
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;avid&quot;&gt;AVID&lt;/h4&gt;

&lt;h4 id=&quot;完整性-vss-with-share-recovery-vss-r&quot;&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;完整性&lt;/code&gt; VSS with Share Recovery （VSS-R）&lt;/h4&gt;

&lt;h4 id=&quot;异步&quot;&gt;异步&lt;/h4&gt;
&lt;p&gt;http://www.soumyabasu.com/assets/pdf/basu-ccs19.pdf&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;随机化：在ACSS协议中，参与方使用随机数来生成多项式和份额。这种随机化可以使攻击者无法预测参与方的行为，并增加了协议的安全性。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;纠错码：为了检测和纠正消息传输过程中的错误，ACSS协议使用纠错码。这些码可以检测并纠正一定数量的错误，并确保参与方收到正确的消息。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;超时：如果某个节点长时间未响应，则其他节点可以将其视为故障节点，并继续执行协议。这种超时机制可以确保即使存在故障节点，也不会影响整个系统的运行。&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;hbpolycommit&quot;&gt;hbPolyCommit&lt;/h4&gt;

&lt;h3 id=&quot;访问控制结构&quot;&gt;访问控制结构&lt;/h3&gt;

&lt;h3 id=&quot;tips-1&quot;&gt;Tips&lt;/h3&gt;
&lt;h4 id=&quot;加法秘密共享的缺陷&quot;&gt;加法秘密共享的缺陷&lt;/h4&gt;
&lt;p&gt;可扩展性低
（没有分析出缺陷在哪）&lt;/p&gt;

&lt;h4 id=&quot;mpc-局限性&quot;&gt;MPC 局限性&lt;/h4&gt;
&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;安全的多方计算&lt;/code&gt;：在多数不诚实设置中，对于容忍非一个恶意破坏的恒定轮次 MPC 协议，一些研究采用剪切和选择方法或 BMR 和 SPDZ 的组合方法来构建 MPC 协议。但是，它们的具体效率非常低。在这种情况下，最著名的 MPC 协议遵循基于 TinyOT 类协议的分布式乱码框架。这些 MPC 协议与 2PC 协议具有相同的结构，但需要执行一致性检查程序来检查多次执行之间共享或全局密钥的一致性。最近，Poddar 等人应用具有恶意安全性的恒定轮次 MPC 协议构建了一个称为参议院的系统，该系统允许协作方运行分析SQL查询，同时保持个人数据的私密性。Yang等人提出了具有恶意安全性的最先进的常量轮MPC协议，并可用于进一步提高上述应用程序的性能。虽然半门优化完全应用于两方设置中的分布式乱码构建，但这仅在多方设置中部分完成。将半栅技术（甚至最近的切片和切割技术）完全应用于多方混淆电路是一个挑战。&lt;/p&gt;

&lt;p&gt;在多数诚实设置中，可以使用较少的通信和计算基于复制的秘密共享来构建恒定轮次 MPC 协议。在最多一个恶意方的三方设置中，Mohassel 等人通过构建单个 Yao 式的混淆电路，提出了目前最有效的三轮 3PC 协议，其中恶意安全的 3PC 协议与半诚实的 Yao 的 2PC 协议具有基本相同的成本。同时，Ishai 等人构建了一个两轮3PC协议，同时需要发送三个混淆电路。在最多有一次恶意破坏的四方设置中，Byali 等人提出了最先进的协议，并且有五轮通信，需要发送一个单Yao式的混淆电路。该协议可以实现更强的安全属性，即GOD。在最多有两个恶意破坏的五方设置中，Chandran 等人提出了最著名的 MPC 协议，进行了 8 轮通信。他们采用 BMR 混淆电路来防止串通，并提出了一种经过验证的 OT 原语，使整个 MPC 协议只依赖于对称密钥原语，而不需要 OT 协议。在通信成本方面，它们的恶意安全协议比不诚实多数的半诚实 MPC 协议减少 60%，而其半诚实变体需要的通信减少 8 倍。他们的构造也可以扩展到阈值的 方。后来，Byali等人构建了具有公平性或 GOD 的安全五方计算 (5PC)，其开销比 5PC 协议的开销小，满足中止的安全性。&lt;/p&gt;

&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;N. Alon, O. Goldreich, J. H ̊astad, and R. Peralta. Simple constructions of almost k- wise independent random variables. Random Structures &amp;amp; Algorithms, 3:289–304, 1992.&lt;/li&gt;
  &lt;li&gt;L. Babai, A. G ́al, and A. Wigderson. Superpolynomial lower bounds for monotone span programs. Combinatorica, 19(3):301–319, 1999.&lt;/li&gt;
  &lt;li&gt;A. Beimel. Secure Schemes for Secret Sharing and Key Distribution. PhD thesis, Technion, 1996. www.cs.bgu.ac.il/ beimel/pub.html.&lt;/li&gt;
  &lt;li&gt;A. Beimel and B. Chor. Universally ideal secret sharing schemes. IEEE Trans. on Information Theory, 40(3):786–794, 1994.&lt;/li&gt;
  &lt;li&gt;A. Beimel, A. G ́al, and M. Paterson. Lower bounds for monotone span programs. Computational Complexity, 6(1):29–45, 1997. Conference version: FOCS ’95.&lt;/li&gt;
  &lt;li&gt;A. Beimel and Y. Ishai. On the power of nonlinear secret-sharing. SIAM J. on Discrete Mathematics, 19(1):258–280, 2005.&lt;/li&gt;
  &lt;li&gt;A. Beimel, N. Livne, and C. Padro ́. Matroids can be far from ideal secret sharing. In R. Canetti, editor, Proc. of the Fifth Theory of Cryptography Conference – TCC 2008, volume 4948 of Lecture Notes in Computer Science, pages 194–212, 2008.&lt;/li&gt;
  &lt;li&gt;A. Beimel and I. Orlov. Secret sharing and non-shannon information inequalities. IEEE Trans. on Information Theory, 2011. Accepted for publication. Preliminary version in TCC 2009, LNCS vol, 5444:539–557, 2009.&lt;/li&gt;
  &lt;li&gt;A. Beimel and A. Paskin. On linear secret sharing for connectivity in directed graphs. In R. Ostrovsky, R. De Prisco, and I. Visconti, editors, Proc. of the Sixth Conference on Security and Cryptography for Networks, volume 5229 of Lecture Notes in Computer Science, pages 172–184. Springer-Verlag, 2008.&lt;/li&gt;
  &lt;li&gt;A. Beimel and E. Weinreb. Separating the power of monotone span programs over different fields. SIAM J. on Computing, 34(5):1196–1215, 2005.&lt;/li&gt;
  &lt;li&gt;A. Beimel and E. Weinreb. Monotone circuits for monotone weighted threshold functions. Inform. Process. Lett., 97(1):12–18, 2006. Conference version: Proc. of 20th Annu. IEEE Conf. on Computational Complexity, pages 67-75, 2005.&lt;/li&gt;
  &lt;li&gt;M. Bellare and P. Rogaway. Robust computational secret sharing and a unified account of classical secret-sharing goals. In Proc. of the 14th ACM conference on Computer and communications security, pages 172–184, 2007.&lt;/li&gt;
  &lt;li&gt;M. Ben-Or, S. Goldwasser, and A. Wigderson. Completeness theorems for non- cryptographic fault-tolerant distributed computations. In Proc. of the 20th ACM Symp. on the Theory of Computing, pages 1–10, 1988.&lt;/li&gt;
  &lt;li&gt;J. Benaloh and J. Leichter. Generalized secret sharing and monotone functions. In S. Goldwasser, editor, Advances in Cryptology – CRYPTO ’88, volume 403 of Lecture Notes in Computer Science, pages 27–35. Springer-Verlag, 1990.&lt;/li&gt;
  &lt;li&gt;J. Benaloh and S. Rudich. Private communication, 1989.&lt;/li&gt;
  &lt;li&gt;M. Bertilsson and I. Ingemarsson. A construction of practical secret sharing
schemes using linear block codes. In J. Seberry and Y. Zheng, editors, Advances in Cryptology – AUSCRYPT ’92, volume 718 of Lecture Notes in Computer Science, pages 67–79. Springer-Verlag, 1993.&lt;/li&gt;
  &lt;li&gt;G. R. Blakley. Safeguarding cryptographic keys. In R. E. Merwin, J. T. Zanca, and M. Smith, editors, Proc. of the 1979 AFIPS National Computer Conference, volume 48 of AFIPS Conference proceedings, pages 313–317. AFIPS Press, 1979.&lt;/li&gt;
  &lt;li&gt;C. Blundo, A. De Santis, R. De Simone, and U. Vaccaro. Tight bounds on the information rate of secret sharing schemes. Designs, Codes and Cryptography, 11(2):107–122, 1997.&lt;/li&gt;
  &lt;li&gt;C. Blundo, A. De Santis, L. Gargano, and U. Vaccaro. On the information rate of secret sharing schemes. Theoretical Computer Science, 154(2):283–306, 1996.&lt;/li&gt;
  &lt;li&gt;C. Blundo, A. De Santis, and U. Vaccaro. On secret sharing schemes. Inform.
Process. Lett., 65(1):25–32, 1998.&lt;/li&gt;
  &lt;li&gt;E. F. Brickell. Some ideal secret sharing schemes. Journal of Combin. Math. and
Combin. Comput., 6:105–113, 1989.&lt;/li&gt;
  &lt;li&gt;E. F. Brickell and D. M. Davenport. On the classification of ideal secret sharing
schemes. J. of Cryptology, 4(73):123–134, 1991.&lt;/li&gt;
  &lt;li&gt;R. M. Capocelli, A. De Santis, L. Gargano, and U. Vaccaro. On the size of shares
for secret sharing schemes. J. of Cryptology, 6(3):157–168, 1993.&lt;/li&gt;
  &lt;li&gt;D. Chaum, C. Cr ́epeau, and I. Damg ̊ard. Multiparty unconditionally secure proto- cols. In Proc. of the 20th ACM Symp. on the Theory of Computing, pages 11–19, 1988.&lt;/li&gt;
  &lt;li&gt;B. Chor, S. Goldwasser, S. Micali, and B. Awerbuch. Verifiable secret sharing and achieving simultaneity in the presence of faults (extended abstract). In Proc. of the 26th IEEE Symp. on Foundations of Computer Science, pages 383–395, 1985.&lt;/li&gt;
  &lt;li&gt;B. Chor and E. Kushilevitz. Secret sharing over infinite domains. J. of Cryptology,
6(2):87–96, 1993.&lt;/li&gt;
  &lt;li&gt;T. M. Cover and J. A. Thomas. Elements of Information Theory. John Wiley &amp;amp;
Sons, 1991.&lt;/li&gt;
  &lt;li&gt;R. Cramer, I. Damg ̊ard, and U. Maurer. General secure multi-party computation
from any linear secret-sharing scheme. In B. Preneel, editor, Advances in Cryp- tology – EUROCRYPT 2000, volume 1807 of Lecture Notes in Computer Science, pages 316–334. Springer-Verlag, 2000.&lt;/li&gt;
  &lt;li&gt;L. Csirmaz. The size of a share must be large. In A. De Santis, editor, Advances in Cryptology – EUROCRYPT ’94, volume 950 of Lecture Notes in Computer Science, pages 13–22. Springer-Verlag, 1995. Journal version in: J. of Cryptology, 10(4):223–231, 1997.&lt;/li&gt;
  &lt;li&gt;L. Csirmaz. The dealer’s random bits in perfect secret sharing schemes. Studia Sci. Math. Hungar., 32(3–4):429–437, 1996.&lt;/li&gt;
  &lt;li&gt;Y. Desmedt and Y. Frankel. Shared generation of authenticators and signatures. In J. Feigenbaum, editor, Advances in Cryptology – CRYPTO ’91, volume 576 of Lecture Notes in Computer Science, pages 457–469. Springer-Verlag, 1992.&lt;/li&gt;
  &lt;li&gt;M. van Dijk. A linear construction of perfect secret sharing schemes. In A. De Santis, editor, Advances in Cryptology – EUROCRYPT ’94, volume 950 of Lecture Notes in Computer Science, pages 23–34. Springer-Verlag, 1995.&lt;/li&gt;
  &lt;li&gt;M. van Dijk. On the information rate of perfect secret sharing schemes. Designs, Codes and Cryptography, 6:143–169, 1995.&lt;/li&gt;
  &lt;li&gt;M. van Dijk, T. Kevenaar, G.-J. Schrijen, and P. Tuyls. Improved constructions of secret sharing schemes by applying (λ, ω)-decompositions. Inform. Process. Lett., 99(4):154 – 157, 2006.&lt;/li&gt;
  &lt;li&gt;S.Even,O.Goldreich,andA.Lempel.Arandomizedprotocolforsigningcontracts. CACM, 28(6):637–647, 1985.&lt;/li&gt;
  &lt;li&gt;A. G ́al. A characterization of span program size and improved lower bounds for monotone span programs. Computational Complexity, 10(4):277–296, 2002.&lt;/li&gt;
  &lt;li&gt;A. G ́al and P. Pudl ́ak. Monotone complexity and the rank of matrices. Inform. Process. Lett., 87:321–326, 2003.&lt;/li&gt;
  &lt;li&gt;R. Gennaro, M. O. Rabin, and T. Rabin. Simplified vss and fact-track multiparty computations with applications to threshold cryptography. In Proc. of the 17th ACM Symp. on Principles of Distributed Computing, pages 101–111, 1998.&lt;/li&gt;
  &lt;li&gt;O. Goldreich, S. Micali, and A. Wigderson. How to play any mental game. In Proc. of the 19th ACM Symp. on the Theory of Computing, pages 218–229, 1987.&lt;/li&gt;
  &lt;li&gt;V. Goyal, O. Pandey, A. Sahai, and B. Waters. Attribute-based encryption for
fine-grained access control of encrypted data. In Proc. of the 13th ACM conference
on Computer and communications security, pages 89–98, 2006.&lt;/li&gt;
  &lt;li&gt;J. H ̊astad, R. Impagliazzo, L. A. Levin, and M. Luby. Construction of a pseudo- random generator from any one-way function. SIAM J. on Computing, 28(4):1364–
1396, 1999.&lt;/li&gt;
  &lt;li&gt;M. Hirt and U. Maurer. Player simulation and general adversary structures in
perfect multiparty computation. J. of Cryptology, 13(1):31–60, 2000.&lt;/li&gt;
  &lt;li&gt;R. Impagliazzo. A personal view of average-case complexity. In Proc. of the 10th
IEEE Structure in Complexity Theory, pages 134–147, 1995.&lt;/li&gt;
  &lt;li&gt;R. Impagliazzo and S. Rudich. Limits on the provable consequences of one-way permutations. In Proc. of the 21st ACM Symp. on the Theory of Computing, pages
44–61, 1989.&lt;/li&gt;
  &lt;li&gt;M. Ito, A. Saito, and T. Nishizeki. Secret sharing schemes realizing general access
structure. In Proc. of the IEEE Global Telecommunication Conf., Globecom 87, pages 99–102, 1987. Journal version: Multiple assignment scheme for sharing secret. J. of Cryptology, 6(1):15-20, 1993.&lt;/li&gt;
  &lt;li&gt;M. Karchmer and A. Wigderson. On span programs. In Proc. of the 8th IEEE Structure in Complexity Theory, pages 102–111, 1993.&lt;/li&gt;
  &lt;li&gt;E. D. Karnin, J. W. Greene, and M. E. Hellman. On secret sharing systems. IEEE Trans. on Information Theory, 29(1):35–41, 1983.&lt;/li&gt;
  &lt;li&gt;E. Kushilevitz and N. Nisan. Communication Complexity. Cambridge University Press, 1997.&lt;/li&gt;
  &lt;li&gt;J. Mart ́ı-Farr ́e and C. Padro ́. On secret sharing schemes, matroids and polyma- troids. In S. Vadhan, editor, Proc. of the Fourth Theory of Cryptography Conference – TCC 2007, volume 4392 of Lecture Notes in Computer Science, pages 253–272. Springer-Verlag, 2007.&lt;/li&gt;
  &lt;li&gt;F. Matu ́ˇs. Infinitely many information inequalities. In IEEE International Sym- posium on Information Theory 2007, pages 41–44, 2007.&lt;/li&gt;
  &lt;li&gt;J. R. Metcalf-Burton. Improved upper bounds for the information rates of the secret sharing schemes induced by the Vamos matroid. Technical Report abs/0809.3010, CoRR, 2008.&lt;/li&gt;
  &lt;li&gt;M. Naor and A. Wool. Access control and signatures via quorum secret sharing. IEEE Transactions on Parallel and Distributed Systems, 9(1):909–922, 1998.&lt;/li&gt;
  &lt;li&gt;M. O. Rabin. How to exchange secrets by oblivious transfer. Technical Report TR-81, Harvard Aiken Computation Laboratory, 1981. Available online in the Cryptology ePrint Archive, Report 2005/187, eprint.iacr.org/2005/187.&lt;/li&gt;
  &lt;li&gt;M. O. Rabin. Randomized Byzantine generals. In Proc. of the 24th IEEE Symp. on Foundations of Computer Science, pages 403–409, 1983.&lt;/li&gt;
  &lt;li&gt;J. Rompel. One-way functions are necessary and sufficient for secure signatures. In Proc. of the 22nd ACM Symp. on the Theory of Computing, pages 387–394, 1990.&lt;/li&gt;
  &lt;li&gt;S. Rudich. Private communication (via M. Naor), 1989.&lt;/li&gt;
  &lt;li&gt;A. Sahai and B. Waters. Fuzzy identity-based encryption. In R. Cramer, editor, Advances in Cryptology – EUROCRYPT 2005, pages 457–473. Springer-Verlag,2005.&lt;/li&gt;
  &lt;li&gt;A. Shamir. How to share a secret. Communications of the ACM, 22:612–613, 1979.&lt;/li&gt;
  &lt;li&gt;B. Shankar, K. Srinathan, and C. Pandu Rangan. Alternative protocols for gen-
eralized oblivious transfer. In S. Rao, M. Chatterjee, P. Jayanti, C. S. Murthy,and S. K. Saha, editors, Proc. of ICDCN 2008, volume 4904 of Lecture Notes in
Computer Science, pages 304–309. Springer-Verlag, 2008.&lt;/li&gt;
  &lt;li&gt;G. J. Simmons. How to (really) share a secret. In S. Goldwasser, editor, Advances
in Cryptology – CRYPTO ’88, volume 403 of Lecture Notes in Computer Science,
pages 390–448. Springer-Verlag, 1990.&lt;/li&gt;
  &lt;li&gt;G. J. Simmons, W. Jackson, and K. M. Martin. The geometry of shared secret
schemes. Bulletin of the ICA, 1:71–88, 1991.&lt;/li&gt;
  &lt;li&gt;J. Simonis and A. Ashikhmin. Almost affine codes. Designs, Codes and Cryptog-
raphy, 14(2):179–197, 1998.&lt;/li&gt;
  &lt;li&gt;D.R.Stinson.Decompositionconstructionforsecretsharingschemes.IEEETrans.
on Information Theory, 40(1):118–125, 1994.&lt;/li&gt;
  &lt;li&gt;T. Tassa. Hierarchical threshold secret sharing. In M. Naor, editor, Proc. of the
First Theory of Cryptography Conference – TCC 2004, volume 2951 of Lecture
Notes in Computer Science, pages 473–490. Springer-Verlag, 2004.&lt;/li&gt;
  &lt;li&gt;T. Tassa. Generalized oblivious transfer by secret sharing. Designs, Codes and
Cryptography, 58, 2011.&lt;/li&gt;
  &lt;li&gt;T. Tassa and N. Dyn. Multipartite secret sharing by bivariate interpolation. In
M. Bugliesi, B. Preneel, V. Sassone, and I. Wegener, editors, Proc. of the 33rd International Colloquium on Automata, Languages and Programming, volume 4052 of Lecture Notes in Computer Science, pages 288–299. Springer-Verlag, 2006.&lt;/li&gt;
  &lt;li&gt;V. Vinod, A. Narayanan, K. Srinathan, C. Pandu Rangan, and K. Kim. On the power of computational secret sharing. In T. Johansson and S. Maitra, editors, Indocrypt 2003, volume 2904 of Lecture Notes in Computer Science, pages 162–176. Springer-Verlag, 2003.&lt;/li&gt;
  &lt;li&gt;B. Waters. Ciphertext-policy attribute-based encryption: An expressive, efficient, and provably secure realization. Technical Report 2008/290, Cryptology ePrint Archive, 2008. http://eprint.iacr.org/.&lt;/li&gt;
  &lt;li&gt;A. C. Yao. Unpublished manuscript, 1989. Presented at Oberwolfach and DIMACS workshops.&lt;/li&gt;
  &lt;li&gt;R. W. Yeung. Information Theory and Network Coding. Springer, 2008.&lt;/li&gt;
  &lt;li&gt;Z.ZhangandR.W.Yeung.Oncharacterizationofentropyfunctionviainformation
inequalities. IEEE Trans. on Information Theory, 44(4):1440–1452, 1998.&lt;/li&gt;
&lt;/ol&gt;

</description>
        <pubDate>Wed, 24 May 2023 00:00:00 -0500</pubDate>
        <link>/2023/05/dairy6/</link>
        <guid isPermaLink="true">/2023/05/dairy6/</guid>
        
        <category>黄焖鸡日记</category>
        
        
      </item>
    
      <item>
        <title>随意的密码</title>
        <description>&lt;p&gt;[TOC]&lt;/p&gt;
&lt;h2 id=&quot;盲签名&quot;&gt;盲签名&lt;/h2&gt;
&lt;h3 id=&quot;性质&quot;&gt;性质&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;签名者对其签名的消息是不可见的（这就是“盲”的含义），即签名者不知道他所签名消息的具体内容。&lt;/li&gt;
  &lt;li&gt;签名消息不可追踪，即当签名消息被公布后，签名者无法知道这是他何时/哪次的签署的。&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;rsa盲签名流程&quot;&gt;RSA盲签名流程&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Alice选择一个随机数$k$作为盲化因子&lt;/li&gt;
  &lt;li&gt;Alice对原始的消息进行计算，$m’ = m k^e (mod \ n)$ 并把计算后（盲化）的消息 $m’$发送给Bob&lt;/li&gt;
  &lt;li&gt;Bob计算 $s’ = (m’)^d (mod \ n)$ 并把计算后的签名值 $s’$ 发送给Alice&lt;/li&gt;
  &lt;li&gt;Alice计算 $s = s’k^{-1} (mod \ n)$，$s$ 就是Bob对原始消息 $m$的数字签名&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;e,d是RSA的元素，e是d的逆元，ed % φ(n) = 1&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/youngbug/blindsignatures_rsa.git&quot;&gt;C语言实现&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/arisath/Blind-RSA&quot;&gt;java实现&lt;/a&gt;&lt;/p&gt;

&lt;hr /&gt;
&lt;p&gt;Tips: &lt;a href=&quot;https://en.wikipedia.org/wiki/Blind_signature&quot;&gt;RSA 盲签名的危险&lt;/a&gt;,&lt;a href=&quot;https://www.ledger.com/zh-hans/academy/%E5%8A%A0%E5%AF%86%E8%B4%A7%E5%B8%81%E6%9C%80%E8%87%B4%E5%91%BD%E7%9A%84%E5%BC%B1%E7%82%B9-%E7%9B%B2%E7%AD%BE%E5%90%8D%E8%A7%A3%E8%AF%BB&quot;&gt;盲签名诈骗&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;防御措施：&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.packetmania.net/2020/12/01/RSA-attack-defense/&quot;&gt;单独给每个用户生成唯一的公钥模数n，防止共模攻击&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;h2 id=&quot;不可重复使用素因数生成公钥模数n杜绝模不互素攻击&quot;&gt;不可重复使用素因数生成公钥模数n，杜绝模不互素攻击&lt;/h2&gt;
    &lt;h3 id=&quot;reedsolomon&quot;&gt;Reed–Solomon&lt;/h3&gt;
    &lt;p&gt;用于数据传输、数据存储、空间传输，几乎所有二维码条形码都使用了Reed–Solomon&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;比较详细的算法介绍&lt;/code&gt;
&lt;a href=&quot;https://en.wikipedia.org/wiki/Reed%E2%80%93Solomon_error_correction&quot;&gt;wiki&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.nayuki.io/page/reed-solomon-error-correcting-code-decoder#preliminaries&quot;&gt;preliminaries&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;backblaze-storage-pods&quot;&gt;Backblaze Storage Pods&lt;/h4&gt;
&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;无限在线备份服务和世界上最便宜的云存储服务需要大量数据存储&lt;/code&gt;
对于 Backblaze Vault 存储盒，每个存储盒都是创建 Backblaze Vault 所需的 20 个存储盒之一。Backblaze Vault 将文件分成 20 个部分（17 个数据和 3 个奇偶校验），并将文件的一部分放在 Vault 中的 20 个存储盒中的每一个上。我们使用我们自己的 Reed-Solomon 实现来编码文件并将其分发到 20 个 pod，实现 99.99999% 的数据持久性。我们也开源了 Reed-Solomon 编码实现。
https://www.backblaze.com/b2/storage-pod.html
https://www.backblaze.com/blog/reed-solomon/
https://github.com/klauspost/reedsolomon&lt;/p&gt;

&lt;p&gt;用 Intel SIMD 指令来加速 Galois 域，使用汇编可以加速Solomon编码
https://github.com/Backblaze/JavaReedSolomon&lt;/p&gt;

&lt;h3 id=&quot;paillier&quot;&gt;Paillier&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/paillierStep.png&quot; alt=&quot;paillierStep&quot; /&gt;
&lt;a href=&quot;https://github.com/ZenGo-X/zk-paillier&quot;&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;zk-paillier &lt;/code&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;论文 [&lt;code class=&quot;highlighter-rouge&quot;&gt;Public-Key Cryptosystems Based on Composite Degree Residuosity Classes&lt;/code&gt;]
 (https://link.springer.com/chapter/10.1007/3-540-48910-X_16)&lt;/p&gt;

&lt;p&gt;### Pedersen承诺&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Commitment_scheme&quot;&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;承诺方案综述&lt;/code&gt;&lt;/a&gt;
可验证秘密共享&lt;a href=&quot;https://link.springer.com/content/pdf/10.1007/3-540-46766-1_9.pdf&quot;&gt; &lt;code class=&quot;highlighter-rouge&quot;&gt;Non-Interactive and Information-Theoretic Secure Verifiable Secret Sharing&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;### tips&lt;/p&gt;

&lt;p&gt;https://github.com/unboundsecurity/blockchain-crypto-mpc&lt;/p&gt;

&lt;p&gt;https://github.com/unboundsecurity/blockchain-crypto-mpc/blob/master/docs/Unbound_Cryptocurrency_Wallet_Library_White_Paper.md&lt;/p&gt;
</description>
        <pubDate>Wed, 24 May 2023 00:00:00 -0500</pubDate>
        <link>/2023/05/dairy5/</link>
        <guid isPermaLink="true">/2023/05/dairy5/</guid>
        
        <category>黄焖鸡日记</category>
        
        
      </item>
    
      <item>
        <title>ABE密码学习</title>
        <description>&lt;p&gt;[TOC]&lt;/p&gt;

&lt;h2 id=&quot;abe&quot;&gt;ABE&lt;/h2&gt;
&lt;h3 id=&quot;访问结构&quot;&gt;访问结构&lt;/h3&gt;
&lt;h4 id=&quot;与门结构&quot;&gt;与门结构&lt;/h4&gt;
&lt;h4 id=&quot;访问控制树&quot;&gt;访问控制树&lt;/h4&gt;
&lt;h4 id=&quot;lsss&quot;&gt;LSSS&lt;/h4&gt;

&lt;h3 id=&quot;abe存在的问题&quot;&gt;ABE存在的问题&lt;/h3&gt;
&lt;p&gt;(1) CP-ABE机制中的策略由消息发送方制定,使得系统公钥设计的复杂性与策略复杂性相关,限制了访问结构的设计;&lt;/p&gt;

&lt;p&gt;(2) ABE 机制中用户密钥与属性相关,属性的动态性增加了密钥撤销 的开销和难度;&lt;/p&gt;

&lt;p&gt;(3) ABE 机制中用户私钥由授权机构产生,且用户私钥与用户的隐私信息(如 ID)无关,造成了授 权机构和用户都可能泄露用户私钥,无法分清密钥泄露的责任;&lt;/p&gt;

&lt;p&gt;(4) 多机构 ABE 能够分担授权机构的责任,也满 足分布式应用的多机构协作的需求&lt;/p&gt;

&lt;h2 id=&quot;椭圆曲线加密&quot;&gt;椭圆曲线加密&lt;/h2&gt;
&lt;p&gt;https://switch-router.gitee.io/blog/ecc/&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/标量积.png&quot; alt=&quot;标量积&quot; /&gt;
时间复杂度按照二进制算法&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;def bits(n):
    while n:
        yield n &amp;amp; 1
        n &amp;gt;&amp;gt;= 1

def double_and_add(n, x):
    &quot;&quot;&quot;
    Returns the result of n * x, computed using
    the double and add algorithm.
    &quot;&quot;&quot;
    result = 0
    addend = x   // P点

    for bit in bits(n):
        if bit == 1:
            result += addend
        addend *= 2

    return result
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;如果倍乘和加法都是时间复杂度为常数的运算，那么这个算法的时间复杂度是O(logn)。（或者是O(k)，k是比特长度的话），这个结果还是非常好的。&lt;/p&gt;

&lt;h3 id=&quot;双线性映射&quot;&gt;双线性映射&lt;/h3&gt;
&lt;p&gt;https://zhuanlan.zhihu.com/p/100636577&lt;/p&gt;

&lt;p&gt;e: G1 × G2 → GT&lt;/p&gt;

&lt;p&gt;Bilinear groups are the basis of many of the new cryptographic protocols. They consist of a triplet of groups
(G₁, G₂ and GT) such that there exists a function e(G&lt;sub&gt;1&lt;/sub&gt;&lt;sup&gt;x&lt;/sup&gt;,G&lt;sub&gt;2&lt;/sub&gt;&lt;sup&gt;y&lt;/sup&gt;)=GT&lt;sup&gt;xy&lt;/sup&gt;(where gₓ is a
generator of the respective group). That function is called a pairing function.&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;e(3, 4 + 5) = 2³˙⁹ = 2²⁷
e(3, 4) * e(3, 5) = 2³˙⁴ * 2³˙⁵ = 2¹² * 2¹⁵ = 2²⁷.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;例: 通过 pairing 证明您知道 x² - x - 42 = 0 的解, 然而并不透露这个解的具体数值.&lt;/p&gt;

&lt;p&gt;答: 如果 e(G, G)k = 1 成立, 那么 k 必须为 0 或者目标群的倍数. 因此, 如果存在 e(G, G)x² - x - 42 , 我们可以确定原始二次方程式成立. 使用双线性性重写方程 e(G, G)x² ⋅ e(G, G)-x ⋅ e(G, G)-42 = 1, 进一步的 e(xG, xG) ⋅ e(xG, -G) ⋅ e(G, -42G) = 1. 因此, 我们只需要提供 xG 的值. 同时由于椭圆曲线的离散对数问题, 从 xG 反推回 x 是困难的.&lt;/p&gt;

&lt;p&gt;双线性映射在ABE中的使用是通过将属性映射到椭圆曲线上的点，并利用双线性性质来实现访问策略的验证和解密操作。&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;元素的阶&lt;/code&gt;  一个群内的一个元素a的阶（有时称为周期）是指会使得a&lt;sup&gt;m&lt;/sup&gt; = e的最小正整数m（其中的e为这个群的单位元素，且a&lt;sup&gt;m&lt;/sup&gt;为a的m次幂）。若没有此数存在，则称a有无限阶。有限群的所有元素都有有限阶。&lt;/p&gt;

&lt;h2 id=&quot;cpabe&quot;&gt;cpabe&lt;/h2&gt;
&lt;p&gt;https://acsc.cs.utexas.edu/cpabe/
设 G0 是素阶 p 的双线性群，设 g是G0的生成元，G0×G0→ G1 表示双线性映射。安全参数 κ 将确定组的大小。&lt;/p&gt;

&lt;p&gt;参考 cpabe python实现 https://jhuisi.github.io/charm/_modules/abenc_bsw07.html#main&lt;/p&gt;

&lt;p&gt;访问控制树实现 https://jhuisi.github.io/charm/toolbox/secretutil.html&lt;/p&gt;
&lt;h3 id=&quot;setup&quot;&gt;setup&lt;/h3&gt;
&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;生成元&lt;/code&gt; 椭圆曲线上所有点加上O包含了很多循环子群(cyclic subgroups), 循环子群中的生成元(Generator)也被称作素元(primitive element)，通过不断自加，它可以“生成”群众其他所有元素,就是椭圆曲线上的一个点P，通过不断自加，它可以生成椭圆曲线上所有点。 即椭圆曲线上 = P、2P、3P、….nP，其中n为循环子群的阶。&lt;code class=&quot;highlighter-rouge&quot;&gt;生成元是椭圆曲线上的点&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;PK = G0,g,h = g&lt;sup&gt;β&lt;/sup&gt;,f = g&lt;sup&gt;1/β&lt;/sup&gt;,e(g,g)&lt;sup&gt;α&lt;/sup&gt;
MK = (β, g&lt;sup&gt;α&lt;/sup&gt;)&lt;/p&gt;

&lt;h3 id=&quot;加密&quot;&gt;加密&lt;/h3&gt;
&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;访问树 T&lt;/code&gt;: 设 T 是表示访问结构的树。树的每个非叶节点代表一个阈值门，由其子节点和阈值描述。如果 numx 是节点 x 的子节点数，kx 是其阈值，则 0 &amp;lt; kx ≤ numx。&lt;code class=&quot;highlighter-rouge&quot;&gt;当 kx = 1 时，阈值门是一个或门，当 kx = numx 时，它是一个与门。树的每个叶节点 x 由一个属性和一个阈值 kx = 1 来描述&lt;/code&gt;。 为了便于使用访问树，定义了一些函数。我们用 parent(x) 表示树中节点 x 的父节点。仅当 x 是叶节点时才定义函数 att(x)，并表示与树中叶节点 x 关联的属性。访问树 T 还定义了每个节点的子节点之间的顺序，即节点的子节点从 1 到 num 编号。函数 index(x) 返回与节点 x 关联的数字。其中索引值以任意方式唯一分配给给定键的访问结构中的节点。&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;Each interior node of the tree is a threshold gate and the leaves are associated with attributes. (We note that this setting is very expressive. For example, we can represent a tree with “AND” and “OR” gates by using respectively 2 of 2 and 1 of 2 threshold gates.) A user will be able to decrypt a ciphertext with a given key if and only if there is an assignment of attributes from the private key to nodes of the tree such that the tree is satisfied. We use the same notation as [15] to describe the access trees, even though in our case the attributes are used to identify the keys (as opposed to the data).
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;加密过程&lt;/code&gt; （其中dx是每个节点的阶）每个叶子都是多项式构造的阈值门，加密过程的访问控制树构造，从根节点R开始，算法选择一个随机的s∈Zp，并设置qR(0)=s。然后，它随机选择多项式qR的其他dR点来完全定义它。对于任何其他节点x，它设置qx(0)=q&lt;sub&gt;parent(x)&lt;/sub&gt;(index(x))，并随机选择dx其他点来完全定义qx。
让，Y是T中叶子节点的集合。然后，通过给出树状访问结构T并计算出密码文本，构建出密码文本&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/cpabeencrypt.png&quot; alt=&quot;cpabeEncrypt&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;T是访问控制树&lt;/li&gt;
  &lt;li&gt;C’ = 密文 * e(g,g)&lt;sup&gt;αs&lt;/sup&gt;,其中e(g,g)&lt;sup&gt;α&lt;/sup&gt;来自公钥&lt;/li&gt;
  &lt;li&gt;C = h&lt;sup&gt;s&lt;/sup&gt;,h = g&lt;sup&gt;β&lt;/sup&gt;来自公钥&lt;/li&gt;
  &lt;li&gt;C&lt;sub&gt;y&lt;/sub&gt;和 C’&lt;sup&gt;y&lt;/sup&gt; 是在G0上对访问控制树的加密&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pk_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ct_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;encrypt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;policy_str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt; 
        &lt;span class=&quot;n&quot;&gt;policy&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;util&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;createPolicy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;policy_str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;a_list&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;util&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getAttributeList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;policy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ZR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;shares&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;util&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;calculateSharesDict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;policy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;      

        &lt;span class=&quot;n&quot;&gt;C&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'h'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;C_y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;C_y_pr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{},&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shares&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;util&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strip_index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;C_y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'g'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shares&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;C_y_pr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;hash&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;G2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shares&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; 
        
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'C_tilde'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'e_gg_alpha'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                 &lt;span class=&quot;s&quot;&gt;'C'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'Cy'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;C_y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'Cyp'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;C_y_pr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'policy'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;policy_str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'attributes'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a_list&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;keygenmk-s-&quot;&gt;KeyGen(MK, S )&lt;/h3&gt;
&lt;p&gt;&lt;script type=&quot;math/tex&quot;&gt;SK = (D = g^{(α+r)/β},∀j∈S: D_j=g^r·H(j)^{r_j},D'_j=g^{r_j}).&lt;/script&gt;&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pk_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mk_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sk_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;keygen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; 
        &lt;span class=&quot;n&quot;&gt;g_r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'g2'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;    
        &lt;span class=&quot;n&quot;&gt;D&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'g2_alpha'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g_r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'beta'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;        
        &lt;span class=&quot;n&quot;&gt;D_j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;D_j_pr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{},&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;r_j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;D_j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;g_r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;hash&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;G2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r_j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;D_j_pr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'g'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r_j&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'D'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;D&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'Dj'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;D_j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'Djp'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;D_j_pr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'S'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;S&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;decryptctsk&quot;&gt;Decrypt(CT,SK)&lt;/h3&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pk_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sk_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ct_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;decrypt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;policy&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;util&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;createPolicy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'policy'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;pruned_list&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;util&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;prune&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;policy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'S'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pruned_list&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;util&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getCoefficients&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;policy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; 
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pruned_list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getAttributeAndIndex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getAttribute&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pair&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Cy'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Dj'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pair&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Djp'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Cyp'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
        
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'C_tilde'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pair&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'C'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'D'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;delegatesk-s&quot;&gt;Delegate(SK, S’)&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/stefano81/dcpabe&quot;&gt;dcpabe&lt;/a&gt;&lt;/p&gt;
</description>
        <pubDate>Wed, 24 May 2023 00:00:00 -0500</pubDate>
        <link>/2023/05/dairy4/</link>
        <guid isPermaLink="true">/2023/05/dairy4/</guid>
        
        <category>黄焖鸡日记</category>
        
        
      </item>
    
      <item>
        <title>数据共享的一些论文</title>
        <description>&lt;p&gt;[TOC]&lt;/p&gt;

&lt;h1 id=&quot;abe方案解释&quot;&gt;ABE方案解释&lt;/h1&gt;
&lt;p&gt;访问策略的实现，一种可能的方法是对共享数据进行加密，只给授权用户提供解密密钥。然而，传统的公钥加密方法不适合用于数据加密，因为它们通常为系统中的每个数据产生多份密码文本，其数量与用户数量成正比。另外，基于属性的加密(ABE)是这里数据加密的一 个好选择，因为:1.它使数据所有者能够对属性定义细 粒度的访问策略;2.访问策略由密码学而不是可信的中 央服务器执行;3.无论用户数量多少，它都能产生单一的密码文副本。&lt;/p&gt;

&lt;h1 id=&quot;数据选择性共享和获取&quot;&gt;数据选择性共享和获取&lt;/h1&gt;
&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;Efficient and Provably Secure Data Selective Sharing and Acquisition in Cloud-Based Systems&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;主要方案是ABE+SE&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;可搜索加密（SE）：对关键词进行加密，使用户 能够生成加密的陷阱门，并对加密的关键词进行搜索。&lt;/li&gt;
  &lt;li&gt;在ABE基础上增加了query一步，讲se集成进入query设置陷阱门&lt;/li&gt;
  &lt;li&gt;ABE+SE实现有俩种方式，策略-关键字评估和关键字-策略评估。在策略-关键字评估中，将首先评估访问策略，然后再评估关键字匹配。分别是abe的策略优先和se的关键词优先。&lt;/li&gt;
  &lt;li&gt;实验部分基于策略-关键字评估和关键字-策略评估分别做了针对dataowner、user和云服务器三个参与者的计算时间
    &lt;ul&gt;
      &lt;li&gt;每次实验取20次的平均值&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/abe开销表格.png&quot; alt=&quot;abe开销&quot; /&gt;&lt;/p&gt;
</description>
        <pubDate>Sat, 20 May 2023 00:00:00 -0500</pubDate>
        <link>/2023/05/dairy3/</link>
        <guid isPermaLink="true">/2023/05/dairy3/</guid>
        
        <category>黄焖鸡日记</category>
        
        
      </item>
    
      <item>
        <title>Zeestar与其他</title>
        <description>&lt;p&gt;[TOC]&lt;/p&gt;

&lt;h2 id=&quot;未来叙事和方向&quot;&gt;未来叙事和方向&lt;/h2&gt;
&lt;p&gt;https://www.techflowpost.com/article/detail_11927.html&lt;/p&gt;

&lt;h2 id=&quot;zeestar&quot;&gt;Zeestar&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/eth-sri&quot;&gt;苏黎世理工sri实验室，zk前沿&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;实验与评估&quot;&gt;实验与评估&lt;/h3&gt;
&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;选择了对同态进行数据共享或者权限控制的相关部分，合约加密的同态中不经意传输&lt;/code&gt;
测试多个交易合约，标记代码行数(loc)，在zeestar编译后以太坊内执行所花费的时间和gas&lt;/p&gt;

&lt;h2 id=&quot;zether&quot;&gt;Zether&lt;/h2&gt;
&lt;p&gt;consensus开发并且开源了
https://github.com/ConsenSys/anonymous-zether，是一个私人支付系统，协议论文中了21年的sp
https://crypto.stanford.edu/~buenz/papers/zether.pdf&lt;/p&gt;

&lt;p&gt;Anonymous Zether 是一个私人价值跟踪系统，其中以太坊智能合约维护加密账户余额。每个 Zether 智能合约 (ZSC) 必须在部署时“附加”到一些已经部署的 ERC-20 合约；一旦部署，该合约将建立特殊的“Zether”账户，用户可以从中存入或取出ERC-20 资金。将资金记入 Zether 账户后，其所有者可以私下将这些资金发送到其他 Zether 账户，保密（转账金额是私人的）和匿名的（交易者的身份是私人的）。只有每个账户密钥的所有者才能使用其资金，透支是不可能的。&lt;/p&gt;

&lt;p&gt;为增强隐私，用户应尽可能多地在 ZSC 内开展业务。&lt;/p&gt;

&lt;p&gt;（匿名）Zether 智能合约的运行大致如下（参见原始 Zether 论文更多细节）。每个账户都包含一个 ElGamal 密文，它使用自己的公钥对账户余额进行加密。为了发送资金，Alice 发布了一个有序的公钥列表——其中包含她自己和接收者，以及其他任意选择的各方——以及相应的 ElGamal 密文列表，这些密文分别加密（在适当的公钥下）Alice 的金额打算调整这些不同账户的余额。ZSC 使用 ElGamal 加密（带有“指数中的消息”）的同态属性应用这些调整。爱丽丝最终发布了一个零知识证明，断言她知道自己的密钥，她拥有足够的资金来支付她的扣除，她只从她自己身上扣除资金，并只将它们记入 Bob（她借记的金额相同，不少于此）；她当然也证明了除了她自己和 Bob 的余额之外，她没有改变这些余额。这些调整密文——对任何外部观察者都是不透明的——隐藏了谁向谁汇款以及汇款了多少。&lt;/p&gt;

&lt;p&gt;用户永远不需要直接与 ZSC 交互；相反，我们的前端客户端简化了它的使用。&lt;/p&gt;

&lt;h2 id=&quot;server-aided-bilateral-access-control&quot;&gt;Server-Aided Bilateral Access Control&lt;/h2&gt;
&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;SRB-ABE&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;访问控制树做撤销列表&lt;/li&gt;
  &lt;li&gt;双向LSSS&lt;/li&gt;
  &lt;li&gt;ACE加密(&lt;a href=&quot;https://eprint.iacr.org/2016/106.pdf&quot;&gt;Access Control Encryption:
Enforcing Information Flow with Cryptography&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;主要算法流程&quot;&gt;主要算法流程&lt;/h3&gt;

&lt;hr /&gt;
&lt;p&gt;Setup(1&lt;sup&gt;λ&lt;/sup&gt;,N,T ) → (mpk,msk,st,rl): :概率设置算法由KGC运行的。该算法输出一个主公钥mpk、一个主秘钥msk、一个状态st和一个撤销列表rl,所有其他算法都以mpk作为输入。&lt;/p&gt;

&lt;p&gt;KeyGen(id) → (pk&lt;sub&gt;id&lt;/sub&gt; ,sk&lt;sub&gt;id&lt;/sub&gt; ) :概率性密钥生成算法由每 个数据接收者运行。该算法将一个身份ID作为输入，并 输出一个公钥pkid 和一个秘钥sk&lt;sub&gt;id&lt;/sub&gt;，其中sk&lt;sub&gt;id&lt;/sub&gt;由每个数据 接收者保存，pk&lt;sub&gt;id&lt;/sub&gt;被发送到KGC。&lt;/p&gt;

&lt;p&gt;TKGen(msk, st, pk&lt;sub&gt;id&lt;/sub&gt;, R) → (tk&lt;sub&gt;id&lt;/sub&gt;, st):概率转换密钥生成算法由KGC运行。将主秘钥msk、状态st、公钥pk&lt;sub&gt;id&lt;/sub&gt;和接收者的属性集R作为输入，并输出转换密钥tk&lt;sub&gt;id&lt;/sub&gt;和更新的状态st，其中tk&lt;sub&gt;id&lt;/sub&gt;被发送到不受信任的服务器。&lt;/p&gt;

&lt;p&gt;KUGen(st, rl, t) → ku&lt;sub&gt;t&lt;/sub&gt;:概率性密钥更新原料生成算法是由KGC运行的。该算法将一个状态st，一个撤销列表rl和一个时间戳t作为输入、 并输出一个密钥更新材料ku&lt;sub&gt;t&lt;/sub&gt;，其中ku&lt;sub&gt;t&lt;/sub&gt; 被公开广播给每个数据接收器。&lt;/p&gt;

&lt;p&gt;TKUpdate(tk&lt;sub&gt;id&lt;/sub&gt;, ku&lt;sub&gt;t&lt;/sub&gt; ) → utk&lt;sub&gt;id,t&lt;/sub&gt; /⊥: 概率转换密钥更新算法是由不受信任的服务器运行的。这个算法需要一个转换密钥tk&lt;sub&gt;id&lt;/sub&gt; ，一个密钥更新材料ku&lt;sub&gt;t&lt;/sub&gt;作为输入，并输出一个更新的转换密钥utk&lt;sub&gt;id,t&lt;/sub&gt; ，如果数据接收器被撤销，则输出失败。&lt;/p&gt;

&lt;p&gt;EKGen(msk, S) → ek&lt;sub&gt;S&lt;/sub&gt;:概率加密密钥生成算法由KGC运 行。该算法将主秘钥msk和发送者S的属性集作为输入 ，并输出一个加密密钥ek&lt;sub&gt;S&lt;/sub&gt;，其中ek&lt;sub&gt;S&lt;/sub&gt;被发送给每个数据发送者。&lt;/p&gt;

&lt;p&gt;Enc(ek&lt;sub&gt;S&lt;/sub&gt; , S‘, t, R, m) → c:概率性加密算法是由每个数据发送者运行的。该算法将一个加密密钥 ek&lt;sub&gt;S&lt;/sub&gt;、一个发送者S’⊆S的属性集、一个时间戳t、一个指定接收者R的访问结构和一个消息m作为输入，并输出一个密码文本c，其中c被发送到云服务提供商处。&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;CTUpdate(c, t) → ct :确定性的密码文本更新算法由服务提供商运行。该算法将一个密码文本c和一个时间戳t作为输入，并输出一个更新的密码文本ct，其中ct被发送到不受信任的服务器。Verify(S, ct ) → {0, 1}:确定性的验证算法是由不可信任的服务器运行的。该算法将发件人S的访问结构和密码文本ct作为输入、并且当且仅当S&lt;/td&gt;
      &lt;td&gt;= S时输出0;否则输出0。&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Transfer(utk&lt;sub&gt;id&lt;/sub&gt;, t , ct ) → c ̇:确定性的转换算法是由不受信任的服务器运行的。该算法以更新的转换密钥utk&lt;sub&gt;id&lt;/sub&gt;,t ，密码文本ct为输入，并输出转换后的密码文本c‘，其中c’以身份id发送给数据接收者。&lt;/p&gt;

&lt;p&gt;Dec(skid , c’) → m: 确定性的解密算法由每个数据接收者运行。该算法以秘钥skid和转换后的密文c’为输入，并输出一个信息m。&lt;/p&gt;

&lt;p&gt;Rev(rl, id, t) → rl:有状态撤销算法由KGC运行。该算法将一个撤销列表rl、一个身份id和一个时间戳t作为输入 ，并输出一个更新的撤销列表rl。&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;实验设计&quot;&gt;实验设计&lt;/h3&gt;
&lt;p&gt;比较了S-ABE，SR-ABE和SRB-ABE，在Eclipse中，通过JPBC库，使 用JPBC库提供的 “a.properties”中的A型椭圆曲线，使用 Java版本13.0.2，用户数设为1024，如果没有规范，则将系统lifetime约束为1024，比较函数时间复杂度&lt;/p&gt;

&lt;p&gt;变量都是运行时间，自变量分别是epoch of bounded system lifetime（运行周期），属性个数和Policy大小&lt;/p&gt;

&lt;p&gt;设置前提假设：硬假设决策性q-1假设和 决策性双线性Diffie-Hellman(BDH)假设，讲述了假设原理，并给予假设设置了俩条定理，并进行证明。&lt;/p&gt;

&lt;p&gt;最后分析假设被打破的概率。&lt;/p&gt;

&lt;h2 id=&quot;abe加密的论文&quot;&gt;ABE加密的论文&lt;/h2&gt;
&lt;p&gt;[1]Zhibin Zhou, Dijiang Huang:On efficient ciphertext-policy attribute based encryption and broadcast encryption: extended abstract. ACM Conference on Computer and Communications Security 2010: 753-755
[2]Shlomi Dolev, Niv Gilboa, Marina Kopeetsky:
Poster: attribute based broadcast encryption with permanent revocation. ACM Conference on Computer and Communications Security 2011: 757-760
[3]Tran Viet Xuan Phuong, Guomin Yang, Willy Susilo:
POSTER: Efficient Ciphertext Policy Attribute Based Encryption Under Decisional Linear Assumption. ACM Conference on Computer and Communications Security 2014: 1490-1492
[4]Shashank Agrawal, Melissa Chase:
FAME: Fast Attribute-based Message Encryption. ACM Conference on Computer and Communications Security 2017: 665-682
[5] Brent Waters:Ciphertext-Policy Attribute-Based Encryption: An Expressive, Efficient, and Provably Secure Realization. Public Key Cryptography 2011: 53-70
[6]Allison B. Lewko, Brent Waters:Decentralizing Attribute-Based Encryption. EUROCRYPT 2011: 568-588
[7]Amit Sahai, Hakan Seyalioglu, Brent Waters:
Dynamic Credentials and Ciphertext Delegation for Attribute-Based Encryption. CRYPTO 2012: 199-217
Allison B. Lewko, Brent Waters:
[8]New Proof Methods for Attribute-Based Encryption: Achieving Full Security through Selective Techniques. CRYPTO 2012: 180-198
[9]Susan Hohenberger, Brent Waters:
Online/Offline Attribute-Based Encryption. Public Key Cryptography 2014: 293-310
[10]Venkata Koppula, Brent Waters:
Realizing Chosen Ciphertext Security Generically in Attribute-Based Encryption and Predicate Encryption. CRYPTO (2) 2019: 671-700
[11]Jiming Liu, Zhenfu Cao, Xiaolei Dong, Jiachen Shen:
DMU-ABSE: Dynamic Multi-user Attribute-Based Searchable Encryption with File Deletion and User Revocation. SocialSec 2019: 17-31
[11]Gang Yu, Xiaoxiao Ma, Zhenfu Cao, Weihua Zhu, Guang Zeng:
Server-Aided Directly Revocable Ciphertext-Policy Attribute-Based Encryption with Verifiable Delegation. ICICS 2017: 172-179
[12]Kotoko Yamada, Nuttapong Attrapadung, Keita Emura, Goichiro Hanaoka, Keisuke Tanaka:
Generic Constructions for Fully Secure Revocable Attribute-Based Encryption. ESORICS (2) 2017: 532-551
[13]Nuttapong Attrapadung, Hideki Imai:
Attribute-Based Encryption Supporting Direct/Indirect Revocation Modes. IMACC 2009: 278-300
[14]Yinghui Zhang, Xiaofeng Chen, Jin Li, Hui Li, Fenghua Li:
FDR-ABE: Attribute-Based Encryption with Flexible and Direct Revocation. INCoS 2013: 38-45&lt;/p&gt;
</description>
        <pubDate>Fri, 19 May 2023 00:00:00 -0500</pubDate>
        <link>/2023/05/dairy2/</link>
        <guid isPermaLink="true">/2023/05/dairy2/</guid>
        
        <category>黄焖鸡日记</category>
        
        
      </item>
    
      <item>
        <title>数据分享与格密码</title>
        <description>&lt;p&gt;[TOC]&lt;/p&gt;

&lt;h1 id=&quot;cobra&quot;&gt;COBRA&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;Dynamic Proactive Secret Sharing for Confidential BFT Services&lt;/strong&gt;
主要的三个过程：Share/Combine 、Recovery 和Reshare 。&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Share/Combine：该协议用于在一组副本之间生成秘密共享。副本交换消息以计算它们的份额并将它们组合以重建秘密。&lt;/li&gt;
  &lt;li&gt;Recovery：该协议用于通过从幸存的副本中重建它们的份额来从副本故障中恢复。Recovery 协议可确保即使某些副本遭到破坏或出现故障，所有秘密仍然保密。&lt;/li&gt;
  &lt;li&gt;Reshare：该协议用于在新副本加入或旧副本离开组时更新秘密的份额。Reshare 协议允许在不影响安全性或性能的情况下动态更改组成员身份。&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;dpss&quot;&gt;DPSS&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;分布式多项式生成
    &lt;ul&gt;
      &lt;li&gt;包括三个步骤，多项式提案(步骤S1和S2),选择(步骤S3和S4),以及共享计算（步骤S5）
&lt;img src=&quot;/images/posts/dpssgenpoly.png&quot; alt=&quot;分布式多项式生成&quot; /&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Share Recovery
    &lt;ul&gt;
      &lt;li&gt;份额恢复
&lt;img src=&quot;/images/posts/dpssReshare.png&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Recovery
    &lt;ul&gt;
      &lt;li&gt;遇到恶意节点时的重新分享
&lt;img src=&quot;/images/posts/dpssRecover.png&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;实验设计与评估&quot;&gt;实验设计与评估&lt;/h2&gt;
&lt;h3 id=&quot;实验基础算法&quot;&gt;实验基础算法&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;基于&lt;a href=&quot;https://www.di.fc.ul.pt/~bessani/publications/dsn14-bftsmart.pdf&quot;&gt;BFTSMaRt&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;使用拉格朗日多项式插值和霍纳方法实现Shamir秘密共享进行共享计算。此方法可确保仅使用t次乘法和t次加法计算t次多项式，而不是使用t次指数、t次乘法和t次加法。在256位的素数域中完成。&lt;/li&gt;
  &lt;li&gt;支持俩种承诺方案，Feldman’s线性承诺和Kate 承诺&lt;/li&gt;
  &lt;li&gt;使用SHA256作为哈希函数，SHA256withECDSA用于签名，不带密码套件的TLS用于实现经过身份验证的通道(TLS_ECDHE_ECDSA_WITH_NULL_SHA)，以及AES用于加密所携带机密信息的256位密钥在消息上。&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;环境设置&quot;&gt;环境设置&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;实现了 VSSR 和 MPSS 与 COBRA 进行对比&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;讲明实验目的aiming at answering the following questions: What is the overall impact of integrating COBRA’s
DPSS into BFT SMR normal operation? What is the cost of
recovering and resharing a significant number of secrets using&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;14台Dell PowerEdge R410 servers, with 32GB of
memory and two quadcore 2.27 Intel Xeon E5520 processor
with hyperthreading (supporting thus 16 hardware threads).
The machines run Ubuntu Linux 20.04.1 LTS and JRE 1.8.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;10台机器作为副本（共识节点），4台作为客户机，运行超过1500个客户&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;实验方法&quot;&gt;实验方法&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;量化建立kv存储的保密性的性能成本。1kb更新值（数据大小），在4、7、10个节点下的更新吞吐量。无保密性下的BFT，COBRA的线性和常数变体、副本不进行份额验证（不满足客户的线性化）的变体和vssr，mpss协议结果和conra一样&lt;/li&gt;
  &lt;li&gt;在4、7、10个节点下，恢复具有包含 100k 的non-trivial状态（当系统或算法处于一个非预期的状态时，我们就可以说它处于一个non-trivial状态。在拜占庭容错技术中，当系统中存在错误节点时，系统就处于一个non-trivial状态）的副本共享，统计值包括Pol. Gen.(多项式生成)，Blind.，Recon(重建份额和承诺)，其他(包括数据传输、序列化、其他密码学计算)的时间
    &lt;ul&gt;
      &lt;li&gt;补充：副本、数据大小不变，份额增加，recover延迟的关系，Pol. Gen和其他步骤的时间占比；数据份额不变，增大副本数目，时间延迟和各步骤占比&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;同2，做reshare实验&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;恶意节点的影响，不同份额（1个和1024个）情况下，恶意节点个数对延迟的影响 – 验证检测和删除恶意节点并重新执行Pol. Gen对时间在份额越大的时候会被稀释&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/bft-smart/cobra&quot;&gt;COBRA开源代码&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;vss各类方案的比较&quot;&gt;VSS各类方案的比较&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/pss比较.png&quot; alt=&quot;pss比较&quot; /&gt;
比较参数包括同步性，动态性，秘密分享和合并算法的时间复杂度，重新分享的时间复杂度，存储和恢复&lt;/p&gt;

&lt;h3 id=&quot;tips&quot;&gt;Tips&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;MPSS10个节点分享100000个秘密需要一个小时
    &lt;ul&gt;
      &lt;li&gt;MPSS&lt;/li&gt;
      &lt;li&gt;Churp&lt;/li&gt;
      &lt;li&gt;Baron&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;所有的ss都会分析拜占庭容错&lt;/li&gt;
  &lt;li&gt;PSS比VSS更具有动态性和安全性&lt;/li&gt;
  &lt;li&gt;BFT SMR提交命令来更新一组不受信任的系统上的服务状态，保密状态下的BFT SMR相当于MPC的一种受限形式，具有时间解耦并支持受限形式的私有状态计算。&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;拜占庭容错的副本是指在分布式系统中，为了保证系统能够在存在最多 t 个错误节点的情况下仍然能够正常运行，采用了拜占庭容错技术的副本。副本通常指的是分布式系统中的节点或服务器。这些节点可以相互通信并达成共识，以确保系统在面对错误节点时仍然能够保持一致性和可靠性。在拜占庭容错技术中，每个节点都有一个副本，这些副本可以相互协作来保证系统的正确性和可用性。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;Blind 盲签名
    &lt;ul&gt;
      &lt;li&gt;
        &lt;p&gt;在拜占庭容错技术中，Blind过程是指使用Blind参数来保护分布式系统中的节点免受攻击的一种过程。具体来说，Blind过程包括以下步骤：&lt;/p&gt;

        &lt;ol&gt;
          &lt;li&gt;
            &lt;p&gt;生成Blind参数：使用多项式生成器生成一组随机数作为Blind参数。&lt;/p&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;p&gt;Blind化节点值：将每个节点的真实值与对应的Blind参数进行异或运算，得到一个经过Blind化处理的值。&lt;/p&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;p&gt;发送Blinded值：将经过Blind化处理的值发送给其他节点。&lt;/p&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;p&gt;解除Blind化：在接收到其他节点发送的经过Blind化处理的值后，将其与自己持有的对应的Blind参数进行异或运算，得到原始值。&lt;/p&gt;
          &lt;/li&gt;
        &lt;/ol&gt;

        &lt;p&gt;通过这个过程，可以保护分布式系统中的节点免受攻击，并确保系统能够在存在错误节点的情况下仍然能够保持一致性和可靠性。&lt;/p&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;kzg-承诺做数据可用性&quot;&gt;KZG 承诺做数据可用性&lt;/h1&gt;
&lt;h2 id=&quot;ethstoragescaling-ethereum-storage-via-l2-and-da&quot;&gt;Ethstorage:Scaling Ethereum Storage via L2 and DA&lt;/h2&gt;
&lt;p&gt;https://ethresear.ch/t/ethstorage-scaling-ethereum-storage-via-l2-and-da/14223&lt;/p&gt;

&lt;h1 id=&quot;数据市场revelate&quot;&gt;数据市场revelate&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;数据估值的各种方法&lt;/li&gt;
  &lt;li&gt;将数据转化为产品，数据商业化
https://revelate.co/&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;world-computer&quot;&gt;world computer&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;World Supercomputer
    &lt;ul&gt;
      &lt;li&gt;World Supercomputer: https://worldsupercomputer.io/&lt;/li&gt;
      &lt;li&gt;ETH Wolrd Supercomputer: https://ethresear.ch/t/towards-world-supercomputer/15487&lt;/li&gt;
      &lt;li&gt;Stanford Blockchain Review: https://stanfordblockchainreview.substack.com/p/towards-world-supercomputer&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;zkML AIGC-NFT: https://github.com/ethereum/EIPs/pull/7007/commits/20c4ac300964d2fea2c23907538b23c6fbf8125b?short_path=da71de3#diff-da71de3584fcdbaac732f730c8d695b0ba45ddbbdcd558388909f42720543154&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;https://ethresear.ch/t/towards-world-supercomputer/15487&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;zkpow&quot;&gt;zkpow&lt;/h1&gt;
&lt;p&gt;https://zerosync.org/&lt;/p&gt;

&lt;p&gt;puncturable encryption&lt;/p&gt;

</description>
        <pubDate>Thu, 18 May 2023 00:00:00 -0500</pubDate>
        <link>/2023/05/dairy1/</link>
        <guid isPermaLink="true">/2023/05/dairy1/</guid>
        
        <category>黄焖鸡日记</category>
        
        
      </item>
    
      <item>
        <title>Harmoney </title>
        <description>&lt;h1 id=&quot;harmoney&quot;&gt;Harmoney&lt;/h1&gt;

&lt;p&gt;[TOC]&lt;/p&gt;

&lt;h2 id=&quot;概述&quot;&gt;概述&lt;/h2&gt;

&lt;p&gt;Harmony包含一个信标链和多个分片链。信标链充当随机信标和身份寄存器，而分片链存储单独的区块链状态并同时处理交易。Harmony通过结合可验证随机函数（VRF）和可验证延迟函数（VDF）提出了一种有效的随机性生成算法。Harmony还在分片过程中加入了PoS，这将分片的安全性考虑从最小节点数更改为最小投票份额数。&lt;/p&gt;

&lt;h2 id=&quot;drg分布式随机生成&quot;&gt;DRG（分布式随机生成）&lt;/h2&gt;

&lt;p&gt;融合VRF和VDF&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Algorand利用基于VRF（可验证随机函数）的加密分类来选择共识验证组；以太坊2.0提出VDF（可验证延迟函数）用于延迟实际随机数的揭示，防止最后揭示者的攻击--这个总结不错
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;协议步骤：&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1. leader发送带上一个区块链的哈希值的初始化信息给所有验证节点
2. 验证者受到初始化信息，使用VRF生成随机数r和证明p，(r, p) = VRF(ski, H(B&amp;lt;sub&amp;gt;n−1&amp;lt;/sub&amp;gt;, v),v为当前视图，验证者将(r,p)发送给leader
3. 验证者受到至少f+1个有效的随机数后，对所有随机数做XOR运算得到最终的随机数pRND的preimage原像
4. 领导者允许BFT在所有验证者节点达成对pRND的共识，完成提交至B&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;
5. pRnd成功提交后，leader运行VDF计算当前actual随机数Rnd = VDF (pRnd, T )，随机数将会延迟k个区块计算出
6. Rnd被计算出后，leader发起BFT验证Rnd，最终提交上B&amp;lt;sub&amp;gt;n+k&amp;lt;/sub&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/drg.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;分片方式&quot;&gt;分片方式&lt;/h2&gt;

&lt;h3 id=&quot;分片链和信标链&quot;&gt;分片链和信标链&lt;/h3&gt;

&lt;p&gt;分片链是处理和验证其自身交易并存储其自身状态的区块链。分片仅处理与其自身相关的交易。尽管分片链相对独立，但是它将通过跨分片通信与其他分片链通信。&lt;/p&gt;

&lt;h3 id=&quot;跨片交易&quot;&gt;跨片交易&lt;/h3&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;主链驱动：zillqa，跨片交易依赖于主链驱动
客户端驱动：Omniledger，客户端驱动的跨分片事务处理机制，其中分片之间的消息由客户端收集并发送到分片
分片链驱动：RapidChain，分片之间的消息是由分片中的节点直接发送
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Harmony采用分片驱动的方法，使用Kademlia路由协议将分片驱动的通信复杂性O（N）降低到O（log（N））。另外，将使用擦除码（erasure code）对正在通信的数据进行编码，以确保跨分片通信的鲁棒性。&lt;/p&gt;

&lt;h3 id=&quot;信标链&quot;&gt;信标链&lt;/h3&gt;

&lt;p&gt;信标链也是一条分片链，除了执行分片链的处理交易的功能外，另外还负责生成随机数额接受stakes,意味着信标链是stakers将其令牌存入成为验证节点的链。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/beaconchain.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;信标链通过包含每个分片链中的块头来帮助增强分片链状态的安全性和一致性。具体来说，在将新块提交到分片链之后，其块头将（通过基于Kademlia的分片间通信）发送到信标链。信标链上已提交的块头将被广播到整个网络，每个分片都会为所有其他分片保留一串有效的块头，这将用于检查来自其他分片的交易的有效性（即简单的付款验证SPV）。&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;增加了攻击单个碎片的难度。&lt;/li&gt;
  &lt;li&gt;减少在分片之间广播块头的网络成本。
如果我们让每个分片分别广播其标头，则将进行O（N&lt;sup&gt;2&lt;/sup&gt;）网络通信。以信标链作为中央中继，复杂度降低为O（N）。&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;保证一致性&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;原子锁定机制确保跨分片交易的一致性&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;采用Kademlia路由实现跨分片交易&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;状态分片&quot;&gt;状态分片&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;账户模型&lt;/li&gt;
  &lt;li&gt;一个用户帐户可以在不同的分片上拥有多个余额&lt;/li&gt;
  &lt;li&gt;用户帐户可以通过发出跨分片交易在分片之间移动其余额&lt;/li&gt;
  &lt;li&gt;合约账户限制在创建合约的那个分片，同时开发者可以在其他分片上创建多个实例，实例间不共享状态但是可以通过跨片通信进行交流&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;pos入口&quot;&gt;POS入口&lt;/h3&gt;

&lt;p&gt;— 基于staking的分片方式&lt;/p&gt;

&lt;p&gt;harmony的验证者注册是通过POS入口防女巫攻击（zilliqa和quarkchain是通过POW），即成为验证者节点需要质押代币，投入的代币数量决定验证者的投票份额&lt;/p&gt;

&lt;h3 id=&quot;resharding&quot;&gt;Resharding&lt;/h3&gt;

&lt;h2 id=&quot;网络加速方案&quot;&gt;网络加速方案&lt;/h2&gt;

&lt;h3 id=&quot;基于kademlia的路由方案&quot;&gt;基于Kademlia的路由方案&lt;/h3&gt;

&lt;h4 id=&quot;kademlia算法&quot;&gt;kademlia算法&lt;/h4&gt;

&lt;p&gt;​	kad算法是DHT的一种实现。kad算法给每个节点分配了一个节点id，根据节点id之间的异或距离建立路由表。给资源设置了一个key，根据key与节点id的异或距离查找资源。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;节点维护的信息&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;
        &lt;p&gt;储存的资源，key-value对，文件名-文件&lt;/p&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;p&gt;&lt;strong&gt;路由表–K桶&lt;/strong&gt;&lt;/p&gt;

        &lt;ul&gt;
          &lt;li&gt;
            &lt;p&gt;概念:对于位于&lt;em&gt;[0,160)&lt;/em&gt; 中的每个 &lt;em&gt;i&lt;/em&gt; ，每个节点都保存有一些 &amp;lt;IP地址， UDP 端口，节点 ID&amp;gt;三元组列表，三元组中的节点 &lt;em&gt;ID&lt;/em&gt; 为那些和其距离位于 2 &lt;sup&gt;  &lt;em&gt;i&lt;/em&gt;&lt;/sup&gt; 和 2&lt;sup&gt; &lt;em&gt;i+1&lt;/em&gt;&lt;/sup&gt; 之间的节点的 &lt;em&gt;ID&lt;/em&gt;&lt;/p&gt;

            &lt;p&gt;K是一个平衡系统性能和网络负载的参数，设定一个三元组列表的最大容量为k，保证网络中k个节点同时失效的可能性很小&lt;/p&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;p&gt;k桶内节点排序：每个 &lt;em&gt;k-bucket&lt;/em&gt; 都按照节点最近联系时间排序——最近未联系的节点放在表头，最近联系的节点放在表尾&lt;/p&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;p&gt;K桶的生成&lt;/p&gt;

            &lt;ul&gt;
              &lt;li&gt;主要是根据于节点的XOR距离，距离位于  2 &lt;sup&gt;  &lt;em&gt;i&lt;/em&gt;&lt;/sup&gt; 和 2&lt;sup&gt; &lt;em&gt;i+1&lt;/em&gt;&lt;/sup&gt; 之间的节点在同一个k桶&lt;/li&gt;
              &lt;li&gt;在i较小时，可能k桶是空的，节点数目比较小&lt;/li&gt;
              &lt;li&gt;
                &lt;p&gt;当i比较大时，此时可能节点数目会超过k。当节点接收到任何节点信息时，会进行k桶的更新：1.  如果节点已经存在k桶内，则将节点移到k桶尾部；&lt;/p&gt;

                &lt;ol&gt;
                  &lt;li&gt;
                    &lt;p&gt;如果节点不再k桶内，当k桶未满时，则将其加入到k桶尾部&lt;/p&gt;

                    &lt;ol&gt;
                      &lt;li&gt;如果节点不再k桶内，当k桶已满时，则节点ping k桶表头节点（最近未联系），如果ping通则将该表头节点移至表尾并抛弃发送者节点的联系信息，否则舍弃表头节点并将发送者节点加入到表尾&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                &lt;/ol&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;

        &lt;p&gt;&lt;img src=&quot;/images/posts/find.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;XOR 度量&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;两节点间距离是 nodeid1 $\bigoplus$ nodeid2&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Kademlia协议&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;4&lt;/em&gt; 个 &lt;em&gt;RPCs&lt;/em&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;em&gt;PING&lt;/em&gt;
            &lt;ul&gt;
              &lt;li&gt;探测节点是否在线&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;STORE
            &lt;ul&gt;
              &lt;li&gt;节点存储一个 &amp;lt;key ,value&amp;gt; 对&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;em&gt;FIND_NODE&lt;/em&gt;
            &lt;ul&gt;
              &lt;li&gt;输入参数为一个160位的节点ID&lt;/li&gt;
              &lt;li&gt;输出距离目标 &lt;em&gt;ID&lt;/em&gt; 最近的 &lt;em&gt;k&lt;/em&gt; 个节点的三元组&amp;lt;IP地址， &lt;em&gt;UDP&lt;/em&gt; 端口，节点 &lt;em&gt;ID&amp;gt;&lt;/em&gt; 列表&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;em&gt;FIND_VALUE&lt;/em&gt;
            &lt;ul&gt;
              &lt;li&gt;输入参数为一个160位的keyID&lt;/li&gt;
              &lt;li&gt;输出和find_node是一样的，当请求者存有对应key时发回value&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;路由算法&lt;/strong&gt;&lt;/p&gt;

    &lt;ol&gt;
      &lt;li&gt;发起者计算自身到目标节点（T)的异或距离cpl,根据cpl找到对应的k桶,再从该k桶中寻找与L具有最长公共前缀的K个节点（cpl最小），然后对这些节点 发起查询请求&lt;/li&gt;
      &lt;li&gt;X节点收到查询请求，从自身查找并返回距离T更近的K个节点给发起者，如果是自身则返回自身&lt;/li&gt;
      &lt;li&gt;节点发起者收到响应后再次对着K个节点发起查询请求，重复2&lt;/li&gt;
    &lt;/ol&gt;

    &lt;p&gt;最终查询结果是收到一批距离目标节点很近的节点列表&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;使用擦除码加速广播&quot;&gt;使用擦除码加速广播&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/erasercode.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;使用RaptorQ fountain code替代源Reed-Solomon 擦除码来改善IDA的坚固性&lt;/p&gt;

&lt;h3 id=&quot;快速状态同步&quot;&gt;快速状态同步&lt;/h3&gt;

&lt;p&gt;验证者加入新的分片时，他们将需要快速同步到分片的当前状态，以验证新交易。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/Synchronization.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;新块加入时先下载当前分片的当前共识周期的状态信息，方便立刻验证交易&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;然后下载历史的区块头并通过检查签名验证区块头，只要能通过加密路径（hash pointers and signatures）溯源到创世区块则状态可信&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;hash pointer：每一个epoch的第一个区块会有一个hash pointer指向上一个epoch的第一个区块，这样可以节省时间   — why接下来n个区块内有效&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;避免重放攻击并且节省状态空间：设定一个数n,在一个交易只在&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;fbft共识&quot;&gt;FBFT共识&lt;/h2&gt;

&lt;p&gt;F指Fast，主要技术：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Schnorr多签
    &lt;ul&gt;
      &lt;li&gt;相比PBFT，不再通过询问验证节点签名，通信复杂度扩展，每个验证者只需接收一个多重签名，将通信的复杂度从O(n^2)减少到O(n)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;RaptorQ fountain code
    &lt;ul&gt;
      &lt;li&gt;加速块广播&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;FBFT步骤
    &lt;ul&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;leader广播新块给验证者，通过RaptorQ fountain code   – announce&lt;/li&gt;
          &lt;li&gt;验证者验证新块块头然后通过BLS进行签名，返回签名给leader&lt;/li&gt;
          &lt;li&gt;leader收到超过2f+1个有效签名后，讲签名聚集成BLS多签，广播BLS多签和位图指示（已签名的验证者列表），第三步和第二步合称  prepare&lt;/li&gt;
          &lt;li&gt;验证者检查多签是否有至少2f+1个验证者然后签名，返回签名给leader&lt;/li&gt;
          &lt;li&gt;leader收到超过2f+1份签名，生成BLS多签，同样打包一个位图进新块，提交新块并广播   – broadcast&lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/fbft.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Harmony的验证者是根据权益证明选举出来的。在某种意义上，具有更多投票份额的验证者具有比其他人更多的投票权，而不是单签名一票的投票权。因此，领导者不等待验证者的至少2f +1个签名，而是等待集体拥有至少2f +1个投票份额的验证者的签名。&lt;/p&gt;

&lt;h2 id=&quot;reference&quot;&gt;Reference&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://pdos.csail.mit.edu/~petar/papers/maymounkov-kademlia-lncs.pdf&quot;&gt;Kademlia：A Peer-to-peer Information System Based on XOR Metric&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://shuwoom.com/?p=813&quot;&gt;Kademlia协议的一些具体算法&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;[Kademlia协议的一个实现]&lt;/p&gt;
</description>
        <pubDate>Thu, 07 Oct 2021 00:00:00 -0500</pubDate>
        <link>/2021/10/harmony/</link>
        <guid isPermaLink="true">/2021/10/harmony/</guid>
        
        <category>区块链</category>
        
        
      </item>
    
      <item>
        <title>在本地搭建一个ethereum的私有节点(2)</title>
        <description>&lt;h1 id=&quot;在本地搭建一个ethereum的私有网络&quot;&gt;在本地搭建一个ethereum的私有网络&lt;/h1&gt;

&lt;h2 id=&quot;setting-up-a-private-blockchain&quot;&gt;Setting Up A Private Blockchain&lt;/h2&gt;

&lt;p&gt;上一期教程我们已经完成了以太坊环境的搭建和geth客户端的安装，这一期我们使用geth搭建第一个ethereum的私有节点。在上一期的环境下，仍然先进入到管理员用户，然后配置geth环境：&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;su root 

export  PATH=&amp;lt;go-ethereum存放的文件夹&amp;gt;/build/bin  
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;一条区块链的运行首先需要一个初始块，我们需要对我们私有网络的区块链进行初始化。&lt;/p&gt;

&lt;p&gt;以太坊的创世块信息储存在一个json文件中，实际上目前几乎所有区块链信息都可以用json文件储存。&lt;/p&gt;

&lt;p&gt;这个是我的初始块信息&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;{

  &quot;config&quot;: {

​    &quot;chainId&quot;: 2019,

​    &quot;homesteadBlock&quot;: 0,

​    &quot;eip155Block&quot;: 0,

​    &quot;eip158Block&quot;: 0

  },



  &quot;alloc&quot;      : {},

  &quot;coinbase&quot;   : &quot;0x0000000000000000000000000000000000000000&quot;,

  &quot;difficulty&quot; : &quot;0x400&quot;,

  &quot;extraData&quot;  : &quot;&quot;,

  &quot;gasLimit&quot;   : &quot;0x2fefd8&quot;,

  &quot;nonce&quot;      : &quot;0x0000000000000042&quot;,

  &quot;mixhash&quot;    : &quot;0x0000000000000000000000000000000000000000000000000000000000000000&quot;,

  &quot;parentHash&quot; : &quot;0x0000000000000000000000000000000000000000000000000000000000000000&quot;,

  &quot;timestamp&quot;  : &quot;0x00&quot;

}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;上面参数的意思分别是
    &lt;ul&gt;
      &lt;li&gt;nonce用于挖矿的随机数&lt;/li&gt;
      &lt;li&gt;timestamp初始块的时间戳设置为0&lt;/li&gt;
      &lt;li&gt;parentHash上一个区块的hash，创世块因为没有前驱所以为0&lt;/li&gt;
      &lt;li&gt;mixHash 上一个区块的一部分生成的256位的哈希证明，与nonce相结合用于挖矿&lt;/li&gt;
      &lt;li&gt;extraData附加信息&lt;/li&gt;
      &lt;li&gt;gasLimit GAS的消耗总量限制，燃料上限&lt;/li&gt;
      &lt;li&gt;difficulty 计算难度-前多少位为0&lt;/li&gt;
      &lt;li&gt;coinbase 矿工帐号&lt;/li&gt;
      &lt;li&gt;alloc 创世中初始账户资产配置（允许定义预先填充的钱包列表）&lt;/li&gt;
      &lt;li&gt;config是定义链配置，影响共识协议&lt;/li&gt;
      &lt;li&gt;chainid是链的id号&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;官方解释会更加权威一些，建议大家直接看英文的参数介绍，也有利于理解区块链的结构，内容不想看可以直接跳过–&amp;gt;&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-----------------------------------------------Genesis block Explanation------------------------------------------------------



mixhash A 256-bit hash which proves, combined with the nonce, that a sufficient amount of computation has been carried out on this block: the Proof-of-Work (PoW). The combination of nonce and mixhash must satisfy a mathematical condition described in the Yellowpaper, 4.3.4. Block Header Validity, (44). It allows to verify that the Block has really been cryptographically mined, thus, from this aspect, is valid.



nonce A 64-bit hash, which proves, combined with the mix-hash, that a sufficient amount of computation has been carried out on this block: the Proof-of-Work (PoW). The combination of nonce and mixhash must satisfy a mathematical condition described in the Yellowpaper, 4.3.4. Block Header Validity, (44), and allows to verify that the Block has really been cryptographically mined and thus, from this aspect, is valid. The nonce is the cryptographically secure mining proof-of-work that proves beyond reasonable doubt that a particular amount of computation has been expended in the determination of this token value. (Yellowpager, 11.5. Mining Proof-of-Work).



difficulty A scalar value corresponding to the difficulty level applied during the nonce discovering of this block. It defines the mining Target, which can be calculated from the previous block’s difficulty level and the timestamp. The higher the difficulty, the statistically more calculations a Miner must perform to discover a valid block. This value is used to control the Block generation time of a Blockchain, keeping the Block generation frequency within a target range. On the test network, we keep this value low to avoid waiting during tests, since the discovery of a valid Block is required to execute a transaction on the Blockchain.



alloc Allows defining a list of pre-filled wallets. That’s an Ethereum specific functionality to handle the “Ether pre-sale” period. Since we can mine local Ether quickly, we don’t use this option.



coinbase The 160-bit address to which all rewards (in Ether) collected from the successful mining of this block have been transferred. They are a sum of the mining reward itself and the Contract transaction execution refunds. Often named “beneficiary” in the specifications, sometimes “etherbase” in the online documentation. This can be anything in the Genesis Block since the value is set by the setting of the Miner when a new Block is created.



timestamp A scalar value equal to the reasonable output of Unix time() function at this block inception. This mechanism enforces a homeostasis in terms of the time between blocks. A smaller period between the last two blocks results in an increase in the difficulty level and thus additional computation required to find the next valid block. If the period is too large, the difficulty, and expected time to the next block, is reduced. The timestamp also allows verifying the order of block within the chain (Yellowpaper, 4.3.4. (43)).



parentHash The Keccak 256-bit hash of the entire parent block header (including its nonce and mixhash). Pointer to the parent block, thus effectively building the chain of blocks. In the case of the Genesis block, and only in this case, it’s 0.



extraData An optional free, but max. 32-byte long space to conserve smart things for ethernity. :)



gasLimit A scalar value equal to the current chain-wide limit of Gas expenditure per block. High in our case to avoid being limited by this threshold during tests. Note: this does not indicate that we should not pay attention to the Gas consumption of our Contracts.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;然后我们需要有一个存放区块链数据的文件夹，命名data，文件夹data/与genesis.json最好在一个文件夹下，比如他们都在一个myblockchain/目录下，实际上我的并不在同一个目录，在同一个目录仅仅是方便管理。&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;geth --datadir=/data/ init genesis.json
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;–datadir指定data目录用来储存区块链数据&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;genesis.json就是用来初始化区块链的文件，是init 的参数&lt;/p&gt;

    &lt;p&gt;从geth –help可以看到参数的意义&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;     init                       Bootstrap and initialize a new genesis block    
  --datadir &quot;/root/.ethereum&quot;  Data directory for the databases and keystore 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;​&lt;/p&gt;

&lt;p&gt;geth客户端会根据genesis.json的文件内容，将创世区块写入的我们的区块链中，构建好我们的私有的区块链，当输出如下类似内容时说明创建成功&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/eth-2-1.png&quot; alt=&quot;1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;至此，我们的个人区块链创建成功，之后我们就可以在这条链上发我们自己的token了。&lt;/p&gt;

&lt;p&gt;接下来我们开启我们的区块链网络进行测试&lt;/p&gt;

&lt;h2 id=&quot;启动区块链网络&quot;&gt;启动区块链网络&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;geth --identity &quot;TestNode&quot; --rpc --rpcport &quot;8545&quot; --datadir=/data0/eth-test --port &quot;30303&quot; --nodiscover console
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;节点名字设置成TestNode，允许HTTP-RPC访问，访问端口为8545,监听端口为30303，这样就建立好了一个ethereum的私有节点&lt;/p&gt;

&lt;p&gt;但是新版本的geth默认禁止了HTTP通道解锁账户，需要添加参数–allow-insecure-unlock,变成&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;geth --identity &quot;TestNode&quot; --rpc --allow-insecure-unlock --rpcport &quot;8545&quot; --datadir=/data0/eth-test --port &quot;30303&quot; --nodiscover console
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;输出如下内容&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/eth-2-2.png&quot; alt=&quot;2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;区块链网络启动成功。接下来我们测试启动的节点完成创建帐号，查看帐号，挖矿，转帐，查看余额，查看区块等等操作。&lt;/p&gt;

&lt;h2 id=&quot;创建帐号&quot;&gt;创建帐号&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;personal.newAccount()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;​       终端提示输入密码，比如可以直接输入0等一些好记的密码,这里不需要用复杂的密码。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/eth-2-3.png&quot; alt=&quot;3&quot; /&gt;&lt;/p&gt;

&lt;p&gt;​       返回值可以看到帐号的地址和密钥的储存文件地址，这里请创建多个帐号以备之后的转账操作。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;也可以直接输入&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;personal.newAccount(“***”)  //引号内内容是设置的密码。
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;查看帐号&quot;&gt;查看帐号&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;eth.accounts
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;会输出已创建帐号的地址&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/eth-2-4.png&quot; alt=&quot;4&quot; /&gt;&lt;/p&gt;

&lt;p&gt;​      你可以直接查看文件内容找到账户的地址，使用tree 命令，如果没有请自行安装，&lt;code class=&quot;highlighter-rouge&quot;&gt;sudo apt-get install tree&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/eth-2-5.jpeg&quot; alt=&quot;5&quot; /&gt;&lt;/p&gt;

&lt;p&gt;tree 后面参数是想要查看的文件名字，我们需要查看储存密钥的文件夹，本教程是储存在/data中，你需要在/目录下运行 sudo tree data/ ,输出内容可以看到在keystore下有你创建的所有的账户的密钥和地址。&lt;/p&gt;

&lt;h2 id=&quot;获取账户的信息&quot;&gt;获取账户的信息&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;eth.getBalance(&quot;0x4fcb4d27485ceaa619024090ef50b49d86c2ebf1&quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;引号内内容是想要查看账户的地址，会输出账户的资产数值，也可以设置参数为eth.accounts[ ]，括号内是需要查看的账户的序号，第一个账户序号是0。&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;eth.getBalance(eth.accounts[2])
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;这里的账户资产应该是0。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/eth-2-6.png&quot; alt=&quot;6&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;挖矿&quot;&gt;挖矿&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;miner.start(1)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;​    括号内的参数是线程数，数值越大出块越快，第一次启动挖矿会先生成挖矿所需的DAG文件，这个过程有点慢，需要等一会儿才会开始挖矿。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/eth-2-7.jpeg&quot; alt=&quot;7&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;停止挖矿的命令为&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;miner.stop()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;​    直接在挖矿的同一个终端同时输入命令就好，挖矿不影响命令的执行。挖矿的奖励会直接给到coinbase的地址的账户，默认条件下会给到你的第一个账户。可以运行命令查看你的地一个账户的资产，会发现不再是0.&lt;/p&gt;

&lt;p&gt;​      要想使挖矿奖励进入其他账户，通过&lt;code class=&quot;highlighter-rouge&quot;&gt;miner.setEtherbase()&lt;/code&gt;将其他账户设置成coinbase即可。&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; miner.setEtherbase(eth.accounts[2])
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;​      这里把第三个账户设置成coinbase。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/eth-2-8.png&quot; alt=&quot;8&quot; /&gt;&lt;/p&gt;

&lt;p&gt;查看到coinbase已被修改。再次尝试挖矿，之后查看coinage.账户的资产。&lt;/p&gt;

&lt;h2 id=&quot;发出交易&quot;&gt;发出交易&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[1],value:5})
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;​      命令的意思是从地一个账户发送5 wei的以太币给第二个账户，from是发出交易的地址，to是接受方，value是发送的交易额。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/eth-2-9.png&quot; alt=&quot;9&quot; /&gt;&lt;/p&gt;

&lt;p&gt;​      你会发现报错了，阅读内容是因为需要password或者解锁，我们需要去给发送方的账户解锁。&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;personal.unlockAccount(eth.accounts[3])
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;这里我解锁的是第四个账户，你需要解锁的是第一个账户，这里需要提醒的是大家一定要记住自己设置的密码和密钥，以防丢失。&lt;/p&gt;

&lt;p&gt;解锁成功会返回true&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/eth-2-10.png&quot; alt=&quot;10&quot; /&gt;&lt;/p&gt;

&lt;p&gt;然后就可以转账了&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/eth-2-11.png&quot; alt=&quot;11&quot; /&gt;&lt;/p&gt;

&lt;p&gt;转账成功后查看接收方的账户余额还是0,是没有转账成功吗，不是是因为和没有记录到链上，我们需要挖矿。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/eth-2-12.png&quot; alt=&quot;12&quot; /&gt;&lt;/p&gt;

&lt;p&gt;挖矿只需要出一个块就够了，挖矿后我们发现，接收方账户的资产变成了5,成功收到了转账。&lt;/p&gt;

&lt;p&gt;​      我们已经完成了使用geth客户端搭建地一个节点，并进行了一些链上的简单操作。下一篇我们将在私有节点上部署一个发布ERC20 token的智能合约。&lt;/p&gt;
</description>
        <pubDate>Thu, 01 Jul 2021 00:00:00 -0500</pubDate>
        <link>/2021/07/ETH-develop2/</link>
        <guid isPermaLink="true">/2021/07/ETH-develop2/</guid>
        
        <category>区块链</category>
        
        
      </item>
    
      <item>
        <title>计算机系统的硬件结构</title>
        <description>&lt;h1 id=&quot;计算机系统的硬件结构&quot;&gt;计算机系统的硬件结构&lt;/h1&gt;

&lt;p&gt;计算机硬件部分由运算器、控制器、存储器、输入设备和输出设备五部分组成。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/计算机组成框图.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;系统总线&quot;&gt;系统总线&lt;/h2&gt;

&lt;p&gt;计算机系统的五大部件之间的联系方式包括分散连接和总线连接。&lt;/p&gt;

&lt;h3 id=&quot;总线概念&quot;&gt;总线概念&lt;/h3&gt;

&lt;h4 id=&quot;总线分类&quot;&gt;总线分类&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;片内总线。指芯片内部的总线，寄存器与寄存器之间、寄存器与逻辑部件之间互连的总线&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;系统总线。指 CPU、主存、I/O 设备各大部件之间的信息传输线，按系统总线传输信息的不同，分为数据总线、地址总线和控制总线&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;
        &lt;p&gt;数据总线：用于传输各部件之间的数据信息，它是双向传输总线，其位数称为数据总线宽度，与机器字长、存储字长有关，一般为 8 位、16 位或 32 位。&lt;/p&gt;
      &lt;/li&gt;
      &lt;li&gt;地址总线：用于指出数据总线上的源数据或目的数据在主存单元的地址或 I/O设备的地址，也就是说地址总线上的代码用来指明 CPU 欲访问的存储单元或I/O 端口的地址，由 CPU 输出，单向传输。地址总线的位数与存储单元的个数有关，如地址线为 20 根，则对应的存储单元个数为 2^20^个。&lt;/li&gt;
      &lt;li&gt;控制总线：用于发出各种控制信号，通常对任一控制线而言，它的传输是单向的，如存储器读/写命令都是由 CPU 发出的，但对控制总线总体而言，又可认为是双向的，如当某设备准备就绪时，便可通过控制总线向 CPU 发送中断请、求。常用的控制信号有：时钟、复位、总线请求、总线允许、中断请求、中断响应、主存读/写、I/O 读写和传输响应等。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;通信总线。用于计算机系统之间或计算机系统与其他系统之间的通信。通信总线按数据传输方式可分为串行通信和并行通信。&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;串行通信：指数据在单条 1 位宽的传输线上，一位一位地按顺序分时传送，如 1 字节数据在串行传送中要通过一条传输线分 8 次由低位到高位按顺序逐位传送。&lt;/li&gt;
      &lt;li&gt;并行通信：指数据在多条并行 1 位宽的传输线上，同时由源地址传送到目的地址，如 1 字节的数据在并行传送中要通过 8 条并行传输线同时由源地址传送到目的地址。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;总线指标&quot;&gt;总线指标&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;总线宽度：是指数据总线的根数，用 bit（位）表示，如 8 位（8 根）、16 位（16根）、32 位（32 根）&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;32/64位操作系统指的是计算机地址总线宽度为32/64，32/64根地址总线，处理器指数据总线&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;总线带宽：总线的数据传输速率，即单位时间内总线上传输数据的位数，通常用每秒传输信息的字节数来衡量，单位可用 MB/s（兆字节每秒）表示，总线带宽=总线工作频率×(总线宽度/8) Byte/s&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;总线工作频率：总线工作频率=1/总线周期,指一秒钟内传输几次数据&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;总线周期：指一次总线操作所需的时间（包括申请阶段、寻址阶段、传送阶段和结束阶段），若干个总线时钟周期构成&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;总线时钟频率：指机器的时钟频率，总线时钟频率=1/总线时钟周期&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;单总线结构&quot;&gt;单总线结构&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;CPU、主存、I/O 设备（通过 I/O 接口）挂到一组总线上&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;单总线结构中设备的寻址采用统一编址的方法，即所有的主存单元以及 I/O 设备接口寄存器的地址一起构成一个统一的地址空间&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;小型机和微型机采用。&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/单总线.png&quot; alt=&quot;单总线&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;双总线结构&quot;&gt;双总线结构&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;面向CPU的双总线，一条是主存总线，用于CPU、主存和通道之间进行数据传送；另一条是 I/O 总线，用于多个 I/O 设备与通道之间进行数据传送。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;在双总线系统中采用单独编址的方法，CPU 对内存总线和系统总线必须有不同的指令系统，内存地址和 I/O 设备的地址是分开的，当访问内存时，由存储读、存储写两条控制线来控制；当访问 I/O 设备时，由 I/O 读、I/O写两条控制线来控制。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;将速度较低的 I/O 设备从单总线上分离出来，形成存储器总线和 I/O 总线分开的结构。适合大、中型计算机。&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/双总线.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;通道是一种具有特殊功能的处理器，CPU可以将原来的一部分功能（和I/O设备之间的通信功能）下放给通道，提高效率&lt;/p&gt;

&lt;h4 id=&quot;三总线结构&quot;&gt;三总线结构&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;三总线结构是在计算机系统各部件之间采用三条各自独立的总线来构成信息通路。这三条总线是：主存总线、I/O 总线和直接内存访问（DMA）总线&lt;/li&gt;
  &lt;li&gt;主存总线用于 CPU 和内存之间传送地址、数据和控制信息，是 CPU、内存和通道进行数据传送的公共通路；I/O 总线用于 CPU 和各类外设之间通信，是多个外部设备与通道之间进行数据传送的公共通路；DMA 总线用于内存和高速外设之间直接传送数据，DMA 方式中 I/O设备与存储器直接交换数据而不经过 CPU（在三总线结构中，任意时刻只能使用一种线）&lt;/li&gt;
  &lt;li&gt;三总线系统通常用于中、大型计算机，&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/三总线.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;三总线第二种，处理器和cache之间的局部总线将CPU和cache或其他局部设备连接，I/O设备与主存的传输不通过CPU，同时cache连接到系统总线和主存传输信息，系统总线又通过扩展总线接口连接到扩展总线之间与各类I/O设备直接传递信息。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/三总线2.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;四总线结构&quot;&gt;四总线结构&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;增加了一条与计算机系统紧密相连的高速总线。在高速总线上挂接了一些高速I/O设备&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/四总线.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;pci总线&quot;&gt;PCI总线&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;PCI总线通过PCI桥（PCI控制器和PCI加速器）与系统总线相连，使得PCI总线和CPU系统总线隔离，具有更高的灵活性，告诉I/O设备直接连接在PCI总线，标准总线控制器连接ISA和EISA总线连接低速I/O。&lt;/li&gt;
  &lt;li&gt;现代计算机总线结构，PCI总线和设备树是X86硬件体系内重要的组成部分&lt;/li&gt;
  &lt;li&gt;PCI结构比较复杂，Intel在2004开始提出PCIe总线体系，现在已经到了PCIe5.0&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/PCI.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/PCI线.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;更详细的PCI架构：&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/PCI拓扑.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;PCI 总线主要被分成三部分：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;PCI 设备。符合 PCI 总线标准的设备就被称为 PCI 设备，PCI 总线架构中可以包含多个 PCI 设备。PCI 设备同时也分为主设备和目标设备两种，主设备是一次访问操作的发起者，而目标设备则是被访问者。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;PCI 总线。PCI 总线在系统中可以有多条，类似于树状结构进行扩展，每条 PCI 总线都可以连接多个 PCI 设备/桥。可以有多条PCI总线&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;PCI 桥。当一条 PCI 总线的承载量不够时，可以用新的 PCI 总线进行扩展，而 PCI 桥则是连接 PCI 总线之间的纽带。&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h5 id=&quot;pcie&quot;&gt;PCIe&lt;/h5&gt;

&lt;p&gt;&lt;strong&gt;PCI是总线结构，而PCIe是点对点结构&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/pcie.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://blog.csdn.net/fivedoumi/article/details/50209163&quot;&gt;PCIE各类总线介绍&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;总线控制&quot;&gt;总线控制&lt;/h3&gt;

&lt;h4 id=&quot;总线判优控制&quot;&gt;总线判优控制&lt;/h4&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;链式查询&lt;/p&gt;

    &lt;p&gt;用3条控制线进行控制:BS(总线忙); BR(总线讲求); BG(总线允许).&lt;/p&gt;

    &lt;p&gt;BG总线允许信号串行的从第一个IO开始传递直到有接口有总线请求，给设备获得总线使用权，并建立总线忙BS信号表示占用总线。离控制部件越近优先级越高&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;计数器定时查询&lt;/p&gt;

    &lt;p&gt;总线上的任一设备要求使用总线时,通过BR线发出总线请求.中央仲裁器接到请求信号以后,在BS线为”0”(未被使用）、的情况下让计数器开始计数,计数值通过一组地址线发向各设备.每个设备接口都有一个设备地址判别电路,当地址线上的计数值与请求总线的设备地址相一致时,该设备 置”1”BS线,获得了总线使用权,此时中止计数查询&lt;/p&gt;

    &lt;p&gt;多一组地址线，少一根BG线&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;独立请求方式&lt;/p&gt;

    &lt;p&gt;每个设备有一堆总线请求先BR和允许线BG，在总线控制部件内决定使用权&lt;/p&gt;

    &lt;p&gt;&lt;img src=&quot;/images/posts/总线判优.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;总线通信控制&quot;&gt;总线通信控制&lt;/h4&gt;

&lt;p&gt;完成一次总线操作（总线周期）的分四个阶段：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;申请分配阶段：主模块申请占用总线的请求，总线运用判优控制仲裁决定&lt;/li&gt;
  &lt;li&gt;寻址阶段：主模块向从模块给出地址和命令&lt;/li&gt;
  &lt;li&gt;传数阶段：主模块和从模块交换数据&lt;/li&gt;
  &lt;li&gt;结束阶段：主模块撤销有关消息&lt;/li&gt;
&lt;/ol&gt;

&lt;h5 id=&quot;同步通信&quot;&gt;同步通信&lt;/h5&gt;

&lt;p&gt;统一时标控制数据传送  clk&lt;/p&gt;

&lt;h5 id=&quot;异步通信&quot;&gt;异步通信&lt;/h5&gt;

&lt;p&gt;不要统一工作时间，采用应答方式（握手），主模块发送请求信号等等返回响应信号才开始通信。&lt;/p&gt;

&lt;p&gt;不互锁、半互锁、全互锁&lt;/p&gt;

&lt;p&gt;0 1  0 就是低电压 010&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/锁.png&quot; alt=&quot;	   &quot; /&gt;&lt;/p&gt;

&lt;p&gt;不互锁：&lt;/p&gt;

&lt;p&gt;主设备发出请求信号，从设备发出应答信号，经过一定的延时，主设备不管有没有收到从设备的应答信号都会撤销请求信号，从设备也如此，不管主设备有没有收到应答信号，经过一定的延时以后，会自动撤销应答信号。&lt;/p&gt;

&lt;p&gt;半互锁：&lt;/p&gt;

&lt;p&gt;主设备发出请求信号以后，从设备接受到请求信号，发出应答信号，主设备唯有接受到从设备发出的应答信号后才会撤销请求信号，但是从设备不管主设备有没有接受到应答信号，经过一定的延时，都会撤销应答信号，这就可能造成主设备一直没有接受到应答信号导致主设备发出的请求信号一直处于高电平状态。&lt;/p&gt;

&lt;p&gt;全互锁：&lt;/p&gt;

&lt;p&gt;全互锁解决了半互锁存在的问题，当主设备向从设备发出请求信号以后，从设备接收到请求信号之后将发出应答信号直到主设备接收到来自从设备的应答信号才撤销请求信号，主设备撤销请求应答信号之后，从设备才会撤销应答信号，这就避免了可能导致主设备发出的请求信号一直处于高电平的状态。&lt;/p&gt;

&lt;h5 id=&quot;半同步通信&quot;&gt;半同步通信&lt;/h5&gt;

&lt;p&gt;保留同步通信的所有地址、命令、数据信号的发出时间参照系统的时钟信号的某个前沿，而接收方按照同一系统时钟信号的后沿来进行判断识别，同时允许不同速度的模块和谐工作，增设wait响应信号线，通过插入时钟周期来协调通信双方的配合&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;分离式通信–其基本思想是将一个传输周期（或总线周期）分解为两个子周期。在第一个子周期中，主模块 A 在获得总线使用权后将命令、地址以及其他有关信息，包括主模块编号（当有多个主模块时，此编号尤为重要）发到系统总线上，经过总线传输后，由有关的从模块 B 接收下来。主模块 A 向系统总线发布这些信息只占用总线很短的时间，一旦发送完成，立即放弃总线使用权，以便其他模块使用。在第二个子周期中，当 B 模块接收到 A 模块发来的有关命令信号后，经过选择、译码、读取等一系列内部操作，将 A 模块所需的数据准备好，便由 B 模块申请总线使用权，一旦获准，B 模块便将 A 模块的编号、B 模块的地址、A 模块所需的数据等一系列信息送到总线上，供 A 模块接收。很显然，上述两个子周期都只有单方向的信息流，每个模块都变成了主模块。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;存储器&quot;&gt;存储器&lt;/h2&gt;

&lt;p&gt;存储器是计算机系统中的记忆设备，用来存放程序和数据。&lt;/p&gt;

&lt;h3 id=&quot;存储器的分类&quot;&gt;存储器的分类&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;按存储介质分类&lt;/p&gt;

    &lt;p&gt;存储介质是指能寄存“0”、“1”两种代码并能区别两种状态的物质或元器件。存储介质主要有半导体器件、磁性材料和光盘等。&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;（1）半导体存储器
存储元件由半导体组成的存储器称为半导体存储器，断电信息丢失的易失性存储器
半导体存储器又可按材料的不同分为两类&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;双极型（TTL）半导体存储器&lt;/li&gt;
  &lt;li&gt;MOS半导体存储器&lt;/li&gt;
  &lt;li&gt;CPU内的寄存器&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;（2）磁表面存储器
磁表面存储器是在金属或塑料基体的表面上涂一层磁性材料作为记录介质，工作时磁层随载磁铁高速运转，用磁头在磁层上进行读/写操作，故称为磁表面存储器。按载磁体形状的不同，可分为磁盘、磁带和磁鼓。
这类存储器具有非易失性的特点&lt;/p&gt;

&lt;p&gt;（3）磁芯存储器
磁芯是由硬磁材料做成的环状元件，在磁芯中穿有驱动线和读出线，这样便可进行读写操作。它是不易失的永久记忆存储器。
（4）光盘存储器
应用激光在记录介质（磁光材料）上进行读/写的存储器，具有非易失性的特点。&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;按存取方式分类
（1）随机存储器（Random Access Memory, RAM）
RAM是一种可读/写存储器，其特点是存储器的任何一个存储单元的内容都可以随机存取，而且存取时间与存储单元的物理位置无关。计算机系统中的主存都采用这种随机存储器。由于存储信息原理的不同，RAM又可分为&lt;strong&gt;静态SRAM（以触发器原理寄存信息）&lt;/strong&gt;和&lt;strong&gt;动态DRAM（以电容充放电原理寄存信息）&lt;/strong&gt;
（2）只读存储器（Read Only Memory, ROM）
只读存储器是能对其存储的内容读出，而不能对器重新写入的存储器。这种存储器一旦存入了原始信息后，在程序执行过程中，只能将内部信息读出，而不能随意重新写入新的信息去改变原始信息。
（3）串行访问存储器
如果对存储单元进行读/写操作时，需按其物理位置的先后顺序寻找地址，则这种存储器称为串行访问存储器&lt;/li&gt;
  &lt;li&gt;按在计算机中的作用分类
（1）主存储器：在计算机内，最大的储存数据的存储器
（2）辅助存储器：主存储器的后援存储器，用来存放当前暂时不用的程序和数据。
（3）缓冲存储器：可以和CPU直接交换信息，连接CPU和主存&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/存储分类.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;主存&quot;&gt;主存&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/存储系统.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;主存包括存储体M、逻辑单元和控制电路&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;MAR寄存器是储存器地址寄存器,存放欲访问的储存单元的地址&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;MDR储存器数据寄存器，存放从储存器取出的数据代码或需要存入储存单元的代码。&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;根据MAR中的地址访问某个存储单元时，需要经过地址译码、驱动，到访问单元。驱动器、译码器、读写电路制作在存储芯片，MAR和MDR在CPU芯片。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/主存.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;MIPS mips的 lw $s0,8($0) 命令。
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;存储芯片&quot;&gt;存储芯片&lt;/h3&gt;

&lt;h4 id=&quot;寄存器&quot;&gt;寄存器&lt;/h4&gt;

&lt;h5 id=&quot;flip-flop&quot;&gt;Flip-Flop&lt;/h5&gt;

&lt;p&gt;D触发器&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/500px-D-Type_Transparent_Latch.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/d_latch.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;当Enable输入为0状态存储，1时修改&lt;/p&gt;

&lt;h5 id=&quot;latch&quot;&gt;Latch&lt;/h5&gt;

&lt;p&gt;锁存器&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/R-S_mk2.gif&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/nand_latch.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;S R同时为0时存储，0 1 reset，1 0 写入&lt;/p&gt;

&lt;h4 id=&quot;rom&quot;&gt;ROM&lt;/h4&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/rom.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;dram&quot;&gt;DRAM&lt;/h4&gt;

&lt;p&gt;DRAM通常以一个电容和一个晶体管为一个单元排成二维矩阵。基本的操作机制分为读(Read)和写(Write)，读的时候先让Bitline(BL)先充电到操作电压的一半，然后在把晶体管打开让BL和电容产生电荷共享的现象，若内部存储的值为1，则BL的电压会被电荷共享抬高到高于操作电压的一半，反之，若内部存储的值为0，则会把BL的电压拉低到低于操作电压的一半，得到了BL的电压后，在经过放大器来判别出内部的值为0和1。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/dram.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;sram&quot;&gt;SRAM&lt;/h4&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/WechatIMG4613.png&quot; alt=&quot;image-20200509120652216&quot; /&gt;&lt;/p&gt;

&lt;p&gt;SRAM的速度相对照较快。并且省电。&lt;/p&gt;

&lt;h4 id=&quot;存储矩阵&quot;&gt;存储矩阵&lt;/h4&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/存储矩阵.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/DRAM 矩阵.jpeg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;io&quot;&gt;IO&lt;/h2&gt;

&lt;p&gt;计算机的输入输出系统与IO软件和硬件组成，IO软件主要任务是将用户编制的程序或数据输入主机、返回运算结果到用户、协调输入输出系统与CPU工作的协调，一般通过指令系统的IO指令和系统软件的管理程序协调。&lt;/p&gt;

&lt;h3 id=&quot;io软件&quot;&gt;IO软件&lt;/h3&gt;

&lt;p&gt;控制IO硬件，IO软件的指令包括分成I/O指令和通道指令&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;I/O指令： I/O指令实际上是CPU指令的一部分，基本格式是这样的：【操作码&lt;/td&gt;
          &lt;td&gt;命令码&lt;/td&gt;
          &lt;td&gt;设备码】。操作码是一种控制指令，如访存、算数逻辑运算等，命令码是执行具体的指令，比如说算数逻辑运算中的加减乘除，而设备码就是外围设备在I/O系统中的编号。通过I/O指令，就能够实现对I/O设备的基本控制。&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/li&gt;
  &lt;li&gt;通道指令： IO设备太多会给CPU带来负担于是就有了通道作为借口连接在IO总线和IO设备之间起桥梁的作用，可以缓冲数据和处理中断使得设备可以分时占用CPU。通道指令是在通道内用于执行IO指令的指令，比如控制磁盘、控制IO的工作状态等等&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;io硬件&quot;&gt;I/O硬件&lt;/h3&gt;

&lt;p&gt;I/O硬件基本包括接口和I/O设备两个部分&lt;/p&gt;

&lt;h3 id=&quot;io系统与主机的信息传输方式&quot;&gt;I/O系统与主机的信息传输方式&lt;/h3&gt;

&lt;p&gt;主要有五种，轮询‘程序控制、中断、DMA直接内存存取、通道。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;轮询&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;早期的传输方式，不断询问IO设备有无处理要求&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;通道&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;输入/输出通道控制是专门管理IO的处理机，独立于CPU，是一种以内存为中心，实现设备和内存直接交换数据的控制方式。在通道方式中，数据的传送方向、存放数据的内存起始地址以及传送的数据块长度等都由通道来进行控制。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;程序查询方式&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;
        &lt;p&gt;程序控制方式是指在程序控制下进行信息传送的方式。如果能够确信一个IO设备已经准备就绪，那就不必查询设备的状态而可直接进行信息传输。在条件传送方式下，程序会判断IO设备是否准备就绪， CPU通过执行程序不断读取并检查设备的状态，如果设备处于准备好状态或者空闲状态，则CPU执行输入/输出指令与外设交换信息&lt;/p&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;p&gt;通常使用三条指令，测试指令：查询IO设备是否准备好，传送指令：IO设备准备就绪时只需传送指令，转移指令：未准备就绪就执行转移指令，转移到测试指令继续测试&lt;/p&gt;

        &lt;p&gt;&lt;img src=&quot;/images/posts/程序查询方式.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;中断方式&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;
        &lt;p&gt;处理器的高速和输入输出设备的低速是一对矛盾。中断方式下的IO设备之间的数据的传输步骤：&lt;/p&gt;

        &lt;ol&gt;
          &lt;li&gt;在某个进程需要数据时，发出指令启动输入输出设备准备数据&lt;/li&gt;
          &lt;li&gt;在进程发出指令启动设备之后，该进程放弃处理器，等待相关I/O操作完成。此时，进程调度程序会调度其他就绪进程使用处理器。&lt;/li&gt;
          &lt;li&gt;当I/O操作完成时，输入输出设备控制器通过中断请求线向处理器发出中断信号，处理器收到中断信号之后，转向预先设计好的中断处理程序，对数据传送工作进行相应的处理。&lt;/li&gt;
          &lt;li&gt;得到了数据的进程，转入就绪状态。在随后的某个时刻，进程调度程序会选中该进程继续工作。&lt;/li&gt;
        &lt;/ol&gt;

        &lt;p&gt;&lt;img src=&quot;/iages/中断方式.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;DMA直接内存存取&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;直接内存存取技术是指，数据在内存与I/O设备间直接进行成块传输。&lt;/li&gt;
      &lt;li&gt;直接传送：内存与IO设备间传送一个数据块的过程中，不需要CPU的任何中间干涉，只需要CPU开始时发出传送数据的指令，之后的操作通过中断来控制，通过中断来得知过程是否结束和下次操作是否准备就绪&lt;/li&gt;
      &lt;li&gt;DMA工作过程
        &lt;ol&gt;
          &lt;li&gt;当进程要求设备输入数据时，CPU把准备存放输入数据的内存起始地址以及要传送的字节数分别送入DMA控制器中的内存地址寄存器和传送字节计数器。&lt;/li&gt;
          &lt;li&gt;发出数据传输要求，内存进入等待状态。此时正在执行的CPU指令被暂时挂起。进程调度程序调度其他进程占据CPU。&lt;/li&gt;
          &lt;li&gt;输入设备不断地窃取CPU工作周期，将数据缓冲寄存器中的数据源源不断地写入内存，直到所要求的字节全部传送完毕。&lt;/li&gt;
          &lt;li&gt;DMA控制器在传送完所有字节时，通过中断请求线发出中断信号。CPU在接收到中断信号后，转入中断处理程序进行后续处理。&lt;/li&gt;
          &lt;li&gt;中断处理结束后，CPU返回到被中断的进程中，或切换到新的进程上下文环境中，继续执行。&lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

</description>
        <pubDate>Sat, 26 Jun 2021 00:00:00 -0500</pubDate>
        <link>/2021/06/blog_-architecture/</link>
        <guid isPermaLink="true">/2021/06/blog_-architecture/</guid>
        
        <category>计算机基础</category>
        
        
      </item>
    
      <item>
        <title>CSS-in-JS</title>
        <description>&lt;h1 id=&quot;css-in-js&quot;&gt;CSS-in-JS&lt;/h1&gt;

&lt;p&gt;[toc]&lt;/p&gt;

&lt;p&gt;CSS-in-JS是组织CSS代码的方式，代表库有styled-component和emotion&lt;/p&gt;

&lt;h2 id=&quot;传统css的缺陷&quot;&gt;传统CSS的缺陷&lt;/h2&gt;

&lt;h3 id=&quot;1-缺乏模块组织&quot;&gt;1. 缺乏模块组织&lt;/h3&gt;

&lt;p&gt;传统的JS和CSS都没有模块的概念，后来在JS界陆续有了 CommonJS 和 ECMAScript Module，CSS-in-JS可以用模块化的方式组织CSS，依托于JS的模块化方案，比如：&lt;/p&gt;

&lt;div class=&quot;language-jsx highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// button1.ts&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;styled&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'@emotion/styled'&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Button&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;styled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`
  color: turquoise;
`&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// button2.ts&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;styled&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'@emotion/styled'&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Button&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;styled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`
  font-size: 16px;
`&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;两个文件的两个同名元素的&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;CSS&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;不会互相影响&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;2-缺乏作用域&quot;&gt;2. 缺乏作用域&lt;/h3&gt;

&lt;p&gt;传统的CSS只有一个全局作用域，比如说一个class可以匹配全局的任意元素。随着项目成长，CSS会变得越来越难以组织，最终导致失控。CSS-in-JS可以通过生成独特的选择符，来实现作用域的效果&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F0f62fac7-c078-439a-964f-17bbfa478c0d%2FUntitled.png?table=block&amp;amp;id=5a6d3457-f37c-4f89-a8c9-d6a1545dee1e&amp;amp;spaceId=fc9b5453-3a66-40ed-807b-b878e6df58c4&amp;amp;width=1140&amp;amp;userId=&amp;amp;cache=v2&quot; alt=&quot;img&quot; /&gt;&lt;/p&gt;

&lt;div class=&quot;language-jsx highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;css&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;styleBlock&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;className&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Hash&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;styleBlock&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;styleEl&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'style'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;styleEl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;textContent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;`
    .&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; {
      &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;styleBlock&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;
    }
  `&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;styleEl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;className&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;css&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`
  color: red;
  padding: 20px;
`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 'c23j4'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;3-隐式依赖让样式难以追踪&quot;&gt;3. 隐式依赖，让样式难以追踪&lt;/h3&gt;

&lt;p&gt;比如这个CSS样式：&lt;/p&gt;

&lt;div class=&quot;language-css highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nc&quot;&gt;.target&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;.name&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;h1&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nl&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;red&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nt&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;#container&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;h1&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nl&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;green&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;!doctype html&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;html&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;lang=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;en&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'container'&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'target'&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
     &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'name'&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
       &lt;span class=&quot;nt&quot;&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;颜色？&lt;span class=&quot;nt&quot;&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
     &lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;比较麻烦判断h1元素最终显式为什么颜色，DOM树越复杂越难追踪&lt;/p&gt;

&lt;p&gt;而CSS-in-JS的方案就简单直接、易于追踪&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;export const Title = styled.h1`
  color: green;
`
&lt;span class=&quot;nt&quot;&gt;&amp;lt;Title&amp;gt;&lt;/span&gt;
  颜色？
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/Title&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;4-没有变量&quot;&gt;4. 没有变量&lt;/h3&gt;

&lt;p&gt;传统的CSS规则里没有变量，但是在 CSS-in-JS 中可以方便地控制变量&lt;/p&gt;

&lt;div class=&quot;language-css highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;Container&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;styled&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;.div&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;props&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nl&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;'flex'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;flexDirection&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;props&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;column&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;'column'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;//&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;加入条件判断或变量计算&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;5-css选择器与html元素耦合&quot;&gt;5. CSS选择器与HTML元素耦合&lt;/h3&gt;

&lt;div class=&quot;language-css highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nc&quot;&gt;.target&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;.name&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;h1&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nl&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;red&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nt&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;#container&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;h1&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nl&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;green&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;!doctype html&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;html&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;lang=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;en&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'container'&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'target'&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
     &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'name'&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
       &lt;span class=&quot;nt&quot;&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;我是啥颜色？&lt;span class=&quot;nt&quot;&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
     &lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;如果想把 &lt;code class=&quot;highlighter-rouge&quot;&gt;h1&lt;/code&gt; 改成&lt;code class=&quot;highlighter-rouge&quot;&gt;h2&lt;/code&gt;，必须要同时改动 CSS 和 HTML。而在CSS-in-JS中，HTML和CSS是结合在一起的，易于修改&lt;/p&gt;

&lt;h2 id=&quot;emotion-介绍&quot;&gt;Emotion 介绍&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;library： https://github.com/emotion-js/emotion&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;docs： https://emotion.sh/docs/introduction&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;emotion是一个JavaScript库，使用emotion可以用写js的方式写css代码。在react中安装emotion后，可以很方便进行css的封装，复用。使用emotion后，浏览器渲染出来的标签是会加上一个css开头的标识。&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/** @jsx jsx */
import { jsx } from '@emotion/react'

render(
  &amp;lt;div
    css={
      backgroundColor: 'hotpink',
       '&amp;amp;:hover': {
        color: 'lightgreen'
      }
    }
  &amp;gt;
    This has a hotpink background.
  &amp;lt;/div&amp;gt;
)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;这种写法比起React自带的style的写法功能更强大，比如可以处理级联、伪类等style处理的不了的情况&lt;/p&gt;

&lt;div class=&quot;language-css highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;span&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;keyword&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;span&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;jss&quot;&gt;JSS&lt;/h2&gt;

&lt;p&gt;https://cssinjs.org/?v=v10.6.0&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;阮一峰
https://www.ruanyifeng.com/blog/2017/04/css_in_js.html
https://polished.js.org/&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Tue, 22 Jun 2021 00:00:00 -0500</pubDate>
        <link>/2021/06/blog_CSS-in-JS/</link>
        <guid isPermaLink="true">/2021/06/blog_CSS-in-JS/</guid>
        
        <category>语言学习</category>
        
        
      </item>
    
  </channel>
</rss>
