Skip to content

fix: ignore special transactions on block version 0 (pre DIP-0002)#675

Merged
QuantumExplorer merged 2 commits intodashpay:v0.42-devfrom
owl352:feat/fix-tx-type
May 4, 2026
Merged

fix: ignore special transactions on block version 0 (pre DIP-0002)#675
QuantumExplorer merged 2 commits intodashpay:v0.42-devfrom
owl352:feat/fix-tx-type

Conversation

@owl352
Copy link
Copy Markdown
Contributor

@owl352 owl352 commented Apr 22, 2026

Issue

There is one malformed block in mainnet network with special transaction type set to 8192 on pre DIP-0002 blocks. This is a block before special transaction were introduced in the network, and shouldn't even been set to 8192 (it should have been just 0), however Dash Core software tolerated this and as a result such block was included in the chain.

Rust dashcore, when tries to decode such block from hex, tries to decode the field but fails to match to any known special transaction type from the codebase eventually failing with:

Failed to decode transactions for block 000000000000000cdf5cc24c3beb0669b31e942d1301e07b53d6f0c7db10860d: unknown special transaction type: 8192

Here is the reference for that block
842284

Proposed solution

Simply decode all transaction as TransactionType::Classic if the block version is 0

Summary by CodeRabbit

  • Bug Fixes
    • Improved transaction deserialization logic to correctly process transactions across different version encodings, ensuring accurate type field interpretation.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 22, 2026

📝 Walkthrough

Walkthrough

Transaction deserialization now conditionally interprets the special_transaction_type field based on the version value. For non-zero versions, it attempts TransactionType::try_from with error mapping. For version 0, it unconditionally assigns TransactionType::Classic.

Changes

Transaction Deserialization Logic

Layer / File(s) Summary
Consensus Decode Conditional
dash/src/blockdata/transaction/mod.rs
special_transaction_type decoding now branches on version: non-zero versions use try_from with UnknownSpecialTransactionType error mapping; version 0 forces TransactionType::Classic instead of attempting conversion.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A version's tale, now split in two,

Where zero hops to Classic true,

While others leap through types anew,

Consensus blocks in shades of blue! 🎲✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main fix: ignoring special transaction types on block version 0 transactions to handle pre-DIP-0002 blocks, which aligns with the changeset's core purpose.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@pshenmic pshenmic changed the title fix: Error on deserialization old coinbase transactions fix: ignore special transactions on block version 0 (pre DIP-0002) Apr 22, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 68.76%. Comparing base (5f40cf8) to head (bfd2d11).
⚠️ Report is 38 commits behind head on v0.42-dev.

Files with missing lines Patch % Lines
dash/src/blockdata/transaction/mod.rs 75.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##           v0.42-dev     #675      +/-   ##
=============================================
+ Coverage      68.07%   68.76%   +0.69%     
=============================================
  Files            319      320       +1     
  Lines          67661    67939     +278     
=============================================
+ Hits           46057    46721     +664     
+ Misses         21604    21218     -386     
Flag Coverage Δ
core 75.68% <75.00%> (+0.15%) ⬆️
ffi 40.88% <ø> (+2.94%) ⬆️
rpc 20.00% <ø> (ø)
spv 85.81% <ø> (-0.02%) ⬇️
wallet 68.75% <ø> (+0.70%) ⬆️
Files with missing lines Coverage Δ
dash/src/blockdata/transaction/mod.rs 86.17% <75.00%> (+0.02%) ⬆️

... and 36 files with indirect coverage changes

Copy link
Copy Markdown
Member

@QuantumExplorer QuantumExplorer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed

@QuantumExplorer QuantumExplorer marked this pull request as ready for review May 4, 2026 19:21
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
dash/src/blockdata/transaction/mod.rs (1)

595-606: ⚡ Quick win

Add a regression test for the malformed version-0 encoding.

This branch needs a unit test with a raw version-0 transaction whose type field is non-zero, so the mainnet edge case stays covered. At minimum, assert that deserialization succeeds and that the intended round-trip / txid behavior is locked in.

As per coding guidelines, **/*.rs: Write unit tests for new functionality.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dash/src/blockdata/transaction/mod.rs` around lines 595 - 606, Add a unit
test that constructs a raw version-0 transaction byte stream whose "type" field
is non-zero and verifies deserialization succeeds and txid/round-trip behavior
is preserved: create the test inside the transaction module (#[cfg(test)] mod
tests) and feed the bytes to Transaction::consensus_decode_from_finite_reader
(or the module's consensus_decode_from_finite_reader) to ensure it returns
Ok(Transaction) rather than an UnknownSpecialTransactionType error; then
re-serialize or compute the txid from the resulting Transaction and assert it
matches the expected/round-tripped value. Use TransactionType and encode::Error
in assertions to ensure the version-0 special-case remains covered.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@dash/src/blockdata/transaction/mod.rs`:
- Around line 600-606: The fix must preserve the original on-wire
special_transaction_type_u16 for version == 0 while still treating it as
TransactionType::Classic for logic; update the struct/backing fields used by
TransactionType::try_from so that the raw u16 (or the full raw version word) is
stored (e.g., add/keep a raw_special_tx_type field) and use
TransactionType::Classic only for behavior, but have consensus_encode(), txid(),
and tx_type() re-emit the preserved raw u16 when serializing/hashing; change the
deserialization branch around
TransactionType::try_from(special_transaction_type_u16) so version == 0 assigns
TransactionType::Classic but also saves special_transaction_type_u16 into the
raw field, and update consensus_encode()/txid()/tx_type() to prefer the raw
field for output.

---

Nitpick comments:
In `@dash/src/blockdata/transaction/mod.rs`:
- Around line 595-606: Add a unit test that constructs a raw version-0
transaction byte stream whose "type" field is non-zero and verifies
deserialization succeeds and txid/round-trip behavior is preserved: create the
test inside the transaction module (#[cfg(test)] mod tests) and feed the bytes
to Transaction::consensus_decode_from_finite_reader (or the module's
consensus_decode_from_finite_reader) to ensure it returns Ok(Transaction) rather
than an UnknownSpecialTransactionType error; then re-serialize or compute the
txid from the resulting Transaction and assert it matches the
expected/round-tripped value. Use TransactionType and encode::Error in
assertions to ensure the version-0 special-case remains covered.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0c9f0d00-6de1-4368-aa7d-be50d2abebe8

📥 Commits

Reviewing files that changed from the base of the PR and between 90a41df and bfd2d11.

📒 Files selected for processing (1)
  • dash/src/blockdata/transaction/mod.rs

Comment on lines +600 to +606
let special_transaction_type = if version != 0 {
TransactionType::try_from(special_transaction_type_u16).map_err(|_| {
encode::Error::UnknownSpecialTransactionType(special_transaction_type_u16)
})?;
})?
} else {
TransactionType::Classic
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Preserve the raw type bits for version-0 transactions.

Line 600 fixes deserialization, but it also drops the original on-wire special_transaction_type_u16 when version == 0. After that, consensus_encode() and txid() re-emit/hash self.tx_type() as 0, so this malformed mainnet transaction no longer round-trips and its IDs can change after decode. If we need to treat pre-DIP-0002 transactions as Classic, we still need to retain the raw u16 (or full raw version word) somewhere so serialization and hashing stay faithful to the chain data.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dash/src/blockdata/transaction/mod.rs` around lines 600 - 606, The fix must
preserve the original on-wire special_transaction_type_u16 for version == 0
while still treating it as TransactionType::Classic for logic; update the
struct/backing fields used by TransactionType::try_from so that the raw u16 (or
the full raw version word) is stored (e.g., add/keep a raw_special_tx_type
field) and use TransactionType::Classic only for behavior, but have
consensus_encode(), txid(), and tx_type() re-emit the preserved raw u16 when
serializing/hashing; change the deserialization branch around
TransactionType::try_from(special_transaction_type_u16) so version == 0 assigns
TransactionType::Classic but also saves special_transaction_type_u16 into the
raw field, and update consensus_encode()/txid()/tx_type() to prefer the raw
field for output.

@QuantumExplorer QuantumExplorer merged commit 7dc1225 into dashpay:v0.42-dev May 4, 2026
42 of 43 checks passed
QuantumExplorer added a commit that referenced this pull request May 4, 2026
…ons (#726)

PR #675 made version=0 transactions decode as Classic, but it dropped
the original on-wire `nTxType` u16. After decode, `consensus_encode`/
`txid` re-emitted `tx_type()` as 0, breaking byte-exact round-trip and
changing the txid for the malformed mainnet transaction.

Add a `TransactionType::ClassicalWithNonStandardVersionTypeBytes(u16)`
variant (and a matching pseudo-payload `TransactionPayload::
ClassicalWithNonStandardVersionTypeBytesPayloadType(u16)`) that carry
the raw u16 read from the wire. Encoding, txid, and sighash now emit
those bytes verbatim, and the encoder skips the payload section since
pre-DIP-0002 transactions have no payload section on the wire (not even
a length prefix).

`#[repr(u16)]` is dropped from `TransactionType` since the enum is no
longer field-less; replaced `(... as u16)` casts with a new `to_u16()`
method.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants