Pages:
Author

Topic: [Quiz] Answer the Bitcoin question and earn merits! #5 (Read 642 times)

legendary
Activity: 1512
Merit: 7340
Farewell, Leo
Thanks for the correction, pooya. So, to rephrase: it's a good practice to not leave anything extra in stack when creating a P2SH script, and it's necessary to not leave anything extra (apart from one non-zero value) in stack when creating a P2WSH script.

For simplicity, just use OP_EQUAL instead of OP_1 OP_EQUALVERIFY.
legendary
Activity: 3472
Merit: 10611
but in general, it's a good practice to not leave anything in stack, if it's possible.
You need to leave at least one item on the stack if it is a legacy script[1] and only one item if it is a witness script[2]. That item has to evaluate to true otherwise after the script evaluation ends and stack is empty the result is a fail.
[1] https://github.com/bitcoin/bitcoin/blob/a74bdeea1b8e27b2335f0f7da78006e87ecfb235/src/script/interpreter.cpp#L1983-L1986
[2] https://github.com/bitcoin/bitcoin/blob/a74bdeea1b8e27b2335f0f7da78006e87ecfb235/src/script/interpreter.cpp#L1823-L1824

In order to spend any of those scripts that end with OP_EQUALVERIFY the user would have to add an extra arbitrary value (that evaluates to true) to their signature script when spending the output.
Meaning for example if the number is x their spending script must be OP_1 so that after OP_EQUALVERIFY executes, the stack is not empty.
Using OP_EQUAL fixes that.
jr. member
Activity: 28
Merit: 37
How does it compare to what people have wrote, is the ChatGPT more optimized ?
It is more or less the same; for example, it's the same with this one.

Interesting, ChatGPT can really help in programming but the user needs to understand the code to verify if there are no mistakes like you have pointed.

This mistakes usually come from outdated data ChatGPT is basing it's research.

Thanks for checking it, have a great day!
legendary
Activity: 1512
Merit: 7340
Farewell, Leo
How does it compare to what people have wrote, is the ChatGPT more optimized ?
It is more or less the same; for example, it's the same with this one.
jr. member
Activity: 28
Merit: 37
Code:
OP_DUP OP_ADD OP_8 OP_ADD OP_SHA256 OP_EQUALVERIFY
That's the correct one.  Smiley

How does it compare to what people have wrote, is the ChatGPT more optimized ?
legendary
Activity: 1512
Merit: 7340
Farewell, Leo
Code:
OP_DUP OP_DUP OP_ADD OP_8 OP_ADD OP_SHA256 OP_EQUALVERIFY
It is correct. It's just pleonastic. If OP_EQUALVERIFY fails, it aborts. Otherwise, you're just left with your initial number in stack. In Bitcoin terms, this would be valid, but in general, it's a good practice to not leave anything in stack, if it's possible.

Code:
OP_2DUP OP_ADD OP_8 OP_ADD OP_SHA256 OP_EQUALVERIFY
The only difference is that you've replaced OP_DUP OP_DUP with OP_2DUP, which is only optimized in terms of readability. It's still pleonastic.

Code:
OP_DUP OP_ADD OP_8 OP_ADD OP_SHA256 OP_EQUALVERIFY
That's the correct one.  Smiley
jr. member
Activity: 28
Merit: 37
Code:
OP_DUP OP_DUP OP_ADD OP_8 OP_ADD OP_SHA256 OP_EQUALVERIFY

Is this correct ?

Then I asked for optimized version:

Code:
OP_2DUP OP_ADD OP_8 OP_ADD OP_SHA256 OP_EQUALVERIFY

This is the most optimized version according to ChatGPT:

Code:
OP_DUP OP_ADD OP_8 OP_ADD OP_SHA256 OP_EQUALVERIFY

legendary
Activity: 1512
Merit: 7340
Farewell, Leo
What you guys say ?
It's correct, except from the OP_MUL part, as that'd abort the script, because it is disabled. You might get the correct answer if you ask it to replace OP_MUL with one or more opcodes that are enabled and do the same operation.
jr. member
Activity: 28
Merit: 37
Code:
OP_DUP OP_2 OP_MUL OP_8 OP_ADD OP_SHA256 OP_EQUALVERIFY

Not looking for merit.
I don't know anything about Bitcoin scripting, but this is what I've got from ChatGPT when asked for most optimized version  Wink

What you guys say ?

sr. member
Activity: 476
Merit: 299
Learning never stops!
~
Alright thanks for this i will go through it and play around with some related stuffs
legendary
Activity: 1512
Merit: 7340
Farewell, Leo
Then I want to ask a question on how you generated the SHA 256 hash for 21,000,000... was there  any encoding or let me just ask how??
Right, important. So, let me explain what's going on when I say that you hash the number 21 million.

A hash function, as we all know, is a function that maps data of arbitrary size to a fixed-size output. The data that it takes as input usually comes in chunks of bytes. In this Github page, you can hash any value you want, with any encoding you want. In Bitcoin, OP_SHA256 takes as input bytes, with little endian order. This means that hashing the number 21 million in Bitcoin would look like this:

  • Convert the number 21 million into hexadecimal, so that it's easier to manipulate. (You can use rapidtables.com)
  • 21000000 = 0x1406F40
  • Convert it to little endian: 0x406F4001 (Used this tool)

Now you need to pass these bytes (0x406F4001) into SHA256 using the Github page I posted above. It'll give you 0xdf3984c3d89ec61f93f2d3060263bbb960a885ffa5d41ca1eb9c2692de71d8b7.

It should be through trial and error because SHA256 can't be decoded
Since it's a one way encryption.
Important corrections:

  • This is not analogous to trial and error. When your input fails to produce the given hash, it does not give you any insights for your future selections, as with any cases where trial and error takes place (i.e., chess). What you probably meant is through brute force.
  • Hashes, while used in encryption, are not encrypting anything, per se. It's a one way function. It simply digests a message.
  • Encoding exists only in the input. For example, if you're hashing binary, will it be hex, or Base64? If you're hashing Text, will it be UTF-8?
sr. member
Activity: 420
Merit: 315
Top Crypto Casino

Correct. However, with x=10499996, you're left with two items in the stack. That doesn't make the script incorrect, but it's better for your understanding to always be left with only one non-zero item.
Noted !
Then I want to ask a question on how you generated the SHA 256 hash for 21,000,000... was there  any encoding or let me just ask how??because I tried to read up on that and couldn't  get a perfect answer for it, the generator I tried doesn't give me something reasonable to that .
Thus when I did wanted to test another number I used OP_SHA256 on the stack element I wanted to use just to get the hash value for testing... just curious how to get that hash format:
Code:
0xdf3984c3d89ec61f93f2d3060263bbb960a885ffa5d41ca1eb9c2692de71d8b7
(maybe a read up,guide...e.t.c).

Nice one Ambatman and promise444c5 I bet you guys learnt a lot too.
Sure I did Smiley


It should be through trial and error because SHA256 can't be decoded
Since it's a one way encryption.
sr. member
Activity: 448
Merit: 560
Crypto Casino and Sportsbook
Alright Blackhatcoiner is soo close to 8000 merits
Why don't we take him there  Grin Grin
Ambatman promise444c5 ??
sr. member
Activity: 476
Merit: 299
Learning never stops!

Correct. However, with x=10499996, you're left with two items in the stack. That doesn't make the script incorrect, but it's better for your understanding to always be left with only one non-zero item.
Noted !
Then I want to ask a question on how you generated the SHA 256 hash for 21,000,000... was there  any encoding or let me just ask how??because I tried to read up on that and couldn't  get a perfect answer for it, the generator I tried doesn't give me something reasonable to that .
Thus when I did wanted to test another number I used OP_SHA256 on the stack element I wanted to use just to get the hash value for testing... just curious how to get that hash format:
Code:
0xdf3984c3d89ec61f93f2d3060263bbb960a885ffa5d41ca1eb9c2692de71d8b7
(maybe a read up,guide...e.t.c).

Nice one Ambatman and promise444c5 I bet you guys learnt a lot too.
Sure I did Smiley

sr. member
Activity: 448
Merit: 560
Crypto Casino and Sportsbook
[...]
Correct. However, with x=10499996, you're left with two items in the stack. That doesn't make the script incorrect, but it's better for your understanding to always be left with only one non-zero item.

Code:
`OP_DUP OP_ADD OP_8 OP_ADD OP_SHA256 OP_PUSHDATA OP_EQUAL`
Without OP_PUSHDATA, that's the correct one!
Wow I later edited the script though and removed OP_PUSHDATA but I wasn't 100% sure it was correct.

When I did I added only the value of X to the stack data and the script ran just fine however I didn't drop it here because I got a final output of 0.

Thanks for the quiz man I learnt a lot. Let's just say with this quiz I've been able to understand how to create simple bitcoin scripts. +1 Blackhatcoiner I look forward to the next quiz Grin Grin

Nice one Ambatman and promise444c5 I bet you guys learnt a lot too. See you all around. See yah Blackhatcoiner on the technical board  Smiley
legendary
Activity: 1512
Merit: 7340
Farewell, Leo
Is there any site or app that can help in testing my knowledge?
Like small challenges in Script? I don't think there is. You can try and do something else, which we might do it the next quiz. Try making a custom script, like the one you made in this thread, and compile its address. For example, for your script, the P2WSH testnet address is: tb1qs462fyl73n460uztz4qjh573vcuh9wfay4upmmz98pveevxrvydq3t53pw. There's a "Compile your script" option in Script Wiz. Any amount of tBTC sent to that address can only be spent if the spender provides <10499996> as the only stack element in their witness.

A good exercise would be to spend money from that address, or at least provide the raw transaction which could be confirmed. (You can't broadcast it, because it is non-standard. Some miner would have to pick it for you, and include it in a block.)
sr. member
Activity: 420
Merit: 315
Top Crypto Casino
[...]
Correct. However, with x=10499996, you're left with two items in the stack. That doesn't make the script incorrect, but it's better for your understanding to always be left with only one non-zero item.

Code:
`OP_DUP OP_ADD OP_8 OP_ADD OP_SHA256 OP_PUSHDATA OP_EQUAL`
Without OP_PUSHDATA, that's the correct one!

Code:
OP_DUP OP_ADD OP_8 OP_ADD OP_SHA256 OP_EQUAL
This one is correct as well. You should have replaced OP_MUL with OP_DUP and OP_ADD, as you did. The reason you're getting the error in the first image, is that you haven't entered the , which is <0xdf3984c3d89ec61f93f2d3060263bbb960a885ffa5d41ca1eb9c2692de71d8b7>.
Thanks for your time and question. With this few I can say I'm quite confident in using the various scripts that we implemented in the above question.
Is there any site or app that can help in testing my knowledge?
Tried searching via web but most are just single questions on Githubs.





It's showing stack data must include min 2 data and I don't know what to place there at part from <10499996>

NGL scriptwiz requires a manual.

not also good in this but i think you  are equating two values here and you didn't add the that you included in your code
use the hash(SHA256) from the question itself,it should be fixed
Didn't quite understand this last time but now I do. Thanks.
legendary
Activity: 1512
Merit: 7340
Farewell, Leo
[...]
Correct. However, with x=10499996, you're left with two items in the stack. That doesn't make the script incorrect, but it's better for your understanding to always be left with only one non-zero item.

Code:
`OP_DUP OP_ADD OP_8 OP_ADD OP_SHA256 OP_PUSHDATA OP_EQUAL`
Without OP_PUSHDATA, that's the correct one!

Code:
OP_DUP OP_ADD OP_8 OP_ADD OP_SHA256 OP_EQUAL
This one is correct as well. You should have replaced OP_MUL with OP_DUP and OP_ADD, as you did. The reason you're getting the error in the first image, is that you haven't entered the , which is <0xdf3984c3d89ec61f93f2d3060263bbb960a885ffa5d41ca1eb9c2692de71d8b7>.
sr. member
Activity: 476
Merit: 299
Learning never stops!


It's showing stack data must include min 2 data and I don't know what to place there at part from <10499996>

NGL scriptwiz requires a manual.

not also good in this but i think you  are equating two values here and you didn't add the that you included in your code
use the hash(SHA256) from the question itself,it should be fixed
sr. member
Activity: 420
Merit: 315
Top Crypto Casino

Code:
OP_SWAP OP_DUP OP_8 OP_ADD OP_SHA256 OP_EQUAL
This one is incorrect. I think that you've misunderstood what OP_DUP does, because you're just one placement away from the solution. Put your code into Script Wiz, using <10499996> as the only stack element, and see what you get:
Using scriptwiz was really hard at first since there's always a pre existing script but have gotten the hang of it.
Code:
OP_DUP OP_ADD OP_8 OP_ADD OP_SHA256 OP_EQUAL

Now I understand especially while using it with scriptwiz
OP DUP duplicates doesn't mean it automatically adds the duplicates
OP _ ADD helps with that which I did
And found out that OP_SWAP felt out of place.

Used the above code and the values I got were getting similar to yours until I used OP_EQUAL and I was given this


It's showing stack data must include min 2 data and I don't know what to place there at part from <10499996>

NGL scriptwiz requires a manual.


Edit

Added <10499996> to the stack making it two
And the error message seized and replaced  by zero








Pages:
Jump to: