Skip to content

update segwit livebook to latest release#5

Open
wchennc wants to merge 5 commits into
RooSoft:mainfrom
wchennc:update_segwit_livebook
Open

update segwit livebook to latest release#5
wchennc wants to merge 5 commits into
RooSoft:mainfrom
wchennc:update_segwit_livebook

Conversation

@wchennc

@wchennc wchennc commented May 23, 2024

Copy link
Copy Markdown

No description provided.

Wen Chen added 2 commits May 23, 2024 09:53
@RooSoft

RooSoft commented May 23, 2024

Copy link
Copy Markdown
Owner

First thing I notice, is that testnet P2SH derivation paths should probably start with m/49'/1' rather than the current m/44'/1'.

See Greg Walker's explanation

@wchennc

wchennc commented May 23, 2024

Copy link
Copy Markdown
Author

First thing I notice, is that testnet P2SH derivation paths should probably start with m/49'/1' rather than the current m/44'/1'.

See Greg Walker's explanation

Oh you mean both the change and destination wallet should be created with m/49'/1' as well? good point, let me give it a try.

@wchennc

wchennc commented May 23, 2024

Copy link
Copy Markdown
Author

Updated both derivation path to m/49' /1' in the output. No luck, still getting
mandatory-script-verify-flag-failed (Opcode missing or not understood) error

Newly generated tx is

0200000001fda3efeb2c0b5567d8426a6e77784ddfbe2ae36dedcc6e0f1a34022d04b7ef39000000006a4730440220515d261add6bf93cdfc9f5791606f5ecb7eaeb849196e14c1da3165853651d0a02204701947402ea13b5a20521102cf064dfb3272e5cbf3e62faeebbe264c02168be0121039d109ebbb5ea0b46b993b182198209822748680696b471d1e606ef0f1e0935e5fdffffff02ebbe12000000000017a9147c6f8d300ea90a234c3c16b82778e9db42d0f4dd87e80300000000000017a914e8ef4ef62c41ee052dd1242f6e49eca376751cf2872caf2400```

@RooSoft

RooSoft commented May 23, 2024

Copy link
Copy Markdown
Owner

Same behavior here...

Trying to send that same transaction through BlockCypher, I got a different error message:

Error validating transaction: Error running script for input 0 referencing 39efb7042d02341a0f6ecced6de32abedf4d78776e6a42d867550b2cebefa3fd at 0: Invalid opcode in script:187.

@RooSoft

RooSoft commented May 23, 2024

Copy link
Copy Markdown
Owner

Here is what I get when I decode the transaction using bitcoinlib:

 %BitcoinLib.Transaction{
   version: 2,
   id: "5868e8c8511aee786bd5fe13d61b89726c3e9fd886cef68051ed8a792894465f",
   inputs: [
     %BitcoinLib.Transaction.Input{
       txid: "39efb7042d02341a0f6ecced6de32abedf4d78776e6a42d867550b2cebefa3fd",
       vout: 0,
       script_sig: [%BitcoinLib.Script.Opcodes.Data{value: <<0x30440220515d261add6bf93cdfc9f5791606f5ecb7eaeb849196e14c1da3165853651d0a02204701947402ea13b5a20521102cf064dfb3272e5cbf3e62faeebbe264c02168be01::568>>},
        %BitcoinLib.Script.Opcodes.Data{value: <<0x039d109ebbb5ea0b46b993b182198209822748680696b471d1e606ef0f1e0935e5::264>>}],
       sequence: 4294967293
     }
   ],
   outputs: [
     %BitcoinLib.Transaction.Output{
       value: 1228523,
       script_pub_key: [%BitcoinLib.Script.Opcodes.Crypto.Hash160{},
        %BitcoinLib.Script.Opcodes.Data{value: <<0x7c6f8d300ea90a234c3c16b82778e9db42d0f4dd::160>>},
        %BitcoinLib.Script.Opcodes.BitwiseLogic.Equal{}],
       invalid_script: nil,
       error_message: nil
     },
     %BitcoinLib.Transaction.Output{
       value: 1000,
       script_pub_key: [%BitcoinLib.Script.Opcodes.Crypto.Hash160{},
        %BitcoinLib.Script.Opcodes.Data{value: <<0xe8ef4ef62c41ee052dd1242f6e49eca376751cf2::160>>},
        %BitcoinLib.Script.Opcodes.BitwiseLogic.Equal{}],
       invalid_script: nil,
       error_message: nil
     }
   ],
   locktime: 2404140,
   segwit?: false,
   coinbase?: false,
   witness: []
 }, ""}

The locktime is a little big and the segwit flag is false with an empty witness...

Will investigate more tomorrow, but let me know if you happen to find something in the meantime.

I got the above result by running this in iex:

Transaction.decode Binary.from_hex "0200000001fda3efeb2c0b5567d8426a6e77784ddfbe2ae36dedcc6e0f1a34022d04b7ef39000000006a4730440220515d261add6bf93cdfc9f5791606f5ecb7eaeb849196e14c1da3165853651d0a02204701947402ea13b5a20521102cf064dfb3272e5cbf3e62faeebbe264c02168be0121039d109ebbb5ea0b46b993b182198209822748680696b471d1e606ef0f1e0935e5fdffffff02ebbe12000000000017a9147c6f8d300ea90a234c3c16b82778e9db42d0f4dd87e80300000000000017a914e8ef4ef62c41ee052dd1242f6e49eca376751cf2872caf2400"

@wchennc

wchennc commented May 23, 2024

Copy link
Copy Markdown
Author

Reading this post on Medium. It seems that script_sig is calculated incorrectly in the lib.

For a valid P2SH tx

0100000001857aff3abca2353193397a7d2eea61b25d8be381cabe5a1935868b74fa4c24ad000000009100473044022051c7546ff919248badd1012317066cc0edd3e5f49050ac54ef52b66a8e80e17b02201dd65963551e0dc7d8ce5721fbd3125fa9272a98bad1ed5df91488a462eac1230147512103b4603330291721c0a8e9cae65124a7099ecf0df3b46921d0e30c4220597702cb2102b2ec7de7e811c05aaf8443e3810483d5dbcf671512d9999f9c9772b0ce9da47a52aeffffffff014062b007000000001976a914ad204de226b3d11a70dc53b4998f4603e138ff3f88ac00000000

script_sig is consist of three parts - the 3rd one is redeem script

script_sig: [%BitcoinLib.Script.Opcodes.Constants.Zero{},
        %BitcoinLib.Script.Opcodes.Data{value: <<0x3044022051c7546ff919248badd1012317066cc0edd3e5f49050ac54ef52b66a8e80e17b02201dd65963551e0dc7d8ce5721fbd3125fa9272a98bad1ed5df91488a462eac12301::568>>},
        %BitcoinLib.Script.Opcodes.Data{value: <<0x512103b4603330291721c0a8e9cae65124a7099ecf0df3b46921d0e30c4220597702cb2102b2ec7de7e811c05aaf8443e3810483d5dbcf671512d9999f9c9772b0ce9da47a52ae::568>>}]

However, looks like public_key is injected instead here

@RooSoft

RooSoft commented May 24, 2024

Copy link
Copy Markdown
Owner

I've been working on this a while ago...

Seems like BetterSigner treats all redeem scripts as P2PK...

Will have to upgrade this so it ends up being comptabile with other types, such as P2SH.

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.

2 participants