Skip to content

Commit 544031d

Browse files
committed
fix: do not pass param 'modOrder' for bls::PrivateKey
1 parent ad7a373 commit 544031d

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/rpc/evo.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,12 @@ static CBLSPublicKey ParseBLSPubKey(const std::string& hexKey, const std::string
197197
return pubKey;
198198
}
199199

200-
static CBLSSecretKey ParseBLSSecretKey(const std::string& hexKey, const std::string& paramName, bool specific_legacy_bls_scheme)
200+
static CBLSSecretKey ParseBLSSecretKey(const std::string& hexKey, const std::string& paramName)
201201
{
202202
CBLSSecretKey secKey;
203203

204-
if (!secKey.SetHexStr(hexKey, specific_legacy_bls_scheme)) {
204+
// Actually, bool flag for bls::PrivateKey has other meaning (modOrder)
205+
if (!secKey.SetHexStr(hexKey, false)) {
205206
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%s must be a valid BLS secret key", paramName));
206207
}
207208
return secKey;
@@ -964,7 +965,6 @@ static UniValue protx_update_service_common_wrapper(const JSONRPCRequest& reques
964965
EnsureWalletIsUnlocked(*wallet);
965966

966967
const bool isV19active{DeploymentActiveAfter(WITH_LOCK(cs_main, return chainman.ActiveChain().Tip();), Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
967-
const bool is_bls_legacy = !isV19active;
968968
if (isEvoRequested && !isV19active) {
969969
throw JSONRPCError(RPC_INVALID_REQUEST, "EvoNodes aren't allowed yet");
970970
}
@@ -979,7 +979,7 @@ static UniValue protx_update_service_common_wrapper(const JSONRPCRequest& reques
979979
throw std::runtime_error(strprintf("invalid network address %s", request.params[1].get_str()));
980980
}
981981

982-
CBLSSecretKey keyOperator = ParseBLSSecretKey(request.params[2].get_str(), "operatorKey", is_bls_legacy);
982+
CBLSSecretKey keyOperator = ParseBLSSecretKey(request.params[2].get_str(), "operatorKey");
983983

984984
size_t paramIdx = 3;
985985
if (isEvoRequested) {
@@ -1210,12 +1210,11 @@ static RPCHelpMan protx_revoke()
12101210
EnsureWalletIsUnlocked(*pwallet);
12111211

12121212
const bool isV19active{DeploymentActiveAfter(WITH_LOCK(cs_main, return chainman.ActiveChain().Tip();), Params().GetConsensus(), Consensus::DEPLOYMENT_V19)};
1213-
const bool is_bls_legacy = !isV19active;
12141213
CProUpRevTx ptx;
12151214
ptx.nVersion = CProUpRevTx::GetVersion(isV19active);
12161215
ptx.proTxHash = ParseHashV(request.params[0], "proTxHash");
12171216

1218-
CBLSSecretKey keyOperator = ParseBLSSecretKey(request.params[1].get_str(), "operatorKey", is_bls_legacy);
1217+
CBLSSecretKey keyOperator = ParseBLSSecretKey(request.params[1].get_str(), "operatorKey");
12191218

12201219
if (!request.params[2].isNull()) {
12211220
int32_t nReason = ParseInt32V(request.params[2], "reason");
@@ -1766,7 +1765,7 @@ static RPCHelpMan bls_fromsecret()
17661765
if (!request.params[1].isNull()) {
17671766
bls_legacy_scheme = ParseBoolV(request.params[1], "bls_legacy_scheme");
17681767
}
1769-
CBLSSecretKey sk = ParseBLSSecretKey(request.params[0].get_str(), "secretKey", bls_legacy_scheme);
1768+
CBLSSecretKey sk = ParseBLSSecretKey(request.params[0].get_str(), "secretKey");
17701769
UniValue ret(UniValue::VOBJ);
17711770
ret.pushKV("secret", sk.ToString());
17721771
ret.pushKV("public", sk.GetPublicKey().ToString(bls_legacy_scheme));

src/test/bls_tests.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,21 @@ void FuncSetHexStr(const bool legacy_scheme)
6363
{
6464
bls::bls_legacy_scheme.store(legacy_scheme);
6565

66+
// Note: 2nd bool argument for SetHexStr for bls::PrivateKey has a meaning modOrder, not is-legacy
6667
CBLSSecretKey sk;
6768
std::string strValidSecret = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f";
6869
// Note: invalid string passed to SetHexStr() should cause it to fail and reset key internal data
69-
BOOST_CHECK(sk.SetHexStr(strValidSecret, legacy_scheme));
70-
BOOST_CHECK(!sk.SetHexStr("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1g", legacy_scheme)); // non-hex
70+
BOOST_CHECK(sk.SetHexStr(strValidSecret, false));
71+
BOOST_CHECK(!sk.SetHexStr("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1g", false)); // non-hex
7172
BOOST_CHECK(!sk.IsValid());
7273
BOOST_CHECK(sk == CBLSSecretKey());
7374
// Try few more invalid strings
74-
BOOST_CHECK(sk.SetHexStr(strValidSecret, legacy_scheme));
75-
BOOST_CHECK(!sk.SetHexStr("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e", legacy_scheme)); // hex but too short
75+
BOOST_CHECK(sk.SetHexStr(strValidSecret, false));
76+
BOOST_CHECK(!sk.SetHexStr("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e", false)); // hex but too short
7677
BOOST_CHECK(!sk.IsValid());
77-
BOOST_CHECK(sk.SetHexStr(strValidSecret, legacy_scheme));
78-
BOOST_CHECK(!sk.SetHexStr("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20", legacy_scheme)); // hex but too long
78+
BOOST_CHECK(sk.SetHexStr(strValidSecret, false));
79+
BOOST_CHECK(
80+
!sk.SetHexStr("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20", false)); // hex but too long
7981
BOOST_CHECK(!sk.IsValid());
8082

8183
return;

0 commit comments

Comments
 (0)