public inbox for bitcoindev@googlegroups.com
 help / color / mirror / Atom feed
From: Nadav Ivgi <nadav@shesek.info>
To: Bitcoin Protocol Discussion <bitcoin-dev@lists.linuxfoundation.org>
Subject: [bitcoin-dev] Minsc, a Miniscript-based scripting language
Date: Wed, 29 Jul 2020 18:10:42 +0300	[thread overview]
Message-ID: <CAGXD5f3SiXHOmjSVxUQWOLT5SocQ62qTNGJOmTUtW7kDeduFjA@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2667 bytes --]

Hi all,

I recently released Minsc, a high-level scripting language for expressing
Bitcoin Script spending conditions using a simple and familiar syntax.

Minsc is based on the Miniscript Policy language, with additional features
and syntactic sugar sprinkled on top, including variables, functions, infix
notation, human-readable times and more.

A live compiler (Minsc->Policy->Miniscript->Script) and documentation are
available on the website: https://min.sc

Source code (in Rust) is available on github:
https://github.com/shesek/minsc

Some example Minsc scripts:

- A user and a 2FA service need to sign off, but after 90 days the user
alone is enough

      pk(user_pk) && (9@pk(service_pk) || older(90 days))

- Traditional preimage-based HTLC

      $redeem = pk(A) && sha256(H);
      $refund = pk(B) && older(10);

      likely@$redeem || $refund

- Liquid-like federated pegin with emergency recovery keys

      $federation = 4 of [ pk(A), pk(B), pk(C), pk(D), pk(E) ];
      $recovery = 2 of [ pk(F), pk(G), pk(H) ];
      $timeout = older(heightwise 2 weeks);

      likely@$federation || ($timeout && $recovery)

- The BOLT #3 received HTLC policy

      fn htlc_received($revoke_pk, $local_pk, $remote_pk, $secret, $delay) {
        $success = pk($local_pk) && hash160($secret);
        $timeout = older($delay);

        pk($revoke_pk) || (pk($remote_pk) && ($success || $timeout))
      }

      htlc_received(A, B, C, H, 3 hours)

- 2FA where the user has a 2-of-2 setup and the service provider is a
3-of-4 federation

      fn two_factor($user, $provider, $delay) =
        $user && (likely@$provider || older($delay));

      $user = pk(user_desktop) && pk(user_mobile);
      $providers = [ pk(P1), pk(P2), pk(P3), pk(P4) ];

      two_factor($user, 3 of $providers, 4 months)

- Easily add NSA backdoors to everything 🕵️🚪

      _backdoor=pk(usgovt), _pk=pk, _older=older, _after=after,
      _sha256=sha256, _ripemd160=ripemd160;

      fn pk(x) = _pk(x) || _backdoor;
      fn older(x) = _older(x) || _backdoor;
      fn after(x) = _after(x) || _backdoor;
      fn sha256(x) = _sha256(x) || _backdoor;
      fn ripemd160(x) = _ripemd160(x) || _backdoor;

      (pk(A) && sha256(H)) || (pk(B) && older(10))

Feedback is appreciated!

Nadav

P.S Since every Miniscript Policy is also a valid Minsc expression, the
min.sc web code editor UI could also be useful for experimenting with bare
policies. You'll get syntax highlighting, parentheses matching, real-time
compilation (in a web worker so the browser doesn't freeze) and syntax
error reporting.

[-- Attachment #2: Type: text/html, Size: 3151 bytes --]

                 reply	other threads:[~2020-07-29 15:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGXD5f3SiXHOmjSVxUQWOLT5SocQ62qTNGJOmTUtW7kDeduFjA@mail.gmail.com \
    --to=nadav@shesek.info \
    --cc=bitcoin-dev@lists.linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox