Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Frodek on March 14, 2017, 11:26:02 AM



Title: How to use script interpreter?
Post by: Frodek on March 14, 2017, 11:26:02 AM
I have extracted file interpreter.cpp from Bitcoin sources with dependencies.
I call:
Code:
EvalScript(stack, scriptOut, SCRIPT_VERIFY_STRICTENC, BaseSignatureChecker(), SIGVERSION_BASE);
scriptOut is "76a914592fc3990026334c8c6fb2b9da457179cdb5c68888ac":
OP_DUP OP_HASH160 N/A_20 [20 bytes] OP_EQUALVERIFY OP_CHECKSIG
But is error: at start, stack is empty and need OP_DUP opcode.
Next I try interpret input script, then output:
Code:
	int err = EvalScript(stack, scriptInp, SCRIPT_VERIFY_STRICTENC, BaseSignatureChecker(), SIGVERSION_BASE);
err = EvalScript(stack, scriptOut, SCRIPT_VERIFY_STRICTENC, BaseSignatureChecker(), SIGVERSION_BASE);
but is also badly.
How to use EvalScript and maybe VerifyScript instead?
p.s.I must use SCRIPT_VERIFY_STRICTENC or SCRIPT_VERIFY_NONE,SCRIPT_VERIFY_P2SH? class BaseSignatureChecker or TransactionSignatureChecker?
--Goal: acquire address from script (or addresses from multisig script) using Bitcoin script interperter


Title: Re: How to use script interpreter?
Post by: LensFlareProject on March 14, 2017, 11:43:24 AM
I have extracted file interpreter.cpp from Bitcoin sources with dependencies.
I call:
Code:
EvalScript(stack, scriptOut, SCRIPT_VERIFY_STRICTENC, BaseSignatureChecker(), SIGVERSION_BASE);
scriptOut is "76a914592fc3990026334c8c6fb2b9da457179cdb5c68888ac":
OP_DUP OP_HASH160 N/A_20 [20 bytes] OP_EQUALVERIFY OP_CHECKSIG
But is error: at start, stack is empty and need OP_DUP opcode.
Next I try interpret input script, then output:
Code:
	int err = EvalScript(stack, scriptInp, SCRIPT_VERIFY_STRICTENC, BaseSignatureChecker(), SIGVERSION_BASE);
err = EvalScript(stack, scriptOut, SCRIPT_VERIFY_STRICTENC, BaseSignatureChecker(), SIGVERSION_BASE);
but is also badly.
How to use EvalScript and maybe VerifyScript instead?
p.s.I must use SCRIPT_VERIFY_STRICTENC or SCRIPT_VERIFY_NONE,SCRIPT_VERIFY_P2SH? class BaseSignatureChecker or TransactionSignatureChecker?
--Goal: acquire address from script (or addresses from multisig script) using Bitcoin script interperter

Try SCRIPT_VERIFY_P2SH, it should not cause any trouble


Title: Re: How to use script interpreter?
Post by: Frodek on March 14, 2017, 11:57:06 AM
OK - SCRIPT_VERIFY_P2SH
but when I interpret script OP_DUP OP_HASH160 N/A_20 [20 bytes] OP_EQUALVERIFY OP_CHECKSIG
is error: OP_DUP required non empty stack and I at start have empty stack.
In https://github.com/bitcoinbook/bitcoinbook/blob/first_edition/ch05.asciidoc#pay-to-script-hash-p2sh (https://github.com/bitcoinbook/bitcoinbook/blob/first_edition/ch05.asciidoc#pay-to-script-hash-p2sh) is
Quote
In the first few years of bitcoin’s development, the developers introduced some limitations in the types of scripts that could be processed by the reference client. These limitations are encoded in a function called isStandard(), which defines five types of "standard" transactions. These limitations are temporary and might be lifted by the time you read this. Until then, the five standard types of transaction scripts are the only ones that will be accepted by the reference client and most miners who run the reference client. Although it is possible to create a nonstandard transaction containing a script that is not one of the standard types, you must find a miner who does not follow these limitations to mine that transaction into a block.
But in blockchain I can found nonstandard.
Locking script is in output script
but where is unlocking? How interpret input scripts?
What is <sig> how much bytes have <sig>?


Title: Re: How to use script interpreter?
Post by: achow101 on March 14, 2017, 05:31:45 PM
You are verifying the script incorrectly. The way that script verification works is that the scripts have to be spent. You take the input script and concatenate the output script it spends from to the end of the input script. That is the full script as the input script and the output script by themselves are not full scripts.