【以太坊源码阅读】椭圆曲线加密和EIP155

1、以太坊椭圆曲线加密r,s,v

https://crypto.stackexchange.com/questions/59506/ecdsa-recover-on-arbitrary-values

https://crypto.stackexchange.com/questions/18105/how-does-recovering-the-public-key-from-an-ecdsa-signature-work/18106

在以太坊加密中,通过r,s能够恢复出两种可能性的公钥地址,分别为

  R,G,z为固定参数

因此需要通过v(奇偶校验位)还原出特定的公钥地址。

如果固定v,只通过r,s只有50%可能性还原出正确的公钥地址。

2、EIP155

https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md

不同的共有链定义不同的chainId, 防止同一笔交易在不同的共有链上进行两次交易,防止重放攻击

v = 35 + chainId *2 | v = 36 + chainId * 2

不同的chainId会得到不同的v,还原出来的公钥也会不同

因为只通过r,s恢复公钥有两种可能,所以每个chainId也该拥有两个不同的v,代表两个不同的地址

参考资料:

wiki百科椭圆曲线加密

https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm

国外密码学论坛

https://crypto.stackexchange.com/

猜你喜欢

转载自blog.csdn.net/tianlongtc/article/details/81140549
今日推荐