LearnBitcoin

Bitcoin Dev Archive 2018

Multi CSV Transaction

3 messages, 20 to 21 Feb 2018. Started by Praveen Baratam.

Praveen Baratam (2), Dan Robinson

Permalink Original thread on gnusha.org

Praveen Baratam permalink original

Hello Everybody,

I need a little clarity about how OP_CHECKSEQUENCEVERIFY (CSV) works in transactions.

Can I use multiple CSV end points as depicted in the figure below? I basically want to allow different conditions at different delays.

[image: Inline image 3]

I just want to know if OP_CHECKSEQUENCEVERIFY can be used to achieve the above.

Thank you.

Praveen ᐧ

Dan Robinson in reply to Praveen Baratam permalink original

Yes, although it's a functionality of Bitcoin Script generally, not OP_CSV in particular. Bitcoin Script allows you to use nested IF statements, and enforce whatever different conditions you want in each branch.

Here's your contract in Ivy <https://ivy-lang.org/bitcoin/>:

contract MultiCSV(
  bob: PublicKey,
  carol: PublicKey,
  bobDelay: Duration,
  carolDelay: Duration,
  val: Value
) {
  clause bobSpend(sig: Signature) {
    verify checkSig(bob, sig)
    verify older(bobDelay)
    unlock val
  }
  clause carolSpend(sig: Signature) {
    verify checkSig(carol, sig)
    verify older(carolDelay)
    unlock val
  }
  clause bothSpend(bobSig: Signature, carolSig: Signature) {
    verify checkMultiSig([bob, carol], [bobSig, carolSig])
    unlock val
  }
}

It compiles to the following Bitcoin Script:

PUSH(carolKey) PUSH(bobKey) 2 PICK 2 EQUAL IF ROT DROP 0 4 ROLL 4 ROLL 2 2ROT 2 CHECKMULTISIG ELSE ROT IF DROP CHECKSIGVERIFY PUSH(carolDelay) CHECKSEQUENCEVERIFY DROP 1 ELSE NIP CHECKSIGVERIFY PUSH(bobDelay) CHECKSEQUENCEVERIFY DROP 1 ENDIF ENDIF

On Tue, Feb 20, 2018 at 5:32 PM Praveen Baratam via bitcoin-dev < bitcoin-dev@lists•linuxfoundation•org> wrote:

Quoted text (22 lines)
> Hello Everybody,
>
> I need a little clarity about how OP_CHECKSEQUENCEVERIFY (CSV) works in
> transactions.
>
> Can I use multiple CSV end points as depicted in the figure below? I
> basically want to allow different conditions at different delays.
>
> [image: Multi CSV.png]
>
> I just want to know if OP_CHECKSEQUENCEVERIFY can be used to achieve the
> above.
>
> Thank you.
>
> Praveen
> ᐧ
> _______________________________________________
> bitcoin-dev mailing list
> bitcoin-dev@lists•linuxfoundation•org
> https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev
>
Praveen Baratam in reply to Dan Robinson permalink original

Thank you Daniel!

Your detailed explanation did clear things up :-) ᐧ

On Wed, Feb 21, 2018 at 6:29 AM, Daniel Robinson <danrobinson010@gmail•com> wrote:

Quoted text (62 lines)
> Yes, although it's a functionality of Bitcoin Script generally, not OP_CSV
> in particular. Bitcoin Script allows you to use nested IF statements, and
> enforce whatever different conditions you want in each branch.
>
> Here's your contract in Ivy <https://ivy-lang.org/bitcoin/>:
>
> contract MultiCSV(
>   bob: PublicKey,
>   carol: PublicKey,
>   bobDelay: Duration,
>   carolDelay: Duration,
>   val: Value
> ) {
>   clause bobSpend(sig: Signature) {
>     verify checkSig(bob, sig)
>     verify older(bobDelay)
>     unlock val
>   }
>   clause carolSpend(sig: Signature) {
>     verify checkSig(carol, sig)
>     verify older(carolDelay)
>     unlock val
>   }
>   clause bothSpend(bobSig: Signature, carolSig: Signature) {
>     verify checkMultiSig([bob, carol], [bobSig, carolSig])
>     unlock val
>   }
> }
>
> It compiles to the following Bitcoin Script:
>
> PUSH(carolKey) PUSH(bobKey) 2 PICK 2 EQUAL IF ROT DROP 0 4 ROLL 4 ROLL 2
> 2ROT 2 CHECKMULTISIG ELSE ROT IF DROP CHECKSIGVERIFY PUSH(carolDelay)
> CHECKSEQUENCEVERIFY DROP 1 ELSE NIP CHECKSIGVERIFY PUSH(bobDelay)
> CHECKSEQUENCEVERIFY DROP 1 ENDIF ENDIF
>
> On Tue, Feb 20, 2018 at 5:32 PM Praveen Baratam via bitcoin-dev <
> bitcoin-dev@lists•linuxfoundation•org> wrote:
>
>> Hello Everybody,
>>
>> I need a little clarity about how OP_CHECKSEQUENCEVERIFY (CSV) works in
>> transactions.
>>
>> Can I use multiple CSV end points as depicted in the figure below? I
>> basically want to allow different conditions at different delays.
>>
>> [image: Multi CSV.png]
>>
>> I just want to know if OP_CHECKSEQUENCEVERIFY can be used to achieve the
>> above.
>>
>> Thank you.
>>
>> Praveen
>> ᐧ
>> _______________________________________________
>> bitcoin-dev mailing list
>> bitcoin-dev@lists•linuxfoundation•org
>> https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev
>>
>