From a6274034921f6af8d5eeba560307653fac1180cb Mon Sep 17 00:00:00 2001 From: Kayos Date: Thu, 7 May 2026 16:24:34 -0700 Subject: [PATCH] diag: reproducer also reports script bytes-header consistency --- .../examples/repro_script_corruption.rs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/crates/aldabra-dao/examples/repro_script_corruption.rs b/crates/aldabra-dao/examples/repro_script_corruption.rs index a0376f1..240f478 100644 --- a/crates/aldabra-dao/examples/repro_script_corruption.rs +++ b/crates/aldabra-dao/examples/repro_script_corruption.rs @@ -91,6 +91,48 @@ fn main() { if let Some(pos) = find_subseq(&tx_bytes, &script_bytes) { println!("✅ FOUND input script bytes verbatim at tx-body offset {}", pos); println!(" pallas-txbuilder serialized them clean."); + + // BUT: check the bytes-header that precedes them. In CBOR, a + // bytestring of length N has a leader byte of 0x40+N for N<24, + // 0x58 + 1 length byte for N<=255, 0x59 + 2 length bytes for + // N<=65535. For 7213, header = 0x59 0x1c 0x2d. If the header + // claims a different length, encoding is inconsistent. + if pos >= 3 { + let h = &tx_bytes[pos - 3..pos]; + println!( + " bytes-header preceding script: {:02x} {:02x} {:02x}", + h[0], h[1], h[2] + ); + if h[0] == 0x59 { + let claimed_len = u16::from_be_bytes([h[1], h[2]]) as usize; + if claimed_len == script_bytes.len() { + println!( + " ✅ header length {} == input length {} — consistent.", + claimed_len, + script_bytes.len() + ); + } else { + println!( + " ❌ header length {} != input length {} — encoder is OFF BY {}.", + claimed_len, + script_bytes.len(), + script_bytes.len() as i64 - claimed_len as i64 + ); + } + } else { + println!( + " ⚠️ preceding byte not 0x59 (uint16 bytes header) — different size class?" + ); + } + } + + // Print the very first 100 bytes of tx body for inspection + let preview_len = 100.min(tx_bytes.len()); + let preview: String = tx_bytes[..preview_len] + .iter() + .map(|b| format!("{:02x}", b)) + .collect(); + println!(" tx body first {} bytes: {}", preview_len, preview); } else { println!("❌ DID NOT find input script bytes verbatim in tx body."); println!(" pallas-txbuilder mutated the bytes during encoding.");