Skip to content

Commit

Permalink
fix UB in rpc/evo for update registrar
Browse files Browse the repository at this point in the history
  • Loading branch information
knst committed Dec 26, 2024
1 parent 4631b81 commit 5189807
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/rpc/evo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"),
Expand All @@ -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{self.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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 5189807

Please sign in to comment.