Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: deglobalization of bls_legacy_scheme 3/N #6508

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: do not pass param 'modOrder' for bls::PrivateKey
  • Loading branch information
knst committed Dec 25, 2024
commit 544031db273eaabe33d80d317db8b0d9e60b47b1
13 changes: 6 additions & 7 deletions src/rpc/evo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,12 @@ static CBLSPublicKey ParseBLSPubKey(const std::string& hexKey, const std::string
return pubKey;
}

static CBLSSecretKey ParseBLSSecretKey(const std::string& hexKey, const std::string& paramName, bool specific_legacy_bls_scheme)
static CBLSSecretKey ParseBLSSecretKey(const std::string& hexKey, const std::string& paramName)
{
CBLSSecretKey secKey;

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

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

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

size_t paramIdx = 3;
if (isEvoRequested) {
Expand Down Expand Up @@ -1210,12 +1210,11 @@ static RPCHelpMan protx_revoke()
EnsureWalletIsUnlocked(*pwallet);

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

CBLSSecretKey keyOperator = ParseBLSSecretKey(request.params[1].get_str(), "operatorKey", is_bls_legacy);
CBLSSecretKey keyOperator = ParseBLSSecretKey(request.params[1].get_str(), "operatorKey");

if (!request.params[2].isNull()) {
int32_t nReason = ParseInt32V(request.params[2], "reason");
Expand Down Expand Up @@ -1766,7 +1765,7 @@ static RPCHelpMan bls_fromsecret()
if (!request.params[1].isNull()) {
bls_legacy_scheme = ParseBoolV(request.params[1], "bls_legacy_scheme");
}
CBLSSecretKey sk = ParseBLSSecretKey(request.params[0].get_str(), "secretKey", bls_legacy_scheme);
CBLSSecretKey sk = ParseBLSSecretKey(request.params[0].get_str(), "secretKey");
UniValue ret(UniValue::VOBJ);
ret.pushKV("secret", sk.ToString());
ret.pushKV("public", sk.GetPublicKey().ToString(bls_legacy_scheme));
Expand Down
14 changes: 8 additions & 6 deletions src/test/bls_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,21 @@ void FuncSetHexStr(const bool legacy_scheme)
{
bls::bls_legacy_scheme.store(legacy_scheme);

// Note: 2nd bool argument for SetHexStr for bls::PrivateKey has a meaning modOrder, not is-legacy
CBLSSecretKey sk;
std::string strValidSecret = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f";
// Note: invalid string passed to SetHexStr() should cause it to fail and reset key internal data
BOOST_CHECK(sk.SetHexStr(strValidSecret, legacy_scheme));
BOOST_CHECK(!sk.SetHexStr("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1g", legacy_scheme)); // non-hex
BOOST_CHECK(sk.SetHexStr(strValidSecret, false));
BOOST_CHECK(!sk.SetHexStr("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1g", false)); // non-hex
BOOST_CHECK(!sk.IsValid());
BOOST_CHECK(sk == CBLSSecretKey());
// Try few more invalid strings
BOOST_CHECK(sk.SetHexStr(strValidSecret, legacy_scheme));
BOOST_CHECK(!sk.SetHexStr("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e", legacy_scheme)); // hex but too short
BOOST_CHECK(sk.SetHexStr(strValidSecret, false));
BOOST_CHECK(!sk.SetHexStr("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e", false)); // hex but too short
BOOST_CHECK(!sk.IsValid());
BOOST_CHECK(sk.SetHexStr(strValidSecret, legacy_scheme));
BOOST_CHECK(!sk.SetHexStr("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20", legacy_scheme)); // hex but too long
BOOST_CHECK(sk.SetHexStr(strValidSecret, false));
BOOST_CHECK(
!sk.SetHexStr("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20", false)); // hex but too long
BOOST_CHECK(!sk.IsValid());

return;
Expand Down