Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject sending UTXO to Eth addresses #2083

Merged
merged 1 commit into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/rpc/rawtransaction_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal
}
CScript scriptPubKey = GetScriptForDestination(destination);

RejectEthAddress(scriptPubKey);

auto amounts = DecodeAmounts(chain, outputs[name_], name_);
for (auto const & kv : amounts.balances) {
CTxOut out(kv.second, scriptPubKey, kv.first);
Expand Down
4 changes: 4 additions & 0 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ static UniValue sendtoaddress(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
}

RejectEthAddress(GetScriptForDestination(dest));

// Amount
CTokenAmount const tokenAmount = DecodeAmount(pwallet->chain(), request.params[1], request.params[0].get_str()); // don't support multiple tokens due to "SendMoney()" compatibility

Expand Down Expand Up @@ -922,6 +924,8 @@ static UniValue sendmany(const JSONRPCRequest& request)

for (auto const & scriptBalances : recip) {

RejectEthAddress(scriptBalances.first);

bool fSubtractFeeFromAmount = false;
for (unsigned int idx = 0; idx < subtractFeeFromAmount.size(); idx++) {
const UniValue& addr = subtractFeeFromAmount[idx];
Expand Down
6 changes: 5 additions & 1 deletion test/functional/feature_evm.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def run_test(self):
self.nodes[0].getbalance()

# Fund DFI address
self.nodes[0].utxostoaccount({address: "101@DFI"})
txid = self.nodes[0].utxostoaccount({address: "101@DFI"})
self.nodes[0].generate(1)
self.sync_blocks()

Expand All @@ -107,6 +107,10 @@ def run_test(self):
assert_equal(len(self.nodes[0].getaccount(ethAddress, {}, True)), 0)

# Check for invalid parameters in transferdomain rpc
assert_raises_rpc_error(-5, "Eth type addresses are not valid", self.nodes[0].createrawtransaction, [{'txid': txid, 'vout': 1}], [{ethAddress: 1}])
assert_raises_rpc_error(-5, "Eth type addresses are not valid", self.nodes[0].sendmany, "", {ethAddress: 1})
assert_raises_rpc_error(-5, "Eth type addresses are not valid", self.nodes[0].sendmany, "", {ethAddress: 1})
assert_raises_rpc_error(-5, "Eth type addresses are not valid", self.nodes[0].sendtoaddress, ethAddress, 1)
assert_raises_rpc_error(-5, "Eth type addresses are not valid", self.nodes[0].accounttoaccount, address, {ethAddress: "1@DFI"})
assert_raises_rpc_error(-8, "Invalid parameters, src argument \"address\" must not be null", self.nodes[0].transferdomain, [{"src": {"amount":"100@DFI", "domain": 2}, "dst":{"address":ethAddress, "amount":"100@DFI", "domain": 3}}])
assert_raises_rpc_error(-8, "Invalid parameters, src argument \"amount\" must not be null", self.nodes[0].transferdomain, [{"src": {"address":address, "domain": 2}, "dst":{"address":ethAddress, "amount":"100@DFI", "domain": 3}}])
Expand Down