Skip to content

Commit

Permalink
Cap data in transferdomain (#2058)
Browse files Browse the repository at this point in the history
* Cap data in transferdomain

* Add check for empty data field

* Protect against fork on Changi

* Add Changi intermediate fork to test

* test: update argument name after merge
  • Loading branch information
Bushstar authored Jun 19, 2023
1 parent f5ac32c commit 1248c50
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 104 deletions.
14 changes: 9 additions & 5 deletions src/masternodes/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

class DeFiErrors {
public:
static Res MNInvalid(const std::string &nodeRefString) {
static Res MNInvalid(const std::string &nodeRefString) {
return Res::Err("node %s does not exists", nodeRefString);
}

static Res MNInvalidAltMsg(const std::string &nodeRefString) {
static Res MNInvalidAltMsg(const std::string &nodeRefString) {
return Res::Err("masternode %s does not exist", nodeRefString);
}

static Res MNStateNotEnabled(const std::string &nodeRefString) {
static Res MNStateNotEnabled(const std::string &nodeRefString) {
return Res::Err("Masternode %s is not in 'ENABLED' state", nodeRefString);
}

Expand Down Expand Up @@ -178,8 +178,8 @@ class DeFiErrors {
return Res::Err("Negative price (%s/%s)", tokenSymbol, currency);
}

static Res AmountOverflowAsValuePrice(const CAmount amount, const CAmount price) {
return Res::Err("Value/price too high (%s/%s)", GetDecimalString(amount), GetDecimalString(price));
static Res AmountOverflowAsValuePrice(const CAmount amount, const CAmount price) {
return Res::Err("Value/price too high (%s/%s)", GetDecimalString(amount), GetDecimalString(price));
}

static Res GovVarVerifyInt() {
Expand Down Expand Up @@ -398,6 +398,10 @@ class DeFiErrors {
return Res::Err("Not enough balance in %s to cover \"EVM\" domain transfer", address);
}

static Res TransferDomainInvalidDataSize(const uint32_t max_data) {
return Res::Err("Excess data set, maximum allow is %d", max_data);
}

static Res InvalidAuth() {
return Res::Err("tx must have at least one input from account owner");
}
Expand Down
9 changes: 9 additions & 0 deletions src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3853,6 +3853,15 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor {
balanceIn *= CAMOUNT_TO_GWEI * WEI_IN_GWEI;
evm_add_balance(evmContext, HexStr(toAddress.begin(), toAddress.end()), ArithToUint256(balanceIn).ToArrayReversed(), tx.GetHash().ToArrayReversed());
}

// If you are here to change ChangiIntermediateHeight to NextNetworkUpgradeHeight
// then just remove this fork guard and comment as CTransferDomainMessage is already
// protected by NextNetworkUpgradeHeight.
if (height >= static_cast<uint32_t>(consensus.ChangiIntermediateHeight)) {
if (src.data.size() > MAX_TRANSFERDOMAIN_EVM_DATA_LEN || dst.data.size() > MAX_TRANSFERDOMAIN_EVM_DATA_LEN) {
return DeFiErrors::TransferDomainInvalidDataSize(MAX_TRANSFERDOMAIN_EVM_DATA_LEN);
}
}
}

return res;
Expand Down
2 changes: 2 additions & 0 deletions src/masternodes/mn_checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ enum AuthStrategy: uint32_t {

constexpr uint8_t MAX_POOL_SWAPS = 3;

constexpr uint32_t MAX_TRANSFERDOMAIN_EVM_DATA_LEN = 0;

enum CustomTxErrCodes : uint32_t {
NotSpecified = 0,
// NotCustomTx = 1,
Expand Down
Loading

0 comments on commit 1248c50

Please sign in to comment.