Author

Topic: How to assemble this type of pay to pubkey hash transaction ? (Read 349 times)

member
Activity: 285
Merit: 27
I think it's an issue with how the network runs although it could be the http/https thing as it is a research institution so they'll want to keep connections as secure as possible, you also have to use their dns and no one else's (probably for the logs thing again).

The wifi also requires 801.x aes certificates (from what I can remember when setting it up - it took about a week as I had to go to the labs to download the certificate and then install it on my computer). My connection is about 50Mbps here I think which is slow.
Ah ! I understand better now… Why Don’t your have a personal connection outside ? Does the certificate you have is just for accessing Wi‑Fi or is it just for being able to decipher arbitrary secure connections ? If you can’t access Wi‑Fi without it, then it’s a client certificate which acts like a personal account with password and has nothing to do with ʜᴛᴛᴘꜱ.

Step aside : my future job is to design such kind of protection in corporate environments in real life (or public hotspot). I can say that most of what you see often boils down to just allow port 80 and 443 and ᴍᴀᴄ addresses. Why never allow custom ᴅɴꜱ servers ? Because how easy it is to send ɪᴘ traffic over a protocol which can use ᴜᴅᴘ.
 Though more expensive filters exist.
I can't understand something from 10 lines of code without seeing what the other subroutines do that are called. To be honest, you're better off looking at the bitcoin wiki in order to work out how transactions are actually made and broadcast (it's hard to understand code sources without relevant documents).

Once again I think there's some multisig confusion as a redeem script only occurs with multisig (afaik).
Once you sign a transaction it can then be broadcast so they don't have to add it to their wallet (unless they can't connect to the internet).

Transactions are sort of fixed size (I think there's an extra 20 bytes you can add somewhere which is what miners do when setting the nonce for a block in a coinbase transaction).



Ahhh, this is what you keep referencing: https://en.bitcoin.it/wiki/Transaction#Data

This might be more helpful although I can''t find where OP_DUP is mentioned, https://en.bitcoin.it/wiki/Script#Standard_Transaction_to_Bitcoin_address_.28pay-to-pubkey-hash.29
The code explains how to check if the transaction is Pay to Pubkey or Pay to Pubkey Hash. The parameters called are from C++ vectors, otherwise the name are very clear without having the underlying definition. If they return false then it means the transaction doesn’t match the underlying type (they also compute the target address of the transaction).

For example, in order to be a pay to Pubkey hash the transaction Script must be in the following conditions :
  • The Script is 25 bytes long.
  • The first byte match the OP_DUP opcode
  • The second byte match the OP_HAS160 opcode
  • The third byte math a 20 bytes pushdata which is the only part of the transaction which can be anything (in practice the address)
  • The 24 byte match the OP_EQUALVERIFY opcode
  • The 25 and last byte match the OP_DUP opcode

Anything else not being SegWit is either a pay to Script Hash or a nonstandard transaction which should be rejected. That is the payment is not done to the address specified but to the address generated from the hash of the Script (MultiSig might need to be merged in Scripting one day).


Back to the original point, can you not use bitcoin core to generate and sign your transaction if you have it downloaded and installed?
If you want to use the command line then the commands are still a lot easier than what you're trying to do here...
Unfortunately, I both need a wallet and manual because I don’t know how to use Bitcoin core for that.
copper member
Activity: 2856
Merit: 3071
https://bit.ly/387FXHi lightning theory
I think it's an issue with how the network runs although it could be the http/https thing as it is a research institution so they'll want to keep connections as secure as possible, you also have to use their dns and no one else's (probably for the logs thing again).

The wifi also requires 801.x aes certificates (from what I can remember when setting it up - it took about a week as I had to go to the labs to download the certificate and then install it on my computer). My connection is about 50Mbps here I think which is slow.

No, I don’t know if you understand the code above, but if you do you can see that in order to have the payment appear in block explorers to be made to a recipient, there’s no room for adding or exchanging opcodes (transaction size is fixed).

What I wanted to do is to send the payment directly without requiring the recipient to redeem it from the address of script first. So as far I understand, this is not possible. Please correct me if I’m wrong.

I can't understand something from 10 lines of code without seeing what the other subroutines do that are called. To be honest, you're better off looking at the bitcoin wiki in order to work out how transactions are actually made and broadcast (it's hard to understand code sources without relevant documents).

Once again I think there's some multisig confusion as a redeem script only occurs with multisig (afaik).
Once you sign a transaction it can then be broadcast so they don't have to add it to their wallet (unless they can't connect to the internet).

Transactions are sort of fixed size (I think there's an extra 20 bytes you can add somewhere which is what miners do when setting the nonce for a block in a coinbase transaction).



Ahhh, this is what you keep referencing: https://en.bitcoin.it/wiki/Transaction#Data

This might be more helpful although I can''t find where OP_DUP is mentioned, https://en.bitcoin.it/wiki/Script#Standard_Transaction_to_Bitcoin_address_.28pay-to-pubkey-hash.29


Back to the original point, can you not use bitcoin core to generate and sign your transaction if you have it downloaded and installed?
If you want to use the command line then the commands are still a lot easier than what you're trying to do here...
member
Activity: 285
Merit: 27
Yeah I also can't use tor and most vpns though it's only for a few months...
Is your connection restricted to a whitelist ? Is ʜᴛᴛᴘꜱ blocked (or do you have to install a custom certificate in order to have your connection inspected) ? Is real bandwidth above 160Kb/s ? Otherwise, there’s no reason you shouldn’t be able to not access tor (not directly but over an ʜᴛᴛᴘꜱ relay). I would also add without paying for anything of course.

And I'm guessing you're now talking about op_scriptSig. Although you're going to want to look at what the script code actually does as all you have there is something that identifies the key type.
No, I don’t know if you understand the code above, but if you do you can see that in order to have the payment appear in block explorers to be made to a recipient, there’s no room for adding or exchanging opcodes (transaction size is fixed).

What I wanted to do is to send the payment directly without requiring the recipient to redeem it from the address of script first. So as far I understand, this is not possible. Please correct me if I’m wrong.
copper member
Activity: 2856
Merit: 3071
https://bit.ly/387FXHi lightning theory
Yeah I also can't use tor and most vpns though it's only for a few months...

And I'm guessing you're now talking about op_scriptSig. Although you're going to want to look at what the script code actually does as all you have there is something that identifies the key type.
member
Activity: 285
Merit: 27
Pay to script is when you're transferring to a multisig afdress%?
p2pkh is where you're paying to a public key hash.

If it's the first one, the redeem script is generated by the client with the multisig address.

Why can't you just use walllet software in a virtual environment and just delete it after?

Edit: if you have bitcoin core then just click on send and send the coins wherever you want. I haven't used core in a while as my Internet is censored though.
No :
From bitcoin core standard.cpp :
Code:
static bool MatchPayToPubkey(const CScript& script, valtype& pubkey)
{
    if (script.size() == CPubKey::PUBLIC_KEY_SIZE + 2 && script[0] == CPubKey::PUBLIC_KEY_SIZE && script.back() == OP_CHECKSIG) {
        pubkey = valtype(script.begin() + 1, script.begin() + CPubKey::PUBLIC_KEY_SIZE + 1);
        return CPubKey::ValidSize(pubkey);
    }
    if (script.size() == CPubKey::COMPRESSED_PUBLIC_KEY_SIZE + 2 && script[0] == CPubKey::COMPRESSED_PUBLIC_KEY_SIZE && script.back() == OP_CHECKSIG) {
        pubkey = valtype(script.begin() + 1, script.begin() + CPubKey::COMPRESSED_PUBLIC_KEY_SIZE + 1);
        return CPubKey::ValidSize(pubkey);
    }
    return false;
}

static bool MatchPayToPubkeyHash(const CScript& script, valtype& pubkeyhash)
{
    if (script.size() == 25 && script[0] == OP_DUP && script[1] == OP_HASH160 && script[2] == 20 && script[23] == OP_EQUALVERIFY && script[24] == OP_CHECKSIG) {
        pubkeyhash = valtype(script.begin () + 3, script.begin() + 23);
        return true;
    }
    return false;
}
Anything else will result in the payment being made to the address generated from the hash of the script instead of the addresses specified as far I understand. With a such strict enforcement, I wonder why Bitcoin ever had to disable opcodes.
Otherwise why using a virtual environment when I installed the wallet directly.

And about your case, what about hidden tor ? (aka tor over ʜᴛᴛᴘꜱ) (Bitcoin core even as an option to use tor)
copper member
Activity: 2856
Merit: 3071
https://bit.ly/387FXHi lightning theory
Pay to script is when you're transferring to a multisig afdress%?
p2pkh is where you're paying to a public key hash.

If it's the first one, the redeem script is generated by the client with the multisig address.

Why can't you just use walllet software in a virtual environment and just delete it after?

Edit: if you have bitcoin core then just click on send and send the coins wherever you want. I haven't used core in a while as my Internet is censored though.
member
Activity: 285
Merit: 27
The wallet does it for you. You don't have to worry about assembling a script or anything.

You're just after sending bitcoins right?
Ah. Ok.
I found how this works… This type of transaction can only be pay to script hash where scripting is exected on redeeming.

So how to redeem coins with a wallet ?
copper member
Activity: 2856
Merit: 3071
https://bit.ly/387FXHi lightning theory
The wallet does it for you. You don't have to worry about assembling a script or anything.

You're just after sending bitcoins right?
member
Activity: 285
Merit: 27
This one? https://coinb.in/#newTransaction

OK if you're wanting a wallet, I'd suggest electrum.

Go to electrum.org/#download

I'd suggest you download the portable version for Windows or run it without installing for Linux (the instructions are on the download page).if you're wanting to keep using bitcoin though feel free to install electrum fully.

Once running you're going to want to click to use public or private keys and then you're wanting to paste the private keys into the following screen..

If you're after emptying your wallet, you'll then go to the send tab, type or paste in the address you want to send your coins to and hit the max button (set the fee slider to within 25 blocks before doing this and you'll get more btc out).
and then the question is how to assemble the script and create a transaction with it ?
copper member
Activity: 2856
Merit: 3071
https://bit.ly/387FXHi lightning theory
This one? https://coinb.in/#newTransaction

OK if you're wanting a wallet, I'd suggest electrum.

Go to electrum.org/#download

I'd suggest you download the portable version for Windows or run it without installing for Linux (the instructions are on the download page).if you're wanting to keep using bitcoin though feel free to install electrum fully.

Once running you're going to want to click to use public or private keys and then you're wanting to paste the private keys into the following screen..

If you're after emptying your wallet, you'll then go to the send tab, type or paste in the address you want to send your coins to and hit the max button (set the fee slider to within 25 blocks before doing this and you'll get more btc out).
member
Activity: 285
Merit: 27
It sounds like you might need a bitcoin wallet to do this instead if you can't work out this (that or you're just trolling)..

Most imports and exports work in hex. I have a text editor that allows me to edit hex and ascii like most people have and a lot of wallets export and import in pute hex anyway, its what you're going to need to broadcast the transaction.
Last I checked ethereum and bitcoin were two different coins and with bitcoin transactions at least you have to list the inputs which contain the vout and the txid.



From what you quoted yp0u also have to sign the transaction you make in the sign function I'm putting the private key. I stated the website above in a previous post...
Correct. I need a bitcoin wallet which can do custom scripting in TxOut. Since that time I download bitcoin core in full. So it might help.

The website you stated in your previous post if for using a public key. But I’ve only the address.
copper member
Activity: 2856
Merit: 3071
https://bit.ly/387FXHi lightning theory
It sounds like you might need a bitcoin wallet to do this instead if you can't work out this (that or you're just trolling)..

Most imports and exports work in hex. I have a text editor that allows me to edit hex and ascii like most people have and a lot of wallets export and import in pute hex anyway, its what you're going to need to broadcast the transaction.
Last I checked ethereum and bitcoin were two different coins and with bitcoin transactions at least you have to list the inputs which contain the vout and the txid.



From what you quoted yp0u also have to sign the transaction you make in the sign function I'm putting the private key. I stated the website above in a previous post...
member
Activity: 285
Merit: 27
well you are basically asking us to teach you how script works in one comment and that is impossible. you need to read about it yourself, it is quite long and complicated:
https://blockgeeks.com/guides/best-bitcoin-script-guide/
https://en.bitcoin.it/wiki/Script

here is some quick pointers that cover your questions also:
- each OP code is 1 byte. eg: OP_DUP = 0x76, OP_DROP = 0x75
- when pushing data you use shortest form and it is followed by its size. eg: 0x14 (=size which is 20) then followed by the 20 bytes
- when including numbers you push them in little-endian order. eg: 1519394400  = 0x04 0x601e905a

- to get a list of UTXOs you either have to use JSON-RPC of bitcoin core which i am not familiar with or use a block explorer API like https://www.blockchain.com/api/blockchain_api (i think it only offers HTML now and no JSON) check other explorers for UTXO list
- each tx hex has to be reversed before you put it in your transaction as an outpoint
- to broadcast it you can again either use bitcoin-core or block explorers that have a testnet explorer such as blockcypher

No… You know very well that when peoples create transactions in Bitcoin they don’t use Telnet and Hex editors. Or more generally that assembly is assembled through automated programs called assemblers not manually. In an unrelated example, When you want to call a contract in ethereum you don’t select previous transactions nor sign the current one : you just use metamask with the parameter you build and you don’t have to care about the remaining. Here only TxOut should be manual.
I’ve an idea of how to do it but the question is definitely more about which tools ?
legendary
Activity: 3472
Merit: 10611
well you are basically asking us to teach you how script works in one comment and that is impossible. you need to read about it yourself, it is quite long and complicated:
https://blockgeeks.com/guides/best-bitcoin-script-guide/
https://en.bitcoin.it/wiki/Script

here is some quick pointers that cover your questions also:
- each OP code is 1 byte. eg: OP_DUP = 0x76, OP_DROP = 0x75
- when pushing data you use shortest form and it is followed by its size. eg: 0x14 (=size which is 20) then followed by the 20 bytes
- when including numbers you push them in little-endian order. eg: 1519394400  = 0x04 0x601e905a

- to get a list of UTXOs you either have to use JSON-RPC of bitcoin core which i am not familiar with or use a block explorer API like https://www.blockchain.com/api/blockchain_api (i think it only offers HTML now and no JSON) check other explorers for UTXO list
- each tx hex has to be reversed before you put it in your transaction as an outpoint
- to broadcast it you can again either use bitcoin-core or block explorers that have a testnet explorer such as blockcypher
member
Activity: 285
Merit: 27
1. It'll be in an understandable format once the signing is complete.

2. I'm not sure if you can or not

3. That page will probably take testnet keys.

Be proactive and test stuff yourself...

No definitely no…

Something like :
Code:
1519394400 CHECKLOCKTIMEVERIFY DROP DUP HASH160 9169b1c4fc26d870d29205144bd51deb43decd80 EQUALVERIFY CHECKSIG
Won’t work as is. Opcodes need to be converted and encoded first. How ? I have no idea about where. What you gave is only for public keys and is not general purpose whereas I can only use the address.

For selecting utxo, this is definitely linked to finding the right program or web service. When performing normal transactions users don’t have to even think what utxo is. There’s no reason it should be done manually here since it’s not the purpose of the question.

And last… which page ? It seems to me you forgot a ᴜʀʟ…
copper member
Activity: 2856
Merit: 3071
https://bit.ly/387FXHi lightning theory
1. It'll be in an understandable format once the signing is complete.

2. I'm not sure if you can or not

3. That page will probably take testnet keys.

Be proactive and test stuff yourself...
member
Activity: 285
Merit: 27

i'm not exactly sure what you mean by "requirement", but a P2PKH script is a script that you make by having the resulting 20 byte hash of the public key or the address which is the same thing but encoded differently.
to do that, in any wallet you simply enter the address and if it is a base58 legacy address (starting with 1) it creates it for you.
if you want to know what the script itself is, it is this sequence:
Code:
<..here you include the hash result..>
example: 76 A9 14 89ABCDEFABBAABBAABBAABBAABBAABBAABBAABBA 88 AC

to get the "hash result" you either have your public key in which case depending on whether you want compressed or uncompressed you serialize it and then perform SHA256 first and then RIPEMD160 on it. the result is a 20 byte hash.
if you only have the address and not the public key then use base58 encoder to decode the address, remove its checksum (4 last bytes) remove its first byte and the renaming bytes are the hash you need.

I’m saying this because I know not all transaction can be in the form of ᴘ2ᴘᴋʜ. I definitely need the payment to be made to instead of in a block explorer.
member
Activity: 285
Merit: 27
@pooya he said he had the address. While posting that information is interesting, it might just inadvertantly confuse.

as I stated earlier, you can use this to make and sign your transaction: https://coinb.in/#newTransaction

You can get the required information from a block explorer or it might do it automatically (i forget).
So the following remains unanswered :
— How to assemble this into bytecode the network can understand ?
— How to automatically select utxo for sending payment ?
— How to publish the resulting transaction to Bitcoin testnet (not on the real network because I don’t have access to Bitcoins currently) ?
copper member
Activity: 2856
Merit: 3071
https://bit.ly/387FXHi lightning theory
@pooya he said he had the address. While posting that information is interesting, it might just inadvertantly confuse.

as I stated earlier, you can use this to make and sign your transaction: https://coinb.in/#newTransaction

You can get the required information from a block explorer or it might do it automatically (i forget).
legendary
Activity: 3472
Merit: 10611

i'm not exactly sure what you mean by "requirement", but a P2PKH script is a script that you make by having the resulting 20 byte hash of the public key or the address which is the same thing but encoded differently.
to do that, in any wallet you simply enter the address and if it is a base58 legacy address (starting with 1) it creates it for you.
if you want to know what the script itself is, it is this sequence:
Code:
<..here you include the hash result..>
example: 76 A9 14 89ABCDEFABBAABBAABBAABBAABBAABBAABBAABBA 88 AC

to get the "hash result" you either have your public key in which case depending on whether you want compressed or uncompressed you serialize it and then perform SHA256 first and then RIPEMD160 on it. the result is a 20 byte hash.
if you only have the address and not the public key then use base58 encoder to decode the address, remove its checksum (4 last bytes) remove its first byte and the renaming bytes are the hash you need.
member
Activity: 285
Merit: 27
Ah, these two pages might be of interest to you: https://coinb.in/#newTransaction

https://coinb.in/#newTransaction

I think you might need to get the riepmd160 hash from your computer and convert it into base58 unless you want to pay to public key instaed (I thought p2pk is still supported though I could be completely wrong).
Nope. I’ve only the address, not the public key…
legendary
Activity: 3472
Merit: 10611
I think you might need to get the riepmd160 hash from your computer and convert it into base58 unless you want to pay to public key instaed (I thought p2pk is still supported though I could be completely wrong).

if you have the address (base58) just opening it in blockchain.com explorer will show you both the address and its hash160 and the conversion itself is a very easy one using the base58 decode function that exists in all libraries.
as for P2PK, it is an standard transaction still.

get type: https://github.com/bitcoin/bitcoin/blob/2068f089c8b7b90eb4557d3f67ea0f0ed2059a23/src/script/standard.cpp#L131-L135
doesn't consider non-standard: https://github.com/bitcoin/bitcoin/blob/2068f089c8b7b90eb4557d3f67ea0f0ed2059a23/src/policy/policy.cpp#L57-L78
copper member
Activity: 2856
Merit: 3071
https://bit.ly/387FXHi lightning theory
Ah, these two pages might be of interest to you: https://coinb.in/#newTransaction

https://coinb.in/#newTransaction

I think you might need to get the riepmd160 hash from your computer and convert it into base58 unless you want to pay to public key instaed (I thought p2pk is still supported though I could be completely wrong).
member
Activity: 285
Merit: 27
Do you have any ideas as to the platform you are using with this? At least an os or something. Are you trying to do all of this without a wallet and just bare cli instructions also?


I’d like to install nothing. Which means I’d prefer a web service. Otherwise Windows or Linux is Ok.
Also, yes I’d like to do this from a Wallet or a private key as Text. And as result, I don’t want to perform signing an utxo selection manually. I mean automatically like with a normal transaction as only the output needs to be manual.
copper member
Activity: 2856
Merit: 3071
https://bit.ly/387FXHi lightning theory
Do you have any ideas as to the platform you are using with this? At least an os or something. Are you trying to do all of this without a wallet and just bare cli instructions also?

member
Activity: 285
Merit: 27
I’d like to perform a transaction like this…
Code:
CHECKLOCKTIMEVERIFY DROP DUP HASH160 EQUALVERIFY CHECKSIG
Which brings many questions :
— How to encode
Code:
for setting the timing as a block height ?
— How to convert an address to a pubkeyHash ?
— How to assemble this into bytecode the network can understand ?
— How to automatically select utxo ?
— How to publish the resulting transaction to Bitcoin testnet ?
Jump to: