Closed ongrid closed 3 months ago
Thanks for sharing. I will look into it as soon as I find some time.
Btw, up to approximately what size of witness does it stop working?
I will reiterate later this week, check and come back with updates, but if you see any obvious misuse of the library and data or any other recommendations that may help in debugging, please let me know.
@karask @ongrid I was facing a similar problem and I think it might be related with the sign bit on the control block. I pushed a PR that might help. (I actually could confirm modifying a little bit the example from @ongrid that the fix works) I'm kind of new on bitcoin protocols, so PTAL if it works for you.
My experiments have shown that the result depends on two factors - both size AND content ind it seems two separate issues:
These payloads always succeed
payload = 'deadbeef' * 31 + "dead" + '83'
payload = 'deadbeef' * 31 + "dead" + '53'
These payloads always fail
payload = 'deadbeef' * 31 + "dead" + 'f3'
payload = 'deadbeef' * 31 + "dead" + '7b'
The failure reason is same in both cases - when I push raw tx to electrumx on this line I get
Exception: the transaction was rejected by network rules.
mandatory-script-verify-flag-failed (Witness program hash mismatch)
@jonasmartin I've installed bitcoin-utils from your repo #64
pip install git+https://github.com/jonasmartin/python-bitcoin-utils.git
Collecting git+https://github.com/jonasmartin/python-bitcoin-utils.git
Cloning https://github.com/jonasmartin/python-bitcoin-utils.git to /private/var/folders/31/zqqkzzk1645f56szy7pzvtym0000gn/T/pip-req-build-kb1ezchh
Running command git clone --filter=blob:none --quiet https://github.com/jonasmartin/python-bitcoin-utils.git /private/var/folders/31/zqqkzzk1645f56szy7pzvtym0000gn/T/pip-req-build-kb1ezchh
Resolved https://github.com/jonasmartin/python-bitcoin-utils.git to commit 8b8ea5c473bf9cbf2fd7f095d785086a1ebe81dd
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: base58check<2.0,>=1.0.2 in ./.venv/lib/python3.12/site-packages (from bitcoin-utils==0.6.5) (1.0.2)
Requirement already satisfied: ecdsa==0.17.0 in ./.venv/lib/python3.12/site-packages (from bitcoin-utils==0.6.5) (0.17.0)
Requirement already satisfied: sympy<2.0,>=1.2 in ./.venv/lib/python3.12/site-packages (from bitcoin-utils==0.6.5) (1.12)
Requirement already satisfied: python-bitcoinrpc<2.0,>=1.0 in ./.venv/lib/python3.12/site-packages (from bitcoin-utils==0.6.5) (1.0)
Requirement already satisfied: hdwallet==2.2.1 in ./.venv/lib/python3.12/site-packages (from bitcoin-utils==0.6.5) (2.2.1)
Requirement already satisfied: six>=1.9.0 in ./.venv/lib/python3.12/site-packages (from ecdsa==0.17.0->bitcoin-utils==0.6.5) (1.16.0)
Requirement already satisfied: mnemonic<1,>=0.19 in ./.venv/lib/python3.12/site-packages (from hdwallet==2.2.1->bitcoin-utils==0.6.5) (0.21)
Requirement already satisfied: pycryptodome<4,>=3.15 in ./.venv/lib/python3.12/site-packages (from hdwallet==2.2.1->bitcoin-utils==0.6.5) (3.20.0)
Requirement already satisfied: base58<3,>=2.0.1 in ./.venv/lib/python3.12/site-packages (from hdwallet==2.2.1->bitcoin-utils==0.6.5) (2.1.1)
Requirement already satisfied: mpmath>=0.19 in ./.venv/lib/python3.12/site-packages (from sympy<2.0,>=1.2->bitcoin-utils==0.6.5) (1.3.0)
Building wheels for collected packages: bitcoin-utils
Building wheel for bitcoin-utils (pyproject.toml) ... done
Created wheel for bitcoin-utils: filename=bitcoin_utils-0.6.5-py3-none-any.whl size=43509 sha256=cc9d44c476bdf7057118aa3adc82b3541abe6a89c9e9bc022338495d1e6785d7
Stored in directory: /private/var/folders/31/zqqkzzk1645f56szy7pzvtym0000gn/T/pip-ephem-wheel-cache-5oki0vzy/wheels/3e/01/42/a6eb8003a9d836a567dcbd5b2071a95ba90d4db21727998fcf
Successfully built bitcoin-utils
Installing collected packages: bitcoin-utils
Successfully installed bitcoin-utils-0.6.5
The behavior is still same. "Lucky" payloads continue working, Failing - still fail.
@ongrid when you tried my changes did you also modified your code? It requires a simple change when creating the controlblock like this: https://github.com/karask/python-bitcoin-utils/pull/64/files#diff-de03fd558138bb99805803f9139b364e3dc9462b1ab228dad615d6f7d2f53477R114 In your code the change should be here: https://github.com/ongrid/bitcoin-playground/blob/42a4405cee9bff4018ac1b4f1c2ea9b964987c5f/generator/inscribe.py#L122
Tried after your comment @jonasmartin
-control_block = ControlBlock(alice_priv_key.get_public_key())
+control_block = ControlBlock(alice_priv_key.get_public_key(), is_odd=alice_p2tr.is_odd())
With random byte in payload, results are still sporadical
+import random
+random_byte = format(random.randint(0, 255), '02x')
+payload = 'deadbeef' * 31 + "dead" + random_byte
@ongrid Pleaes try with taproot_script_address.is_odd()
because is_odd
result is dependent of the script passed as argument when calculating tweaking
@jonasmartin fantastic! It works 🎉. Both size limitations and content issues solved by #64! Highly apreciate!
Oh great news! 👍
@ongrid , @jonasmartin solution was fine. I just merged his PR; new version is v0.6.6. Also updated library in pypi. Thanks for reporting!
Trying to execute commit-reveal process for ordinals I noticed that after some size threshold the following code produces invalid raw transactions that get discarded by broadcasting endpoints with the following error:
Error: non-mandatory-script-verify-flag (Witness program hash mismatch)
.Context
Ordinals standard allows to store various metadata in taproot scripts on-chain https://docs.ordinals.com/inscriptions/metadata.html. Examples prove that there is
Expected Behavior
Here is the proper flow with downsized witness:
Reproduction
The code below has larger taproot script, and produces invalid reveal Tx
I'm trying to put HTML page into taproot script
I encode the data into OP_IF - OP_ENDIF block
Calculate fees and values for outputs
Getting UTXO to spend (from the wallet API)
Generate "commit" Tx
It's always properly broadcasted
Examples: 22cd4a7002b2e4e19abf5fa15694024c3fb3e80dbe4657c5630b708962ffe561
Building reveal Tx:
Nodes / broadcasting services return
Error: non-mandatory-script-verify-flag (Witness program hash mismatch)
. The only service that accepts these Txes is https://live.blockcypher.com/btc/pushtx/ (but anyway, these transactions are never relayed to other nodes and never included in the block)Examples of failing txes:
b707672166b71c86c85a608b8aec9db715892ec511a6a0752a95f509a65bba37
5095c3caf4dc1a8d8b813596bb3f62b52b7ef59ec6e2b239a4d717038aef3660
If I make content ~30% shorter, the reveal tx becomes valid (see "Expected behavior examples").
Highly appreciate any help