Bitcoin Stack Trade is a query and reply website for Bitcoin crypto-currency fans. It solely takes a minute to enroll.
Anyone can ask a query
Anyone can reply
One of the best solutions are voted up and rise to the highest
Requested
Considered
273 occasions
I wish to create a bitcoin locking script that takes 3 numbers, every of them are lower than 8 and if sum of three numbers are 15 then script will return true. How am i able to try this?
The one who will redeem the transaction wants to supply solely these 3 numbers.
Thanks
bitcointapir is a brand new contributor to this website. Take care in asking for clarification, commenting, and answering.
Take a look at our Code of Conduct.
That is the smallest script I might give you, at 13 opcodes:
OP_3DUP
OP_ADD
OP_ADD
OP_15 OP_NUMEQUALVERIFY
OP_8 OP_LESSTHAN OP_VERIFY
OP_8 OP_LESSTHAN OP_VERIFY
OP_8 OP_LESSTHAN
It saves some bytes by utilizing OP_3DUP
to duplicate all three enter numbers, and one byte by checking the addition first utilizing OP_NUMEQUALVERIFY
as an alternative of OP_NUMEQUAL
, which saves one OP_VERIFY
opcode.
2
OP_DUP OP_8 OP_LESSTHAN OP_VERIFY
OP_SWAP OP_DUP OP_8 OP_LESSTHAN OP_VERIFY
OP_ROT OP_DUP OP_8 OP_LESSTHAN OP_VERIFY
OP_ADD OP_ADD OP_15 OP_NUMEQUAL
Tracing the execution (for a profitable enter):
- Preliminary: a b c
OP_DUP
: a b c cOP_8
: a b c c 8OP_LESSTHAN
: a b c 1OP_VERIFY
: a b cOP_SWAP
: a c bOP_DUP
: a c b bOP_8
: a c b b 8OP_LESSTHAN
: a c b 1OP_VERIFY
: a c bOP_ROT
: c b aOP_DUP
: c b a aOP_8
: c b a a 8OP_LESSTHAN
: c b a 1OP_VERIFY
: c b aOP_ADD
: c (a+b)OP_ADD
: (a+b+c)OP_15
: (a+b+c) 15OP_NUMEQUAL
: 1
3