Return better errors for BlindingStatus

This commit is contained in:
Andrew Chow 2020-12-09 12:31:29 -05:00
parent f686e0fa54
commit 124efa2668
3 changed files with 29 additions and 4 deletions

View file

@ -12,6 +12,27 @@
#include <random.h>
#include <util/system.h>
std::string GetBlindingStatusError(const BlindingStatus& status)
{
switch(status) {
case BlindingStatus::OK:
return "No error";
case BlindingStatus::NEEDS_UTXOS:
return "Inputs are missing UTXOs (or peg-in data for peg-in inputs)";
case BlindingStatus::INVALID_ASSET:
return "Provided asset tag is invalid";
case BlindingStatus::INVALID_ASSET_COMMITMENT:
return "Provided asset commitment is invalid";
case BlindingStatus::SCALAR_UNABLE:
return "Unable to compute the scalars for the final blinder";
case BlindingStatus::INVALID_BLINDER:
return "Computed blinding factor is invalid";
case BlindingStatus::ASP_UNABLE:
return "Unable to create an asset surjection proof";
}
assert(false);
}
// Create surjection proof
bool CreateAssetSurjectionProof(std::vector<unsigned char>& output_proof, const std::vector<secp256k1_fixed_asset_tag>& fixed_input_tags, const std::vector<secp256k1_generator>& ephemeral_input_tags, const std::vector<uint256>& input_asset_blinders, const uint256& output_asset_blinder, const secp256k1_generator& output_asset_tag, const CAsset& asset)
{

View file

@ -28,6 +28,8 @@ enum class BlindingStatus
ASP_UNABLE,
};
std::string GetBlindingStatusError(const BlindingStatus& status);
bool CreateAssetSurjectionProof(std::vector<unsigned char>& output_proof, const std::vector<secp256k1_fixed_asset_tag>& fixed_input_tags, const std::vector<secp256k1_generator>& ephemeral_input_tags, const std::vector<uint256>& input_asset_blinders, const uint256& output_asset_blinder, const secp256k1_generator& output_asset_tag, const CAsset& asset);
uint256 GenerateRangeproofECDHKey(CPubKey& ephemeral_pubkey, const CPubKey blinding_pubkey);
bool CreateValueRangeProof(std::vector<unsigned char>& rangeproof, const uint256& value_blinder, const uint256& nonce, const CAmount amount, const CScript& scriptPubKey, const secp256k1_pedersen_commitment& value_commit, const secp256k1_generator& gen, const CAsset& asset, const uint256& asset_blinder);

View file

@ -4813,8 +4813,9 @@ static RPCHelpMan walletprocesspsbt()
}
}
if (needs_blinding) {
if (pwallet->WalletBlindPSBT(psbtx) != BlindingStatus::OK) {
throw JSONRPCError(RPC_WALLET_ERROR, "Something went wrong");
BlindingStatus status = pwallet->WalletBlindPSBT(psbtx);
if (status != BlindingStatus::OK) {
throw JSONRPCError(RPC_WALLET_ERROR, GetBlindingStatusError(status));
}
}
@ -4873,8 +4874,9 @@ static RPCHelpMan walletblindpsbt()
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, strprintf("TX decode failed %s", error));
}
if (pwallet->WalletBlindPSBT(psbtx) != BlindingStatus::OK) {
throw JSONRPCError(RPC_WALLET_ERROR, "Something went wrong");
BlindingStatus status = pwallet->WalletBlindPSBT(psbtx);
if (status != BlindingStatus::OK) {
throw JSONRPCError(RPC_WALLET_ERROR, GetBlindingStatusError(status));
}
UniValue result(UniValue::VOBJ);