Commit graph

76 commits

Author SHA1 Message Date
David Hill
2803ea17c2 Remove the use of go-spew. 2014-08-29 16:06:17 -04:00
Jonathan Gillham
516db23576 Replaced privkey in entire codebase. 2014-08-25 21:14:19 +01:00
Jonathan Gillham
da080e1598 Changed privkey to privKey for consistency. 2014-08-25 21:09:23 +01:00
Dave Collins
5beafbd2d8 goimports -w . 2014-07-02 19:37:49 -05:00
David Hill
a591c7ec03 Add new ScriptFlag ScriptStrictMultiSig.
ScriptStrictMultiSig verifies that the stack item used by CHECKMULTISIG
is zero length.
2014-05-29 10:55:35 -04:00
Josh Rickmar
be325b9d9c Update API for btcnet and btcutil changes.
ok @davecgh
2014-05-27 17:42:01 -05:00
David Hill
27e1ad758b Add new function PushedData.
PushedData returns an array of byte slices containing any pushed data
found in the passed script.  This includes OP_0, but not OP_1 - OP_16.

help from and ok @owainga
2014-05-20 12:24:23 -04:00
Owain G. Ainsworth
6e2ba386dd Add an entypoint to sign and verify a transaction input.
This handles merging in of previous scripts, also. Add tests for the important
paths. ok @davecgh
2014-05-07 16:05:55 +01:00
David Hill
76e8fa9766 Reduce OP_RETURN standard relay bytes to 40.
This matches commit 8175c790eb12f0b0ca3197895a6d1d479b340b67 of
the reference software.
2014-05-01 09:42:15 -04:00
Owain G. Ainsworth
1b1fef7369 Make removeOpcodeByData only search canonical pushes.
Matches bitcoind behaviour. Pointed out by one of their tx_invalid tests.
2014-03-18 18:28:09 +00:00
Owain G. Ainsworth
76339baf6c Make removeOpcodeByData in line with bitcoind behaviour.
It should remove the opcode and data is the data is contained within the data
pushed, not just if it is equal to it. Found by bitcoind tx tests.
2014-03-18 00:49:24 +00:00
Dave Collins
c8332cc9a7 Correct num expected inputs calc for multisig.
This commit corrects the number of expected inputs for a multi-sig script
to include the additional item that is popped from the stack due to the
OP_CHECKMULTISIG consensus bug (which is required and properly performed).

Note this issue did NOT affect the consensus critical code and hence would
not cause a chain fork.  It did however, cause standard p2sh multisig txns
to be rejected from the mempool as nonstandard.

The tx rejected as non-standard which prompted this was spotted by
@mbelshe on IRC.

ok @owainga
2014-03-17 10:47:02 -05:00
Owain G. Ainsworth
9375c8dc48 move data extraction fof OP_PUSHDATA into main function.
This allows us to centralise the error checking to simplify things a bit.
2014-03-14 22:46:41 +00:00
Owain G. Ainsworth
299dcc2fad PushDataN with a 0 length is valid, we were too tight here.
Found by bitcoind positive tests. (but of course that is noncanonical
anyway, it should be OP_0 ;).
2014-03-14 22:46:14 +00:00
Owain G. Ainsworth
42f6576b02 Enforce max script length of 10000.
Detected by bitcoind negative script tests. Note that this length is only for
*executing* scripts, this is why it is in NewScript.
2014-03-14 22:45:14 +00:00
Owain G. Ainsworth
dec16d7ff2 Enforce a combined max stack depth of 1000 after every opcode.
This limit is for the sum of main and alt stacks. Found by bitcoind
negative tests.
2014-03-14 21:06:08 +00:00
Owain G. Ainsworth
d6d755e411 Always return reserved opcode for always-illegal ops. 2014-03-14 21:06:08 +00:00
Owain G. Ainsworth
8beb0dec54 Make opcode.Exec run a bunch of unconditional checks
Add push length and number of operations to this to match bitcoind behaviour.
found that we differed here by their negative tests.
2014-03-14 21:06:05 +00:00
Owain G. Ainsworth
c7d5102954 Alt stack should be purged between scripts.
Found by bitcoind negative scripts.
2014-03-14 21:05:25 +00:00
Owain G. Ainsworth
a5e7e9ebb6 Disabled opcodes are `fail if pc passes' not fail if execute.
Detected by bitcoind negative tests.
2014-03-14 21:04:59 +00:00
Owain G. Ainsworth
c1a6e47f38 Conditionals must not straddle two scripts.
Found by tests dhill is working on. We checked that ifs were closed at the end
of execution but not at script switching time, we now move this to just after
finishing a single script.
2014-03-14 21:04:37 +00:00
Owain G. Ainsworth
8df0af32d6 Encountering OP_VERIF and OP_VERNOTIF in execution is always an error.
I honestly thought we already handled this, but some tests dhill is
working on shows that we didn't.
2014-03-14 20:28:23 +00:00
Dave Collins
da1fcc6dbd Tighten the check for pay-to-pubkey scripts.
This commit tightens the check for a pay-to-pubkey script by ensuring the
length of the pubkey is one of the two valid values of 33 or 65.  This
mirrors the checks in the multisig script type check as well.

ok @owainga
2014-02-21 12:18:43 -06:00
Dave Collins
982f282e10 Go fmt. 2014-02-21 02:10:38 -06:00
Owain G. Ainsworth
88f3c73ad1 Add MultiSigScript to provide a canonical script for a multisig transaction. 2014-02-21 00:20:24 +00:00
Owain G. Ainsworth
2b0b512a83 Add support for pay to pubkey addresses to PayToAddrScript
Based on some initial code from @davecgh, finished by me.
2014-02-20 19:26:34 +00:00
Owain G. Ainsworth
5171cb803c Convert builder.Push* to builder.Add* we think this is clearer.
Also, shorter!  Discussed with @davecgh.
2014-02-20 18:42:58 +00:00
Owain G. Ainsworth
1566366346 convert internal script generation to use ScriptBuilder.
Also, unexport the functions to generate script types. Everything should
(and is) be using PayToAddrScript() with an address type instead of
throwing bytes around.

discussed with #@davecgh
2014-02-20 17:52:46 +00:00
Dave Collins
cff7f9704b Fix a few comment typos. 2014-02-20 11:20:53 -06:00
David Hill
61d270957e Add HasCanonicalPushes
Closes #6.

ok @davecgh
2014-02-20 01:20:47 -06:00
Dave Collins
37a45ec683 Allow multi-sig scripts with zero signatures.
This commit builds off the previous commit which fixed the execution of
multi-signature scripts with zero required signatures.

It introduces the concept of a "small int" which is one of OP_0 or OP_1 -
OP_16.  All areas of code that deal with multi-sig transactions now make
use of these to ensure consistent handling.

This fixes a few issues surrounding multi-sig zero required signature
transactions included proper detection as a multi-sig script, signature
counting for script statistics, and

ok @owainga
2014-02-19 16:34:50 -06:00
Dave Collins
fcd73f75ea Correct log trace for failed script execution.
The function needs to be wrapped by a newLogClosure for the logger to be
able to log it.
2014-02-19 13:22:33 -06:00
David Hill
971fbf8b28 gofmt 2014-02-04 16:18:37 -05:00
Dave Collins
565f11409c Add 2014 to copyright dates. 2014-01-08 23:47:47 -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
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
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
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
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
1ca389aa3d Go fmt. 2013-11-14 11:13:58 -06:00
Owain G. Ainsworth
e8321441af add a stringer for ScriptClass 2013-11-06 00:11:14 +00: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
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