Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Bitcoin Scriptで遊ぶ〜Bitcoin Contractの可能性を探る〜

Shu Kobuchi
February 21, 2019

Bitcoin Scriptで遊ぶ〜Bitcoin Contractの可能性を探る〜

2019年2月21日bitbank LT Night #4 ~Blockchain~で発表させていただいた資料です。
https://bitbank.connpass.com/event/115449/

Shu Kobuchi

February 21, 2019
Tweet

More Decks by Shu Kobuchi

Other Decks in Technology

Transcript

  1. #JUDPJO4DSJQU -*'0 -BTU*O'JSTU0VU ͷ୯७ͳεΫϦϓτ 'PSUIͷΑ͏ͳٯϙʔϥϯυه๏ #JUDPJO5SBOTBDUJPOʹ͸ඞؚͣ·ΕΔ #JUDPJO$PSF CJUDPJOE ΍ϥΠϒϥϦΛ࢖͏ͱɺ#JUDPJO4DSJQUΛҙࣝ͠ͳ ͯ͘΋ɺϓϩάϥϜ͸ॻ͚Δ

    6OMPDLJOH4DSJQUͱ-PDLJOH4DSJQUΛಉ࣌ʹ࣮ߦ ਖ਼࣮͘͠ߦͰ͖Ε͹6OMPDLJOH4DSJQUͰ-PDLJOH4DSJQUΛղআͯ͠ɺτϥϯ βΫγϣϯͷ༗ޮੑΛࣔͤΔ !4 6OMPDLJOH4DSJQU -PDLJOH4DSJQU
  2. CJUDPJOSC CJUDPJOSCͰ͸ɺTUSJOHܕͰ#JUDPJO4DSJQUΛ࣮ߦՄೳ IUUQTHJUIVCDPNDIBJOUPQFCJUDPJOSC CJUDPJOSVCZͷޙܧϥΠϒϥϦ DIBJOUPQF$50҆౔ໜږࢯ͕։ൃ .BDͷ৔߹
 CSFXJOTUBMMMFWFMEC
 HFNJOTUBMMCJUDPJOSC
 !6 $

    irb irb(main):001:0> require 'bitcoin' => true irb(main):002:0> Bitcoin::Script.from_string("2 3 OP_ADD 5 OP_EQUAL").run => true irb(main):003:0> Bitcoin::Script.from_string("2 3 OP_ADD 6 OP_EQUAL").run => false
  3. 11,) 1BZUP1VCMJD,FZ)BTIʢ11,ͷൃల൛ʣ ެ։伴ϋογϡΛ༻͍Δ͜ͱͰΞυϨεΛ୹͘දݱͰ͖Δ TDSJQU͸ʢʣ಺Ͱͷݺͼํ΋͋Δ !9 -PDLJOH4DSJQU TDSJQU1VC,FZ 6OMPDLJOH4DSJQU TDSJQU4JH TJH

    TJH1VC,01@%6101@)"4)1VC,)BTI01@&26"-7&3*': 01@$)&$,4*(Λ࣮ߦ TJH 536& 1VC, TJH 1VC, TJH 1VC, 1VC, 1VC, 1VC,)BTI TJH 1VC, 1VC,)BTI 1VC,)BTI TJH 1VC, 1VC,)BTI 1VC,)BTI TJH 1VC, 01@%61 )"4) ෳ੡ 01@&26"- ౳͍͠ TJH1VC, 01@%6101@)"4)1VC,)BTI 01@&26"-7&3*':01@$)&$,4*( ಉ஋͔ 4)"ͷޙ 3*1&.% ෳ੡
  4. 11,)ʢଓ͖ʣ ࢒Γ͸11,ͱಉ͡ !10 -PDLJOH4DSJQU 6OMPDLJOH4DSJQU TJH 1VC, TJH 1VC, 

    536& $)&$,4*( TJH1VC, 01@%6101@)"4)1VC,)BTI 01@&26"-7&3*':01@$)&$,4*( ॺ໊Λݕূ
  5. PGͷ৔߹  ະॺ໊59࡞੒  ॺ໊ऀ"͕ͭ໨ͷॺ໊  ॺ໊ऀ#͕ͭ໨ͷॺ໊  ॺ໊ࡁ59Λ
 ϒϩʔυΩϟετ

    Ϛϧνγάͷॺ໊ͰϒϩʔυΩϟετ !12 ະॺ໊59 PG ॺ໊ࡁ59 ΋͏Ұਓ͸ॺ໊ෆཁ ॺ໊ऀ$ ॺ໊ऀ" ॺ໊ऀ# ॺ໊ऀ$ͷ ॺ໊ࡁ59 ॺ໊ ॺ໊ ॺ໊ऀ#ͷ ॺ໊ࡁ59 ൿີ伴" ൿີ伴$ ผਓ͕ ૢ࡞ ॺ໊͕ ἧ͏ ϒϩʔυ Ωϟετ ൿີ伴#
  6. Ϛϧνγά NPGOʢOਓதNਓͷॺ໊ͰϩοΫղআͰ͖ΔʣϚϧνγά Α͋͘ΔPGͷྫ !13 -PDLJOH4DSJQU TDSJQU1VC,FZ 6OMPDLJOH4DSJQU TDSJQU4JH 01@TJH"4JH#1VC,"1VC,#1VC,$01@$)&$,.6-5*4*( )"4)

    01@TJH"TJH# 1VC,"1VC,#1VC,$ 01@$)&$,.6-5*4*( 536&  TJHOBUVSF#  1VCMJD,FZ$  $)&$,.6-5*4*( TJHOBUVSF" 1VCMJD,FZ# 1VCMJD,FZ" 
  7. ΤεΫϩʔΛϒϩοΫνΣʔϯͰ !18 #MPDLDIBJO#J[ औҾͷ҆શΛอো͢ΔʮΤεΫϩʔʯ IUUQTHBJBYCMPDLDIBJODPNFTDSPX ֤͕ࣗѱҙΛ͍࣋ͬͯͨ৔߹ ങ͍ख
 ɾങ͍खͷૹ͕ۚ͞Εͳ͚Ε͹औҾΛ ։࢝͠ͳ͍ ചΓख


    ɾങ͍ख΋ΤεΫϩʔ΋ॺ໊ͤͣɺച Γख΁ͷૹۚΛ્ࢭ ΤεΫϩʔΤʔδΣϯτ
 ɾങ͍खͱചΓखͰॺ໊ͯ͠ૹۚͰ͖ɺ औҾ੒ཱ ˞ೋਓҎ্͕ѱҙ͕͋Ε͹࢓૊Έ͕੒ཱ ͠ͳ͍
  8. ΤεΫϩʔΛ#JUDPJO4DSJQUͰ Ϛϧνγάʹૹ͕ۚͨ͠ɺ໊ͷॺ໊͕ಘΒΕͳ͔ͬͨͱ͖ʹങ͍खʹࢿۚΛ ໭͢࢓૊Έ΋ඞཁ Լهͷྫ͸೔ؒखΛ͚ͭΒΕͳ͔ͬͨΒങ͍खʹ໭͢ !19 IF 2 <Alice's pubkey> <Bob's

    pubkey> <Escrow's pubkey> 3 CHECKMULTISIG ELSE "30d" CHECKSEQUENCEVERIFY DROP <Alice's pubkey> CHECKSIG ENDIF IUUQTHJUIVCDPNCJUDPJOCJQTCMPCNBTUFSCJQNFEJBXJLJ
  9. )5-$ͷ؆қతͳྫ ᶃ4FDSFU3Λ࡞੒͠ɺ4FDSFU)BTI3Λ"MJDFʹ࿈ܞ ᶄ)5-$59"Ͱɺ"MJDF͔Β#PC΁ͷࢧ෷͍Λอূ ᶅ)5-$59#ͱᶆ)5-$59$Ͱ#PC͔Β$BSPM΁ͷૹۚ ᶄ)5-$59"ͱᶇ)5-$59#Ͱ"MJDF͔Β#PC΁ͷૹۚ !26 "MJDF #PC $BSPM 4FDSFU3

    ᶃ)BTI3 ᶄ)5-$59" 4FDSFU3ͱ#PC`T1SJW,FZͰೖखՄ ·ͨ͸ɺ̎िؒܦաޙ"MJDF`T1SJW,FZ ͰೖखՄ ᶅ)5-$59# 4FDSFU3ͱ$BSPM`T1SJW,FZͰೖखՄ ·ͨ͸ɺ̎िؒܦաޙ#PC`T1SJW,FZ ͰೖखՄ ᶆ)5-$59$ 4FDSFU3ͱ$BSPM`T1SJW,FZͰೖख ᶇ)5-$59# 4FDSFU3ͱ#PC`T1SJW,FZͰೖख 4FDSFU3
  10. )5-$͸#*1ͰൃҊ #JUDPJO*NQSPWFNFOU1SPSPTBMʢϏοτίΠϯվળఏҊʣ
 #*1Ͱ)5-$͕ൃҊ͞Εͨ
 IUUQTHJUIVCDPNCJUDPJOCJQTCMPCNBTUFSCJQNFEJBXJLJ !28 HASH160 DUP <R-HASH> EQUAL IF

    "24h" CHECKSEQUENCEVERIFY 2DROP <Alice's pubkey> ELSE <Commit-Revocation-Hash> EQUAL NOTIF "2015/10/20 10:33" CHECKLOCKTIMEVERIFY DROP ENDIF <Bob's pubkey> ENDIF CHECKSIG HASH160 DUP <R-HASH> EQUAL SWAP <Commit-Revocation-Hash> EQUAL ADD IF <Alice's pubkey> ELSE "2015/10/20 10:33" CHECKLOCKTIMEVERIFY "24h" CHECKSEQUENCEVERIFY 2DROP <Bob's pubkey> ENDIF CHECKSIG "MJDF #PC $BSPM
  11. ೔ຊ҉߸௨՟ϢʔβձɹIUUQTDSZQUPDVSSFODZDPOOQBTTDPN ॳ৺ऀʙதڃऀ޲͚ͷʮϏοτίΠϯͱ͔ษڧձʯʢ݄̍ճɿฏ೔໷ʣ w ࣍ճ͸ Ր ʙ'J/$5FDIOPMPHJFTʢ༗ָொʣ தڃऀʙ্ڃऀ޲͚ͷʮ҉߸௨՟ಡॻձʯʢ݄̍ճɿฏ೔໷ʣ w ࣍ճ͸ ݄

    ʙ)BTI)VCʢຊڷࡾஸ໨ʣͰDPOOQBTTެ։४උத DSBTIBDBEFNZ *5ܥಈը഑৴ ʹͯϏοτίΠϯͱ͔ษڧձͷΞʔΧΠϒ഑৴த
 IUUQTDSBTIBDBEFNZDPNNVOJUZDSZQUPDVSSFODZ :PV5VCFνϟϯωϧʢಡॻձʗษڧձʣIUUQTHPPHM"2&W+ ϩάϛʔ5FDI ษڧձॻ͖ى͜͠ IUUQTHPPHMK,"-3 ίϛϡχςΟ঺հ !31