# Basic vault prototype using OP\_CAT

**URL:** <https://delvingbitcoin.org/t/basic-vault-prototype-using-op-cat/576>\
**Category:** Protocol Design\
**Created:** [February 15, 2024, 10:13pm UTC](https://delvingbitcoin.org/t/basic-vault-prototype-using-op-cat/576 "2024-02-15T22:13:48Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![dgpv](https://delvingbitcoin.org/user_avatar/delvingbitcoin.org/dgpv/32/75_2.png) [@dgpv](https://delvingbitcoin.org/u/dgpv)\
**Post date:** [February 16, 2024, 1:07pm UTC](https://delvingbitcoin.org/t/basic-vault-prototype-using-op-cat/576/2 "2024-02-16T13:07:25Z")

</div>

Since I like to try B’SST on any not-entirely-trivial script I stumble upon, I’ve tried it with `vault_trigger_withdrawal` script from your demo. (B’sst is one of the names of Bastet, the ancient egyptian cat-goddess, so cannot ignore the CAT demo :-))

I think it might be interesting to look at the report, as it shows what this script does quite concisely, in my opinion.

The annotated script can be found here: [purrfect\_vault\_trigger\_withdraw\_script\_with\_bsst\_annotations · GitHub](https://gist.github.com/dgpv/f875e021905eb113070a23eb7fa981f6), you need to call `bsst-cli` with `--explicitly-enabled-opcodes=cat`

The report:

```auto
==============================
Enforced constraints per path:
==============================

All valid paths:
----------------

        EQUAL(&script_computed_sig, precomputed_sig_sans_last_byte<wit0>.x('00')) @ 77:L104
        CHECKSIG(precomputed_sig_sans_last_byte<wit0>.x('01'), $G_X) @ END

=================================
Witness usage and stack contents:
=================================

All valid paths:
----------------
Witnesses used: 17

Stack values:
        <result> = CHECKSIG(precomputed_sig_sans_last_byte<wit0>.x('01'), $G_X) : one_of(0, 1)

================
Data references:
================

        outputs_single_hash = SHA256(amount_buffer<wit4>.script_pubkey_buffer<wit3>.$DUST_AMOUNT.target_script_pubkey_buffer<wit5>)
        spent_scripts_single_hash = SHA256(script_pubkey_buffer<wit3>.fee_script_pubkey_buffer<wit1>)
        spent_amounts_single_hash = SHA256(amount_buffer<wit4>.fee_amount_buffer<wit2>)
        sig_hash = epoch<wit16>.control<wit15>.tx_version<wit14>.lock_time<wit13>.prevouts_single_hash<wit12>.&spent_amounts_single_hash.&spent_scripts_single_hash.prev_sequences_single_hash<wit11>.&outputs_single_hash.spend_type<wit10>.input_idx<wit9>.leaf_hash<wit8>.key_version_0<wit7>.code_separator_pos<wit6>
        tagged_sig_hash = SHA256(SHA256($TAPSIGHASH_TAG).SHA256($TAPSIGHASH_TAG).&sig_hash)
        s_value = SHA256(SHA256($BIP0340_CHALLENGE_TAG).SHA256($BIP0340_CHALLENGE_TAG).$G_X.$G_X.&tagged_sig_hash)
        script_computed_sig = $G_X.&s_value

```

(edit: I wonder if it is possible to make the codeblock to have the text to wrap, it would look better I think

edit2: it seems that currently it only wraps on whitespace, but not as terminal would wrap on any char)

There’s one obvious witness size optimization that comes to mind when looking at the report:

`epoch<wit16>.control<wit15>.tx_version<wit14>.lock_time<wit13>.prevouts_single_hash<wit12>`

and

`spend_type<wit10>.input_idx<wit9>.leaf_hash<wit8>.key_version_0<wit7>.code_separator_pos<wit6>`

can be given as just two witness values, not as 10 witnesses - this will save a few bytes used to encode witness sizes.

---

_[View the full topic](https://delvingbitcoin.org/t/basic-vault-prototype-using-op-cat/576)._
