Commit graph

120 commits

Author SHA1 Message Date
Dave Collins
c0c167cc15 Remove logging bits from script_test.go.
The allows the tests to run without showing warning for malformed bits
(which are intentionally malformed for testing purposes).  Also, the
tests would not compile since the new btclog backend was switched out.
This commit resolves that.
2013-12-10 18:31:21 -06:00
Dave Collins
18576ab105 Add support for TravisCI.
Also add TravisCI build status badge to README.md.
2013-12-10 18:01:11 -06:00
Dave Collins
58e5fd3aec Use btclog for logging. 2013-11-21 09:36:58 -06:00
Marco Peereboom
aa3cdbe7b1 use fastsha256 2013-11-19 09:22:38 -06:00
Dave Collins
d4c5b3d04d Add tests for new nulldata standard script type. 2013-11-14 16:20:11 -06:00
Dave Collins
cfc2a4cc76 Add support for nulldata standard scripts.
This commit adds the new standard script type for empty, but data carrying
and provably prunable transaction scripts.

Closes #2.

ok @owainga
2013-11-14 16:20:02 -06:00
Dave Collins
c33bd15df2 Add a new func CalcMultiSigStats.
This commit adds a new function to extract the number of pulic keys and
number of signatures from a multi-signature script.

ok @owainga
2013-11-14 16:18:11 -06:00
Dave Collins
8550b11685 Fix missing comma. 2013-11-14 14:43:40 -06:00
Dave Collins
80e8c589d8 Bring back nonstand script class stringer test. 2013-11-14 14:42:44 -06:00
Dave Collins
e2770d3691 Go fmt. 2013-11-14 14:39:57 -06:00
Dave Collins
1ca389aa3d Go fmt. 2013-11-14 11:13:58 -06:00
Owain G. Ainsworth
f4a6449ad3 Actually just fail the opcode, not returning an error.
should fix some crazy script on testnet.
2013-11-07 18:23:20 +00:00
Owain G. Ainsworth
f0e7011b6f fix previous.
test patch, commit patch. Not the other way around, dumbass.
2013-11-07 17:32:11 +00:00
Owain G. Ainsworth
3aaafbd7fa handle op_checksig with an empty signature on the stack.
Crash found by jy-p, fix by me.
2013-11-07 17:09:22 +00:00
Owain G. Ainsworth
e8321441af add a stringer for ScriptClass 2013-11-06 00:11:14 +00:00
Josh Rickmar
b0899204d9 Update NewScript example after API change.
This change updates the doc.go documentation file with the correct use
of the new (since 8eead5217d) API used
for passing additional options when creating new script engines.

Spotted by davec@
2013-10-27 19:45:07 -04:00
David Hill
8eead5217d Add flag bitmask to NewScript for canonical sig checks.
This removes the bip16 bool from NewScript and adds it to flags (with
the constant ScriptBip16), and also adds a new flag,
ScriptCanonicalSignatures, which will call btcec.ParseDERSignature
parsing a signature during an Execute.  This is needed to emulate
bitcoind behavior, as bitcoind performs canonical signature validation
(DER format) in some places (like mempool acceptance) but not others
(like block validation).

Updated tests and test coverage file to reflect changes.
2013-10-25 15:15:00 -04:00
Owain G. Ainsworth
40c75b27ac Add CalcScriptInfo entrypoint to return info about scriptpairs.
Specficially the class of the pkScript, the  expected numbers of
arguments and the number of sigops.
2013-10-17 17:07:39 +01:00
Dale Rahn
003a41f66f Slightly cleaner fix. 2013-10-10 00:33:09 +01:00
Owain G. Ainsworth
53ca29efad fix multi-byte bug in previous.
Use the right offset when working out if we should mask off the sign bit.
Add more tests that would have caught this case.
2013-10-10 00:20:14 +01:00
Owain G. Ainsworth
4e608c115f Prevent asInt() from modifying stack data.
The stack data is normally sliced from the actual script and btcscript is not
supposed to ever change the tx passed into it.

Add a test (and fix the other leading zeros tests) to stop this happening again.
2013-10-09 23:59:23 +01:00
Owain G. Ainsworth
093ddbe193 *sigh*, accidentally commited a wrong chunk as well as the right chunk.
Fix length check back to what it should be.
2013-10-09 01:27:19 +01:00
Owain G. Ainsworth
7ff3d5f871 Handle sign extended numbers in parsing variable length opcodes. 2013-10-08 23:24:19 +01:00
Josh Rickmar
8a743c344a Update all comments and test coverage with new func name 2013-10-08 13:12:24 -04:00
Josh Rickmar
83a19b239d Replace ScriptToAddress with ScriptToAddrHash to return an address hash. 2013-10-08 13:01:51 -04:00
Owain G. Ainsworth
52a1488eaf bitcoind only fails on invalid (undefined) opcodes when they are executed.
So add entries for them that disassemble and parse ok, but will fail
when executed with the appropriate error. Add a full suite of tests to confirm
that this happens.

Found by a strange transaction in testnet.
2013-10-08 00:16:23 +01:00
Josh Rickmar
a5f81fc545 Add PayToPubKeyHashScript and SignatureScript functions.
PayToPubKeyHashScript generates a new pay to pubkey hash script to use
as the pkScript when creating new transactions.  If the passed pubkey
hash is an invalid size, StackErrInvalidOpcode will be returned as an
error.

SignatureScript returns the signature script necessary to validate a
single input of a transaction.

This also adds sanity checking for serializing scripts into byte
slices.  If the length of a serialized opcode does not equal the
expected length, StackErrInvalidOpcode will be returned when unparsing
a []parsedOpcode.

New internal tests were added to verify checks for valid and invalid
parsed opcodes.
2013-10-01 12:50:22 -04:00
Dave Collins
29ed09cc98 Add IsPushOnlyScript.
This commit adds an exported function, IsPushOnlyScript, which can be used
to tell whether or not a script only pushes data (only contains opcodes
that push data).
2013-09-30 16:54:54 -05:00
Owain G. Ainsworth
0a3e7f682b Avoid the risk of leaking small amounts of memory.
Removing from the bottom of a stack (nipN(depth)) would leak the first
entry in the array by slicing [1:], leaving array[0] dangling an
inaccessible (but unable to be freed until the whole slice is gone). We
left it like this for a while, but best not to leak the memory. Happens
rarely so the performance hit shouldn't matter that much. Do the same
thing for condstack.
2013-09-26 01:53:11 +01:00
Owain G. Ainsworth
a63edcd2dc preallocate a few arrays.
When we do append loops, make an educated guess as to the size and make an array
with that capacity to avoid extra copying.

Doesn't affect the speed of the tests, over 4 runs the difference was lost in
the noise.
2013-09-25 17:38:20 +01:00
Owain G. Ainsworth
87e976a732 Add comment explaining OP_RESERVED behaviour with push ops. 2013-09-25 17:37:36 +01:00
Owain G. Ainsworth
17d37e3b06 Fix up some ErrorF strings in tests.
One was missing a format directive. the others changed for consistency.
Appeases go vet.
2013-08-06 18:00:05 +01:00
Dave Collins
26fb20e4ed Remove need for protocol version.
This commit modifies the code to no longer require a protocol version.  It
does this by making use of the new Serialize function in btcwire.

Unfortuantely this does entail a public API change which I generally don't
like to do, but eliminating the usage of the protocol version throughout
the codebase was important enough to warrant the change.
2013-08-05 18:11:34 -05:00
Owain G. Ainsworth
118014a5b4 gofmt. 2013-07-31 01:31:27 +01:00
Owain G. Ainsworth
927d846f06 Handle bad input in sighash single.
The bitcoinj test suite actually uses it (the only thing i've seen that
does). Specifically it uses it with a bad input which returns a hash of
1.
2013-07-31 01:31:13 +01:00
Owain G. Ainsworth
22c29c4316 Perform pushed length checks at exec time, not parse.
To match bitcoind behaviour. Fix tests to agree with this direction.
2013-07-29 22:00:57 +01:00
Owain G. Ainsworth
fe2233c851 Make count sigops always count up to the point of parse failure.
We do this by allowing the parser to return the list of parsed objects
(it is an internal only api anyway) and then we use this in the sigops
counting and ignore the error. This change due to bitcoind
compatability.
2013-07-29 22:00:11 +01:00
Owain G. Ainsworth
e7f9415e4f Return 0 for bad scripts from sigops code instead of an error.
matches how bitcoind behaves.
2013-07-25 14:27:58 +01:00
Dave Collins
eb5de559ff Fix a couple of comment typos for the word execute. 2013-07-06 11:59:07 -05:00
Owain G. Ainsworth
bedaddb790 add GetScriptClass to return the internal script type of a script.
To be used to tell which class a script is (multisig, scripthash, pubkey,
pkhash, or nonstandard)
2013-07-05 15:23:02 +01:00
Owain G. Ainsworth
4d31b2c850 Remove blurb about 100% coverage and replace with comprehensive.
btcscript contains an amount of debug logging that is very useful to
have. We have agreed that testing this isn't realy practical or indeed
really useful and thus is rather unlikely to grow test coverage any time
soon.
2013-06-28 01:15:10 +01:00
Owain G. Ainsworth
c41330e772 Add basic test for if internal opcode definitions are buggy. 2013-06-28 00:46:34 +01:00
Owain G. Ainsworth
89578c985a add basic test for OP_SHA1
yup, it produces the sha of the data.
2013-06-27 16:15:32 +01:00
Owain G. Ainsworth
e5a2756795 Test empty scripts and out of bounds for DisasmScript()
give disasmscript a defined error return for out of bounds.
2013-06-27 15:07:37 +01:00
Owain G. Ainsworth
244ce4b96e add IsPayToScriptHash api
To tell ifa bytestream matches teh p2sh pattern.
2013-06-27 14:20:08 +01:00
Owain G. Ainsworth
bcd8c9d227 gofmt 2013-06-27 14:20:08 +01:00
Owain G. Ainsworth
dd216cef29 Test pushing at and beyond the boundary for largest stack item. 2013-06-26 23:57:49 +01:00
Owain G. Ainsworth
df898ae1dd test a few non-standards script types to hit some edge cases. 2013-06-26 23:28:44 +01:00
Owain G. Ainsworth
d6161f0d41 fix ScriptToAddress when called with 0 length script.
It did work by luck before, but now it works no matter what the template
tables say. Add tests for the other error cases and internal data
assertions.
2013-06-26 22:11:54 +01:00
Owain G. Ainsworth
7ae307abfd Fix case where we have an empty script that isn't the first.
Silly check needed to confirm it was the first script. Add test for this case.
2013-06-26 14:16:00 +01:00