Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test p2sh encoding with regtest (Failing) #2283

Merged
merged 3 commits into from
Oct 2, 2024
Merged

Test p2sh encoding with regtest (Failing) #2283

merged 3 commits into from
Oct 2, 2024

Conversation

ouziel-slama
Copy link
Contributor

@ouziel-slama ouziel-slama commented Oct 1, 2024

It seems that the p2sh encoding is no longer supported by the latest versions of Bitcoin Core.
When we try to broadcast the second transaction we get the following error:

mandatory-script-verify-flag-failed (Operation not valid with the current stack size)

Here is the transaction not signed:

01000000018a3dc8eb1a64037ef4ec078bc7e55ffe506d39f4c1c9591e469b5f9f51b69dc1000000005a4c582e434e5452505254590200000000000000010000000000001388807b0e97b29c9eb1c4dfb5 9ba2c2261a39e9f0aa8a75210378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71ad0075740087ffffffff0100000000000000000e6a0c0f03fa46c0245f1b32e7fc6800000000

and the same transaction signed:

010000000001018a3dc8eb1a64037ef4ec078bc7e55ffe506d39f4c1c9591e469b5f9f51b69dc10000000000ffffffff0100000000000000000e6a0c0f03fa46c0245f1b32e7fc68024830450221008fcf00afccc09536f1f005dd4d29801ce666461 c350ffbe834ad290013a9d17302205804841b4923e34f1fcaca7f48ecfc0f1fe6ec639a5bbd12660a7c9fbb3175f801210378d430274f8c5ec1321338151e9f27f4c6 76a008bdf8638d07c0b6be9ab35c7100000000 

(https://btc.com/tools/tx/decode)

it is possible to reproduce the error with the script test/regtest/testp2sh.py whose output is as follows:

$ python3 counterpartycore/test/regtest/testp2sh.py 
{'address': 'bcrt1q08alc0e5ua69scxhvyma568nvguqccrvah6ml0', 'secret_key': 'cUB8G5cFtxc4usfgfovqRgCo8qTQUJtctLV8t6YYNfULg3GtehdX', 'public_key': '0378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71'}
{
  "result": {
    "params": {
      "source": "bcrt1q0v8f0v5un6cufha4nw3vyfs6885lp252fehe5d",
      "destination": "bcrt1q08alc0e5ua69scxhvyma568nvguqccrvah6ml0",
      "asset": "XCP",
      "quantity": 10000000000,
      "memo": null,
      "memo_is_hex": false,
      "use_enhanced_send": false
    },
    "name": "send",
    "data": "434e54525052545900000000000000000000000100000002540be400",
    "btc_in": 5000000000,
    "btc_out": 546,
    "btc_change": 4999992879,
    "btc_fee": 6575,
    "rawtransaction": "020000000001017413b5f17308caf75d330f2e492ed091537fd7707288fab07fa6fa4b3e88c08f000000001600147b0e97b29c9eb1c4dfb59ba2c2261a39e9f0aa8affffffff03220200000000000016001479fbfc3f34e7745860d76137da68f362380c606c00000000000000001e6a1c421e2e08c91ee41858882b4b6ef00e32a43ee4869de9c48a2538afd32fd6052a010000001600147b0e97b29c9eb1c4dfb59ba2c2261a39e9f0aa8a02000000000000"
  }
}
Transaction sent: 4c23ffba7743e536edc8d5f2a2e40a31a0bd5daf8c4d416ad810fbbff722f6f2
{
  "result": {
    "params": {
      "source": "bcrt1q0v8f0v5un6cufha4nw3vyfs6885lp252fehe5d",
      "destination": "bcrt1q08alc0e5ua69scxhvyma568nvguqccrvah6ml0",
      "asset": "BTC",
      "quantity": 10000000000,
      "memo": null,
      "memo_is_hex": false,
      "use_enhanced_send": false
    },
    "name": "send",
    "data": null,
    "btc_in": 15000000000,
    "btc_out": 10000000000,
    "btc_change": 4999985325,
    "btc_fee": 14675,
    "rawtransaction": "0200000000010369be192a9182b3b9325ef97e26cc8b5dd27ca7fe572b2dfb1b972319cd5f2bec000000001600147b0e97b29c9eb1c4dfb59ba2c2261a39e9f0aa8affffffff39ac255fbcf1b4e04daaf16eb495972577346c7047ceaef3cfb0c7322b7df295000000001600147b0e97b29c9eb1c4dfb59ba2c2261a39e9f0aa8affffffff4032b4b103363b8508429197df749819f9430e1c17b441af535549bad0354779000000001600147b0e97b29c9eb1c4dfb59ba2c2261a39e9f0aa8affffffff0200e40b540200000016001479fbfc3f34e7745860d76137da68f362380c606cadb8052a010000001600147b0e97b29c9eb1c4dfb59ba2c2261a39e9f0aa8a02000002000002000000000000"
  }
}
Transaction sent: e1f28ecb82633ffc031744587b39ad83213279413680f08ae2f62914245f5e41
unsigned_pretx_hex: 0100000001415e5f241429f6e28af080364179322183ad397b58441703fc3f6382cb8ef2e10000000016001479fbfc3f34e7745860d76137da68f362380c606cffffffff02220200000000000017a9146ea36487cfd933605f8b1d56a37c3216981ff9f587f8e00b540200000016001479fbfc3f34e7745860d76137da68f362380c606c00000000
AMount 10000000000
signed_pretx_hex: 01000000000101415e5f241429f6e28af080364179322183ad397b58441703fc3f6382cb8ef2e10000000000ffffffff02220200000000000017a9146ea36487cfd933605f8b1d56a37c3216981ff9f587f8e00b540200000016001479fbfc3f34e7745860d76137da68f362380c606c02483045022100b649cb853319dd90c33444e0a5c88383a07aeb795b0c7285713a55c4c2c4712902204d494ff3b4671d033b87f29de45a912153dc2e2d9c46dec55ca65366d998814201210378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c7100000000
pretx_txid c19db6519f5f9b461e59c9c1f4396d50fe5fe5c78b07ecf47e03641aebc83d8a
unsigned_finaltx_hex: 01000000018a3dc8eb1a64037ef4ec078bc7e55ffe506d39f4c1c9591e469b5f9f51b69dc1000000005a4c582e434e5452505254590200000000000000010000000000001388807b0e97b29c9eb1c4dfb59ba2c2261a39e9f0aa8a75210378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71ad0075740087ffffffff0100000000000000000e6a0c0f03fa46c0245f1b32e7fc6800000000
signed_finaltx_hex: 010000000001018a3dc8eb1a64037ef4ec078bc7e55ffe506d39f4c1c9591e469b5f9f51b69dc10000000000ffffffff0100000000000000000e6a0c0f03fa46c0245f1b32e7fc68024830450221008fcf00afccc09536f1f005dd4d29801ce666461c350ffbe834ad290013a9d17302205804841b4923e34f1fcaca7f48ecfc0f1fe6ec639a5bbd12660a7c9fbb3175f801210378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c7100000000
Traceback (most recent call last):
  File "/home/ouziel/counterparty/counterparty-core/counterparty-core/counterpartycore/test/regtest/testp2sh.py", line 152, in <module>
    txid = bitcoin_cli("sendrawtransaction", signed_finaltx_hex).strip()
  File "/home/ouziel/.local/lib/python3.10/site-packages/sh.py", line 1508, in __call__
    rc = self.__class__.RunningCommandCls(cmd, call_args, stdin, stdout, stderr)
  File "/home/ouziel/.local/lib/python3.10/site-packages/sh.py", line 737, in __init__
    self.wait()
  File "/home/ouziel/.local/lib/python3.10/site-packages/sh.py", line 799, in wait
    self.handle_command_exit_code(exit_code)
  File "/home/ouziel/.local/lib/python3.10/site-packages/sh.py", line 826, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_26: 

  RAN: /home/ouziel/bitcoin-27.0/bin/bitcoin-cli -rpcuser=rpc -rpcpassword=rpc -rpcconnect=localhost -regtest sendrawtransaction 010000000001018a3dc8eb1a64037ef4ec078bc7e55ffe506d39f4c1c9591e469b5f9f51b69dc10000000000ffffffff0100000000000000000e6a0c0f03fa46c0245f1b32e7fc68024830450221008fcf00afccc09536f1f005dd4d29801ce666461c350ffbe834ad290013a9d17302205804841b4923e34f1fcaca7f48ecfc0f1fe6ec639a5bbd12660a7c9fbb3175f801210378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c7100000000

  STDOUT:


  STDERR:
error code: -26
error message:
mandatory-script-verify-flag-failed (Operation not valid with the current stack size)

If this is confirmed, it would be necessary to disable the p2sh encoding.

@ouziel-slama ouziel-slama marked this pull request as draft October 1, 2024 18:03
@ouziel-slama ouziel-slama changed the title Test p2sh encoding with regtest Test p2sh encoding with regtest (Failing) Oct 1, 2024
@adamkrellenstein adamkrellenstein mentioned this pull request Oct 1, 2024
@ouziel-slama
Copy link
Contributor Author

Fixed the function to sign p2sh tx and now get a this error:

unsigned_pretx_hex: 010000000101b6f4684c8671f2e47241b700cf356f67b2fac8c6367c356b8e414c0bba8cbb0000000016001479fbfc3f34e7745860d76137da68f362380c606cffffffff02220200000000000017a914a92966d3674027049552f550bf1e21d85e4b521887f8e00b540200000016001479fbfc3f34e7745860d76137da68f362380c606c00000000
signed_pretx_hex: 0100000000010101b6f4684c8671f2e47241b700cf356f67b2fac8c6367c356b8e414c0bba8cbb0000000000ffffffff02220200000000000017a914a92966d3674027049552f550bf1e21d85e4b521887f8e00b540200000016001479fbfc3f34e7745860d76137da68f362380c606c0247304402201c97ca16a50351672d5f6fb85ef7f9bf251c9f9bca7166916dc11277262de00902207e06fc0e021a5dfb25ae8dd390cfb16b252b5d25ad9bd61954e756d46782ad5f01210378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c7100000000
pretx_txid 1ed9f0dc50d428107d784600e5239e6e8a890d9cb0f4e3a369ce221077940d08
unsigned_finaltx_hex: 0100000001080d94771022ce69a3e3f4b09c0d898a6e9e23e50046787d1028d450dcf0d91e000000005a4c582e434e545250525459020000000000000001000000000000138880a960db3f4f3803a94d2bdf1fd51f8612627798ae75210378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71ad0075740087ffffffff0100000000000000000e6a0c90de3e351c9bb4587f517b1700000000
signed_finaltx_hex: 0100000001080d94771022ce69a3e3f4b09c0d898a6e9e23e50046787d1028d450dcf0d91e00000000a5483045022100dd6f5a3fa2f5a28c25151a9bac48b80e54e0ae633016334bf0abdc9f543e800f02203a494dd53831a1290880be2d2e6ea6e67b4b3f828d0571582a7ae6ef6d703b47014c5a4c582e434e545250525459020000000000000001000000000000138880a960db3f4f3803a94d2bdf1fd51f8612627798ae75210378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71ad0075740087ffffffff0100000000000000000e6a0c90de3e351c9bb4587f517b1700000000
Traceback (most recent call last):
  File "/home/ouziel/counterparty/counterparty-core/counterparty-core/counterpartycore/test/regtest/testp2sh.py", line 189, in <module>
    txid = bitcoin_cli("sendrawtransaction", signed_finaltx_hex).strip()
  File "/home/ouziel/.local/lib/python3.10/site-packages/sh.py", line 1508, in __call__
    rc = self.__class__.RunningCommandCls(cmd, call_args, stdin, stdout, stderr)
  File "/home/ouziel/.local/lib/python3.10/site-packages/sh.py", line 737, in __init__
    self.wait()
  File "/home/ouziel/.local/lib/python3.10/site-packages/sh.py", line 799, in wait
    self.handle_command_exit_code(exit_code)
  File "/home/ouziel/.local/lib/python3.10/site-packages/sh.py", line 826, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_26: 

  RAN: /home/ouziel/bitcoin-27.0/bin/bitcoin-cli -rpcuser=rpc -rpcpassword=rpc -rpcconnect=localhost -regtest sendrawtransaction 0100000001080d94771022ce69a3e3f4b09c0d898a6e9e23e50046787d1028d450dcf0d91e00000000a5483045022100dd6f5a3fa2f5a28c25151a9bac48b80e54e0ae633016334bf0abdc9f543e800f02203a494dd53831a1290880be2d2e6ea6e67b4b3f828d0571582a7ae6ef6d703b47014c5a4c582e434e545250525459020000000000000001000000000000138880a960db3f4f3803a94d2bdf1fd51f8612627798ae75210378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71ad0075740087ffffffff0100000000000000000e6a0c90de3e351c9bb4587f517b1700000000

  STDOUT:


  STDERR:
error code: -26
error message:
mandatory-script-verify-flag-failed (Script evaluated without error but finished with a false/empty top stack element)

@ouziel-slama ouziel-slama mentioned this pull request Oct 2, 2024
6 tasks
@ouziel-slama
Copy link
Contributor Author

Managed to sign with Bitcoin Core a broadcast with p2sh but again fails to broadcast:

$ python3 tools/xcpcli.py send_broadcast --address bcrt1qlnls6ygywdjq2xa3zx3pl55fnr2msv56qlumq0 --timestamp 4003903985 --value 1 --fee_fraction 0.5 --text "un test de broadcast avec p2sh" --encoding p2sh --fee_per_kb 1000 
{
  "result": {
    "params": {
      "source": "bcrt1qlnls6ygywdjq2xa3zx3pl55fnr2msv56qlumq0",
      "timestamp": 4003903985,
      "value": 1.0,
      "fee_fraction": 0.5,
      "text": "un test de broadcast avec p2sh"
    },
    "name": "broadcast",
    "data": "434e5452505254591eeea6b9f13ff000000000000002faf0801e756e20746573742064652062726f61646361737420617665632070327368",
    "btc_in": 4949990000,
    "btc_out": 546,
    "btc_change": 4949989224,
    "btc_fee": 230,
    "rawtransaction": null,
    "unsigned_pretx_hex": "01000000013f2313db8c1f63ad6033bcf54f9ac0ca1100f767623a41968f06baa5b883a9d001000000160014fcff0d11047364051bb111a21fd28998d5b8329affffffff02220200000000000017a9148439c91e9d37b896f3847d9745d09a9a84c6b7808768d70a2701000000160014fcff0d11047364051bb111a21fd28998d5b8329a00000000"
  }
}
Transaction sent: ae6cabb6f96d553366ee02371b7d9bb1f0004a2af8df7d03c5cb1467640e1043

then

$ python3 tools/xcpcli.py send_broadcast --address bcrt1qlnls6ygywdjq2xa3zx3pl55fnr2msv56qlumq0 --timestamp 4003903985 --value 1 --fee_fraction 0.5 --text "un test de broadcast avec p2sh" --encoding p2sh --fee_per_kb 1000 --p2sh_pretx_txid ae6cabb6f96d553366ee02371b7d9bb1f0004a2af8df7d03c5cb1467640e1043
{
  "result": {
    "params": {
      "source": "bcrt1qlnls6ygywdjq2xa3zx3pl55fnr2msv56qlumq0",
      "timestamp": 4003903985,
      "value": 1.0,
      "fee_fraction": 0.5,
      "text": "un test de broadcast avec p2sh"
    },
    "name": "broadcast",
    "data": "434e5452505254591eeea6b9f13ff000000000000002faf0801e756e20746573742064652062726f61646361737420617665632070327368",
    "btc_in": 0,
    "btc_out": 546,
    "btc_change": null,
    "btc_fee": 0,
    "rawtransaction": "010000000143100e646714cbc5037ddff82a4a00f0b19b7d1b3702ee6633556df9b6ab6cae00000000644c6238434e5452505254591eeea6b9f13ff000000000000002faf0801e756e20746573742064652062726f61646361737420617665632070327368752103a4bbb9078f7a6db11132211f5db082f485068b19b1ab7486b444880766375c84ad0075740087ffffffff0100000000000000000e6a0c1c95b6a013ec2776e7c05fe000000000"
  }
}


  RAN: /home/ouziel/bitcoin-27.0/bin/bitcoin-cli -rpcuser=rpc -rpcpassword=rpc -rpcconnect=localhost -regtest -rpcwallet=xcpwallet sendrawtransaction 010000000143100e646714cbc5037ddff82a4a00f0b19b7d1b3702ee6633556df9b6ab6cae00000000644c6238434e5452505254591eeea6b9f13ff000000000000002faf0801e756e20746573742064652062726f61646361737420617665632070327368752103a4bbb9078f7a6db11132211f5db082f485068b19b1ab7486b444880766375c84ad0075740087ffffffff0100000000000000000e6a0c1c95b6a013ec2776e7c05fe000000000 0

  STDOUT:


  STDERR:
error code: -26
error message:
mandatory-script-verify-flag-failed (Operation not valid with the current stack size)

@ouziel-slama ouziel-slama marked this pull request as ready for review October 2, 2024 10:52
@ouziel-slama ouziel-slama merged commit df0d65a into develop Oct 2, 2024
17 checks passed
@ouziel-slama ouziel-slama deleted the p2sh branch October 2, 2024 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants