Commit graph

146 commits

Author SHA1 Message Date
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
95cd1b97fa Make the OP_FALSE constant untyped.
This makes it consistent with the rest of the opcode constants.
2014-08-13 00:32:16 -05:00
Michalis Kargakis
6ae916bd37 More tests
Tests for IsPushOnlyScript, HasCanonicalPushes, and CalcMultiSigStats
2014-08-08 14:53:55 +03:00
Michalis Kargakis
55ad967b4d Complete SetLogWriter testing 2014-08-03 23:30:37 +03:00
David Hill
ef0ca7dff5 sync bitcoind script tests 2014-08-01 13:40:56 -04:00
Michalis Kargakis
24c3873956 Add log testing
8/10 of SetLogWriter tested
2014-07-31 23:42:09 +03:00
Dave Collins
95167204d9 Add ExtractPkScriptAddrs examples. 2014-07-08 14:59:57 -05:00
Dave Collins
631c7850ec Correct example link in README.md. 2014-07-08 14:43:50 -05:00
Dave Collins
abafe9678b Use testable example and update doc.go README.md.
This commit adds an example test file so it integrates nicely with Go's
example tooling.

This allows the example output to be tested as a part of running the
normal Go tests to help ensure it doesn't get out of date with the code.
It is also nice to have the example in one place rather than repeating it
in doc.go and README.md.

Links and information about the example have been included in README.md in
place of the example.
2014-07-08 14:42:39 -05:00
Dave Collins
3c2ae358b4 Add godoc reference badge to README.md. 2014-07-08 14:13:08 -05:00
Dave Collins
5beafbd2d8 goimports -w . 2014-07-02 19:37:49 -05:00
Dave Collins
79b6e51dff Update tests for recent btcutil.Address API change. 2014-07-02 19:36:41 -05:00
David Hill
7d228846bd sync tx_valid.json test data. 2014-06-13 11:34:47 -04:00
David Hill
e560b6d964 sync bitcoind test data. 2014-05-29 10:56:43 -04: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
David Hill
1240483592 gofmt 2014-04-11 14:54:44 -04:00
Owain G. Ainsworth
03dd134305 adapt for btcec changes. 2014-04-09 19:30:59 +01:00
Dave Collins
4fce6d1476 Sync latest script tests to bitcoind test suite. 2014-04-03 23:18:52 -05:00
Dave Collins
f529a37123 Add tests for doing math on 5-byte ints.
This commit addes a couple of tests to ensure performing math operations
on a 5-byte integer, even if the result is a 4-byte integer, is considered
invalid.
2014-04-03 17:13:44 -05:00
Owain G. Ainsworth
8ec60d4678 Quick and dirty tests harnesses using some bitcoind test data.
Both the script tests (positive and negative) and tx texts (ditto) are
present.  Some of the tx tests in the negative section have been
replaced by a comment line explaining why that test is elided, to add in
diffing. The reasons were always that they test things handled by other
parts of the btcd stack (normally chain). For example MAX_MONEY, number
of outputs, coinbase sizes etc.

Much of the inital test logic from @dajohi using hand transcribed tables
for selected tests. The json parsers, script format parser and a lot of
cleaning up/bugfixing from your truly. @davecgh had some input too.
2014-03-19 01:06:19 +00:00
Owain G. Ainsworth
5f6de02eb8 use bytes.Repeat instead of my perlscript generated lists of zeros.
Pointed out by davec. I'd forgotten about it. Kills just over 10k lines
from the test file.
2014-03-19 00:43:21 +00: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
Owain G. Ainsworth
dab2a7cb0f Don't possibly dereference bad signatures in OP_CHECKMULTISIG.
We do all the preprocessing in one loop. Fixes a bug introduced a while ago to
handle invalid signatures. Found by more tests from bitcoind.
2014-03-17 17:46:56 +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
02ee7762e4 AddData([]byte{}) is valid and should push empty to the stack.
Doing so is perfectly idiomatic.  Fixes the last of the valid bitcoind
script tests. (by fixing the script parser :)
2014-03-14 22:46:15 +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
f80c3255a3 PopInt now guarantees that number will be 32 bit.
So remove later checks that need this.
2014-03-14 21:05:29 +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
Owain G. Ainsworth
201d6651c9 Fix tests after IsForNet addition to btcutil.Address interface.
dhill pointed this out to me.
2014-03-13 17:20:45 +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