@@ -31,21 +31,21 @@ using namespace bls;
3131void benchSigs () {
3232 string testName = " Signing" ;
3333 const int numIters = 5000 ;
34- PrivateKey sk = AugSchemeMPL ().KeyGen (getRandomSeed ());
34+ PrivateKey sk = BasicSchemeMPL ().KeyGen (getRandomSeed ());
3535 vector<uint8_t > message1 = sk.GetG1Element ().Serialize ();
3636
3737 auto start = startStopwatch ();
3838
3939 for (int i = 0 ; i < numIters; i++) {
40- AugSchemeMPL ().Sign (sk, message1);
40+ BasicSchemeMPL ().Sign (sk, message1);
4141 }
4242 endStopwatch (testName, start, numIters);
4343}
4444
4545void benchVerification () {
4646 string testName = " Verification" ;
47- const int numIters = 10000 ;
48- PrivateKey sk = AugSchemeMPL ().KeyGen (getRandomSeed ());
47+ const int numIters = 1000 ;
48+ PrivateKey sk = BasicSchemeMPL ().KeyGen (getRandomSeed ());
4949 G1Element pk = sk.GetG1Element ();
5050
5151 std::vector<G2Element> sigs;
@@ -54,42 +54,44 @@ void benchVerification() {
5454 uint8_t message[4 ];
5555 Util::IntToFourBytes (message, i);
5656 vector<uint8_t > messageBytes (message, message + 4 );
57- sigs.push_back (AugSchemeMPL ().Sign (sk, messageBytes));
57+ sigs.push_back (BasicSchemeMPL ().Sign (sk, messageBytes));
5858 }
5959
6060 auto start = startStopwatch ();
6161 for (int i = 0 ; i < numIters; i++) {
6262 uint8_t message[4 ];
6363 Util::IntToFourBytes (message, i);
6464 vector<uint8_t > messageBytes (message, message + 4 );
65- bool ok = AugSchemeMPL ().Verify (pk, messageBytes, sigs[i]);
65+ bool ok = BasicSchemeMPL ().Verify (pk, messageBytes, sigs[i]);
6666 ASSERT (ok);
6767 }
6868 endStopwatch (testName, start, numIters);
6969}
7070
7171void benchBatchVerification () {
72- const int numIters = 100000 ;
72+ const int numIters = 10000 ;
7373
7474 vector<vector<uint8_t >> sig_bytes;
7575 vector<vector<uint8_t >> pk_bytes;
7676 vector<vector<uint8_t >> ms;
7777
78+ auto start = startStopwatch ();
7879 for (int i = 0 ; i < numIters; i++) {
7980 uint8_t message[4 ];
8081 Util::IntToFourBytes (message, i);
8182 vector<uint8_t > messageBytes (message, message + 4 );
82- PrivateKey sk = AugSchemeMPL ().KeyGen (getRandomSeed ());
83+ PrivateKey sk = BasicSchemeMPL ().KeyGen (getRandomSeed ());
8384 G1Element pk = sk.GetG1Element ();
84- sig_bytes.push_back (AugSchemeMPL ().Sign (sk, messageBytes).Serialize ());
85+ sig_bytes.push_back (BasicSchemeMPL ().Sign (sk, messageBytes).Serialize ());
8586 pk_bytes.push_back (pk.Serialize ());
8687 ms.push_back (messageBytes);
8788 }
89+ endStopwatch (" Batch verification preparation" , start, numIters);
8890
8991 vector<G1Element> pks;
9092 pks.reserve (numIters);
9193
92- auto start = startStopwatch ();
94+ start = startStopwatch ();
9395 for (auto const & pk : pk_bytes) {
9496 pks.emplace_back (G1Element::FromBytes (Bytes (pk)));
9597 }
@@ -105,52 +107,71 @@ void benchBatchVerification() {
105107 endStopwatch (" Signature validation" , start, numIters);
106108
107109 start = startStopwatch ();
108- G2Element aggSig = AugSchemeMPL ().Aggregate (sigs);
110+ G2Element aggSig = BasicSchemeMPL ().Aggregate (sigs);
109111 endStopwatch (" Aggregation" , start, numIters);
110112
111113 start = startStopwatch ();
112- bool ok = AugSchemeMPL ().AggregateVerify (pks, ms, aggSig);
114+ bool ok = BasicSchemeMPL ().AggregateVerify (pks, ms, aggSig);
113115 ASSERT (ok);
114116 endStopwatch (" Batch verification" , start, numIters);
115117}
116118
117- void benchFastAggregateVerification () {
118- const int numIters = 5000 ;
119+ void benchSerialize () {
120+ const int numIters = 5000000 ;
121+ PrivateKey sk = BasicSchemeMPL ().KeyGen (getRandomSeed ());
122+ G1Element pk = sk.GetG1Element ();
123+ vector<uint8_t > message = sk.GetG1Element ().Serialize ();
124+ G2Element sig = BasicSchemeMPL ().Sign (sk, message);
119125
120- vector<G2Element> sigs;
121- vector<G1Element> pks;
122- vector<uint8_t > message = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
123- vector<G2Element> pops;
126+ auto start = startStopwatch ();
127+ for (int i = 0 ; i < numIters; i++) {
128+ sk.Serialize ();
129+ }
130+ endStopwatch (" Serialize PrivateKey" , start, numIters);
124131
132+ start = startStopwatch ();
125133 for (int i = 0 ; i < numIters; i++) {
126- PrivateKey sk = PopSchemeMPL ().KeyGen (getRandomSeed ());
127- G1Element pk = sk.GetG1Element ();
128- sigs.push_back (PopSchemeMPL ().Sign (sk, message));
129- pops.push_back (PopSchemeMPL ().PopProve (sk));
130- pks.push_back (pk);
134+ pk.Serialize ();
131135 }
136+ endStopwatch (" Serialize G1Element" , start, numIters);
132137
133- auto start = startStopwatch ();
134- G2Element aggSig = PopSchemeMPL ().Aggregate (sigs);
135- endStopwatch (" PopScheme Aggregation" , start, numIters);
138+ start = startStopwatch ();
139+ for (int i = 0 ; i < numIters; i++) {
140+ sig.Serialize ();
141+ }
142+ endStopwatch (" Serialize G2Element" , start, numIters);
143+ }
144+
145+ void benchSerializeToArray () {
146+ const int numIters = 5000000 ;
147+ PrivateKey sk = BasicSchemeMPL ().KeyGen (getRandomSeed ());
148+ G1Element pk = sk.GetG1Element ();
149+ vector<uint8_t > message = sk.GetG1Element ().Serialize ();
150+ G2Element sig = BasicSchemeMPL ().Sign (sk, message);
136151
152+ auto start = startStopwatch ();
153+ for (int i = 0 ; i < numIters; i++) {
154+ sk.SerializeToArray ();
155+ }
156+ endStopwatch (" SerializeToArray PrivateKey" , start, numIters);
137157
138158 start = startStopwatch ();
139159 for (int i = 0 ; i < numIters; i++) {
140- bool ok = PopSchemeMPL ().PopVerify (pks[i], pops[i]);
141- ASSERT (ok);
160+ pk.SerializeToArray ();
142161 }
143- endStopwatch (" PopScheme Proofs verification " , start, numIters);
162+ endStopwatch (" SerializeToArray G1Element " , start, numIters);
144163
145164 start = startStopwatch ();
146- bool ok = PopSchemeMPL ().FastAggregateVerify (pks, message, aggSig);
147- ASSERT (ok);
148- endStopwatch (" PopScheme verification" , start, numIters);
165+ for (int i = 0 ; i < numIters; i++) {
166+ sig.SerializeToArray ();
167+ }
168+ endStopwatch (" SerializeToArray G2Element" , start, numIters);
149169}
150170
151171int main (int argc, char * argv[]) {
152172 benchSigs ();
153173 benchVerification ();
154174 benchBatchVerification ();
155- benchFastAggregateVerification ();
175+ benchSerialize ();
176+ benchSerializeToArray ();
156177}
0 commit comments