Source: docs/lotus-v2/research/addendum-designs/T1-v2-only-ctransaction.md
Research — non-normative. This page records an investigation. It defines no rule; a research result enters the specification only through a decision recorded in decision history.

T1 — Transaction versions in Lotus V2: the legacy bridge (primary) and v7-only (alternative)

This is a design only. Nothing here was built, run or committed. Section 0 separates what was read in the source from what is assumed.

The user's final decision is the legacy bridge (Design A):

The earlier direction, v7-only + leaf versions (Design B), is kept as the written alternative. The file name dates from the original brief ("V2-only CTransaction").


0. Baseline, method, verified vs assumed

Source read: read-only git show / git grep / git blame at commit 056a85acb0 of /Users/shammah/repos/lotus-v2-addendum. Nothing was checked out, built or modified; this file is the only write.

Tier boundary:

Patch attribution (from blame and subjects):

Hash Patch or tier
efe84d831e v2/031 (CTransaction → v7 wire)
377ddd518a v2/032 (native state/monetary/script rules)
99c26c1c71 v2/033 (wallet)
84a4fbb6d6 v2/034 (functional fixtures)
ff453606ae v2/035 (chronik-bridge)
2b6456ec68 v2/036 (miner)
9fb1565150 v2/040 (rpc)
a3665460ea v2/045 (native identities/serialization)
5891e31fe9 v2/051 (BIP30 skip)
3a31b90fd8 v2/056 (mining pool)
f61b0e8d64 v2/062 (placeholder genesis)
52bea1842b, 16bc33fd75, 7bf1c1002e, c597186e10, b12a25312a Addendum
fe7ae5f9da, 219ba2acd3 In the repo, but not series entries by subject
0a052c7a09 eCash-tier Merklix overlay (introduced CTxOut::ToV2Output/BranchLeaf there)
f839f1a3b8 eCash-tier "authenticate and install eCash UTXO state" (introduced the legacy state-coin encoding)
b44e0d3870, fddb00fc8c, e614433d1a, 4dc94d1036, f76e0c6310, 05ef30bbc8 Upstream

Verified in source

Transaction shapes and identities

Where shapes 2 and 3 are refused or accepted

Implicit output and input mappings

Coins and the V2 state

V2 signing

Placeholder genesis (chainparams.cpp:89-134, v2/062)

Python framework

Miner fund

Assumed, not verified


1. The two designs side by side

1.1 Design A — legacy bridge (primary, user-decided)

Transaction formats

Coins

v7 spends of legacy coins

Coinbase

1.2 Design B — v7-only + leaf versions (alternative)

1.3 Comparison

A: legacy bridge B: v7-only + leaf versions
Consensus surface Two tx grammars and two id schemes. Legacy interpreter + legacy sighash for v1/v2. Direction rules (bit). Two v7 template rules (P2PKH native, P2SH legacy-interpreter with V2-message checker). Legacy and v7 coinbases One grammar, one id scheme. Leaf-version dispatch. Legacy interpreter reachable only through V1 leaves with the V2-message checker. A cost table for legacy opcodes inside V2 invocations
Code to maintain Legacy serialization, SignatureHash, PrecomputedTransactionData, legacy standardness, legacy CWallet signing, Python legacy classes; all stay. Hybrid fields go away (variant representation). New: coin bit, two template rules, legacy coin wire in the V2 signer Legacy serialization/sighash/standardness leave the node; legacy wallet signing is rewritten as V1-leaf witnesses; Python legacy classes are rewritten. New: leaf versions in codec/hash/signer, V1-leaf evaluator, cost table
Test impact Small. Chained legacy C++/Python tests run unchanged once their coins are legacy (legacy coinbases). Changes only where tests rely on the hybrid shape, the implicit mapping, bad-txns-non-v7-format or bad-txns-v2-identity. New bridge tests Large. About 50 C++ test files and about 170 functional tests build or fund legacy txs and must be ported to v7 builders. Interpreter vectors move to a test-only type. Many fixture hashes are regenerated
ID handling Legacy: SHA256d. v7: structural V2. No fallback, no XOR, no wrapped form. Both namespaces share COutPoint (different hash functions; collision probability negligible). Legacy chains keep their TxIds One id function; constructor throws on non-encodable input. Spend TxIds unchanged, TxHashes change (+1 witness byte)
Hardware wallets Existing eCash-style firmware (legacy FORKID sighash, ECDSA/Schnorr) keeps working for v1/v2 spends of legacy coins. A v7 spend of a legacy coin needs the V2 message: BIP340 for P2PKH, legacy sig encoding over the V2 message for P2SH. That is new firmware either way All spends need V2-message firmware, including legacy-shaped scripts. No legacy signing remains usable
Long-term cost Legacy format is consensus forever. The user's earlier objection (a), "two formats forever", applies but is narrowed: legacy coins never mix with V2 coins except through the one-way bridge One format. Legacy interpreter semantics survive as an opt-in leaf type

Recorded history of alternatives:

1.4 Legacy VM or V2 VM for v7 spends of legacy coins

Legacy (eCash) interpreter V2 VM / native check
P2PKH Possible (DUP HASH160 … CHECKSIG with a V2-message checker) Chosen. A fixed native hash160 check plus V2 CHECKSIG. No legacy bytecode runs. Wallets sign exactly like a native V2 key spend (BIP340, 64/65-byte)
P2SH Chosen. Runs existing redeem scripts (legacy bytecode) byte-for-byte. Reuses the interpreter that v1/v2 transactions need anyway. One meaning per coin Unsafe. The coin commits only to hash160(redeem); running those bytes on the renumbered V2 VM gives the same coin a second, possibly weaker, meaning, which is a theft risk
Wallet signing Legacy signature encoding (DER or 64-byte Schnorr) + sighash byte, over the V2 message (§2.4) BIP340 64/65-byte over the V2 message

The wallet impact is the same in kind for both: any v7 spend signs the V2 message. Only the signature encoding differs. The rule is therefore standardized per template:


2. Design A specification

2.0 Source of legacy coins

The problem. Design A has three rules:

Under those rules a chain whose coinbases are all v7 never contains a legacy coin, so no v1/v2 transaction can ever be valid. The inherited test suite mines a coinbase and spends it with v1/v2 transactions:

That suite is the reason legacy support is kept at all. It must therefore run unchanged, which means it needs legacy coinbases.

Does the V2 coinbase have to be v7? Each candidate blocker was checked at 056a85acb0:

Candidate blocker Finding Blocks a legacy coinbase?
Header transaction root (primitives/block.cpp:889-909, ComputeV2TxRootFromSubtreeA; checked at validation.cpp:4463) The coinbase leaf hashes GetId() ‖ GetHash(). A legacy coinbase supplies SHA256d for both No
State root (primitives/block.cpp:925-945 coinbase coins, 575-620/722-740/1163-1214 other transactions; validation.cpp:2990-3005, 4845-4857) Every transaction's outputs, legacy ones included, enter the SMT through ToV2Output(). So the state commitment already covers legacy coins, but as V0-leaf V2 outputs, without a legacy marker. Design A switches legacy-transaction outputs to LegacyStateOutput (the 0x80 encoding, sparse_state.cpp:111-118), so the commitment then distinguishes them No (encoding change)
Coinbase height and uniqueness (validation.cpp:7090-7111 with its BIP34 scriptSig branch; 4334-4352 BIP30 for non-v7 coinbases; tx_check.cpp:117-121 legacy coinbase length) The legacy branches already exist and are reachable today No
Miner output conversion (node/miner.cpp:273-282) Converts every coinbase output to V2 form with ToV2Output Producer only: make it conditional on the coinbase version
Miner fund (minerfund.cpp:71-87, consensus) Accepts a legacy scriptPubKey via ExtractDestination, so it works for a legacy coinbase No
Treasury (avalanche/treasury.cpp:735-748, a parking policy compared by scriptPubKey ==) and staking rewards (node/miner.cpp:239-247) Winners are legacy scripts (treasury.cpp:239-249), and a legacy coinbase holds them as they are. Only the v7 coinbase needs an explicit V2 encoding (Q6) No
HAS_STATE (tx_check.cpp:35-52) Already rejects legacy-created HAS_STATE outputs. Unrepresentable after T1-02 No
Coinbase-context commitment CheckCoinbaseContext (validation.cpp:7091-7101) Applies to v7 coinbases only. Legacy coinbases use BIP34 + BIP30 No
Monetary state, C17a expiry (block.cpp:580-605) Work on output values and spendability, not on the format No

Conclusion: nothing forces the coinbase to be v7. The only consensus change needed is one per-network parameter.

Options considered:

Option Assessment
(1) Legacy or v7 coinbase; the coin bit follows the creating transaction's version Adopted, with a per-network gate. No special case: the coinbase is "any transaction" for the bit. Nothing breaks (table above)
(2) Legacy transactions may spend template-type V2 coins (P2PKH/P2SH-like) with the legacy sighash, mirroring the bridge Fallback only. Needs the user's explicit approval, because it is a backward migration (V2→legacy), which the user ruled out. It would also give V2 coins a legacy-sighash meaning
(3) Move inherited legacy tests to v7 and keep legacy support only for … Rejected by the user. Without those tests nothing on the V2 chain needs legacy support, so it would be pointless

Adopted rule (user decision):

(a) Consensus. Consensus::Params::allowLegacyCoinbase:

Network Value
regtest true
mainnet, testnet false

(b) Selection.

Framework default: the test framework passes -coinbaseversion=2 to every regtest node (test_node.py default args). The default is chosen from counts at 056a85acb0 (git grep heuristics, approximate):

Suite Tests that mine/create coinbases and spend with legacy txs Tests that do so with v7 txs
Functional 147 of 237 3 (lotus_v2_loopback_tps_stress.py, lotus_v2_native_e2e.py, p2p_v2_fast_sync_and_reverse_peel.py)
C++ (TestChain100Setup/coinbaseKey/CreateValidMempoolTransaction) 36 files 8 files with native coinbases or transactions

(c) Python create_coinbase (blocktools.py:120-154). It already builds an nVersion=1 coinbase with a BIP34 script_BIP34_coinbase_height scriptSig (167-174), a null prevout and legacy outputs. Regtest accepts such blocks today and will continue to:

Under Design A, such a coinbase is legal through allowLegacyCoinbase, and its outputs are legacy coins. One thing must change at the same time: Python must compute the legacy txid as SHA256d (today it mirrors the C++ version-XORed V2 id). Otherwise calc_merkle_root disagrees with the node. This is part of T1-02.

(d) Code sites.

2.1 Consensus rules

Notation: legacy(coin) means the coin's legacy-created bit.

# Rule Reject reason
A1 A raw version other than 1, 2 or 7 does not decode bad-txns-version (decode failure)
A2 A v1/v2 input must spend a coin with legacy(coin) set bad-txns-legacy-spends-v2-coin
A3 Outputs of a v1/v2 transaction (coinbase included) are created with legacy=1 (rule of AddCoins)
A4 Outputs of a v7 transaction (coinbase included) are created with legacy=0. A v7 output cannot hold a legacy script: the type has no field for it (§2.8) —
A5 A v7 input (nFlags=1) spending a coin with legacy(coin) set must have nPathIndex == 0 and exactly one witness with no siblings. The coin's scriptPubKey must be exactly P2PKH (76 a9 14 <20> 88 ac, 25 bytes) or P2SH (a9 14 <20> 87, 23 bytes) bad-txns-v2-legacy-coin-template (other script) / bad-txns-v2-legacy-coin-witness (shape)
A6 P2PKH bridge (§2.3) bad-txns-v2-legacy-p2pkh (hash), script error SIG_* (signature)
A7 P2SH bridge (§2.4) bad-txns-v2-legacy-p2sh-hash (hash); otherwise the legacy ScriptError
A8 A v7 mint (nFlags=3) never refers to a coin, so A5 does not apply. A V2 spend of a V2 coin is unchanged —
A9 Coinbase: a v1/v2 coinbase is valid only if allowLegacyCoinbase (§2.0). It must start its scriptSig with CScript() << nHeight (BIP34, validation.cpp:7103-7111, existing branch), and BIP30 checks apply to it (4339-4352, existing). A v7 coinbase keeps CheckCoinbaseContext and the BIP30 skip. The miner fund (minerfund.cpp) accepts a legacy-script output in a legacy coinbase, or an explicit V2 destination output in a v7 coinbase bad-cb-version, bad-cb-height, bad-txns-BIP30, bad-cb-minerfund

2.2 The legacy-created coin bit

In-memory layout and serialization. The field is Coin::nHeightAndIsCoinBase = (height << 2) | (legacy << 1) | coinbase:

VARINT size cost. VARINT stores 7 bits per byte, so shifting by one more bit adds one byte only where the value crosses a 7-bit group boundary:

Where the bit is checked:

V2 state commitment. No new field is needed:

Expiry and fees. C17a expiry applies identically:

Formats and migration. The coin DB format changes, as does the state content of legacy-tx outputs. The placeholder chain resets, -reindex is required, and there is no migration.

2.3 P2PKH bridge (v7 input spending a legacy P2PKH coin)

Witness (the v7 wire is unchanged):

Argument Contents
sig V2 encoding: 64 bytes (mode 0), or 65 bytes whose last byte is 0x01 or 0x02 (modes 1, 2)
pubkey 33-byte compressed SEC: 0x02/0x03 ‖ x

Check, natively in CScriptCheck with no VM program:

  1. RIPEMD160(SHA256(pubkey)) == scriptPubKey[3..23], else bad-txns-v2-legacy-p2pkh.
  2. msg = SigningMessage(prepared, nIn, 0, mode), with the legacy-coin preparation rules of §2.5.
  3. VerifyBip340Signature(xonly = pubkey[1..33], sig, msg) must be Valid. This goes through BatchSigCollector::Add like any V2 BIP340 signature.
  4. BIP340 x-only keys mean the signer uses d or -d according to the parity of P. This is the standard behaviour of secp256k1_keypair, so wallets sign exactly as for a native V2 key.

Cost: the cost of one V2 CHECKSIG, plus the V2 structural byte cost of the witness, plus a fixed HASH160 charge. The charge is a new VmCostProfile constant, equal to the cost of SHA256 over 33 bytes plus a RIPEMD160 block.

2.4 P2SH bridge (v7 input spending a legacy P2SH coin)

Witness:

Size limits:

Check:

  1. RIPEMD160(SHA256(w.script)) == scriptPubKey[2..22], else bad-txns-v2-legacy-p2sh-hash.
  2. Synthesize scriptSig' = MinimalPush(arguments[0]) ‖ … ‖ MinimalPush(arguments[n-1]) ‖ MinimalPush(w.script). Then call the unchanged VerifyScript(scriptSig', coin.scriptPubKey, LEGACY_FLAGS, LegacyBridgeSignatureChecker(...), metrics, &err).
  3. LEGACY_FLAGS is exactly the flag set the V2 node applies to v1/v2 inputs at the same height (GetBlockScriptFlags; Q4 if it changes over time).
  4. This runs the full legacy P2SH evaluation byte-for-byte: hash160 again, redeem-script evaluation, CLEANSTACK, SIGPUSHONLY, and the INPUT_SIGCHECKS density rule against |scriptSig'|.
  5. The only difference from a v1/v2 spend of the same coin is the signature checker.
  6. LegacyBridgeSignatureChecker : BaseSignatureChecker behaves as follows:
Method Behaviour
CheckSig(sig‖t, pubkey, scriptCode, flags) Signature encodings are the legacy ones: ECDSA DER or 64-byte eCash Schnorr, plus the trailing hashtype byte t, with 33/65-byte keys. t must have FORKID and maps to a V2 mode (table below). The message is SigningMessage(prepared, nIn, 0, mode). scriptCode and OP_CODESEPARATOR do not change the message, because the selector commits to the redeem script (§2.5). Verification uses the existing legacy verifiers and the BatchSigCollector legacy items (signing.h:150-157). This one method covers CHECKSIG, CHECKSIGVERIFY, CHECKMULTISIG(VERIFY) and Schnorr multisig
VerifySignature/CheckDataSig Unchanged; the message is the stack data. CHECKDATASIG(VERIFY) gives the same result on both paths
CheckLockTime(n) The same comparison as legacy, using nLockTime = lock >> 8 from the v7 lock. The lock type must agree with n's height/time class. The input sequence must not be FINAL
CheckSequence(n) BIP68 on the v7 input sequence. There is no nVersion >= 2 gate, because v7 always qualifies

Hashtype to mode:

t V2 mode
0x41 ALL|FORKID 0
0xC1 ALL|FORKID|ANYONECANPAY 1
0xC3 SINGLE|FORKID|ANYONECANPAY 2
anything else SCRIPT_ERR_SIG_HASHTYPE

Cost:

Same-result property. For any redeem script, args and flags, the result is identical on both paths whenever no signature opcode reaches a signature check. With signatures, each path's result is the same function of "signature valid for this path's message". The tests in §6 rely on this property.

2.5 V2 signing message for legacy coins

PreparedSigningContext::PrepareChecked (signing.cpp:~250-457) accepts ResolvedCoins whose entries may be legacy (Output::legacy_script). Three things are defined for them.

1. Coin wire.

LegacyCoinWire = 0x80 || value:u64le || CompactSize(|script|) || script

2. Selector leaf. invocation.selector is (1, input_index, branch_index=0, legacy_leaf), where:

legacy_leaf = TaggedHash("Lotus/v2/branch",
                         0x03 || CompactSize(|coin_script|) || coin_script
                              || CompactSize(|w.script|) || w.script)

3. Membership check. For legacy coins, the V2 branch-membership check (372-382) is replaced by rule A5 and the hash160 check of §2.3/§2.4.

The fast paths are disabled for any transaction that has a legacy-coin input: TxIsAllAutomaticSuccess, InputIsPureMode0Checksig, and the 45-byte batch path at validation.cpp:371.

2.6 Limits, costs and fees for v1/v2 transactions on the V2 chain

Item Rule
Inputs/outputs The V2 cap of 256/256 applies to all versions. tx_check.cpp:26-33 drops its nVersion == 7 guard. This keeps block cost and memory bounds uniform
Size MAX_TX_SIZE / MIN_TX_SIZE unchanged, for all versions
SigChecks The eCash per-tx sigcheck limit still applies to v1/v2. Each legacy sigcheck counts as one V2 CHECKSIG toward the V2 block resource cost (lotus_v2/block_cost, v2/009), the same as bridge sigchecks
Fees The same fee-rate rules by serialized size (fee hysteresis controller, minimum relay fee). Fee burn and miner split are unchanged (monetary rules operate on fees, not formats)
Expiry C17a lifespan and rent apply identically (§2.2)
Tokens/state A legacy output cannot express token, state or burn flags, so v1/v2 cannot create or move V2 tokens. bad-txns-legacy-state-output (tx_check.cpp:35-52) is deleted because the case is unrepresentable

2.7 Mempool and RPC

2.8 CTransaction representation (recommendation)

Recommended: one CTransaction class with a version tag and per-element variants. It has no union of legacy and V2 fields:

struct LegacyTxIn { CScript scriptSig; };
struct V2TxIn     { uint8_t nFlags; uint8_t nPathIndex;
                    std::vector<lotus::v2::BranchWitness> vWitnesses;
                    std::vector<uint8_t> vCoinbaseData; };   // empty <=> no coinbase data
class CTxIn  { public: COutPoint prevout; uint32_t nSequence;
               std::variant<LegacyTxIn, V2TxIn> body;
               bool IsLegacy() const; const LegacyTxIn &Legacy() const; const V2TxIn &V2() const; };

struct V2TxOutBody { uint8_t nFlags; uint256 tokenId, stateRoot;
                     std::vector<lotus::v2::Hash32> vBranches; std::vector<std::vector<uint8_t>> vPaths; };
class CTxOut { public: Amount nValue;
               std::variant<CScript /*legacy scriptPubKey*/, V2TxOutBody> body;
               bool IsLegacy() const; const CScript &LegacyScript() const; const V2TxOutBody &V2() const; };

class CTransaction {   // invariant: nVersion in {1,2} <=> every vin/vout IsLegacy(); nVersion == 7 <=> none is
    const uint32_t nVersion;  const Span<const CTxIn> vin;  const Span<const CTxOut> vout;
    const uint64_t nLock;     // v1/v2: nLockTime (low 32 bits); v7: V2 lock (value << 8 | type)
    uint32_t nLockTime() const;   // legacy view for IsFinalTx/CLTV
    TxId GetId() const; TxHash GetHash() const; // legacy: SHA256d (equal); v7: structural V2
    ...
};

2.9 Serialization and identities

Wire format. UnserializeTransaction reads u32 version:

Version Grammar
1 or 2 Legacy grammar (vin[prevout, scriptSig, seq], vout[value, script], nLockTime), the eCash code
7 v7 grammar, unchanged
anything else throw bad-txns-version

Identity:

Legacy sighash. SignatureHash and PrecomputedTransactionData stay, used only for v1/v2 inputs. FillPrecomputedData now selects on nVersion != 7 instead of nFlags (transaction.cpp:926-944).

Null transaction. NULL_TRANSACTION_WIRE (transaction.cpp:656) becomes legitimately "version 1, empty". It is unchanged.

2.10 Coinbase producers and genesis

Coinbase producers. BlockAssembler::CreateNewBlock (node/miner.cpp:215-291), mining_pool.cpp:472-537 and rpc/mining.cpp:1267-1317 build the coinbase version given by Options::coinbase_version (§2.0). The format is chosen explicitly, not inferred from the payout:

Version Coinbase built
1 or 2 (regtest only) Null prevout, scriptSig = CScript() << nHeight << OP_0 [+ extra nonce], legacy outputs. Miner-fund, staking and treasury outputs are legacy scripts
7 Today's v7 coinbase, with explicit V2 outputs. The payout must be a V2 output; the miner fund uses OutputForDestination (explicit V2 encoding of the fund destination; Q6)

The scriptSig → vCoinbaseData copy goes away; each format writes only its own field.

The mining pool (mining_pool.cpp) always builds v7 coinbases, because a pool is a mainnet feature.

Genesis (chainparams.cpp:89-134):

2.11 Legacy-dependent code under Design A

Subsystem Disposition
Script interpreter Unchanged eCash interpreter. Used by v1/v2 inputs (legacy checker) and P2SH bridge inputs (LegacyBridgeSignatureChecker). The VerifyScript call in CScriptCheck (validation.cpp:3770) is now selected by "legacy input or P2SH bridge", not by nFlags==0
script/sign.cpp Legacy signing unchanged for v1/v2. New BridgeSignatureCreator (in script/bridge_sign.{h,cpp}) produces P2PKH bridge witnesses (BIP340 over the V2 message) and P2SH bridge witnesses (legacy SignStep with the V2 message and the hashtype map)
CWallet Stays a legacy wallet: it receives via legacy coinbases and legacy txs and sends v1/v2. New RPC migratetov2 "address_or_output" [amount] sweeps chosen P2PKH/P2SH (multisig) coins into a v7 transaction that pays a V2 output, using BridgeSignatureCreator. Native V2 receiving stays with lotus::v2::wallet (Q7). Fee estimation adds dummy bridge witness sizes
Policy Legacy IsStandardTx for v1/v2; V2 standardness for v7; bridge inputs standard; version selection by nVersion
RPC decoders (core_write.cpp:240-300) Legacy JSON for v1/v2, unchanged. v7 JSON: vin[].witnesses[{script, siblings, arguments}] and kind; vout[] V2 fields. Bridge inputs add "spends": "legacy-p2pkh"/"legacy-p2sh". ConstructTransaction builds legacy (createrawtransaction default version 2) unless version=7 is passed, in which case outputs must be V2 destinations
rpc/v2vm.cpp DecodeV7 keeps rejecting non-v7. Simulation and test RPCs learn the bridge rules
lotus-tx, PSBT, BIP37 Unchanged for legacy transactions. PSBT and BIP37 do not apply to v7 (they report "unsupported" for v7)
Chronik native (chronik_bridge.cpp) BridgeTxInputScript (103-122): legacy inputs give scriptSig; v7 inputs give witness[0].script (bridge P2SH: the redeem script). .version = tx.nVersion (183) is now accurate. lookup_spent_coins (447-466) must not rebuild-and-hash a legacy-shaped transaction: for v1/v2 its SHA256d is correct; for v7 it must decode the raw v7 bytes or take the TxId from the caller (coordinate with C1 §1 item 2). Expose the coin's legacy bit in UTXO and spent-coin records (is_legacy)
Chronik Rust The legacy Tx model fits v1/v2 unchanged. The V2 records (lotus_v2.rs) are unchanged for v7. Add is_legacy to the UTXO proto
Python framework Legacy CTransaction/CTxIn/CTxOut unchanged in behaviour (§2.12). v7 types split out

2.12 Test-framework impact under Design A

Python (messages.py):

MiniWallet: unchanged (legacy). Its coins come from legacy coinbases because its address is a legacy P2SH-OP_TRUE (§2.10). v7tx.MiniWalletV7 covers native tests.

C++:


3. Inventory of legacy fields and legacy-version code in the V2 tier

A: gives the Design A disposition. The patch is named where it is identifiable (§0).

3.1 Primitives (src/primitives/transaction.{h,cpp})

Location What Introduced A:
h:74-79 CTxIn = scriptSig + V2 fields side by side (nFlags 0 = auto-infer) upstream + v2/031 variant (§2.8)
h:126-128 CTxIn legacy SERIALIZE_METHODS upstream keep for legacy body
h:138-153 Two-regime CTxIn::operator== v2/031 default == on variant
h:165-178 CTxOut = scriptPubKey + V2 fields upstream + v2/031, 7bf1c1002e variant
h:204-228 Cross-representation CTxOut::operator== v2/031 default ==
h:449-462 Wrapped and legacy decode, coinbase from scriptSig v2/045 delete wrapped; legacy decode by version
h:466-473, 598-610 "Pure v2" heuristic, wrapped encode v2/031, v2/045 delete
h:487-575 Encoder fallbacks via ToV2Input, lock from nLockTime v2/031 delete
h:715-725 nLockTime+fHasV2Lock+nV2Lock; MIN/MAX_VERSION = 1..7 v2/031 single nLock; IsValidVersion
h:778-786 HasStructuralV2Identity 52bea1842b delete
h:810-812 IsCoinBase accepts null prevout or nFlags==2 v2/031 per format
h:1039-1042 AdaptLegacy*ToV7 v2/031, v2/045 delete
cpp:28-120 ToV2Input/FromV2Input with scriptSig inference v2/031 lossless copy of V2TxIn
cpp:140-198 ToV2Output implicit mapping (V0 leaf fallback) 0a052c7a09 (eCash) adapted by v2/031 V2 bodies only; legacy outputs never map (the state uses LegacyStateOutput)
cpp:200-228 PopulateV2ScriptPubKeyWire synthetic script (the 45-byte form embeds the value) v2/031 becomes OutputScript() for display only
cpp:253-300 AdaptLegacy* bodies v2/045 delete
cpp:379-447 Version XOR and flat fallback v2/031, 52bea1842b delete
cpp:449-479 Id getters thread nVersion v2/031 dispatch by version
cpp:481-608 InitHashes v7 fast path; fallback v2/031, 219ba2acd3 keep fast path; legacy = SHA256d
cpp:636-654, 740-747 Long-script accounting upstream per variant
cpp:656, 851-859 Null tx wire (version 1) / null tx via the wrapped path upstream/v2/031 legacy null tx
cpp:926-944 FillPrecomputedData selects on nFlags v2/031 select on version

3.2 Consensus (src/consensus/)

Location What Introduced A:
tx_check.cpp:26-33 Caps only for v7 52bea1842b all versions
tx_check.cpp:35-52 bad-txns-legacy-state-output 16bc33fd75 delete (unrepresentable)
tx_check.cpp:100-107 Coinbase HAS_STATE only for v7 7bf1c1002e keep (v7 only by type)
tx_check.cpp:109-121 Coinbase: nFlags==2 vs legacy scriptSig length v2/031 dispatch by version
tx_check.cpp:137-150 Mint/spend same-prevout allowance, unreachable (the decoder rejects repeats, h:365-381) v2/031 simplify to "no repeated prevout"
tx_check.cpp:182-200 bad-txns-v2-identity 52bea1842b delete
tx_verify.cpp:20-38 IsFinalTx on a truncated nLockTime with the 500M threshold upstream legacy: unchanged; v7: R6
tx_verify.cpp:58-63 Versions 1/2/7 v2/032 decode-time (A1)
tx_verify.cpp:114 BIP68 only for nVersion >= 2 b44e0d3870 unchanged (v1 legacy keeps no-BIP68)
tx_verify.cpp CheckTxInputs — — add A2 (legacy spends legacy)

3.3 Validation (src/validation.cpp)

Location What Introduced A:
195-201, 569-573 BIP68 shortcut for v7 spends (assumes FINAL; the decoder permits otherwise) v2/032 unchanged by T1; R5
340 Post-check no-op for non-v7 c597186e10 keep
371-... Batched v7 fast path on 45-byte coin form v2/032 disable if any input is legacy
1116-1128, 1296-1305 is_v2_native_tx picks standardness by nFlags v2/032, fe7ae5f9da select by version
3577-3612 OP_TRUE fast path reads the synthetic scriptPubKey v2/032 read V2() body
3636-3645 nVersion XOR in known ids v2/032 delete
3770-3779 VerifyScript(scriptSig, scriptPubKey) for nFlags==0 fddb00fc8c legacy inputs + P2SH bridge
3893 No deferral for v7 c597186e10 keep
4334-4352 BIP30 skip for v7 coinbases v2/051 keep; legacy coinbases do BIP30
7090-7111 Coinbase height: CheckCoinbaseContext vs BIP34 v2/032 dispatch by version (A9)
AddCoins/UpdateCoins/DisconnectBlock, state-coin construction — — set and restore the legacy bit; LegacyStateOutput for legacy coins

3.4 Coinbase producers, monetary rules, coins, genesis

Location What Introduced A:
coins.h:33-55, 95-104 nHeightAndIsCoinBase upstream add the legacy bit (§2.2)
compressor.h:96-121 Dual TxOutCompression v2/031 dispatch by variant; check against the bit
lotus_v2/sparse_state.cpp:107-191 Legacy coin 0x80 encoding f839f1a3b8 (eCash) reuse as is
lotus_v2/legacy_coin.h:8-23 LegacyStateOutput/LegacyTxOutput f839f1a3b8 used by ConnectBlock/undo
kernel/chainparams.cpp:28-67 Genesis builder writes scriptSig+vCoinbaseData v2/032 v7 coinbase writes vCoinbaseData only
kernel/chainparams.cpp:89-134, 266-277 Placeholder genesis, nonces, asserts v2/062 §2.10
node/miner.cpp:215-291 v7 coinbase with legacy payout script v2/036, 4dc94d1036 format follows payout
node/mining_pool.cpp:472-537 Same pattern v2/056 same
rpc/mining.cpp:1267-1317 Same pattern v2/040 same
minerfund.cpp:71-87 Consensus match via the implicit mapping v2/032 legacy match for legacy coinbases; explicit V2 encoding for v7
avalanche/treasury.cpp:241 Treasury scripts v2/043 follow coinbase format

3.5 Policy, interpreter, signing, wallet, RPC, utilities

Location What Introduced A:
policy/policy.cpp:74-78 Version standardness 1/2/7 v2/032 legacy path: 1/2
script/interpreter.cpp:1471, 1629, 1748, 1794-1910 Legacy sighash, BIP68 gate, VerifyScript upstream keep
script/sign.cpp:110-487 Legacy signing upstream keep; add the bridge creator
wallet/wallet.cpp:2086-2126, spend.cpp:745/969/1078, transaction.cpp:11-15 CWallet legacy signing; today it produces the wrapped shape (default nVersion 7) upstream produce v2 legacy; add migratetov2
rpc/mempool.cpp:49-59, 113-117, 1460-1470, 1776-1786 Non-v7 refusal v2/040 delete
rpc/v2vm.cpp:73-90 DecodeV7 b12a25312a keep
core_write.cpp:240-300; core_read.cpp:196-214 JSON; decode reason swallowed upstream, 7bf1c1002e §2.11; return the reason
rpc/rawtransaction.cpp:1331 etc. PSBT nVersion=2 upstream keep (legacy)
bitcoin-tx.cpp:249-250 MIN/MAX_VERSION e614433d1a IsValidVersion
common/bloom.cpp:156-161 scriptSig parsing upstream legacy only

3.6 Chronik and the Python framework

Location What Introduced A:
chronik-cpp/chronik_bridge.cpp:103-122, 183, 447-466 Input-script projection, version, legacy-shaped TxId recompute v2/035 §2.11
chronik-bridge/src/ffi.rs:77,101; bitcoinsuite-core/src/tx/tx.rs Legacy Tx model upstream keep; add is_legacy
messages.py:380-610, 741, 860-1006 Hybrid Python transaction, implicit mapping, ids with version upstream + v2/034 split by version; delete wrapped/implicit
wallet.py:62-447 Legacy MiniWallet upstream keep

4. Design A commit plan (V2 tier)

These commits land after the coordinator's next integration, on one rebased tip, appended after the last V2 entry. Placeholders T1-01… become the next series numbers. The eCash tier is not changed.

Every commit builds and passes the full test_lotus and functional suites; commits that need fixture updates carry them. The file lists are the expected touch set.

T1-01 test(v2): pin transaction identities, genesis and coin encodings before the bridge

T1-02 primitives(v2): version-tagged transactions without hybrid fields

T1-03 coins(v2): record whether a coin was created by a legacy transaction

T1-04 consensus(v2): legacy transactions spend and create only legacy coins

This commit also adds Consensus::Params::allowLegacyCoinbase (consensus/params.h, kernel/chainparams.cpp: regtest true, main/test false). Its rule is bad-cb-version (§2.0a). Tests:

T1-05 mining(v2): select the coinbase version for regtest block generation

T1-06 consensus(v2): let v7 spend legacy P2PKH coins with a V2 signature

T1-07 consensus(v2): let v7 spend legacy P2SH coins on the legacy interpreter

T1-08 chain(v2): keep the genesis easter egg as a v1 legacy transaction

T1-09 policy(v2): relay and accept legacy and v7 transactions

T1-10 wallet(v2): sign legacy transactions explicitly and migrate legacy coins to V2

T1-11 chronik(v2): index legacy and v7 transactions by their own identities

T1-12 test(v2): split Python transactions by version and add bridge signers

T1-13 test(v2): functional coverage of the legacy bridge and chained legacy transactions

T1-14 lint(v2): forbid hybrid transaction fields

Ordering notes:

5. Risks (Design A)

6. Test matrix (Design A)

Requirement Where
P2PKH legacy coin spent by v7: valid / wrong hash / wrong key / wrong mode / non-template rejected T1-06 unit tests; T1-13 functional
P2SH legacy coin spent by v7: valid / wrong hash / wrong key / wrong hashtype→mode / non-template rejected T1-07 unit tests; T1-13
The same coins spent by v1/v2, unchanged T1-04, T1-07 (legacy control cases), T1-13
The same P2SH redeem script gives the same result on both paths T1-07 same-result suite
Coin bit round-trips through coin DB, undo, reorg, restart, state commitment, fast sync T1-03 unit tests; T1-13 reorg/restart
Chained legacy transactions unchanged TestChain100Setup-based unit tests after T1-02/05; T1-13 25-deep chain; existing MiniWallet functional tests
Mempool/RPC acceptance T1-09
Legacy coinbase gated by allowLegacyCoinbase; coinbase_version RPC args and -coinbaseversion default; Python create_coinbase (v1) blocks accepted on regtest T1-04, T1-05
Full legacy-to-v7 migration T1-13 feature_v2_legacy_bridge.py; T1-10 wallet_migrate_v2.py
Python/C++ signing-message parity T1-12 shared JSON vectors

7. Open questions (Design A)

  1. Q1 (decided) Legacy coinbases are regtest-only via allowLegacyCoinbase. Mainnet and testnet have no legacy coins, so the bridge is exercised only on regtest. Option (2) of §2.0, legacy spends of template V2 coins, remains a fallback that needs the user's approval.
  2. Q2 Bridge error names. Confirm bad-txns-legacy-spends-v2-coin, bad-txns-v2-legacy-coin-template, bad-txns-v2-legacy-coin-witness, bad-txns-v2-legacy-p2pkh and bad-txns-v2-legacy-p2sh-hash.
  3. Q3 Uncompressed P2PKH keys through the bridge. Rejected here; such coins remain spendable by v1/v2. Should they be accepted (x-only of the 65-byte key)?
  4. Q4 P2SH bridge flags. Pin LEGACY_FLAGS as a constant, or follow GetBlockScriptFlags at the spending height (this design)?
  5. Q5 Hashtype map. Only 0x41/0xC1/0xC3 → modes 0/1/2. Should NONE or non-ACP SINGLE get V2 modes later?
  6. Q6 Miner-fund destination in v7 coinbases. The explicit V2 encoding of a fund destination: which template (V2 key leaf from the destination's key, or xpi1)?
  7. Q7 CWallet scope. Legacy wallet plus migratetov2 (this design), or native V2 receiving in CWallet as well?
  8. Q8 V2 lock finality (R6): fix it separately, or within T1?
  9. Q9 HASH160 opcode. A later EXT2 opcode for V2 scripts that check legacy addresses: in scope for O1's opcode registry?
  10. Q10 V2 MiniWallet. The coordinator referred to a "V2 MiniWallet (patch v2/034)". None exists in test_framework/ at 056a85acb0. T1-12 builds MiniWalletV7 from the per-test helpers unless a newer one exists.

8. Verified vs assumed (summary)


9. Design B — v7-only + leaf versions (alternative, full specification)

Kept so the comparison in §1.3 can be checked.

B1 Rule.

B2 Leaf hashing.

B3 Reveal.

B4 Dispatch:

Version Behaviour
V0 V2 VM
V1 EvalLegacyLeaf
V2–255 Success after membership; policy-nonstandard

Fast paths require V0. Effects only from V0.

B5 V1 execution:

B6 Implicit mapping. ToV2Output inference is deleted. Explicit constructors replace it:

B7 Types.

B8 Wallet.

B9 Genesis.

B10 Tests.

B11 Commit sketch.

  1. Pin goldens.
  2. Leaf versions.
  3. V1 evaluator.
  4. Explicit outputs.
  5. Genesis.
  6. C++ builder and migration.
  7. CTransactionLegacy for interpreter vectors.
  8. Python v7 framework.
  9. Functional migration (4 batches).
  10. Wallet V1 leaves.
  11. RPC decoders.
  12. Chronik.
  13. v7-only enforcement.
  14. Type cleanup.
  15. Lint.

B12 Risks and open questions specific to B.