From 348306d6f4001d7029ec6ae05271286a14516a1a Mon Sep 17 00:00:00 2001 From: blondfrogs Date: Thu, 23 Aug 2018 10:07:08 -0600 Subject: [PATCH 1/2] Check Units when issuing assets --- src/assets/assets.cpp | 58 ++++++++++++++++++++++-------- src/assets/assets.h | 2 ++ src/consensus/tx_verify.cpp | 5 ++- src/test/assets/asset_tx_tests.cpp | 58 ++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 17 deletions(-) diff --git a/src/assets/assets.cpp b/src/assets/assets.cpp index eb5865554a..c520b63a00 100644 --- a/src/assets/assets.cpp +++ b/src/assets/assets.cpp @@ -239,28 +239,52 @@ bool CNewAsset::IsValid(std::string& strError, CAssetsCache& assetCache, bool fC } } - if (!IsAssetNameValid(std::string(strName))) + if (!IsAssetNameValid(std::string(strName))) { strError = "Invalid parameter: asset_name must only consist of valid characters and have a size between 3 and 30 characters. See help for more details."; + return false; + } - if (IsAssetNameAnOwner(std::string(strName))) + if (IsAssetNameAnOwner(std::string(strName))) { strError = "Invalid parameters: asset_name can't have a '!' at the end of it. See help for more details."; + return false; + } - if (nAmount <= 0) - strError = "Invalid parameter: asset amount can't be equal to or less than zero."; + if (nAmount <= 0) { + strError = "Invalid parameter: asset amount can't be equal to or less than zero."; + return false; + } - if (units < 0 || units > 8) - strError = "Invalid parameter: units must be between 0-8."; + if (nAmount > MAX_MONEY) { + strError = "Invalid parameter: asset amount greater than max."; + return false; + } - if (nReissuable != 0 && nReissuable != 1) - strError = "Invalid parameter: reissuable must be 0 or 1"; + if (units < 0 || units > 8) { + strError = "Invalid parameter: units must be between 0-8."; + return false; + } - if (nHasIPFS != 0 && nHasIPFS != 1) - strError = "Invalid parameter: has_ipfs must be 0 or 1."; + if (!CheckAmountWithUnits(nAmount, units)) { + strError = "bad-txns-transfer-asset-amount-not-match-units"; + return false; + } - if (nHasIPFS && strIPFSHash.size() != 34) - strError = "Invalid parameter: ipfs_hash must be 34 bytes."; + if (nReissuable != 0 && nReissuable != 1) { + strError = "Invalid parameter: reissuable must be 0 or 1"; + return false; + } - return strError == ""; + if (nHasIPFS != 0 && nHasIPFS != 1) { + strError = "Invalid parameter: has_ipfs must be 0 or 1."; + return false; + } + + if (nHasIPFS && strIPFSHash.size() != 34) { + strError = "Invalid parameter: ipfs_hash must be 34 bytes."; + return false; + } + + return true; } CNewAsset::CNewAsset(const CNewAsset& asset) @@ -696,7 +720,7 @@ bool CReissueAsset::IsValid(std::string &strError, CAssetsCache& assetCache) con return false; } - if (nAmount % int64_t(pow(10, (MAX_UNIT - asset.units))) != 0) { + if (!CheckAmountWithUnits(nAmount, asset.units)) { strError = "Unable to reissue asset: amount must be divisable by the smaller unit assigned to the asset"; return false; } @@ -2472,4 +2496,10 @@ bool VerifyWalletHasAsset(const std::string& asset_name, std::pair Date: Thu, 23 Aug 2018 10:34:12 -0600 Subject: [PATCH 2/2] Update error messages --- src/assets/assets.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/assets/assets.cpp b/src/assets/assets.cpp index c520b63a00..b37f7f218b 100644 --- a/src/assets/assets.cpp +++ b/src/assets/assets.cpp @@ -255,7 +255,7 @@ bool CNewAsset::IsValid(std::string& strError, CAssetsCache& assetCache, bool fC } if (nAmount > MAX_MONEY) { - strError = "Invalid parameter: asset amount greater than max."; + strError = "Invalid parameter: asset amount greater than max money: " + MAX_MONEY / COIN; return false; } @@ -265,7 +265,7 @@ bool CNewAsset::IsValid(std::string& strError, CAssetsCache& assetCache, bool fC } if (!CheckAmountWithUnits(nAmount, units)) { - strError = "bad-txns-transfer-asset-amount-not-match-units"; + strError = "Invalid parameter: amount must be divisible by the smaller unit assigned to the asset"; return false; } @@ -721,7 +721,7 @@ bool CReissueAsset::IsValid(std::string &strError, CAssetsCache& assetCache) con } if (!CheckAmountWithUnits(nAmount, asset.units)) { - strError = "Unable to reissue asset: amount must be divisable by the smaller unit assigned to the asset"; + strError = "Unable to reissue asset: amount must be divisible by the smaller unit assigned to the asset"; return false; }