diag: also exercise aldabra-core's build_unsigned_payment_extras

This commit is contained in:
Kayos 2026-05-07 16:30:20 -07:00
parent f685e53889
commit 288e5815a0

View file

@ -21,6 +21,8 @@ use std::env;
use std::fs;
use aldabra_core::hex_decode as aldabra_hex_decode;
use aldabra_core::tx::build_unsigned_payment_extras;
use aldabra_core::{InputUtxo, Network, ProtocolParams, ReferenceScriptSpec};
use pallas_addresses::Address;
use pallas_crypto::hash::Hash;
use pallas_txbuilder::{BuildConway, Input, Output as TxOutput, ScriptKind, StagingTransaction};
@ -185,6 +187,72 @@ fn main() {
}
}
// ---- ALSO try the FULL aldabra path (build_unsigned_payment_extras) ----
println!();
println!("=== Now testing full aldabra build_unsigned_payment_extras path ===");
// Need a fake wallet UTxO + fake change address. Use a preprod-style
// bech32 address for both.
let fake_wallet_addr =
"addr_test1qpxdvx7k0mtjc88vzc9l0hnpq0rtmkee0kn22qxufluqt793h8qx99hfs34pm5lwmkv4kga4d7zxm3gflqm8x2l6wvgs7x7wax";
let fake_to_addr = fake_wallet_addr;
let fake_utxo = InputUtxo {
tx_hash_hex: "0".repeat(64),
output_index: 0,
lovelace: 100_000_000_000,
assets: Default::default(),
};
let ref_spec = ReferenceScriptSpec {
kind: ScriptKind::PlutusV2,
cbor: &script_bytes,
};
let unsigned = build_unsigned_payment_extras(
Network::Preprod,
std::slice::from_ref(&fake_utxo),
fake_wallet_addr,
fake_to_addr,
5_000_000,
&[],
None,
Some(ref_spec),
&ProtocolParams::default(),
)
.expect("build_unsigned_payment_extras failed");
let aldabra_tx_hex = unsigned.cbor_hex;
let aldabra_tx_bytes: Vec<u8> = (0..aldabra_tx_hex.len())
.step_by(2)
.map(|i| u8::from_str_radix(&aldabra_tx_hex[i..i + 2], 16).unwrap())
.collect();
println!(
"aldabra build produced cbor of {} hex chars ({} bytes)",
aldabra_tx_hex.len(),
aldabra_tx_bytes.len()
);
if let Some(pos) = find_subseq(&aldabra_tx_bytes, &script_bytes) {
println!("✅ aldabra path: found script bytes at offset {}", pos);
if pos >= 3 {
let h = &aldabra_tx_bytes[pos - 3..pos];
println!(
" bytes-header preceding: {:02x} {:02x} {:02x}",
h[0], h[1], h[2]
);
if h[0] == 0x59 {
let claimed = u16::from_be_bytes([h[1], h[2]]) as usize;
println!(
" claimed={} input_len={} {}",
claimed,
script_bytes.len(),
if claimed == script_bytes.len() {
"✅ consistent"
} else {
"❌ MISMATCH — encoder bug"
}
);
}
}
} else {
println!("❌ aldabra path: input bytes NOT verbatim in tx body");
}
// Also search for the known on-chain corrupt fingerprint: at
// bytes 2390..=2424 the on-chain version has the two 9-byte
// blocks SWAPPED relative to input. Build the swapped version