diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 9fce9f3..825e789 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -10,7 +10,7 @@ on: jobs: test: - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 container: bigspider/bitcoin_matt steps: - name: Prepare Configuration File @@ -20,24 +20,32 @@ jobs: - name: Run MATT-enabled bitcoind run: | bitcoind -regtest --daemon + - name: Set up dependencies + run: | + apt-get update + apt-get install -y libssl-dev libffi-dev + apt-get install -y python3-venv - name: Set up Python uses: actions/setup-python@v2 with: python-version: '3.10' - name: Clone uses: actions/checkout@v4 - - name: Install pip and pytest + - name: Install dependencies run: | - apt-get update - apt-get install -y python3-pip + python -m venv venv + source venv/bin/activate + pip install --upgrade pip pip install -r requirements-dev.txt - - name: Install pymatt - run: | pip install . + shell: bash - name: Create test wallet run: bash ./examples/init.sh - name: Run tests and capture output - run: pytest -vv + run: | + source venv/bin/activate + pytest -vv + shell: bash - name: Upload test output as artifact uses: actions/upload-artifact@v4 with: diff --git a/matt/contracts.py b/matt/contracts.py index 1976021..abf4f3f 100644 --- a/matt/contracts.py +++ b/matt/contracts.py @@ -1,3 +1,5 @@ +import hashlib + from abc import ABC, abstractmethod from dataclasses import dataclass from enum import Enum @@ -11,6 +13,19 @@ from .btctools.segwit_addr import encode_segwit_address +def tweak_embed_data(key: bytes, data: bytes) -> Optional[Tuple[bytes, Optional[bool]]]: + """ + Tweaks a key with the sha256 hash of the data, returning the tweaked key and whether the result had to be negated. + If the data is empty, the key is returned as is. + """ + + if len(data) == 0: + return key, None + + data_tweak = hashlib.sha256(key + data).digest() + return tweak_add_pubkey(key, data_tweak) + + class AbstractContract: pass @@ -317,9 +332,7 @@ def get_taptree_merkle_root(self) -> bytes: return self.get_tr_info(b'\0'*32).merkle_root def get_tr_info(self, data: bytes) -> TaprootInfo: - assert len(data) == 32 - - internal_pubkey, _ = tweak_add_pubkey(self.naked_internal_pubkey, data) + internal_pubkey, _ = tweak_embed_data(self.naked_internal_pubkey, data) return script.taproot_construct(internal_pubkey, self.get_scripts())