作者:穿靴子的猫 | 来源:互联网 | 2023-08-27 18:04
Diffie-Hellman 部分我们必须证明我们仍然持有一个秘密 ( 私有 ) 密钥,这是一个非常典型的情况。那我们怎么把 Victor 和 Peggy 绑定到一个证明基础设施中让 Peggy 向
![](https://img.php1.cn/3cd4a/1eebe/cd5/2d903861d5ad779c.png?x-oss-process=style/scale70)
![](https://img.php1.cn/3cd4a/94ce/a6e/865776f6fe3d5f59.jpeg?x-oss-process=style/scale70)
Diffie-Hellman 部分
我们必须证明我们仍然持有一个秘密 ( 私有 ) 密钥,这是一个非常典型的情况。那我们怎么把 Victor 和 Peggy 绑定到一个证明基础设施中让 Peggy 向 Victor 证明她还持有一把私钥呢?为此,我们将通过交换 Diffie-Hellman 密钥来绑定 Victor 和 Peggy。
在 DDH 中,我们有一个由 ⟨ g、g^a、g^b、g^{ab }⟩ 组成的元组,其中 a 和 b 是秘密。g^a 和 g^b 的值在双方交换后,应该都能生成 g^{ab}:
![](https://img.php1.cn/3cd4a/1eebe/cd5/fb32005f2115b419.webp?x-oss-process=style/scale70)
Chaum-Pedersen 部分
如果 Peggy 是证明者,而 Victor 是验证者,那么 Peggy 需要表明她知道一个秘密值 a。有了 Chaum-Pedersen ZKP,Victor 让 Peggy 生成一个 ZKP 来保护一个秘密。在这个过程中,她将 g^a (mod p) 的值发送给 Victor,当 Victor 需要证明她仍然知道一个值时,他将发送一个挑战值 (s),然后 Alice 生成一个随机值 (r),并返回 y_1=g^r 和 y_2=B^r。然后 Victor 检查 gz=A^s y_1 (mod p) 和 B^z=C^s y_2 (mod p) 是否相等。
![](https://img.php1.cn/3cd4a/94ce/a6e/865776f6fe3d5f59.jpeg?x-oss-process=style/scale70)
在 Victor 和 Peggy 交换他们的秘密后,Victor 将持有 g^a (mod p), Peggy 将持有 g^b(mod p)。对于零知识证明,我们这样开始:
![](https://img.php1.cn/3cd4a/1eebe/cd5/b428d8f746fb8d47.webp?x-oss-process=style/scale70)
Peggy 有一个秘密值a并生成A = g^a。Victor 的秘密值为b并生成B = g^b。他们交换A和B,然后使用 Diffie Hellman 方法生成C。
Victor 向 Peggy 发送一个 commitment:
![](https://img.php1.cn/3cd4a/1eebe/cd5/5287a7b3296ea13e.webp?x-oss-process=style/scale70)
Peggy 计算出一个随机值 (r):
![](https://img.php1.cn/3cd4a/189d8/978/7dbdf0f38ad53545.jpeg?x-oss-process=style/scale70)
她发给 Victor:
![](https://img.php1.cn/3cd4a/1eebe/cd5/60405fda58cd0acd.webp?x-oss-process=style/scale70)
和:
![](https://img.php1.cn/3cd4a/1eebe/cd5/21e585a7e21fc7dc.png?x-oss-process=style/scale70)
Peggy 还发送:
![](https://img.php1.cn/3cd4a/1eebe/cd5/d05d9dfd09a56332.webp?x-oss-process=style/scale70)
Victor 会检查:
![](https://img.php1.cn/3cd4a/1eebe/cd5/857a46d091981bac.webp?x-oss-process=style/scale70)
和:
![](https://img.php1.cn/3cd4a/1eebe/cd5/5b97d3b808d031e2.webp?x-oss-process=style/scale70)
如果这些都是真的,那么 Peggy 已经证明她知道这个秘密 (a)。因为:
![](https://img.php1.cn/3cd4a/9b0d/ae9/2d998ad7838fbf16.jpeg?x-oss-process=style/scale70)
代码
代码如下所示:
import random
import libnum
import sys
bitsize=128
if (len(sys.argv)>1):
bitsize=int(sys.argv[1])
p=libnum.generate_prime(bitsize)
s=random.getrandbits(bitsize)
g=2
a=random.getrandbits(bitsize)
b=random.getrandbits(bitsize)
c=random.getrandbits(bitsize)
r=random.getrandbits(bitsize)
A=pow(g,a,p)
B=pow(g,b,p)
C=pow(g,a*b,p)
y1=pow(g,r,p)
y2=pow(B,r,p)
z=(r+a*s) % (p-1)
print("== Chaum-Pederson ZKP with DDH ==")
print("p=",p)
print("a=",a)
print("A=g^a (mod p)=",A)
print("b=",b)
print("B=g^a (mod p)=",B)
print("ab=",a*b)
print("C=g^{ab} (mod p)=",C)
print("\nProof: g^z = A^s y1")
val1= pow(g,z,p)
val2=(pow(A,s,p)*y1) % p
print("Val1=",val1)
print("Val2=",val2)
if (val1==val2):
print("- Proof verified")
print("\nProof: B^z = C^s y2")
val3= pow(B,z,p)
val4=(pow(C,s,p)*y2) % p
print("Val3=",val3)
print("Val4=",val4)
if (val3==val4):
print("- Proof verified")
256 位素数的运行示例如下:
== Chaum-Pederson ZKP ==
p= 71808837207067558396943502247178805470599306337269585872075038503116361400603
a= 36623398984913964172485596625205226031763309121917034188846578869320021978402
A=g^a= 32096207796582799691444233880948982714496908564580085529419678203181985482397
b= 31626404664308059618102781249870451013488637545242770934698960204990436278054
B=g^a= 22868249499514124460303251323889043821880224466294750444534923941031732565838
ab= 1158266436479298052448345755868228483694002563526288816181771624565721107667448582344993414115064433575649547672009235534272667805336831732117954454589708
C=g^{ab}= 8021151953795073005899136029637476282156155200732630284950825682466003109726
Proof: g^z = A^s y1
Val1= 9590670516289397297344719778854690756344241363231213529959870845950311348445
Val2= 9590670516289397297344719778854690756344241363231213529959870845950311348445
- Proof verified
Proof: B^z = C^s y2
Val3= 56336209634019548929170814618015392124101293159018455662661735618180853220223
Val4= 56336209634019548929170814618015392124101293159018455662661735618180853220223
- Proof verified
结论
网络安全的唯一方向是零信任模式。阻止敏感信息数据泄露的一种方法不是储存这些秘密,而是用随机的预言机代替它们。即便这些预言机被泄漏,真正的秘密也不会被泄漏。在我概述的方法中,我们可以通过散列使用证明的生成值轻松地将其转换为 NI-ZKP(非交互式 ZKP)。
Source:https://medium.com/asecuritysite-when-bob-met-alice/hellman-pedersen-and-chaum-zkps-with-the-decisional-diffie-hellman-ddh-assumption-4ed7d4a3220d
关于
ChinaDeFi - ChinaDeFi.com 是一个研究驱动的 DeFi 创新组织,同时我们也是区块链开发团队。每天从全球超过 500 个优质信息源的近 900 篇内容中,寻找思考更具深度、梳理更为系统的内容,以最快的速度同步到中国市场提供决策辅助材料。
Layer 2 道友 - 欢迎对 Layer 2 感兴趣的区块链技术爱好者、研究分析人与 Gavin(微信: chinadefi)联系,共同探讨 Layer 2 带来的落地机遇。敬请关注我们的微信公众号 “去中心化金融社区”。
![](https://img.php1.cn/3cd4a/1eebe/cd5/e62700fe09f8933e.webp?x-oss-process=style/scale70)