我们来用circom写一个签名方案
要签名
那么就需要什么
1.需要公钥和私钥
2.需要sign
3.需要verify
好,那么我们来试试看
pragma circom 2.1.4;
include "circomlib/poseidon.circom";
// include "https://github.com/0xPARC/circom-secp256k1/blob/master/circuits/bigint.circom";
template SkToPk () {
signal input sk;
signal output pk;
component p;
p = Poseidon(1);
p.inputs[0] <== sk;
pk <== p.out;
}
component main = SkToPk();
/* INPUT = {
"sk": "5"
} */
这就是一个最简单的
利用Poseidon来生成公钥的办法
然后接下来我们来写sign签名
pragma circom 2.1.4;
include "circomlib/poseidon.circom";
// include "https://github.com/0xPARC/circom-secp256k1/blob/master/circuits/bigint.circom";
template SkToPk () {
signal input sk;
signal output pk;
component p;
p = Poseidon(1);
p.inputs[0] <== sk;
pk <== p.out;
}
template Sign () {
signal input sk;
signal input pk;
signal input m;
component s2p;
s2p = SkToPk();
s2p.sk <== sk;
s2p.pk === pk;
}
component main {public [pk, m]}= Sign();
/* INPUT = {
"sk": "5",
"pk": "19065150524771031435284970883882288895168425523179566388456001105768498065277",
"m": "1"
} */
然后我们来写GroupSign
pragma circom 2.1.4;
include "circomlib/poseidon.circom";
// include "https://github.com/0xPARC/circom-secp256k1/blob/master/circuits/bigint.circom";
template SkToPk () {
signal input sk;
signal output pk;
component p;
p = Poseidon(1);
p.inputs[0] <== sk;
pk <== p.out;
}
template GroupSign(n) {
signal input sk;
signal input pk[n];
signal input m;
component s2p;
s2p = SkToPk();
s2p.sk <== sk;
// s2p.pk === pk;
signal zeroChecker[n+1];
zeroChecker[0] <== 1;
for (var i=0; i<n ; i++){
zeroChecker[i+1] <== zeroChecker[i] * (s2p.pk - pk[i]);
}
zeroChecker[n] === 0;
}
component main {public [pk, m]}= GroupSign(3);
/* INPUT = {
"sk": "5",
"pk": ["19065150524771031435284970883882288895168425523179566388456001105768498065277", "1", "2"],
"m": "1"
} */
好复杂
其实还好
仔细一看
也挺简单的