Skip to content

Commit

Permalink
Shift transfer domain invalid data size check into prevalidate (#2469)
Browse files Browse the repository at this point in the history
  • Loading branch information
sieniven authored Sep 19, 2023
1 parent 9620968 commit 63132f3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/masternodes/consensus/xvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ Res CXVMConsensus::operator()(const CTransferDomainMessage &obj) const {
return DeFiErrors::TransferDomainSmartContractDestAddress();
}

if (dst.data.size() > MAX_TRANSFERDOMAIN_EVM_DATA_LEN) {
return DeFiErrors::TransferDomainInvalidDataSize(MAX_TRANSFERDOMAIN_EVM_DATA_LEN);
}
const auto evmTx = HexStr(dst.data);
auto hash = evm_try_get_tx_hash(result, evmTx);
if (!result.ok) {
Expand Down Expand Up @@ -272,6 +275,9 @@ Res CXVMConsensus::operator()(const CTransferDomainMessage &obj) const {
return DeFiErrors::TransferDomainSmartContractSourceAddress();
}

if (src.data.size() > MAX_TRANSFERDOMAIN_EVM_DATA_LEN) {
return DeFiErrors::TransferDomainInvalidDataSize(MAX_TRANSFERDOMAIN_EVM_DATA_LEN);
}
const auto evmTx = HexStr(src.data);
auto hash = evm_try_get_tx_hash(result, evmTx);
if (!result.ok) {
Expand Down Expand Up @@ -320,10 +326,6 @@ Res CXVMConsensus::operator()(const CTransferDomainMessage &obj) const {
else {
return DeFiErrors::TransferDomainInvalidDomain();
}

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);
}
}

auto txHash = tx.GetHash().GetHex();
Expand Down Expand Up @@ -359,7 +361,6 @@ Res CXVMConsensus::operator()(const CEvmTxMessage &obj) const {
}

const auto validateResults = evm_unsafe_try_validate_raw_tx_in_q(result, evmQueueId, HexStr(obj.evmTx));

if (!result.ok) {
LogPrintf("[evm_try_validate_raw_tx_in_q] failed, reason : %s\n", result.reason);
return Res::Err("evm tx failed to validate %s\n", result.reason);
Expand Down

0 comments on commit 63132f3

Please sign in to comment.