Skip to content

Commit c589490

Browse files
committed
vaults: make recovery transaction explicit
Instead of implicitly detecting whether or not an OP_VAULT/OP_UNVAULT spend is a recovery spend by scanning outputs for matching scriptPubKeys, explicitly indicate recoveries by requiring a witness stack element that is either -1 in the case of no recovery OR corresponds to an output index that is the recovery output.
1 parent 9124f29 commit c589490

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

bip-vaults.mediawiki

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -279,32 +279,26 @@ where
279279
** If <code><recovery-params></code> is less than 32 bytes, script execution when spending this output MUST fail and terminate immediately.
280280
** Because the recovery scriptPubKey is committed to with a hash, witness version upgradeability is preserved.
281281
282-
==== Check for recovery ====
282+
==== Witness stack ====
283283

284284
After the witness program is parsed, it must be determined whether this input
285-
is being spent towards a recovery. If an output in the spending transaction is
286-
found whose scriptPubKey hashes to the recovery sPK hash (the
287-
first component of <code><recovery-params></code>), the interpreter will
288-
evaluate for recovery. Otherwise, the interpreter will evaluate assuming a withdrawal
289-
is being triggered.
285+
is being spent towards a recovery.
290286

291-
In pseudocode:
287+
Witness stack shown top to bottom:
292288

293-
<source lang="python">
294-
is_recovery = False
295-
recovery_out: Optional[CTxOut] = None
296-
297-
for out in spending_tx.vout:
298-
if tagged_hash("VaultRecoverySPK", out.scriptPubKey) == recovery_sPK_hash:
299-
is_recovery = True
300-
recovery_out = out
301-
302-
if is_recovery:
303-
eval_for_recovery(recovery_out)
304-
else:
305-
eval_for_withdrawal_trigger()
289+
<source>
290+
<recovery-vout-idx>
291+
[other potential witness stack items ...]
306292
</source>
307293

294+
where
295+
296+
* <code><recovery-vout-idx></code> is an integer indicating which output, if any, is a recovery output.
297+
** If this value cannot be decoded as a CScriptNum and cast to an integer, script execution MUST fail and terminate immediately.
298+
** If this value is less than -1, script execution MUST fail and terminate immediately.
299+
** If this value is greater than or equal to 0, this spend is a recovery transaction and this value denotes the recovery output that corresponds to this vault input.
300+
* The parse of the other stack items depends on whether or not this is a recovery spend.
301+
308302
==== <code>OP_VAULT</code> evaluation for recovery spend ====
309303

310304
* If the recovery output does not have an <code>nValue</code> greater than this input's amount, the script MUST fail and terminate immediately.

0 commit comments

Comments
 (0)