ECDSA,全称为Elliptic curve Digital Signature Algorithm,采用Elliptic curve cryptography来实现的数字签名算法。
目前Bitcoin采用的是ECDSA签名方案。
公私钥对 ( p k , P ) (pk,P) (pk,P),其中公钥 P = p k × G P=pk\times G P=pk×G, G G G为所选椭圆曲线的base point。(elliptic curve base point: a point on the curve that generates a subgroup of large prime order n n n。 n × G = O n\times G=\mathcal{O} n×G=O, O \mathcal{O} O is the identity element。)
ECDSA对消息 m m m的签名流程为:
hash
函数可为SHA-2,输出转换为数值。)整个ECDSA签名流程中,要求:
对收到的签名 ( r , s ) (r,s) (r,s),采用公钥 P P P进行验签的流程为:
hash
函数应与签名时一致。 e = h a s h ( m ) e=hash(m) e=hash(m)。注意,以上ECDSA验签算法可做如下改进:
ECDSA也支持public key recovery算法,前提是提前知道签名方的公钥或者公钥hash值,否则有可能恢复出错误的公钥信息。
Bitcoin中采用ECDSA的弊端主要有:
1)ECDSA的验签过程中,需要进行求倒数和scalar multiplication运算,这些运算操作都是computationally heavy的。
在Bitcoin中,每个节点都需要验证所有的交易,当你广播一条交易时,数以千记的计算机都需要验证你的签名。因此,Making verification process simpler will be very beneficial even if signing process is harder。
2)每个节点需要分别验证每个签名。对于m-of-n multisig transaction,节点甚至需要对同一签名进行多次验证。如具有7-of-11 multisig input的transaction,将包含7个签名,同时需要网络中的每个节点验证7到11个签名信息。同时,这样的transaction将占据区块中大量的空间,需要pay larger fees for that。
观察ECDSA的签名 ( r , s = ( z + r ⋅ p k ) / k m o d n ) (r,s=(z+r\cdot pk)/k \mod n) (r,s=(z+r⋅pk)/kmodn)(其中 z = h a s h ( m ) z=hash(m) z=hash(m), k k k为随机数, R = k × G R=k\times G R=k×G,r为random point R R R的 x x x坐标),尽管其没有Schnorr和BLS签名的linearity,无法通过对公钥和签名的addition来进行key aggregation,但是multiplication可以。
aggregated public key可为:
P = p k 1 ⋅ p k 2 × G P=pk_1\cdot pk_2\times G P=pk1⋅pk2×G
通过Diffie Helman key exchange即可实现——every party takes the public key of another party and multiplies it by his private key, then both parties know the common public key without exposing anything about their private keys。
R 1 = k 1 × G R_1=k_1\times G R1=k1×G
R 2 = k 2 × G R_2=k_2\times G R2=k2×G
aggregated random point为:
R = k 1 ⋅ k 2 × G R=k_1\cdot k_2\times G R=k1⋅k2×G
相应的aggregated r r r为aggregated random point R R R 的 x x x 坐标。
接下来的目标是构建 s = ( z + r ⋅ p k 1 ⋅ p k 2 ) / k 1 / k 2 s=(z+r\cdot pk_1\cdot pk_2)/{k_1}/k_2 s=(z+r⋅pk1⋅pk2)/k1/k2,但是要求private key和random number of one party stay unknown to another。可利用同态属性来实现。
具体流程如下图所示:(其中红色字体代表的是private data, 蓝色字体代表的是public data,橙色的字体代表的是homomorphic encryption and decryption。)
上图中的e()
同态加密算法和d()
同态解密算法可以借助Paillier scheme类似的思路来实现。
详细为:
选择两个长度一样的large prime numbers p , q p,q p,q。
n = p ⋅ q n=p\cdot q n=p⋅q, g = n + 1 g=n+1 g=n+1。 ( n , g ) (n,g) (n,g)为public,用于加密。
λ = l c m ( p − 1 , q − 1 ) \lambda=lcm(p-1,q-1) λ=lcm(p−1,q−1)(lcm
表示最小公倍数。) λ \lambda λ具有Carmichael function 有趣的特性,满足:任意的 r r r值, r λ ≡ 1 m o d n , r λ ⋅ n ≡ 1 m o d n 2 , r − 1 ≡ r λ − 1 m o d n r^{\lambda}\equiv 1 \mod n,r^{\lambda\cdot n}\equiv 1\mod n^2,r^{-1}\equiv r^{\lambda -1}\mod n rλ≡1modn,rλ⋅n≡1modn2,r−1≡rλ−1modn,当 r = λ r=\lambda r=λ时,仍然成立。于是有: μ = λ − 1 = λ λ − 1 m o d n \mu=\lambda^{-1}=\lambda^{\lambda-1}\mod n μ=λ−1=λλ−1modn。 ( λ , μ ) (\lambda,\mu) (λ,μ)为secret,用于解密。
对secret number x x x进行加密的流程为:
选择随机的 r r r, e ( x ) = g x ⋅ r n m o d n 2 e(x)=g^x\cdot r^n\mod n^2 e(x)=gx⋅rnmodn2。
e ( x ) ⋅ g a = g x + a ⋅ r n m o d n 2 = e ( x + a ) e(x)\cdot g^a=g^{x+a}\cdot r^n\mod n^2=e(x+a) e(x)⋅ga=gx+a⋅rnmodn2=e(x+a),具有加法同态属性。
e ( x ) b = g ( x ⋅ b ) ⋅ ( r b ) n m o d n 2 = e ( x ⋅ b ) e(x)^b=g^{(x\cdot b)}\cdot (r^b)^n\mod n^2=e(x\cdot b) e(x)b=g(x⋅b)⋅(rb)nmodn2=e(x⋅b),具有乘法同态属性。(The random number changes from r r r to r b r^b rb, but we don’t really care. It’s just a different random number. )
对secret number x x x的解密流程为:
x = ( e ( x ) λ m o d n 2 − 1 ) / n ⋅ μ m o d n x=(e(x)^{\lambda}\mod n^2-1)/n\cdot \mu\mod n x=(e(x)λmodn2−1)/n⋅μmodn
具体为:
e ( x ) λ m o d n 2 = g ( x ⋅ λ ) ⋅ r ( n ⋅ λ ) m o d n 2 = g ( x ⋅ λ ) m o d n 2 e(x)^{\lambda}\mod n^2=g^{(x\cdot \lambda)}\cdot r^{(n\cdot \lambda)}\mod n^2=g^{(x\cdot \lambda)}\mod n^2 e(x)λmodn2=g(x⋅λ)⋅r(n⋅λ)modn2=g(x⋅λ)modn2
注意之前有 g = n + 1 g=n+1 g=n+1,利用 binomial theorem :
有 g x m o d n 2 = ( n + 1 ) x m o d n 2 = ( 1 + x ⋅ n + x ⋅ ( x − 1 ) / 2 ⋅ n 2 + ⋯ ) m o d n 2 = ( 1 + x ⋅ n ) g^x\mod n^2=(n+1)^x\mod n^2=(1+x\cdot n+x\cdot (x-1)/2\cdot n^2+\cdots)\mod n^2=(1+x\cdot n) gxmodn2=(n+1)xmodn2=(1+x⋅n+x⋅(x−1)/2⋅n2+⋯)modn2=(1+x⋅n)。
于是令 x = λ x x=\lambda x x=λx有: g ( x ⋅ λ ) m o d n 2 = 1 + λ x ⋅ n g^{(x\cdot \lambda)}\mod n^2=1+\lambda x\cdot n g(x⋅λ)modn2=1+λx⋅n
于是 e ( x ) λ m o d n 2 − 1 ) / n ⋅ μ m o d n = ( 1 + λ x ⋅ n − 1 ) / n ⋅ μ = x e(x)^{\lambda}\mod n^2-1)/n\cdot \mu\mod n=(1+\lambda x\cdot n -1)/n\cdot \mu=x e(x)λmodn2−1)/n⋅μmodn=(1+λx⋅n−1)/n⋅μ=x成立。
同时,以上流程图setup 阶段,Party 1在发送 e ( p k 1 ) e(pk_1) e(pk1)的同时,应该再发送proof证明密文 e ( p k 1 ) e(pk_1) e(pk1)确实是public key P 1 P_1 P1的秘钥。Party 2验证通过后,则setup phase结束。
详细的协议实现参看 Yehuda Lindell 2017年论文《Fast Secure Two-Party ECDSA Signing》:
Schnorr signature与ECDSA比,仅有轻微的差异:
Schnorr signature验签过程中使用的方程式 s × G = R + h a s h ( P , R , m ) × P s\times G=R+hash(P,R,m)\times P s×G=R+hash(P,R,m)×P为线性的。因此有一些很好的特性。如:
在Bitcoin中,需要首先验证区块内的所有签名均有效,若其中某一签名无效,不用关心具体是哪一个,直接拒绝整个区块。
若采用ECDSA,需要对每个签名都分别进行验证,若区块内有1000个签名,则需要进行1000次倒数运算和2000次point multiplication运算,总的有大约3000次heavy operations。
若采用Schnorr signature,则仅需将所有的验签方式累加一块进行验证,可节约计算资源。若区块内有1000个签名,仅需验证:
( s 1 + s 2 + ⋯ + s 1000 ) × G = ( R 1 + ⋯ + R 1000 ) + ( h a s h ( P 1 , R 1 , m 1 ) × P 1 + ⋯ + ( h a s h ( P 1000 + R 1000 + m 1000 ) ) × P 1000 ) (s_1+s_2+\cdots+s_{1000})\times G=(R_1+\cdots+R_{1000})+(hash(P_1,R_1,m_1)\times P_1+\cdots+(hash(P_{1000}+R_{1000}+m_{1000}))\times P_{1000}) (s1+s2+⋯+s1000)×G=(R1+⋯+R1000)+(hash(P1,R1,m1)×P1+⋯+(hash(P1000+R1000+m1000))×P1000)
对应有一些point additions(几乎可忽略相应的计算开销)和1001次point multiplication,相对于ECDSA方案验签速度几乎提升了3倍。相当于对one heavy operation per signature。
为保证比特币安全,用户通常会有至少2个不同的私钥用于控制其所拥有的比特币。如1个私钥用于笔记本上的热钱包,1个私钥用于硬件钱包或者冷钱包。当某一个私钥泄露了,要求仍然可以控制比特币账户的安全。
目前采用的方案是使用2-of-2 multisig script,即要求在交易中包含2个不同的签名。
Naive方案:
采用Schnorr signature,使用2个私钥 ( p k 1 , p k 2 ) (pk_1,pk_2) (pk1,pk2)生成shared public key P = P 1 + P 2 = p k 1 × G + p k 2 × G P=P_1+P_2=pk_1\times G+pk_2\times G P=P1+P2=pk1×G+pk2×G。生成随机数 ( k 1 , k 2 ) (k_1,k_2) (k1,k2),对应的随机point ( R 1 = k 1 × G , R 2 = k 2 × G ) (R_1=k_1\times G,R_2=k_2\times G) (R1=k1×G,R2=k2×G)。 R = R 1 + R 2 R=R_1+R_2 R=R1+R2计算通用 h a s h ( P , R , m ) hash(P,R,m) hash(P,R,m),计算 s 1 = k 1 + h a s h ( h a s h , R , m ) ⋅ p k 1 , s 2 = k 2 + h a s h ( h a s h , R , m ) ⋅ p k 2 s_1=k_1+hash(hash,R,m)\cdot pk_1, s_2=k_2+hash(hash,R,m)\cdot pk_2 s1=k1+hash(hash,R,m)⋅pk1,s2=k2+hash(hash,R,m)⋅pk2。基于shared public key P = P 1 + P 2 = p k 1 × G + p k 2 × G P=P_1+P_2=pk_1\times G+pk_2\times G P=P1+P2=pk1×G+pk2×G生成的shared signature为: ( R , s ) = ( R 1 + R 2 , s 1 + s 2 ) (R,s)=(R_1+R_2,s_1+s_2) (R,s)=(R1+R2,s1+s2)。
这种直观naive的签名方案存在以下几个问题:
1)要求私钥方相互间能够interact。
且当有 > 2 >2 >2个以上的私钥需要进行key aggregation时,整个交互流程将更复杂。
而事实上上图流程还需要额外增加一个环节:
在发送 R i R_i Ri之前,应将其hash值 t i = h a s h ( R i ) t_i=hash(R_i) ti=hash(Ri),这样每个人才能be sure that you will not change your mind after learning other’s random numbers。
2)存在Rogue key attack流氓密钥攻击问题。
Alice公私钥对为 ( p k 1 , P 1 ) (pk_1,P_1) (pk1,P1),同时知道Bob的公钥 ( p k 2 , P 2 ) (pk_2,P_2) (pk2,P2),Bob可以伪造声称其公钥为 P ’ = P 2 − P 1 P’=P_2-P1 P’=P2−P1,其他人会认为 P = P 1 + P ’ P= P_1+P’ P=P1+P’为Alice和Bob的aggregated key,但事实上其 P P P仅包含Bob的公钥,Bob可以自己进行签名然后声称其为与Alice的联合签名。这就是流氓密钥攻击。
避免流氓密钥攻击的方法之一是要求Alice和Bob都能证明其actually possess the private keys corresponding to their claimed public keys。即each participant would need to prove to others, that their Public Key is valid according to Signature produced by its corresponding Private Key。这种方案,将把问题带回到on-chain proof for each participant generating a Signature to validate the authenticity of a Public Key, 从而失去了scaling和efficiency benefits。
需要构建a scheme whose security does not rely on out-of-band verification of the keys。
3)在签名过程中,无法使用deterministic k k k。假设私钥 p k 1 pk_1 pk1被黑客攻击控制,理论上认为,仍然可以使用 ( p k 1 , p k 2 ) (pk_1,pk_2) (pk1,pk2)联合签名保证账户资金安全。但是,如下图所示,私钥 p k 2 = ( s 2 − s 2 ’ ) / ( h a s h ( P , R 1 + R 2 , m ) − h a s h ( P , R 1 ’ + R 2 , m ) ) pk_2=(s_2-s_2’)/(hash(P,R_1+R_2,m)-hash(P,R_1’+R_2,m)) pk2=(s2−s2’)/(hash(P,R1+R2,m)−hash(P,R1’+R2,m))也被泄露。因此,在key aggregation时,需要使用good random number generators everywhere。
鉴于naïve Schnorr multi-signatures存在以上问题,Blockstream团队Maxwell等人2018年论文《Simple Schnorr Multi-Signatures with Applications to Bitcoin》中提出了MuSig方案,可有效解决流氓密钥攻击问题。
Musig方案的目的是aggregate signatures and public keys from several parties/devices to a single one but without proving that you have a private key corresponding to the public key。
The aggregated signature corresponds to the aggregated public key.
与naïve方案中将所有签名方公钥直接相加不同,Musig方案中的aggregated public key生成方式为:
P = h a s h ( L , P 1 ) × P 1 + ⋯ + h a s h ( L , P n ) × P n P=hash(L,P_1)\times P_1+\cdots+hash(L,P_n)\times P_n P=hash(L,P1)×P1+⋯+hash(L,Pn)×Pn
其中 L = h a s h ( P 1 , ⋯ , P n ) L=hash(P_1,\cdots,P_n) L=hash(P1,⋯,Pn),为a common number depending on all public keys。
这种非线性可有效防止流氓密钥攻击。
Musig的签名流程为:
采用的是Merkle Multisig方案。
MuSig和key aggregation要求的是所有签名方对同一交易进行签名。当需要2-of-3 multisig with public keys P 1 , P 2 , P 3 P_1,P_2,P_3 P1,P2,P3时,需要construct a Merkle tree of aggregated public keys for所有可能的组合: ( P 1 , P 2 ) , ( P 2 , P 3 ) , ( P 1 , P 3 ) (P_1,P_2),(P_2,P_3),(P_1,P_3) (P1,P2),(P2,P3),(P1,P3),and put the root in the locking script。当需要spend bitcoins时,需要提供a signature and a proof that our public key is in the tree。
当需要7-of-11 multisig时,涉及的组合可能有 11 ! / 7 ! / 4 ! = 330 11!/7!/4!=330 11!/7!/4!=330种,相应的proof将需要8个elements。且对于m-of-n multisig,the number of elements in the proof scales almost linear with the number of keys in multisig ( log 2 ( n ! / m ! / ( n − m ) ! ) \log_{}2(n!/m!/(n-m)!) log2(n!/m!/(n−m)!))。
BLS signature 来自于Boneh,Lynn和Shacham 2001年论文《Short signatures from the Weil pairing》。
如Boneh 2018年论文《Compact Multi-Signatures for Smaller Blockchains》中指出,BLS signature具有一些Schnorr签名所没有的extremely nice features。
ECDSA 存在的问题是can’t combine signatures or keys and every signature has to be verified independently。对于多重签名的交易,采用ECDSA的化需要逐个验证所有公钥和签名,浪费区块空间和交易费用。
Schnorr signature如果设计好的话,支持combine all signatures and public keys in the transaction to a single key and a signature,而且nobody will find out that they correspond to multiple keys。因为可以一次对所有签名进行验证,区块验证速度更快。
Schnorr multisig方案存在以下问题:
BLS signature可有效解决以上问题:
BLS signautre为completely deterministic signature algorithm。
BLS signature中需要用的两个关键点是:
1)Hashing to the curve:
ECDSA和Schnorr 签名过程中,需要使用hash函数将消息 m m m映射为a number。
而BLS signature中需要调整hash算法,将消息 m m m hashes directly to the elliptic curve。
最简单的方式是,仍然将消息 m m m通过hash函数映射为a number,然后将该number作为elliptic curve 上point的x坐标。
Elliptic curves通常有 2 256 2^{256} 2256个points,采用SHA-256
算法可以生成256-bit result。
但是对于 y 2 = x 3 + a x + b y^2=x^3+ax+b y2=x3+ax+b形式的eclliptic curve,相同的x坐标,存在 ( x , y ) 和 ( x , − y ) (x,y)和(x,-y) (x,y)和(x,−y)两个point均在curve上的情况。这就意味着借助SHA-256
有约50%的概率能找到two points for some x x x,有50%的概率找到point on the curve。
为了保证对任意的消息 m m m均能hashing to the curve,可以在消息 m m m后面追加数字,依次尝试直到能找到相应的curve point。如若 h a s h ( m ∣ ∣ 0 ) hash(m||0) hash(m∣∣0)不能find a point,则依次试 h a s h ( m ∣ ∣ 1 ) , h a s h ( m ∣ ∣ 2 ) hash(m||1),hash(m||2) hash(m∣∣1),hash(m∣∣2),直到找到point on the curve。【对于 ( x , y ) 和 ( x , − y ) (x,y)和(x,-y) (x,y)和(x,−y)两个point,实际选择y坐标值更小的那个point。】(如上图所示)
2)curve pairing
BLS signautre要求能够将(相同或者不同)curve上的P和Q两个点映射a number:
e ( P , Q ) ↦ n e(P,Q)\mapsto n e(P,Q)↦n
同时,应满足如下属性:(使得secret number x x x unreveal。)
e ( x × P , Q ) = e ( P , x × Q ) e(x\times P,Q)=e(P,x\times Q) e(x×P,Q)=e(P,x×Q)
更通用的表达为应具有如下属性:
e ( a × P , b × Q ) = e ( P , a b × Q ) = e ( a b × P , Q ) = e ( P , Q ) ( a b ) e(a\times P,b\times Q)=e(P,ab\times Q)=e(ab\times P,Q)=e(P,Q)^{(ab)} e(a×P,b×Q)=e(P,ab×Q)=e(ab×P,Q)=e(P,Q)(ab)
Bitcoin 的secp256k1不具有pairing属性,不满足以上条件。需要使用pairing-friendly curve。
私钥 p k pk pk,对应的公钥为 P = p k × G P=pk\times G P=pk×G。待签名消息 m m m。
BLS signature的签名流程为:
BLS signature is just one single point on the curve that takes only 33bytes in compressed serialization format。
具体如下图示意:
BLS的验签流程为:
具有pairing属性,以上验签等式恒成立:
e ( P , H ( m ) ) = e ( p k × G , H ( m ) ) = e ( G , p k × H ( m ) ) = e ( G , S ) e(P,H(m))=e(pk\times G,H(m))=e(G,pk\times H(m))=e(G,S) e(P,H(m))=e(pk×G,H(m))=e(G,pk×H(m))=e(G,S)
具体如下图示意:
整个BLS signature非常简洁优美。
与Schnorr aggregation仅支持对同一message m m m进行聚合签名不同,BLS signature支持对不同消息 m i m_i mi的不同签名的聚合,即支持combine all signatures in the block。
假设区块中有1000笔交易,每笔交易包含签名 S i S_i Si、公钥 P i P_i Pi及所签名的消息 m i m_i mi。
Aggregated signature仅需要对所有的签名进行累加即可:
S = S 1 + S 2 + ⋯ + S 1000 S=S_1+S_2+\cdots+S_{1000} S=S1+S2+⋯+S1000
验签仅需要验证以下等式成立即可:
e ( G , S ) = e ( P 1 , H ( m 1 ) ) ⋅ e ( P 2 , H ( m 2 ) ) ⋯ e ( P 1000 , H ( m 1000 ) ) e(G,S)=e(P_1,H(m_1))\cdot e(P_2,H(m_2))\cdots e(P_{1000},H(m_{1000})) e(G,S)=e(P1,H(m1))⋅e(P2,H(m2))⋯e(P1000,H(m1000))
以上等式恒成立,因为:
e ( G , S ) = e ( G , S 1 + S 2 + ⋯ + S 1000 ) = e ( G , S 1 ) ⋅ e ( G , S 2 ) ⋯ e ( G , S 1000 ) = e ( G , p k 1 × H ( m 1 ) ) ⋅ e ( G , p k 2 × H ( m 2 ) ) ⋯ e ( G , p k 1000 × H ( m 1000 ) ) = e ( P 1 , H ( m 1 ) ) ⋅ e ( P 2 , H ( m 2 ) ) ⋯ e ( P 1000 , H ( m 1000 ) ) e(G,S)=e(G,S_1+S_2+\cdots +S_{1000})=e(G,S_1)\cdot e(G,S_2)\cdots e(G,S_{1000})= e(G,pk_1\times H(m_1))\cdot e(G,pk_2\times H(m_2))\cdots e(G,pk_{1000}\times H(m_{1000}))= e(P_1,H(m_1))\cdot e(P_2,H(m_2))\cdots e(P_{1000},H(m_{1000})) e(G,S)=e(G,S1+S2+⋯+S1000)=e(G,S1)⋅e(G,S2)⋯e(G,S1000)=e(G,pk1×H(m1))⋅e(G,pk2×H(m2))⋯e(G,pk1000×H(m1000))=e(P1,H(m1))⋅e(P2,H(m2))⋯e(P1000,H(m1000))
整个signature aggregation仍然需要知道所有的public keys P 1 , P 2 , ⋯ , P 1000 P_1,P_2,\cdots,P_{1000} P1,P2,⋯,P1000,需要进行1001次pairing计算,但是可以将区块内的所有签名压缩为33bytes。而且signature aggregation can be done by a miner and save a lot of space in the block。
对于multisignature,需要sign the same transaction with different keys。BLS可实现与Schnorr类似的key aggregation——combine all signatures and all keys to a single pair of a key and a signature。
Naïve方案为:
S = S 1 + S 2 + S 3 S=S_1+S_2+S_3 S=S1+S2+S3
P = P 1 + P 2 + P 3 P=P_1+P_2+P_3 P=P1+P2+P3
验签等式为:
e ( G , S ) = e ( P , H ( m ) ) e(G,S)=e(P,H(m)) e(G,S)=e(P,H(m))
以上等式恒成立,因为:
e ( G , S ) = e ( G , S 1 + S 2 + S 3 ) = e ( G , ( p k 1 + p k 2 + p k 3 ) × H ( m ) ) = e ( ( p k 1 + p k 2 + p k 3 ) × G , H ( m ) ) = e ( P 1 + P 2 + P 3 , H ( m ) ) = e ( P , H ( m ) ) e(G,S)=e(G,S_1+S_2+S_3)=e(G,(pk_1+pk_2+pk_3)\times H(m))=e((pk_1+pk_2+pk_3)\times G,H(m))=e(P_1+P_2+P_3,H(m))=e(P,H(m)) e(G,S)=e(G,S1+S2+S3)=e(G,(pk1+pk2+pk3)×H(m))=e((pk1+pk2+pk3)×G,H(m))=e(P1+P2+P3,H(m))=e(P,H(m))
与Schnorr naïve方案类似,需要能抵抗rogue key attack流氓密钥攻击,方式可为:
具体为:
S = a 1 × S 1 + a 2 × S 2 + a 3 × S 3 S=a_1\times S_1+a_2\times S_2+a_3\times S_3 S=a1×S1+a2×S2+a3×S3
P = a 1 × P 1 + a 2 × P 2 + a 3 × P 3 P=a_1\times P_1+a_2\times P_2+a_3\times P_3 P=a1×P1+a2×P2+a3×P3
其中 a i = h a s h ( P i , P 1 , P 2 , P 3 ) a_i=hash(P_i,{P_1,P_2,P_3}) ai=hash(Pi,P1,P2,P3),或者实际操作时将这些公钥拼接在一起再hash,如 a i = h a s h ( P i ∣ ∣ P 1 ∣ ∣ P 2 ∣ ∣ P 3 ) a_i=hash(P_i||P_1||P_2||P_3) ai=hash(Pi∣∣P1∣∣P2∣∣P3)。
验签等式 e ( G , S ) = e ( P , H ( m ) ) e(G,S)=e(P,H(m)) e(G,S)=e(P,H(m))仍然恒成立。
与Schnorr方案相比,各签名方不需要进行多轮communication。
为了支持m-of-n multisig,Schnorr需要借助merkle tree of public keys。存在的问题是当 n , m n,m n,m值增大时,merkle tree size blows up exponentially。
BLS为了支持m-of-n multisig,需要用到:
以下以2-of-3 multisig scheme with keys stored on 3 different devices为例:(可扩展至任意的 m , n m,n m,n值。)
1)Setup phase:【要求每个签名方维护相同的序号 1 , 2 , 3 1,2,3 1,2,3,即依次为签名方1,签名方2,签名方3.。。。】
P = a 1 × P 1 + a 2 × P 2 + a 3 × P 3 P=a_1\times P_1+a_2\times P_2+a_3\times P_3 P=a1×P1+a2×P2+a3×P3,其中 a i = h a s h ( P i , P 1 , P 2 , P 3 ) a_i=hash(P_i,{P_1,P_2,P_3}) ai=hash(Pi,P1,P2,P3)
所有签名方对数字 i i i(其值必须在序号范围内)进行签名然后key aggregation,每个签名方 i i i存储与其序号一致的key aggregation信息:
M K i = ( a 1 ) × ( p k 1 × H ( P , i ) ) + ( a 2 ) × ( p k 2 × H ( P , i ) ) + ( a 3 ) × ( p k 3 × H ( P , i ) ) = ( a 1 ⋅ p k 1 ) × H ( P , i ) + ( a 2 ⋅ p k 2 ) × H ( P , i ) + ( a 3 ⋅ p k 3 ) × H ( P , i ) MK_i=(a_1)\times (pk_1\times H(P,i))+ (a_2)\times (pk_2\times H(P,i))+ (a_3)\times (pk_3\times H(P,i))=(a_1\cdot pk_1)\times H(P,i)+ (a_2\cdot pk_2)\times H(P,i)+ (a_3\cdot pk_3)\times H(P,i) MKi=(a1)×(pk1×H(P,i))+(a2)×(pk2×H(P,i))+(a3)×(pk3×H(P,i))=(a1⋅pk1)×H(P,i)+(a2⋅pk2)×H(P,i)+(a3⋅pk3)×H(P,i)。
Setup phase的主要目的就是为了构建membership key M K i MK_i MKi,用于证明we are valid participants of the multisignature scheme。
其实 M K i MK_i MKi可理解为对消息 H ( P , i ) H(P,i) H(P,i)的n-of-n signature,满足:
e ( G , M K i ) = e ( P , H ( P , i ) ) e(G,MK_i)=e(P,H(P,i)) e(G,MKi)=e(P,H(P,i))
2)签名阶段:
如使用 p k 1 和 p k 3 pk_1和pk_3 pk1和pk3进行签名:
S 1 = p k 1 × H ( P , m ) + M K 1 , S 3 = p k 3 × H ( P , m ) + M K 3 S_1=pk_1\times H(P,m)+MK_1,S_3=pk_3\times H(P,m)+MK_3 S1=pk1×H(P,m)+MK1,S3=pk3×H(P,m)+MK3
直接累加有:
( S ’ , P ’ ) = ( S 1 + S 3 , P 1 + P 3 ) (S’,P’)=(S_1+S_3,P_1+P_3) (S’,P’)=(S1+S3,P1+P3)
其中 P ’ P’ P’为aggregated public key of participating signers。
3)验签阶段:
验证2-of-3 signature,仅需验证:【验签阶段,除了 P ’ , S ’ P’,S’ P’,S’之外,还需要知道indexes of participating signers,如本例indexes为数字1和3。】
e ( G , S ’ ) = e ( P ’ , H ( P , m ) ) ⋅ e ( P , H ( P , 1 ) + H ( P , 3 ) ) e(G,S’)=e(P’,H(P,m))\cdot e(P,H(P,1)+H(P,3)) e(G,S’)=e(P’,H(P,m))⋅e(P,H(P,1)+H(P,3))
以上等式恒成立。因为membership keys e ( G , S ’ ) = e ( G , S 1 + S 3 ) = e ( G , p k 1 × H ( P , m ) + M K 1 + p k 3 × H ( P , m ) + M K 3 ) = e ( P ’ , H ( P , m ) ) ⋅ e ( P , H ( P , 1 ) + H ( P , 3 ) ) e(G,S’)=e(G,S_1+S_3)=e(G, pk_1\times H(P,m)+MK_1+ pk_3\times H(P,m)+MK_3)= e(P’,H(P,m))\cdot e(P,H(P,1)+H(P,3)) e(G,S’)=e(G,S1+S3)=e(G,pk1×H(P,m)+MK1+pk3×H(P,m)+MK3)=e(P’,H(P,m))⋅e(P,H(P,1)+H(P,3))
BLS signature的弊端主要有:
事实上已经存在针对elliptic curve crypto system的MOV attack。
[1] https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm
[2] Stepan medium博客 How Schnorr signatures may improve Bitcoin
[3] Stepan medium博客BLS signatures: better than Schnorr
[4] Stepan medium博客 ECDSA is not that bad: two-party signing without Schnorr or BLS
[5] Chris Coverdale bitcointalk博客 Scaling Bitcoin: Schnorr Signatures
[6] Blockstream 博客 Key Aggregation for Schnorr Signatures
[7] Blockstream团队Maxwell等人2018年论文《Simple Schnorr Multi-Signatures with Applications to Bitcoin》