Skip to main content

Merkleize All The Things

Project description

pymatt

WIP Python framework for MATT smart contracts

This repository contains a (very much Work In Progress) framework to create and test smart contracts using the OP_CHECKCONTRACTVERIFY opcode.

Prerequisites

Installing the library

Optionally, create a python environment:

$ python -m venv .venv
$ source .venv/bin/activate

Install the library with:

$ pip install pymatt

Run bitcoin-inquisition MATT in regtest mode

The fastest way to get started is this docker container:

$ docker pull bigspider/bitcoin_matt
$ docker run -d -p 18443:18443 bigspider/bitcoin_matt

Alternatively, build the same yourself from this branch. Here's the bitcoin.conf file used for these examples:

bitcoin.conf
regtest=1
printtoconsole=1
server=1
txindex=1
fallbackfee=0.00001
minrelaytxfee=0
blockmintxfee=0

[regtest]
rpcbind=0.0.0.0
rpcallowip=0.0.0.0/0
rpcuser=rpcuser
rpcpassword=rpcpass

Case studies

The examples folder contains some utility scripts to work with regtest bitcoin-core:

  • init.sh creates/loads and funds a wallet named testwallet. Run it once before the examples and you're good to go.
  • fund.sh that allows to fund a certain address.

The following examples are currently implemented

  • Vault [cli]: an implementation of a vault, largely compatible with OP_VAULT BIP-0345.
  • Rock-Paper-Scissors [cli]: play Rock-Paper-Scissors on bitcoin.
  • RAM [cli]: a a contract that uses a Merkle tree to store a vector of arbitrary length in size, with transitions that allow to modify one element of the vector.
  • game256: Implements an end-2-end execution of the toy example for fraud proofs drafted in bitcoin-dev.

For the ones marked with [cli], a simple interactive tool allows to play with the contract. More code examples can be found in the test suite.

Docs

See the docs folder for high-level documentation on how to design smart contracts using MATT.

As the framework is still in development, we recommend looking at the code examples below for developer documentation on using pymatt.

Contribution

Prerequisites

The examples in this repository can be installed and set up using uv.

If you do not have uv installed, run one of the following commands.

Install using pipx
pipx install uv
Install using standalone installer (Darwin and Linux)
curl -LsSf https://astral.sh/uv/install.sh | sh
Install using Homebrew (Darwin)
brew install uv

The following commands help you set up and activate a Python virtual environment where uv can download project dependencies from the PyPI open-sourced registry defined under pyproject.toml file.

Set up environment and synchronize project dependencies
git clone git@github.com:Merkleize/pymatt.git
cd pymatt
uv venv --python 3.9
source .venv/bin/activate
uv sync --dev

Run examples

All the examples use the RPC_USER, RPC_PASSWORD, RPC_HOST, RPC_PORT environment variables to set up a connection with the regtest bitcoin node; the default values are the same as set in the container.

If they differ in your system, make sure to set them appropriately, or create a .env file similar to the following:

RPC_HOST = "localhost"
RPC_USER = "rpcuser"
RPC_PASSWORD = "rpcpass"
RPC_PORT = "18443"

NOTE: the examples do not handle fee management and will send transactions with 0 fees; those are rejected with the default settings of bitcoin-core.

If not using the container above, please see an example of custom bitcoin.conf to work with the scripts in this repository.

You can use the following command to install the extra dependencies required for running the examples in the repository.

Install dependencies for the examples
uv sync --dev --extra examples

Tests

This project uses pytest to run automated tests. Install the dependencies with:

uv sync --dev

The test suite requires a running instance of the MATT-enabled bitcoin-inquisition, for example using the container above. The init.sh script makes sure that a funded test wallet is loaded.

$ docker run -d -p 18443:18443 bigspider/bitcoin_matt
$ bash ./examples/init.sh

Then, run the tests with

$ pytest

Refer to the pytest documentation for more advanced options.

Report

Some tests produce additional illustrative info about the transactions produced during the contract execution, in a Markdown report called report.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymatt-0.1.0.tar.gz (150.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymatt-0.1.0-py3-none-any.whl (91.3 kB view details)

Uploaded Python 3

File details

Details for the file pymatt-0.1.0.tar.gz.

File metadata

  • Download URL: pymatt-0.1.0.tar.gz
  • Upload date:
  • Size: 150.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pymatt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4152bad90fd01493adae5a75fa9cf2a56eb1d5e15533d6985a5addc6d284cf6c
MD5 ef17a6a950986b2b702b111678d537a5
BLAKE2b-256 00ebc65913ddf018586f880077711a7061fed74d946c6ec0d6cdb187df0beb57

See more details on using hashes here.

File details

Details for the file pymatt-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pymatt-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 91.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pymatt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 01d710dda6a305f6f79682403df6348b3e44e7e0cb3c5fda872e9ef4fa374f11
MD5 de5eb5bc89d18989fd45dc7f6178456b
BLAKE2b-256 a752f0459751d805f6de86846ab79eb4c3430c89d7e08e728aaa79a157a12595

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page