Commit Graph

134 Commits

Author SHA1 Message Date
Dave Collins
565f11409c Add 2014 to copyright dates. 2014-01-08 23:47:47 -06:00
Dave Collins
e50681264b Add 100% test coverage for ExtractPkScriptAddrs. 2014-01-07 18:09:48 -06:00
Dave Collins
6c8003b064 Refactor and improve address extraction code.
This commit significantly changes the address extraction code.  The
original code was written before some of the other newer code was written
and as a result essentially duplicated some of the logic for handling
standard scripts which is used elsewhere in the package.

The following is a summary of what has changed:

- CalcPkScriptAddrHashes, ScriptToAddrHash, and ScriptToAddrHashes have
  been replaced by ExtractPkScriptAddresses
- The ScriptType type has been removed in favor of the existing
  ScriptClass type
- The new function returns a slice of btcutil.Addresses instead of raw
  hashes that the caller then needs to figure out what to do with to
  convert them to proper addressses
- The new function makes use of the existing ScriptClass instead of an
  nearly duplicate ScriptType
- The new function hooks into the existing infrastructure for parsing
  scripts and identifying scripts of standard forms
- The new function only works with pkscripts to match the behavior of the
  reference implementation - do note that the redeeming script from a p2sh
  script is still considered a pkscript
- The logic combines extraction for all script types instead of using a
  separate function for multi-signature transactions
- The new function ignores addresses which are invalid for some reason
  such as invalid public keys
2014-01-07 17:48:18 -06:00
Dave Collins
126991b60b Make opcode disasm names match reference impl.
This commit modifies the names of opcdoes shown in the oneline script
disassembly to match the reference implementation.  In particular
OP_1NEGATE, and OP_0 through OP_16 are changed to the raw numbers
they represent when doing oneline disassembly.  When doing full
disassembly, the full opcode names are still shown.

ok @owainga.
2014-01-07 12:07:54 -06:00
Dave Collins
e2f14e2cfa Fix comment typo. 2014-01-06 12:14:43 -06:00
Dave Collins
2005fae908 Change OP_CHECK_MULTISIG -> OP_CHECKMULTISIG.
This change was made to match the reference implementation.
2014-01-04 15:23:51 -06:00
Dave Collins
b713590902 Group the StackErrX definitions.
This improves the godoc display and provides a cleaner separation of the
error definitions from other variables.
2014-01-04 09:58:22 -06:00
Dave Collins
eb4fc19b95 Modify DisasmString to return partial disassembly.
Rather than returning an empty string from DisasmString if a script fails
to parse, return the disassembly up to the point of the failure along with
[error] appended.  The error is still returned in case the caller wants
more information about the script parse failure.
2014-01-03 18:47:00 -06:00
Dave Collins
814c920c96 Add tests for new payment script creation funcs. 2014-01-03 13:42:22 -06:00
Dave Collins
3d60bac238 Add new funcs for creating payment scripts.
This commit adds two new functions named PayToScriptHashScript and
PayToAddrScript.  The first one creates and returns a public-key script
which pays to the provided script hash and conforms to BIP0016.

The second function takes the new btcutil.Address interface type and
returns an appropriate script to pay to the address type in the interface.
It currently works for btcutil.AddressPubKeyHash and
btcutil.AddressScriptHash.
2014-01-03 13:35:51 -06:00
Francis Lam
3a8ec0078b Added another multisig test with compressed pubkey 2014-01-02 13:50:22 -05:00
Francis Lam
3f52f559eb Added tests for multisig scripts and fixed comments
Fixed up bad function comment headers

Added a small set of tests for the ScriptToAddrHashes function to test
functionality of a couple real multisig cases as well as error checking
2014-01-02 13:31:00 -05:00
Francis Lam
a5aaf90687 Added support to decode scripthash/multisig from pkscripts 2014-01-02 00:28:16 -05:00
Dave Collins
4f4afedf39 Use the new btcec Signature.Serialize API.
This commit modifies the code to use the new btcec Signature.Serialize API
instead of the internal sigDER which has now been removed.  This closes #3.

ok @owainga
2013-12-23 11:35:14 -06:00
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