jb55 / btcs Goto Github PK
View Code? Open in Web Editor NEWbitcoin script parser/evaluator/compiler/decoder
License: BSD 2-Clause "Simplified" License
bitcoin script parser/evaluator/compiler/decoder
License: BSD 2-Clause "Simplified" License
We could use the same syntax that bitcoin-tx uses:
btcs <<<'0x6a03 0x010203'
This is done!
It would be nice to have a mode that decoded hex-encoded script, like bitcoin-cli decodescript
but much faster. Then we could do something like:
./bitcoin-iterate -q --output=%os --start 0 --end 80000 | btcs --decode
Would be nice to know if the script is standard in the results section
see gopher://jb55.com/0/bips/sipa/bip-tapscript.txt
Generate addresses from scripts
Depends on #16
Would be nice when ran without input
I just implemented some functional tests for bcalc in jb55/bcalc@ae0b2d3a02bf2c403663ec9f910fd1882ef4860b^...073990b and I'm really liking the csv way of defining tests. Perhaps I can rework the testsuite to do something similar.
$ btcs <<< '@aa dup equal not' ~/src/c/btcs
script 0xaa OP_DUP OP_EQUAL OP_NOT
btcs: script_num.c:126: sn_from_val: Assertion `(*sn)->ind == val.ind' failed
Parameters for script context would be nice. I'm currently missing:
Used in CLTV, CSV, CHECKSIGVERIFY. This is just an interface to the TransactionSignatureChecker which requires extra context, such as txos. How to represent this state for testing scripts?
SCRIPT_VERIFY_NONE = 0,
SCRIPT_VERIFY_P2SH = (1U << 0),
SCRIPT_VERIFY_STRICTENC = (1U << 1),
SCRIPT_VERIFY_DERSIG = (1U << 2),
SCRIPT_VERIFY_LOW_S = (1U << 3),
SCRIPT_VERIFY_NULLDUMMY = (1U << 4),
SCRIPT_VERIFY_SIGPUSHONLY = (1U << 5),
SCRIPT_VERIFY_MINIMALDATA = (1U << 6),
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS = (1U << 7),
SCRIPT_VERIFY_CLEANSTACK = (1U << 8),
SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY = (1U << 9),
SCRIPT_VERIFY_CHECKSEQUENCEVERIFY = (1U << 10),
SCRIPT_VERIFY_WITNESS = (1U << 11),
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM = (1U << 12),
SCRIPT_VERIFY_MINIMALIF = (1U << 13),
SCRIPT_VERIFY_NULLFAIL = (1U << 14),
SCRIPT_VERIFY_WITNESS_PUBKEYTYPE = (1U << 15),
because why not. perhaps an option to continue executing and report an invalid script error in the result.
swap drop
-> nip
dup if dup endif
-> ifdup
swap over
-> tuck
dup dup
-> 2dup
dup dup dup
-> 3dup
drop drop
-> 2drop
rot rot rot
->swap 1 pick
-> tuck
0 pick
-> dup
1 pick 1 pick
-> 2dup
2 pick 2 pick 2 pick
-> 3dup
x add x sub
->0 roll
->Where x
and y
are scriptnums
x y add
-> x + y
x y sub
-> x - y
sha256, ripemd, etc
It would be nice to expand the interpreter's ability to handle future upgrades to the Bitcoin script (thanks to segwit). I wonder if there's anything stopping me from implementing Simplicity? /cc @roconnor-blockstream
examples:
script 0 OP_NOT
script_hex 0091
stack 1
stack_hex 01
results success
script 1 OP_NOT
script_hex 5191
stack 0
stack_hex {missing 00}
results success
script 0 0 OP_SUB
script_hex 000094
stack 0
stack_hex {missing 00}
results success
script 1 0 OP_SUB
script_hex 510094
stack 1
stack_hex 01
results success
script 127 0 127 1
script_hex 017f00017f51
stack 0x7f 0x 0x7f 1 {0x?}
stack_hex 7f7f01 {missing 00}
results success
Sugar for data literals
Would be handy for OP_RETURN stuff maybe?
Indent if statements, etc
so we can do things like btcs 1 dup equalverify
Implement script_handle_input
, which prompts on free variables.
For example, with a script such as:
OP_IF
[HASHOP] <digest> OP_EQUALVERIFY OP_DUP OP_HASH160 <seller pubkey hash>
OP_ELSE
<num> [TIMEOUTOP] OP_DROP OP_DUP OP_HASH160 <buyer pubkey hash>
OP_ENDIF
OP_EQUALVERIFY
OP_CHECKSIG
it should prompt for input on <digest>
, <seller pubkey hash>
etc. otherwise, provide input via cli arguments. Maybe eventually we will have variables...
A lot of bitcoin cli tools use JSON for output. Perhaps there could be a mode that supports this for interop with jq, bitcoin-cli, etc
Testing if a number is within a range, returns 1 (i.e. 'true'):
script 1 -100 100 OP_WITHIN
script_hex 5101e40164a5
stack 1
script 1 -8388607 8388607 OP_WITHIN
script_hex 5103ffffff03ffff7fa5
stack 1
Increment the range (numbers now 4 bytes), returns 0 which is incorrect it should be 1.
script 1 -8388608 8388608 OP_WITHIN
script_hex 5104000080800400008000a5
stack 0
This test is from bitcoin core, expected return value is 1.
script 0 -2147483647 2147483647 OP_WITHIN
script_hex 0004ffffffff04ffffff7fa5
stack 0
Verification, etc
If they have a minimal encoding
Inspired from the mailing list:
0 pkb6 pkb5 pkb4 pkb3 pkb2 pkb1 pka3 pka2 pka1 9 CHECK_AGGSIG_VERIFY
(declare pubkeys)
0b111 CHECK_AGG_SIGNERS VERIFY
(one of pka{1,2,3} must sign)
0b001 CHECK_AGG_SIGNERS
0b010 CHECK_AGG_SIGNERS ADD
0b100 CHECK_AGG_SIGNERS ADD
DUP ADD
(pka{1,2,3} count double)
0b000001000 CHECK_AGG_SIGNERS ADD
0b000010000 CHECK_AGG_SIGNERS ADD
0b000100000 CHECK_AGG_SIGNERS ADD
0b001000000 CHECK_AGG_SIGNERS ADD
0b010000000 CHECK_AGG_SIGNERS ADD
0b100000000 CHECK_AGG_SIGNERS ADD
(pkb{1..6} count single)
6 EQUAL
-O option that cleans up non minimal data, etc.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.