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 index {1}.")]
EmptySignatureScript(RpcTransactionId, usize),

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
7 changes: 7 additions & 0 deletions rpc/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,13 @@ 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;

if let Some((index, _)) = inputs.iter().enumerate().find(|(_, input)| input.signature_script.is_empty()) {
let err = RpcError::EmptySignatureScript(transaction_id, index);
return Err(err)
KaffinPX marked this conversation as resolved.
Show resolved Hide resolved
}

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