Author

Topic: How to use OP_CHECKSEQUENCEVERIFY (Read 1440 times)

jr. member
Activity: 41
Merit: 3
June 11, 2017, 12:39:30 AM
#11
I just told you what was the problem.
the push does matter!
why don't you just try it?

change tx version to 2 and {0x01,0x0a} to 0x5a inside the spending script, and it will work.
trust me.

obviously, you won't be able to spend the existing output through the else condition.
because it contains "illegal" pushes.
you need to make another P2SH address, for the script with 5a (instead of 010a)

your suggestion was awesome!

I managed to redeem the transaction (I created a new P2SH script without the push opcode).

https://blockchain.info/tx/4ba75dfe11988663cfcbbc8911eedee1f867d99fa744a6137e885315b3a073e1

the OP_CSV is simpler compared to OP_CLTV in my opinion, since we do not need to set the nLockTime and calculate a specific time in the future. All we need is just the nSequence with nSequence >= OP_CSV value and set the tx version to 2. Awesome! Thank you @piotr_n.
legendary
Activity: 2053
Merit: 1356
aka tonikt
June 09, 2017, 09:48:57 AM
#10
anyway, do you have any suggestions about this OP_CSV problem? if the push does not matter in OP_CSV as you said it only saves a byte per input. I already have set the version to 2, then what else, did I miss something?
I just told you what was the problem.
the push does matter!
why don't you just try it?

change tx version to 2 and {0x01,0x0a} to 0x5a inside the spending script, and it will work.
trust me.

obviously, you won't be able to spend the existing output through the else condition.
because it contains "illegal" pushes.
you need to make another P2SH address, for the script with 5a (instead of 010a)
legendary
Activity: 1260
Merit: 1019
June 09, 2017, 06:19:53 AM
#9
anyway, do you have any suggestions about this OP_CSV problem? if the push does not matter in OP_CSV
as you said it only saves a byte per input. I already have set the version to 2, then what else, did I miss something?
I haven't dived deep in OP_CSV/OP_CLTV.
PM me about your problem - it is hard for me to read carefully everything in this topic
May be I will be able to check it next week.
jr. member
Activity: 41
Merit: 3
June 09, 2017, 06:09:55 AM
#8
does it mean if we need to push numbers from 1-16, we shall use OP_1 to OP_16?
It is not nessesary in p2sh redeem script to use opcodes OP_0, OP_1...OP_16 instead of pushes
but is saves one byte per input on each full bitcoin node Smiley

hello, it's been a while  Grin

anyway, do you have any suggestions about this OP_CSV problem? if the push does not matter in OP_CSV as you said it only saves a byte per input. I already have set the version to 2, then what else, did I miss something?
legendary
Activity: 1260
Merit: 1019
June 08, 2017, 04:57:54 PM
#7
does it mean if we need to push numbers from 1-16, we shall use OP_1 to OP_16?
It is not nessesary in p2sh redeem script to use opcodes OP_0, OP_1...OP_16 instead of pushes
but is saves one byte per input on each full bitcoin node Smiley
legendary
Activity: 2053
Merit: 1356
aka tonikt
June 08, 2017, 01:44:09 AM
#6
does it mean if we need to push numbers from 1-16, we shall use OP_1 to OP_16?

Yes, but also a few other things that you have to mind:

https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L223

https://github.com/bitcoin/bitcoin/blob/master/src/script/script.h#L226
jr. member
Activity: 41
Merit: 3
June 07, 2017, 04:03:08 PM
#5
@sonicskye, I think your tx is failing the "minimal push" check.
it's some crazy stuff that (I think) is supposed to prevent tx malleability - don't ask me about it Smiley


but what you have to change is the place where you push value 10 onto the stack
instead of using {0x01, 0x0a}, you should use a single 0x5a (OP_10)

plus, as it was said before, you need version 2 or more - then it will work.


Thank you for your reply. I have rechecked my script and it uses 0x01 0x0a instead of 0x5a.
Just to make it clear, according to Bitcoin Wiki (https://en.bitcoin.it/wiki/Script), does it mean if we need to push numbers from 1-16, we shall use OP_1 to OP_16?
legendary
Activity: 2053
Merit: 1356
aka tonikt
June 07, 2017, 03:24:55 AM
#4
@sonicskye, I think your tx is failing the "minimal push" check.
it's some crazy stuff that (I think) is supposed to prevent tx malleability - don't ask me about it Smiley


but what you have to change is the place where you push value 10 onto the stack
instead of using {0x01, 0x0a}, you should use a single 0x5a (OP_10)

plus, as it was said before, you need version 2 or more - then it will work.
jr. member
Activity: 41
Merit: 3
June 06, 2017, 09:19:03 PM
#3
Read the BIP: https://github.com/bitcoin/bips/blob/master/bip-0112.mediawiki

Your transaction needs to have a version number of 2, not 1. There may also be some other issue, but read the BIP carefully and you will be able to find it.

Thank you for your reply.
I have tried to use version 2. I also have read the BIP and I assume that one only need to set the nSequence variable to be higher than the OP_CSV value, it means it has nothing to do with the nLockTime. All Failed.

Someone told me that this OP_CSV is not currently active in mainnet.
staff
Activity: 3458
Merit: 6793
Just writing some code
June 06, 2017, 11:26:22 AM
#2
Read the BIP: https://github.com/bitcoin/bips/blob/master/bip-0112.mediawiki

Your transaction needs to have a version number of 2, not 1. There may also be some other issue, but read the BIP carefully and you will be able to find it.
jr. member
Activity: 41
Merit: 3
June 06, 2017, 02:44:48 AM
#1
Dear all,

I am currently studying the OP_CHECKSEQUENCEVERIFY (OP_CSV) opcode and trying to create transactions manually. I have this construction

OP_IF
   2 [PUBKEY A] [PUBKEY B] 2 OP_CHECKMULTISIG
OP_ELSE
   [CSV VALUE] OP_NOP3 OP_DROP
   OP_DUP OP_HASH160 [PUBKEYHASH B] OP_EQUALVERIFY OP_CHECKSIG
OP_ENDIF

So far I have succeeded redeeming the P2SH tx above through the multisignature (the OP_IF.. block). But I have problems when redeeming the transaction through the OP_ELSE.. OP_ENDIF block which is when the OP_CSV is evaluated. I have set the [CSV VALUE] to 0x0a in hexadecimal (or 10 in decimal).

My current effort was to set the nSequence and the nLockTime variables to be more than the CSV value. I have created a raw tx to redeem the OP_CSV as follows

01000000010c3e18ff26e98ba39381c84d2fb9e8e198e63d0b3697f9bd57f63577c96da23f00000 000d5483045022100fc4f7bfa3c536e743b02af8b7de5d4052f43db54f59692478b25c585b9df21 1a02203cfcfc0ed618fae6aa49b11e803ec4e5654551fb52fe2d026929f4a307fe2ef0012103d7c 6052544bc42eb2bc0d27c884016adb933f15576a1a2d21cd4dd0f2de0c37d004c67635221025e37 e03703f001de34123b513beaf0e4044a2dd39a1dd92ec1706f184920031a2103d7c6052544bc42e b2bc0d27c884016adb933f15576a1a2d21cd4dd0f2de0c37d52ae67010ab27576a914937fe2ee82 229d282edec2606c70e755875334c088ac680f0000000130750000000000001976a914937fe2ee8 2229d282edec2606c70e755875334c088ac0f000000

In the raw tx, I have set the nSequence to 15 and nLockTime to 15 (I know this is not a good idea, but I'm desperate).

The raw tx itself was rejected in many pushtx services, except the blockcypher, although it has not been confirmed to the blockchain.
https://live.blockcypher.com/btc/tx/bcfbb172403ba73643ae02d40cac1332b75173d9726917dd8263a15ce365c012/

Please let me know if you have any suggestions. Thank you.
Jump to: