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

Add input signature_script checking to submitTransaction RPC #479

Merged
merged 12 commits into from
Jul 26, 2024
11 changes: 7 additions & 4 deletions rpc/core/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use kaspa_consensus_core::{subnets::SubnetworkConversionError, tx::TransactionId};
use kaspa_consensus_core::{subnets::SubnetworkConversionError, tx::TransactionId};
use kaspa_utils::networking::IpAddress;
use std::{net::AddrParseError, num::TryFromIntError};
use thiserror::Error;
Expand Down Expand Up @@ -47,6 +47,9 @@ pub enum RpcError {
#[error("Rejected transaction {0}: {1}")]
RejectedTransaction(RpcTransactionId, String),

#[error("Transaction {0} has an input with an empty signature_script at indices {1}.")]
EmptySignatureScript(RpcTransactionId, String),
KaffinPX marked this conversation as resolved.
Show resolved Hide resolved

#[error("Block {0} is invalid. No verbose data can be built.")]
InvalidBlock(RpcHash),

Expand Down Expand Up @@ -116,9 +119,9 @@ pub enum RpcError {
#[error("transaction query must either not filter transactions or include orphans")]
InconsistentMempoolTxQuery,

#[error(transparent)]
SubnetParsingError(#[from] SubnetworkConversionError),
#[error(transparent)]
SubnetParsingError(#[from] SubnetworkConversionError),

#[error(transparent)]
WasmError(#[from] workflow_wasm::error::Error),

Expand Down
9 changes: 9 additions & 0 deletions rpc/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,15 @@ NOTE: This error usually indicates an RPC conversion error between the node and

let transaction: Transaction = (&request.transaction).try_into()?;
let transaction_id = transaction.id();
let inputs = &transaction.inputs;

let empty_indices: Vec<usize> =
inputs.iter().enumerate().filter_map(|(index, input)| (input.signature_script.is_empty()).then(|| index)).collect();
KaffinPX marked this conversation as resolved.
Show resolved Hide resolved
if !empty_indices.is_empty() {
KaffinPX marked this conversation as resolved.
Show resolved Hide resolved
let indices_str = empty_indices.iter().map(|index| index.to_string()).collect::<Vec<_>>().join(", ");
return Err(RpcError::EmptySignatureScript(transaction_id, indices_str));
}

let session = self.consensus_manager.consensus().unguarded_session();
let orphan = match allow_orphan {
true => Orphan::Allowed,
Expand Down
Loading