Return-Path: <achow101-lists@achow101.com>
Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138])
 by lists.linuxfoundation.org (Postfix) with ESMTP id A7068C013B
 for <bitcoin-dev@lists.linuxfoundation.org>;
 Wed,  9 Dec 2020 22:33:04 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by whitealder.osuosl.org (Postfix) with ESMTP id 95CB48756C
 for <bitcoin-dev@lists.linuxfoundation.org>;
 Wed,  9 Dec 2020 22:33:04 +0000 (UTC)
X-Virus-Scanned: amavisd-new at osuosl.org
Received: from whitealder.osuosl.org ([127.0.0.1])
 by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id UQr7-qmTed8J
 for <bitcoin-dev@lists.linuxfoundation.org>;
 Wed,  9 Dec 2020 22:33:02 +0000 (UTC)
X-Greylist: delayed 00:07:09 by SQLgrey-1.7.6
Received: from mail-41103.protonmail.ch (mail-41103.protonmail.ch
 [185.70.41.103])
 by whitealder.osuosl.org (Postfix) with ESMTPS id 60ADA8737C
 for <bitcoin-dev@lists.linuxfoundation.org>;
 Wed,  9 Dec 2020 22:33:02 +0000 (UTC)
Received: from mail-02.mail-europe.com (mail-02.mail-europe.com
 [51.89.119.103])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (4096 bits))
 (No client certificate requested)
 by mail-41103.protonmail.ch (Postfix) with ESMTPS id 1A3632002C6E
 for <bitcoin-dev@lists.linuxfoundation.org>;
 Wed,  9 Dec 2020 22:25:50 +0000 (UTC)
Authentication-Results: mail-41103.protonmail.ch;
 dkim=pass (2048-bit key) header.d=achow101.com header.i=@achow101.com
 header.b="b/u7ML0V"
Date: Wed, 09 Dec 2020 22:25:37 +0000
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=achow101.com;
 s=protonmail2; t=1607552740;
 bh=ds8SPtlXjOwf2uVYhcu0ZDm4N6hVwprzAuFnn4TcyJw=;
 h=Date:To:From:Reply-To:Subject:From;
 b=b/u7ML0VWIgM3noMpvteBlBDFNdyvgCqZeRSI6IE0PnryPBwZh3jTL46drZ2OM+Ks
 3WWwn3w9NwJi8obQPfg4m92ft5q/HVk15eYXJuayKDUoKoChs14xRPwmMKij1wxmPF
 4JW43DuSQrhppvHsVlyhRkAv+UR5+IrqczNOAkHOmRdKWfjF4OQy5fSFcmfzQXVz5y
 JRcdL/yo2hJYhZGK43G2avhzMrLsVk57TGHTaI2RPR0SLPG0XbNYhBAcJtb+yyQJzI
 91xBEAIiWVttBHYbXhzPmEqdtxTQvytyVF+5yz7XYOAbvwVrauuWbhfaa3QKrlOaq8
 pAqMINOKRcNGA==
To: Bitcoin Protocol Discussion <bitcoin-dev@lists.linuxfoundation.org>
From: Andrew Chow <achow101-lists@achow101.com>
Reply-To: Andrew Chow <achow101-lists@achow101.com>
Message-ID: <1dd8c285-e3f4-4f03-d608-103a5026146d@achow101.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Subject: [bitcoin-dev] New PSBT version proposal
X-BeenThere: bitcoin-dev@lists.linuxfoundation.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: Bitcoin Protocol Discussion <bitcoin-dev.lists.linuxfoundation.org>
List-Unsubscribe: <https://lists.linuxfoundation.org/mailman/options/bitcoin-dev>, 
 <mailto:bitcoin-dev-request@lists.linuxfoundation.org?subject=unsubscribe>
List-Archive: <http://lists.linuxfoundation.org/pipermail/bitcoin-dev/>
List-Post: <mailto:bitcoin-dev@lists.linuxfoundation.org>
List-Help: <mailto:bitcoin-dev-request@lists.linuxfoundation.org?subject=help>
List-Subscribe: <https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev>, 
 <mailto:bitcoin-dev-request@lists.linuxfoundation.org?subject=subscribe>
X-List-Received-Date: Wed, 09 Dec 2020 22:33:04 -0000

Hi All,

I would like to propose a new PSBT version that addresses a few=20
deficiencies in the current PSBT v0. As this will be backwards=20
incompatible, a new PSBT version will be used, v1.

The primary change is to truly have all input and output data for each=20
in their respective maps. Instead of having to parse an unsigned=20
transaction and lookup some data from there, and other data from the=20
correct map, all of the data for an input will be contained in its map.=20
Doing so also disallows PSBT_GLOBAL_UNSIGNED_TX in this new version.=20
Thus I propose that the following fields be added:

Global:
* PSBT_GLOBAL_TX_VERSION =3D 0x02
 =C2=A0 * Key: empty
 =C2=A0 * Value: 32-bit little endian unsigned integer for the transaction=
=20
version number. Must be provided in PSBT v1 and omitted in v0.
* PSBT_GLOBAL_PREFERRED_LOCKTIME =3D 0x03
 =C2=A0 * Key: empty
 =C2=A0 * Value: 32 bit little endian unsigned integer for the preferred=20
transaction lock time. Must be omitted in PSBT v0. May be provided in=20
PSBT v1, assumed to be 0 if not provided.
* PSBT_GLOBAL_INPUT_COUNT =3D 0x04
 =C2=A0 * Key: empty
 =C2=A0 * Value: Compact size unsigned integer. Number of inputs in this=20
PSBT. Must be provided in PSBT v1 and omitted in v0.
* PSBT_GLOBAL_OUTPUT_COUNT =3D 0x05
 =C2=A0 * Key: empty
 =C2=A0 * Value: Compact size unsigned integer. Number of outputs in this=
=20
PSBT. Must be provided in PSBT v1 and omitted in v0.

Input:
* PSBT_IN_PREVIOUS_TXID =3D 0x0e
 =C2=A0 * Key: empty
 =C2=A0 * Value: 32 byte txid of the previous transaction whose output at=
=20
PSBT_IN_OUTPUT_INDEX is being spent. Must be provided in PSBT v1 and=20
omitted in v0.
* PSBT_IN_OUTPUT_INDEX =3D 0x0f
 =C2=A0 * Key: empty
 =C2=A0 * Value: 32 bit little endian integer for the index of the output=
=20
being spent. Must be provided in PSBT v1 and omitted in v0.
* PSBT_IN_SEQUENCE =3D 0x0f
 =C2=A0 * Key: empty
 =C2=A0 * Value: 32 bit unsigned little endian integer for the sequence=20
number. Must be omitted in PSBT v0. May be provided in PSBT v1 assumed=20
to be max sequence (0xffffffff) if not provided.
* PSBT_IN_REQUIRED_LOCKTIME =3D 0x10
 =C2=A0 * Key: empty
 =C2=A0 * Value: 32 bit unsigned little endian integer for the lock time th=
at=20
this input requires. Must be omitted in PSBT v0. May be provided in PSBT=20
v1, assumed to be 0 if not provided.

Output:
* PSBT_OUT_VALUE =3D 0x03
 =C2=A0 * Key: empty
 =C2=A0 * Value: 64-bit unsigned little endian integer for the output's=20
amount in satoshis. Must be provided in PSBT v1 and omitted in v0.
* PSBT_OUT_OUTPUT_SCRIPT =3D 0x04
 =C2=A0 * Key: empty
 =C2=A0 * Value: The script for this output. Otherwise known as the=20
scriptPubKey. Must be provided in PSBT v1 and omitted in v0.

This change allows for PSBT to be used in the construction of=20
transactions. With these new fields, inputs and outputs can be added as=20
needed. One caveat is that there is no longer a unique transaction=20
identifier so more care must be taken when combining PSBTs.=20
Additionally, adding new inputs and outputs must be done such that=20
signatures are not invalidated. This may be harder to specify.

An important thing to note in this proposal are the fields=20
PSBT_GLOBAL_PREFERRED_LOCKTIME and PSBT_IN_REQUIRED_LOCKTIME. A Bitcoin=20
transaction only has a single locktime yet a PSBT may have multiple=20
locktimes. To choose the locktime for the transaction, finalizers must=20
choose the maximum of all of the *_LOCKTIME fields.=20
PSBT_IN_REQUIRED_LOCKTIME is added because some inputs, such as those=20
involving OP_CHECKLOCKTIMEVERIFY, require a specific minimum locktime to=20
be set. This field allows finalizers to choose a locktime that is high=20
enough for all inputs without needing to understand the scripts=20
involved. The PSBT_GLOBAL_PREFERRED_LOCKTIME is the locktime to use if=20
no inputs require a particular locktime.

As these changes disallow the PSBT_GLOBAL_UNSIGNED_TX field, PSBT v1=20
needs the version number bump to enforce backwards incompatibility.=20
However once the inputs and outputs of a PSBT are decided, a PSBT could=20
be "downgraded" back to v0 by creating the unsigned transaction from the=20
above fields, and then dropping these new fields.

If the list finds that these changes are reasonable, I will write a PR=20
to modify BIP 174 to incorporate them.

Thanks,
Andrew Chow