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

Always fail bad nonce on validation #2465

Merged
merged 4 commits into from
Sep 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
28 changes: 2 additions & 26 deletions lib/ain-evm/src/core.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::cmp::Ordering;
use std::{path::PathBuf, sync::Arc};

use crate::fee::calculate_prepay_gas_fee;
Expand Down Expand Up @@ -47,7 +46,6 @@ pub struct ValidateTxInfo {
pub signed_tx: SignedTx,
pub prepay_fee: U256,
pub higher_nonce: bool,
pub lower_nonce: bool,
}

fn init_vsdb(path: PathBuf) {
Expand Down Expand Up @@ -281,34 +279,13 @@ impl EVMCoreService {
.into());
}

let higher_nonce = nonce < signed_tx.nonce();
return Ok(ValidateTxInfo {
signed_tx,
prepay_fee,
higher_nonce: false,
lower_nonce: false,
higher_nonce,
});
} else {
// Should be queued for now and don't go through VM validation
match signed_tx.nonce().cmp(&nonce) {
Ordering::Greater => {
return Ok(ValidateTxInfo {
signed_tx,
prepay_fee,
higher_nonce: true,
lower_nonce: false,
});
}
Ordering::Less => {
return Ok(ValidateTxInfo {
signed_tx,
prepay_fee,
higher_nonce: false,
lower_nonce: true,
});
}
_ => {}
}

// Validate tx prepay fees with account balance
let balance = backend.get_balance(&signed_tx.sender);
debug!("[validate_raw_tx] Account balance : {:x?}", balance);
Expand Down Expand Up @@ -341,7 +318,6 @@ impl EVMCoreService {
signed_tx,
prepay_fee,
higher_nonce: false,
lower_nonce: false,
})
}

Expand Down
4 changes: 0 additions & 4 deletions lib/ain-rs-exports/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,6 @@ pub fn evm_unsafe_try_prevalidate_raw_tx_in_q(
signed_tx,
prepay_fee,
higher_nonce,
lower_nonce,
}) => {
let Ok(nonce) = u64::try_from(signed_tx.nonce()) else {
return cross_boundary_error_return(result, "nonce value overflow");
Expand All @@ -492,7 +491,6 @@ pub fn evm_unsafe_try_prevalidate_raw_tx_in_q(
tx_hash: format!("{:?}", signed_tx.hash()),
prepay_fee,
higher_nonce,
lower_nonce,
},
)
}
Expand Down Expand Up @@ -548,7 +546,6 @@ pub fn evm_unsafe_try_validate_raw_tx_in_q(
signed_tx,
prepay_fee,
higher_nonce,
lower_nonce,
}) => {
let Ok(nonce) = u64::try_from(signed_tx.nonce()) else {
return cross_boundary_error_return(result, "nonce value overflow");
Expand All @@ -566,7 +563,6 @@ pub fn evm_unsafe_try_validate_raw_tx_in_q(
tx_hash: format!("{:?}", signed_tx.hash()),
prepay_fee,
higher_nonce,
lower_nonce,
},
)
}
Expand Down
1 change: 0 additions & 1 deletion lib/ain-rs-exports/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ pub mod ffi {
pub tx_hash: String,
pub prepay_fee: u64,
pub higher_nonce: bool,
pub lower_nonce: bool,
}

extern "Rust" {
Expand Down
8 changes: 2 additions & 6 deletions src/masternodes/consensus/xvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,20 +349,16 @@ Res CXVMConsensus::operator()(const CEvmTxMessage &obj) const {
return Res::Err("evm tx size too large");

CrossBoundaryResult result;
ValidateTxCompletion validateResults;
if (evmPreValidate) {
validateResults = evm_unsafe_try_prevalidate_raw_tx_in_q(result, evmQueueId, HexStr(obj.evmTx));
evm_unsafe_try_prevalidate_raw_tx_in_q(result, evmQueueId, HexStr(obj.evmTx));
if (!result.ok) {
LogPrintf("[evm_try_prevalidate_raw_tx] failed, reason : %s\n", result.reason);
return Res::Err("evm tx failed to pre-validate %s", result.reason);
}
return Res::Ok();
}

validateResults = evm_unsafe_try_validate_raw_tx_in_q(result, evmQueueId, HexStr(obj.evmTx));
if (validateResults.higher_nonce) {
return Res::Ok();
}
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);
Expand Down
2 changes: 1 addition & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ bool BlockAssembler::EvmTxPreapply(EvmTxPreApplyContext& ctx)
const auto obj = std::get<CEvmTxMessage>(txMessage);

ValidateTxCompletion txResult;
txResult = evm_unsafe_try_validate_raw_tx_in_q(result, evmQueueId, HexStr(obj.evmTx));
txResult = evm_unsafe_try_prevalidate_raw_tx_in_q(result, evmQueueId, HexStr(obj.evmTx));
if (!result.ok) {
return false;
}
Expand Down