26 std::vector<uint256>& msgHashes,
27 std::vector<bool>& invalid)
29 secKeys.resize(
count);
30 pubKeys.resize(
count);
32 msgHashes.resize(
count);
34 invalid.resize(
count);
35 for (
size_t i = 0; i < invalidCount; i++) {
38 std::random_shuffle(invalid.begin(), invalid.end());
40 for (
size_t i = 0; i <
count; i++) {
41 secKeys[i].MakeNewKey();
42 pubKeys[i] = secKeys[i].GetPublicKey();
44 sigs[i] = secKeys[i].Sign(msgHashes[i]);
49 sigs[i] = s.
Sign(msgHashes[i]);
102 std::vector<uint256> msgHashes;
103 std::vector<bool> invalid;
109 bool valid = sigs[i].VerifyInsecure(pubKeys[i], msgHashes[i]);
110 if (valid && invalid[i]) {
111 std::cout <<
"expected invalid but it is valid" << std::endl;
113 }
else if (!valid && !invalid[i]) {
114 std::cout <<
"expected valid but it is invalid" << std::endl;
117 i = (i + 1) % pubKeys.size();
127 std::vector<uint256> msgHashes;
128 std::vector<bool> invalid;
133 for (
size_t i = 0; i < pubKeys.size(); i++) {
134 sigs[i].VerifyInsecure(pubKeys[i], msgHashes[i]);
154 std::vector<uint256> msgHashes;
155 std::vector<bool> invalid;
180 std::vector<uint256> msgHashes;
181 std::vector<bool> invalid;
207 std::vector<uint256> msgHashes;
208 std::vector<bool> invalid;
213 std::set<size_t> prevalidated;
215 while (prevalidated.size() < 900) {
217 if (prevalidated.count((
size_t)idx)) {
220 prevalidated.emplace((
size_t)idx);
226 std::vector<uint256> nonvalidatedHashes;
227 nonvalidatedPubKeys.reserve(pubKeys.size());
228 nonvalidatedHashes.reserve(msgHashes.size());
230 for (
size_t i = 0; i < sigs.size(); i++) {
231 if (prevalidated.count(i)) {
234 nonvalidatedPubKeys.emplace_back(pubKeys[i]);
235 nonvalidatedHashes.emplace_back(msgHashes[i]);
239 for (
auto idx : prevalidated) {
253 std::vector<uint256> msgHashes;
254 std::vector<bool> invalid;
260 size_t batchSize = 16;
263 if ((j % batchSize) != 0) {
269 std::vector<uint256> testMsgHashes;
270 testPubKeys.reserve(batchSize);
271 testSigs.reserve(batchSize);
272 testMsgHashes.reserve(batchSize);
274 for (
size_t k = 0; k < batchSize; k++) {
275 testPubKeys.emplace_back(pubKeys[i]);
276 testSigs.emplace_back(sigs[i]);
277 testMsgHashes.emplace_back(msgHashes[i]);
278 i = (i + 1) % pubKeys.size();
283 std::vector<bool> valid;
285 valid.assign(batchSize,
true);
287 for (
size_t k = 0; k < batchSize; k++) {
288 bool valid1 = testSigs[k].VerifyInsecure(testPubKeys[k], testMsgHashes[k]);
289 valid.emplace_back(valid1);
292 for (
size_t k = 0; k < batchSize; k++) {
293 if (valid[k] && invalid[(startI + k) % pubKeys.size()]) {
294 std::cout <<
"expected invalid but it is valid" << std::endl;
296 }
else if (!valid[k] && !invalid[(startI + k) % pubKeys.size()]) {
297 std::cout <<
"expected valid but it is invalid" << std::endl;
309 std::vector<uint256> msgHashes;
310 std::vector<bool> invalid;
313 std::list<std::pair<size_t, std::future<bool>>> futures;
315 volatile bool cancel =
false;
316 auto cancelCond = [&]() {
323 if (futures.size() < 100) {
324 while (futures.size() < 10000) {
326 futures.emplace_back(std::make_pair(i, std::move(f)));
327 i = (i + 1) % pubKeys.size();
331 auto fp = std::move(futures.front());
335 bool valid = fp.second.get();
337 if (valid && invalid[j]) {
338 std::cout <<
"expected invalid but it is valid" << std::endl;
340 }
else if (!valid && !invalid[j]) {
341 std::cout <<
"expected valid but it is invalid" << std::endl;
static void BLSVerify_LargeAggregatedBlock10000(benchmark::State &state)
static void BLSVerify_LargeAggregatedBlock1000PreVerified(benchmark::State &state)
std::vector< CBLSPublicKey > BLSPublicKeyVector
static void BLSVerify_LargeBlockSelfAggregated(size_t txCount, benchmark::State &state)
void MilliSleep(int64_t n)
static void BLSVerify_LargeBlockSelfAggregated1000(benchmark::State &state)
static void BLSVerify_Batched(benchmark::State &state)
void SubInsecure(const CBLSSignature &o)
static void BLSVerify_LargeBlock(size_t txCount, benchmark::State &state)
static void BLSVerify_LargeAggregatedBlock(size_t txCount, benchmark::State &state)
static void BuildTestVectors(size_t count, size_t invalidCount, BLSPublicKeyVector &pubKeys, BLSSecretKeyVector &secKeys, BLSSignatureVector &sigs, std::vector< uint256 > &msgHashes, std::vector< bool > &invalid)
void AggregateInsecure(const CBLSSecretKey &o)
std::vector< CBLSSecretKey > BLSSecretKeyVector
bool VerifyInsecureAggregated(const std::vector< CBLSPublicKey > &pubKeys, const std::vector< uint256 > &hashes) const
std::vector< CBLSSignature > BLSSignatureVector
static void BLSVerify_LargeBlockSelfAggregated10000(benchmark::State &state)
static void BLSVerify_LargeAggregatedBlock1000(benchmark::State &state)
static void BLSVerify_LargeBlock1000(benchmark::State &state)
static void BLSPubKeyAggregate_Normal(benchmark::State &state)
bool IsAsyncVerifyInProgress()
void AsyncVerifySig(const CBLSSignature &sig, const CBLSPublicKey &pubKey, const uint256 &msgHash, SigVerifyDoneCallback doneCallback, CancelCond cancelCond=[] { return false;})
static void BLSVerify_BatchedParallel(benchmark::State &state)
void AggregateInsecure(const CBLSPublicKey &o)
void AggregateInsecure(const CBLSSignature &o)
static void BLSVerify_Normal(benchmark::State &state)
CBLSPublicKey GetPublicKey() const
static void BLSSign_Normal(benchmark::State &state)
static void BLSVerify_LargeBlock10000(benchmark::State &state)
static void BLSSecKeyAggregate_Normal(benchmark::State &state)
CBLSSignature Sign(const uint256 &hash) const