Merkleize All The Things
Project description
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_CHECKCONTRACVERIFY
opcode of MATT.
Prerequisites
Installing the library
Optionally, create a python environment:
$ python -m venv venv
$ source venv/bin/activate
Install the library with:
$ pip install .
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
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.
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.
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.
Tests
This project uses pytest
to run automated tests. Install it with:
$ pip install pytest
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pymatt-0.0.1.tar.gz
.
File metadata
- Download URL: pymatt-0.0.1.tar.gz
- Upload date:
- Size: 125.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02c746d5967c32f6eb77a3af5f74944a99fbe1fe27f6bfbecd2e6cc81e2673db |
|
MD5 | bcfd042630313d6c7dff024ebb347745 |
|
BLAKE2b-256 | 945e5d3b92f149a9e34b67380a2c1453142dbcb98a2c0e7d1bb688eb1e819586 |
File details
Details for the file pymatt-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: pymatt-0.0.1-py3-none-any.whl
- Upload date:
- Size: 94.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea588405a33f1289c31b86a68a358d21dafc885c348ca55861813a7e0c6c3249 |
|
MD5 | af3bf1ca2bc8cc33b7aa26f1e00c88ba |
|
BLAKE2b-256 | 3cfe14e8ecfe48a778b4d2c5d1d72c99078b19f1c040e41790cba2319adf68d9 |