Skip to content

Fix invalid witness program length#387

Merged
tnull merged 1 commit into
lightningdevkit:mainfrom
whfuyn:fix-invalid-witness-program-len
Oct 28, 2024
Merged

Fix invalid witness program length#387
tnull merged 1 commit into
lightningdevkit:mainfrom
whfuyn:fix-invalid-witness-program-len

Conversation

@whfuyn
Copy link
Copy Markdown
Contributor

@whfuyn whfuyn commented Oct 23, 2024

list_confirmed_utxos failed with error InvalidSegwitV0Length. It looks like we need to drop the first two bytes(witness version and program length) to get the actual program data.

// src/wallet/mod.rs:390
let witness_program = WitnessProgram::new(version, script_pubkey.as_bytes())
    .map_err(|e| {
        log_error!(self.logger, "Failed to retrieve script payload: {}", e);
    })?;
[src/wallet/mod.rs:387:24] u.txout.script_pubkey = Script(OP_0 OP_PUSHBYTES_20 52a6909ab2a245ca790b98296c27e559b0cd367c)
Failed to retrieve script payload: a v0 witness program must be either 20 or 32 bytes: length=22

Here is a test to reproduce this problem.

#[test]
fn test_witness_program_len() {
	let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
	let chain_source = TestChainSource::Esplora(&electrsd);
	let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false);

	let address_a = node_a.onchain_payment().new_address().unwrap();
	let premine_amount_sat = 5_000_000;
	premine_and_distribute_funds(
		&bitcoind.client,
		&electrsd.client,
		vec![address_a],
		Amount::from_sat(premine_amount_sat),
	);
	
	node_a.sync_wallets().unwrap();
	node_a.list_confirmed_utxos();
}
// Work around the visibility limits.
// impl Node {
	/// Debug
	pub fn list_confirmed_utxos(&self) {
		use lightning::events::bump_transaction::WalletSource;

		self.wallet.list_confirmed_utxos().unwrap();
	}
@whfuyn whfuyn force-pushed the fix-invalid-witness-program-len branch from 6a6fba0 to ec26f06 Compare October 23, 2024 13:30
@tnull
Copy link
Copy Markdown
Collaborator

tnull commented Oct 24, 2024

Thanks for catching this! We're looking to ship a patched version with a fix start of the coming week.

Copy link
Copy Markdown
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Thanks again, seems this was lost-in-translation during the rust-bitcoin upgrade.

@tnull tnull merged commit bcea1c2 into lightningdevkit:main Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants