Skip to content

Instantly share code, notes, and snippets.

@shravan-shandilya
Created June 23, 2018 14:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shravan-shandilya/ddccdf3f29d8880d4395463939f0c37c to your computer and use it in GitHub Desktop.
Save shravan-shandilya/ddccdf3f29d8880d4395463939f0c37c to your computer and use it in GitHub Desktop.
OracleBazaar

The P2SH script:

OP_HASH160 
0x14 
<hash160 of alice's secret>	
OP_EQUAL 
OP_TOALTSTACK 
OP_HASH160 
0x14 
<hash160 of oracle signature when alice wins> 
OP_EQUAL 
OP_TOALTSTACK 
OP_HASH160 
0x14 
<hash160 of bob's secret>
OP_EQUAL 
OP_TOALTSTACK 
OP_HASH160 
0x14 
<hash160 of oracle signature when bob wins> 
OP_EQUAL 
OP_TOALTSTACK 
OP_HASH160 
0x14 
<hash160 of alice's secret>	 
OP_EQUAL 
OP_TOALTSTACK 
OP_HASH160 
0x14 
<hash160 of bob's secret> 
OP_EQUAL 
OP_FROMALTSTACK 
OP_BOOLAND 
OP_FROMALTSTACK 
OP_FROMALTSTACK 
OP_BOOLAND 
OP_BOOLOR 
OP_FROMALTSTACK 
OP_FROMALTSTACK 
OP_BOOLAND 
OP_BOOLOR

Locking:

OP_HASH160 20 <hash160 of serialized p2sh script> OP_EQUAL

The above scriptPubKey translates to a P2SH address, which can be used for funding the bet.

Unlocking:

For the case where Alice wins

1 0x00 1 0x00 1 0x00 1 0x00
<length of oracle signature>
<signature returned by oracle>
<length of alice's secret>
<alice's secret>
OP_PUSHDATA1
<length of serialized script>
<serialized script>

For the case where Bob wins

1 0x00 1 0x00
<length of oracle signature>
<signature returned by oracle>
<length of bob's secret>
<bob's secret>
1 0x00 1 0x00
OP_PUSHDATA1
<length of serialized script>
<serialized script>

For the case where Alice and Bob settle to cancel the bet

<length of alice's secret>
<alice's secret>
<length of bob's secret>
<bob's secret>
1 0x00 1 0x00 1 0x00 1 0x00
OP_PUSHDATA1
<length of serialized script>
<serialized script>

Examples

Case 1: Alice wins

Funding Redeeming

Case 2: Bob wins

Funding Redeeming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment