Transaction floData length limits

This commit is contained in:
Jeremiah Buddenhagen 2018-02-23 17:47:06 -08:00
parent aeb784e398
commit 7cba348b45
5 changed files with 27 additions and 8 deletions

View File

@ -274,6 +274,8 @@ public:
// Default transaction version. // Default transaction version.
static const int32_t CURRENT_VERSION=2; static const int32_t CURRENT_VERSION=2;
static const int32_t MAX_FLO_DATA_SIZE=1040;
// Changing the default transaction version requires a two step process: first // Changing the default transaction version requires a two step process: first
// adapting relay policy by bumping MAX_STANDARD_VERSION, and then later date // adapting relay policy by bumping MAX_STANDARD_VERSION, and then later date
// bumping the default CURRENT_VERSION at which point both CURRENT_VERSION and // bumping the default CURRENT_VERSION at which point both CURRENT_VERSION and

View File

@ -19,6 +19,7 @@
#include "base58.h" #include "base58.h"
#include "chainparams.h" #include "chainparams.h"
#include "wallet/coincontrol.h" #include "wallet/coincontrol.h"
#include "primitives/transaction.h" // FloData size limits
#include "validation.h" // mempool and minRelayTxFee #include "validation.h" // mempool and minRelayTxFee
#include "ui_interface.h" #include "ui_interface.h"
#include "txmempool.h" #include "txmempool.h"
@ -133,6 +134,8 @@ SendCoinsDialog::SendCoinsDialog(const PlatformStyle *_platformStyle, QWidget *p
ui->customFee->setValue(settings.value("nTransactionFee").toLongLong()); ui->customFee->setValue(settings.value("nTransactionFee").toLongLong());
ui->checkBoxMinimumFee->setChecked(settings.value("fPayOnlyMinFee").toBool()); ui->checkBoxMinimumFee->setChecked(settings.value("fPayOnlyMinFee").toBool());
minimizeFeeSection(settings.value("fFeeSectionMinimized").toBool()); minimizeFeeSection(settings.value("fFeeSectionMinimized").toBool());
ui->floData->setMaxLength(CTransaction::MAX_FLO_DATA_SIZE-5); // room for "text:" prefix
} }
void SendCoinsDialog::setClientModel(ClientModel *_clientModel) void SendCoinsDialog::setClientModel(ClientModel *_clientModel)

View File

@ -353,6 +353,10 @@ UniValue createrawtransaction(const JSONRPCRequest& request)
rawTx.strFloData = request.params[4].get_str(); rawTx.strFloData = request.params[4].get_str();
} }
if (rawTx.strFloData.length() > CTransaction::MAX_FLO_DATA_SIZE) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, Flo Data too large");
}
for (unsigned int idx = 0; idx < inputs.size(); idx++) { for (unsigned int idx = 0; idx < inputs.size(); idx++) {
const UniValue& input = inputs[idx]; const UniValue& input = inputs[idx];
const UniValue& o = input.get_obj(); const UniValue& o = input.get_obj();
@ -612,6 +616,9 @@ UniValue combinerawtransaction(const JSONRPCRequest& request)
// starts as a clone of the rawtx: // starts as a clone of the rawtx:
CMutableTransaction mergedTx(txVariants[0]); CMutableTransaction mergedTx(txVariants[0]);
mergedTx.strFloData = strFloData; mergedTx.strFloData = strFloData;
if (mergedTx.strFloData.length() > CTransaction::MAX_FLO_DATA_SIZE) {
throw JSONRPCError(RPC_VERIFY_ERROR, "Flo Data too large");
}
// Fetch previous transactions (inputs): // Fetch previous transactions (inputs):
CCoinsView viewDummy; CCoinsView viewDummy;
@ -935,6 +942,11 @@ UniValue sendrawtransaction(const JSONRPCRequest& request)
CMutableTransaction mtx; CMutableTransaction mtx;
if (!DecodeHexTx(mtx, request.params[0].get_str())) if (!DecodeHexTx(mtx, request.params[0].get_str()))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
if (mtx.strFloData.length() > CTransaction::MAX_FLO_DATA_SIZE) {
throw JSONRPCError(RPC_TRANSACTION_ERROR, "Flo Data too large");
}
CTransactionRef tx(MakeTransactionRef(std::move(mtx))); CTransactionRef tx(MakeTransactionRef(std::move(mtx)));
const uint256& hashTx = tx->GetHash(); const uint256& hashTx = tx->GetHash();

View File

@ -461,14 +461,8 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
return state.DoS(0, false, REJECT_NONSTANDARD, "no-witness-yet", true); return state.DoS(0, false, REJECT_NONSTANDARD, "no-witness-yet", true);
} }
if (tx.nVersion >= 2) { if (tx.strFloData.length() > CTransaction::MAX_FLO_DATA_SIZE) {
int maxCommentLen = 528; return state.DoS(0, false, REJECT_INVALID, "flo-data-too-large");
if (witnessEnabled) {
maxCommentLen = 1040;
}
if (tx.strFloData.length() > maxCommentLen) {
return state.DoS(0, false, REJECT_INVALID, "flo-data-too-large");
}
} }
// Rather not work on nonstandard transactions (unless -testnet/-regtest) // Rather not work on nonstandard transactions (unless -testnet/-regtest)

View File

@ -379,6 +379,10 @@ static void SendMoney(CWallet * const pwallet, const CTxDestination &address, CA
{ {
CAmount curBalance = pwallet->GetBalance(); CAmount curBalance = pwallet->GetBalance();
if (strFloData.length() > CTransaction::MAX_FLO_DATA_SIZE) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Flo data too long");
}
// Check amount // Check amount
if (nValue <= 0) if (nValue <= 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount");
@ -1065,6 +1069,10 @@ UniValue sendmany(const JSONRPCRequest& request)
if (totalAmount > nBalance) if (totalAmount > nBalance)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
if (strFloData.length() > CTransaction::MAX_FLO_DATA_SIZE) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Flo data too long");
}
// Send // Send
CReserveKey keyChange(pwallet); CReserveKey keyChange(pwallet);
CAmount nFeeRequired = 0; CAmount nFeeRequired = 0;