Skip to content

Commit 1446e93

Browse files
committed
typedef uint256 CBLSId
1 parent 30c2ba2 commit 1446e93

File tree

4 files changed

+11
-71
lines changed

4 files changed

+11
-71
lines changed

src/bench/bls_dkg.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "bench.h"
66
#include "random.h"
7+
#include "tinyformat.h"
78
#include "bls/bls_worker.h"
89

910
extern CBLSWorker blsWorker;
@@ -31,7 +32,7 @@ struct DKG
3132
ids.resize(quorumSize);
3233

3334
for (int i = 0; i < quorumSize; i++) {
34-
members[i].id.SetInt(i + 1);
35+
members[i].id.SetHex(strprintf("%x", i + 1));
3536
ids[i] = members[i].id;
3637
}
3738

src/bls/bls.cpp

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include "hash.h"
88
#include "random.h"
9-
#include "tinyformat.h"
109

1110
#ifndef BUILD_BITCOIN_INTERNAL
1211
#include "support/allocators/secure.h"
@@ -16,50 +15,6 @@
1615
#include <assert.h>
1716
#include <string.h>
1817

19-
bool CBLSId::InternalSetBuf(const void* buf, size_t size)
20-
{
21-
assert(size == sizeof(uint256));
22-
memcpy(impl.begin(), buf, sizeof(uint256));
23-
return true;
24-
}
25-
26-
bool CBLSId::InternalGetBuf(void* buf, size_t size) const
27-
{
28-
if (size != GetSerSize()) {
29-
return false;
30-
}
31-
memcpy(buf, impl.begin(), sizeof(uint256));
32-
return true;
33-
}
34-
35-
void CBLSId::SetInt(int x)
36-
{
37-
impl.SetHex(strprintf("%x", x));
38-
fValid = true;
39-
UpdateHash();
40-
}
41-
42-
void CBLSId::SetHash(const uint256& hash)
43-
{
44-
impl = hash;
45-
fValid = true;
46-
UpdateHash();
47-
}
48-
49-
CBLSId CBLSId::FromInt(int64_t i)
50-
{
51-
CBLSId id;
52-
id.SetInt(i);
53-
return id;
54-
}
55-
56-
CBLSId CBLSId::FromHash(const uint256& hash)
57-
{
58-
CBLSId id;
59-
id.SetHash(hash);
60-
return id;
61-
}
62-
6318
bool CBLSSecretKey::InternalSetBuf(const void* buf, size_t size)
6419
{
6520
if (size != GetSerSize()) {
@@ -133,7 +88,7 @@ bool CBLSSecretKey::SecretKeyShare(const std::vector<CBLSSecretKey>& msk, const
13388
fValid = false;
13489
UpdateHash();
13590

136-
if (!_id.IsValid()) {
91+
if (_id.IsNull()) {
13792
return false;
13893
}
13994

@@ -147,7 +102,7 @@ bool CBLSSecretKey::SecretKeyShare(const std::vector<CBLSSecretKey>& msk, const
147102
}
148103

149104
try {
150-
impl = bls::BLS::PrivateKeyShare(mskVec, (const uint8_t*)_id.impl.begin());
105+
impl = bls::BLS::PrivateKeyShare(mskVec, (const uint8_t*)_id.begin());
151106
} catch (...) {
152107
return false;
153108
}
@@ -241,7 +196,7 @@ bool CBLSPublicKey::PublicKeyShare(const std::vector<CBLSPublicKey>& mpk, const
241196
fValid = false;
242197
UpdateHash();
243198

244-
if (!_id.IsValid()) {
199+
if (_id.IsNull()) {
245200
return false;
246201
}
247202

@@ -255,7 +210,7 @@ bool CBLSPublicKey::PublicKeyShare(const std::vector<CBLSPublicKey>& mpk, const
255210
}
256211

257212
try {
258-
impl = bls::BLS::PublicKeyShare(mpkVec, (const uint8_t*)_id.impl.begin());
213+
impl = bls::BLS::PublicKeyShare(mpkVec, (const uint8_t*)_id.begin());
259214
} catch (...) {
260215
return false;
261216
}
@@ -433,11 +388,11 @@ bool CBLSSignature::Recover(const std::vector<CBLSSignature>& sigs, const std::v
433388
idsVec.reserve(sigs.size());
434389

435390
for (size_t i = 0; i < sigs.size(); i++) {
436-
if (!sigs[i].IsValid() || !ids[i].IsValid()) {
391+
if (!sigs[i].IsValid() || ids[i].IsNull()) {
437392
return false;
438393
}
439394
sigsVec.emplace_back(sigs[i].impl);
440-
idsVec.emplace_back(ids[i].impl.begin());
395+
idsVec.emplace_back(ids[i].begin());
441396
}
442397

443398
try {

src/bls/bls.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -188,23 +188,7 @@ class CBLSWrapper
188188
}
189189
};
190190

191-
class CBLSId : public CBLSWrapper<uint256, BLS_CURVE_ID_SIZE, CBLSId>
192-
{
193-
public:
194-
using CBLSWrapper::operator=;
195-
using CBLSWrapper::operator==;
196-
using CBLSWrapper::operator!=;
197-
198-
void SetInt(int x);
199-
void SetHash(const uint256& hash);
200-
201-
static CBLSId FromInt(int64_t i);
202-
static CBLSId FromHash(const uint256& hash);
203-
204-
protected:
205-
bool InternalSetBuf(const void* buf, size_t size);
206-
bool InternalGetBuf(void* buf, size_t size) const;
207-
};
191+
typedef uint256 CBLSId;
208192

209193
class CBLSSecretKey : public CBLSWrapper<bls::PrivateKey, BLS_CURVE_SECKEY_SIZE, CBLSSecretKey>
210194
{

src/bls/bls_worker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ CBLSPublicKey CBLSWorker::BuildPubKeyShare(const BLSVerificationVectorPtr& vvec,
723723
void CBLSWorker::AsyncVerifyContributionShares(const CBLSId& forId, const std::vector<BLSVerificationVectorPtr>& vvecs, const BLSSecretKeyVector& skShares,
724724
bool parallel, bool aggregated, std::function<void(const std::vector<bool>&)> doneCallback)
725725
{
726-
if (!forId.IsValid() || !VerifyVerificationVectors(vvecs)) {
726+
if (forId.IsNull() || !VerifyVerificationVectors(vvecs)) {
727727
std::vector<bool> result;
728728
result.assign(vvecs.size(), false);
729729
doneCallback(result);
@@ -752,7 +752,7 @@ std::future<bool> CBLSWorker::AsyncVerifyContributionShare(const CBLSId& forId,
752752
const BLSVerificationVectorPtr& vvec,
753753
const CBLSSecretKey& skContribution)
754754
{
755-
if (!forId.IsValid() || !VerifyVerificationVector(*vvec)) {
755+
if (forId.IsNull() || !VerifyVerificationVector(*vvec)) {
756756
auto p = BuildFutureDoneCallback<bool>();
757757
p.first(false);
758758
return std::move(p.second);

0 commit comments

Comments
 (0)