Skip to content

Commit e9cd207

Browse files
authored
Merge pull request #20 from Merkleize/newspecs
Update to the new CCV specs
2 parents c955e97 + fb46cca commit e9cd207

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

.github/workflows/run-tests.yml

+15-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010

1111
jobs:
1212
test:
13-
runs-on: ubuntu-20.04
13+
runs-on: ubuntu-24.04
1414
container: bigspider/bitcoin_matt
1515
steps:
1616
- name: Prepare Configuration File
@@ -20,24 +20,32 @@ jobs:
2020
- name: Run MATT-enabled bitcoind
2121
run: |
2222
bitcoind -regtest --daemon
23+
- name: Set up dependencies
24+
run: |
25+
apt-get update
26+
apt-get install -y libssl-dev libffi-dev
27+
apt-get install -y python3-venv
2328
- name: Set up Python
2429
uses: actions/setup-python@v2
2530
with:
2631
python-version: '3.10'
2732
- name: Clone
2833
uses: actions/checkout@v4
29-
- name: Install pip and pytest
34+
- name: Install dependencies
3035
run: |
31-
apt-get update
32-
apt-get install -y python3-pip
36+
python -m venv venv
37+
source venv/bin/activate
38+
pip install --upgrade pip
3339
pip install -r requirements-dev.txt
34-
- name: Install pymatt
35-
run: |
3640
pip install .
41+
shell: bash
3742
- name: Create test wallet
3843
run: bash ./examples/init.sh
3944
- name: Run tests and capture output
40-
run: pytest -vv
45+
run: |
46+
source venv/bin/activate
47+
pytest -vv
48+
shell: bash
4149
- name: Upload test output as artifact
4250
uses: actions/upload-artifact@v4
4351
with:

matt/contracts.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import hashlib
2+
13
from abc import ABC, abstractmethod
24
from dataclasses import dataclass
35
from enum import Enum
@@ -11,6 +13,19 @@
1113
from .btctools.segwit_addr import encode_segwit_address
1214

1315

16+
def tweak_embed_data(key: bytes, data: bytes) -> Optional[Tuple[bytes, Optional[bool]]]:
17+
"""
18+
Tweaks a key with the sha256 hash of the data, returning the tweaked key and whether the result had to be negated.
19+
If the data is empty, the key is returned as is.
20+
"""
21+
22+
if len(data) == 0:
23+
return key, None
24+
25+
data_tweak = hashlib.sha256(key + data).digest()
26+
return tweak_add_pubkey(key, data_tweak)
27+
28+
1429
class AbstractContract:
1530
pass
1631

@@ -317,9 +332,7 @@ def get_taptree_merkle_root(self) -> bytes:
317332
return self.get_tr_info(b'\0'*32).merkle_root
318333

319334
def get_tr_info(self, data: bytes) -> TaprootInfo:
320-
assert len(data) == 32
321-
322-
internal_pubkey, _ = tweak_add_pubkey(self.naked_internal_pubkey, data)
335+
internal_pubkey, _ = tweak_embed_data(self.naked_internal_pubkey, data)
323336

324337
return script.taproot_construct(internal_pubkey, self.get_scripts())
325338

0 commit comments

Comments
 (0)