From 615a252770d5d915833c703533ca2001c0f82396 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Thu, 26 Dec 2024 22:56:28 +0700 Subject: [PATCH] fix UB in rpc/evo for update registrar --- src/rpc/evo.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/rpc/evo.cpp b/src/rpc/evo.cpp index 406e887669b3f2..455c6837f05f8d 100644 --- a/src/rpc/evo.cpp +++ b/src/rpc/evo.cpp @@ -1060,12 +1060,12 @@ static UniValue protx_update_service_common_wrapper(const JSONRPCRequest& reques return SignAndSendSpecialTx(request, chain_helper, chainman, tx); } -static RPCHelpMan protx_update_registrar_wrapper(const bool specific_legacy_bls_scheme) +static RPCHelpMan protx_update_registrar_wrapper(const bool use_legacy) { - LogPrintf("knst protx_update_registrar_wrapper legacy=%d\n", specific_legacy_bls_scheme); - std::string rpc_name = specific_legacy_bls_scheme ? "update_registrar_legacy" : "update_registrar"; + LogPrintf("knst protx_update_registrar_wrapper legacy=%d\n", use_legacy); + std::string rpc_name = use_legacy ? "update_registrar_legacy" : "update_registrar"; std::string rpc_full_name = std::string("protx ").append(rpc_name); - std::string pubkey_operator = specific_legacy_bls_scheme ? "\"0532646990082f4fd639f90387b1551f2c7c39d37392cb9055a06a7e85c1d23692db8f87f827886310bccc1e29db9aee\"" : "\"8532646990082f4fd639f90387b1551f2c7c39d37392cb9055a06a7e85c1d23692db8f87f827886310bccc1e29db9aee\""; + std::string pubkey_operator = use_legacy ? "\"0532646990082f4fd639f90387b1551f2c7c39d37392cb9055a06a7e85c1d23692db8f87f827886310bccc1e29db9aee\"" : "\"8532646990082f4fd639f90387b1551f2c7c39d37392cb9055a06a7e85c1d23692db8f87f827886310bccc1e29db9aee\""; std::string rpc_example = rpc_name.append(" \"0123456701234567012345670123456701234567012345670123456701234567\" ").append(pubkey_operator).append(" \"" + EXAMPLE_ADDRESS[1] + "\""); return RPCHelpMan{rpc_full_name, "\nCreates and sends a ProUpRegTx to the network. This will update the operator key, voting key and payout\n" @@ -1074,7 +1074,7 @@ static RPCHelpMan protx_update_registrar_wrapper(const bool specific_legacy_bls_ + HELP_REQUIRING_PASSPHRASE, { GetRpcArg("proTxHash"), - specific_legacy_bls_scheme ? GetRpcArg("operatorPubKey_update_legacy") : GetRpcArg("operatorPubKey_update"), + use_legacy ? GetRpcArg("operatorPubKey_update_legacy") : GetRpcArg("operatorPubKey_update"), GetRpcArg("votingAddress_update"), GetRpcArg("payoutAddress_update"), GetRpcArg("feeSourceAddress"), @@ -1087,6 +1087,8 @@ static RPCHelpMan protx_update_registrar_wrapper(const bool specific_legacy_bls_ }, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { + const bool specific_legacy_bls_scheme{m_name == "update_registrar_legacy"}; + LogPrintf("knst rpc full name: '%s'\n", rpc_full_name); const NodeContext& node = EnsureAnyNodeContext(request.context); const ChainstateManager& chainman = EnsureChainman(node); @@ -1114,7 +1116,7 @@ static RPCHelpMan protx_update_registrar_wrapper(const bool specific_legacy_bls_ } else { // same pubkey, reuse as is ptx.pubKeyOperator = dmn->pdmnState->pubKeyOperator; - LogPrintf("knst pubkey: %s bls=%d %d\n", ptx.pubKeyOperator.ToString(), bls::bls_legacy_scheme.load(), specific_legacy_bls_scheme); + LogPrintf("knst pubkey: %s key legacy=%d-%d bls=%d %d\n", ptx.pubKeyOperator.ToString(), ptx.pubKeyOperator.IsLegacy(), dmn->pdmnState->pubKeyOperator.IsLegacy(), bls::bls_legacy_scheme.load(), specific_legacy_bls_scheme); } ptx.nVersion = specific_legacy_bls_scheme ? CProUpRegTx::LEGACY_BLS_VERSION : CProUpRegTx::BASIC_BLS_VERSION; @@ -1168,13 +1170,11 @@ static RPCHelpMan protx_update_registrar_wrapper(const bool specific_legacy_bls_ static RPCHelpMan protx_update_registrar() { - LogPrintf("knst protx_update_registrar\n"); return protx_update_registrar_wrapper(false); } static RPCHelpMan protx_update_registrar_legacy() { - LogPrintf("knst protx_update_registrar_legacy\n"); return protx_update_registrar_wrapper(true); }