Commit graph

96 commits

Author SHA1 Message Date
Wladimir J. van der Laan 7fc25c2e5d
Merge pull request #6368
cb54d17 CLTV: Add more tests to improve coverage (Esteban Ordano)
2015-07-09 11:20:17 +02:00
Wladimir J. van der Laan 133601f6a5 tests: Fix bitcoin-tx signing testcase
Fixes wrong scriptPubkey problem, which caused the transaction to
not actually be signed.
2015-07-07 18:26:38 +02:00
Esteban Ordano cb54d17355 CLTV: Add more tests to improve coverage
Four cases included:

* The CLTV operand type mismatches the tx locktime. In the script it is
  1 (interpreted as block height), but in the tx is 500000000
  (interpreted as date)
* The stack is empty when executing OP_CLTV
* The tx is final by having only one input with MAX_INT sequence number
* The operand for CLTV is negative (after OP_0 OP_1 OP_SUB)
2015-07-06 13:09:37 -07:00
Peter Todd bc60b2b4b4 Replace NOP2 with CHECKLOCKTIMEVERIFY (BIP65)
<nLockTime> CHECKLOCKTIMEVERIFY -> <nLockTime>

Fails if tx.nLockTime < nLockTime, allowing the funds in a txout to be
locked until some block height or block time in the future is reached.

Only the logic and unittests are implemented; this commit does not have
any actual soft-fork logic in it.

Thanks to Pieter Wuille for rebase.

Credit goes to Gregory Maxwell for the suggestion of comparing the
argument against the transaction nLockTime rather than the current
time/blockheight directly.
2015-06-21 23:56:28 -04:00
Dave Collins 1c54757f86 Add more script edge condition tests.
This commit adds some tests to the script_valid.json and tx_invalid.json
data which exercise more edge conditions that are not currently being
tested.
2015-05-06 10:20:18 -05:00
Wladimir J. van der Laan df1609f314
Merge pull request #6075
9fadf1c Add additional script edge condition tests. (Dave Collins)
2015-04-29 15:56:30 +02:00
Dave Collins 9fadf1c874 Add additional script edge condition tests.
This commit adds several tests to the script_invalid.json data which
exercise some edge conditions that are not currently being tested.

These are mainly being added to cover several cases a branch coverage
analysis of btcd showed are not already being covered, but given more
tests of edge conditions are always a good thing, I'm contributing
them upstream.
2015-04-28 02:35:43 -05:00
Dave Collins d8f4cc328e Correct the PUSHDATA4 minimal encoding test.
The test which is intended to prove that the script engine is properly
rejecting non-minimally encoded PUSHDATA4 data is using the wrong
opcode and value.  The test is using 0x4f, which is OP_1NEGATE instead
of the desired 0x4e, which is OP_PUSHDATA4.  Further, the push of data
is intended to be 256 bytes, but the value the test is using is
0x00100000 (4096), instead of the desired 0x00010000 (256).

This commit fixes both issues.

This was found while examining the branch coverage in btcd against only
these tests to help find missing branch coverage.
2015-04-27 21:47:55 -05:00
Pieter Wuille 437ada3e55 Switch test case signing to RFC6979 extra entropy
Instead of manually tweaking the deterministic nonce post-generation,
pass the test case number in as extra entropy to RFC6979.
2015-03-27 15:31:47 -07:00
Suhas Daftuar 78c6bedb9c Add test for DER-encoding edge case
The fix to NegateSignatureS caused a test which had been failing
in IsValidSignatureEncoding to then fail in IsLowDERSignature.
Add new test so the original check remains exercised.
2015-02-10 13:25:41 -05:00
Suhas Daftuar 6f50dbd2fd Fix NegateSignatureS to not duplicate last byte of S
NegateSignatureS is called with a signature without a hashtype, so
do not save the last byte and append it after S negation.

Updates the two tests which were affected by this bug.
2015-02-10 13:23:57 -05:00
Wladimir J. van der Laan 41e6e4caba
Merge pull request #5713
bf6cdeb Increase coverage of DERSIG edge cases (Pieter Wuille)
819bcf9 Add RPC test for DERSIG BIP switchover logic (Pieter Wuille)
5a47811 BIP66 changeover logic (Pieter Wuille)
092e9fe Example unit tests from BIP66 (Pieter Wuille)
80ad135 Change IsDERSignature to BIP66 implementation (Pieter Wuille)
2015-02-03 10:34:53 +01:00
Pieter Wuille bf6cdebdc5 Increase coverage of DERSIG edge cases 2015-02-01 17:51:25 -04:00
Pieter Wuille 092e9fe5fb Example unit tests from BIP66 2015-02-01 17:47:21 -04:00
Manuel Araoz d6bed1514c remove sig_canonical.json and sig_noncanonical.json 2015-01-31 17:36:44 -05:00
Peter Todd 2fa9a8ec86
Make empty byte arrays pass CheckSignatureEncoding()
Makes it possible to compactly provide a delibrately invalid signature
for use with CHECK(MULTI)SIG. For instance with BIP19 if m != n invalid
signatures need to be provided in the scriptSig; prior to this change
those invalid signatures would need to be large DER-encoded signatures.

Note that we may want to further expand on this change in the future by
saying that only OP_0 is a "valid" invalid signature; BIP19 even with
this change is inherently malleable as the invalid signatures can be any
validly encoded DER signature.
2015-01-09 06:03:22 -05:00
Wladimir J. van der Laan c6a5ad4819
Fix tests after #5413
Pull #5413 was not rebased after deterministic signing was merged
(#5227), so the testcases had to be regenerated using UPDATE_JSON_TESTS.
2015-01-08 12:53:05 +01:00
Wladimir J. van der Laan 48e1765e27
Merge pull request #5143
da918ac Make SCRIPT_VERIFY_CLEANSTACK a standardness requirement (Pieter Wuille)
b6e03cc Add SCRIPT_VERIFY_CLEANSTACK (BIP62 rule 6) (Pieter Wuille)
ae4151b No semantic change: reuse stack variable in P2SH evaluation (Pieter Wuille)
2015-01-08 12:01:22 +01:00
Wladimir J. van der Laan e6df2bb48f Remove redundant copyright notices from README files
The normative place for these for the entire project is COPYING,
and the main README already has a MIT license section.
2015-01-02 10:46:23 +01:00
Eric R. Schulz 2c14d1532f bitcoin-tx: Add test case for signing a tx 2014-12-24 01:56:28 +00:00
Wladimir J. van der Laan 111a7d45f1
Merge pull request #5470
78253fc Remove references to X11 licence (Michael Ford)
2014-12-19 19:23:23 +01:00
Wladimir J. van der Laan 886eb57507
Merge pull request #5421
cac15be Test unexecuted OP_CODESEPARATOR (Peter Todd)
2014-12-19 17:54:21 +01:00
Michael Ford 78253fcbad Remove references to X11 licence 2014-12-16 15:56:50 +08:00
Manuel Araoz 87e8e1ca8b minor fix on script test data docs 2014-12-16 00:55:21 -03:00
Peter Todd cac15bedb1
Test unexecuted OP_CODESEPARATOR
OP_CODESEPARATOR is an actual executed instruction, not a declarative
thing, so if it's wrapped in an OP_IF it can be turned off.

Using this to implement Rivest's Paywords is left as an exercise for the
reader.
2014-12-04 00:53:16 -05:00
Ryan X. Charles 65b03282c9
newlines in strings are invalid JSON
Although script_valid.json and script_invalid.json are loaded correctly by the
JSON interpreter used by bitcoin core, these same files are often used by other
libraries and do not necessarily load correctly due to the fact that newlines
contained inside strings are not valid and must instead use the escape
character \n. The files tx_valid.json and tx_invalid.json handle this
correctly, so I've changed the formatting in script_valid.json and
script_invalid.json to mirror those files.
2014-12-02 10:02:44 -08:00
Pieter Wuille 362001c19f Move CHECKMULTISIG order tests out of automatically generated block 2014-12-01 21:37:20 +01:00
Pieter Wuille f67a9ce0dc Use deterministically generated script tests
Now that signing is deterministic, we can require exact correspondence between the
automatically generated tests and the ones read from JSON. Do this, and update
the tests to those deterministic versions. Note that some flag changes weren't
correctly applied before.
2014-12-01 21:29:02 +01:00
Pieter Wuille b6e03cc592 Add SCRIPT_VERIFY_CLEANSTACK (BIP62 rule 6)
Based on an earlier patch by Peter Todd, though the rules here are different
(P2SH scripts should not have a CLEANSTACK check before the P2SH evaluation).
2014-11-25 12:38:01 +01:00
Peter Todd ca8158719b Test the exact order of CHECKMULTISIG sig/pubkey evaluation
Possible with STRICTENC
2014-11-20 15:29:28 +01:00
Pieter Wuille 98b135f97f Make STRICTENC invalid pubkeys fail the script rather than the opcode.
This turns STRICTENC turn into a softforking-safe change (even though it
is not intended as a consensus rule), and as a result guarantee that using
it for mempool validation only results in consensus-valid transactions in
the mempool.
2014-11-20 15:29:26 +01:00
Peter Todd 03914234b3
Discourage NOPs reserved for soft-fork upgrades
NOP1 to NOP10 are reserved for future soft-fork upgrades. In the event
of an upgrade such NOPs have *VERIFY behavior, meaning that if their
arguments are not correct the script fails. Discouraging these NOPs by
rejecting transactions containing them from the mempool ensures that
we'll never accept transactions, nor mine blocks, with scripts that are
now invalid according to the majority of hashing power even if we're not
yet upgraded. Previously this wasn't an issue as the IsStandard() rules
didn't allow upgradable NOPs anyway, but 7f3b4e95 relaxed the
IsStandard() rules for P2SH redemptions allowing any redeemScript to be
spent.

We *do* allow upgradable NOPs in scripts so long as they are not
executed. This is harmless as there is no opportunity for the script to
be invalid post-upgrade.
2014-11-17 22:22:33 -05:00
Peter Todd 16d78bd68e Add valid invert of invalid every numeric opcode tests 2014-10-25 03:13:15 -07:00
Peter Todd 2b62e1796b Clearly separate PUSHDATA and numeric argument MINIMALDATA tests 2014-10-25 03:12:39 -07:00
Peter Todd dfeec18b85 Test every numeric-accepting opcode for correct handling of the numeric minimal encoding rule 2014-10-25 03:12:06 -07:00
Peter Todd 554147ad9e Ensure MINIMALDATA invalid tests can only fail one way
Removes the need for the 'negated' versions of the tests, and ensures
other failures don't mask what we're trying to test.
2014-10-25 03:11:38 -07:00
Pieter Wuille 698c6abb25 Add SCRIPT_VERIFY_MINIMALDATA (BIP62 rules 3 and 4)
Also use the new flag as a standard rule, and replace the IsCanonicalPush
standardness check with it (as it is more complete).
2014-10-25 03:03:20 -07:00
Pieter Wuille d752ba86c1 Add SCRIPT_VERIFY_SIGPUSHONLY (BIP62 rule 2) 2014-10-25 03:03:16 -07:00
Pieter Wuille 9df9cf5a9f Make SCRIPT_VERIFY_STRICTENC compatible with BIP62
* Delete canonical_tests.cpp, and move the tests to script_tests.cpp.
* Split off SCRIPT_VERIFY_DERSIG from SCRIPT_VERIFY_STRICTENC (the BIP62 part of it).
* Change signature STRICTENC/DERSIG semantics to fail the script entirely rather than the CHECKSIG result (softfork safety, and BIP62 requirement).
* Add many autogenerated tests for several odd cases.
* Mention specific BIP62 rules in the script verification flags.
2014-10-08 15:42:29 -07:00
Pieter Wuille 2c930d932b Prettify JSON tests and minimize diffs 2014-10-07 09:41:33 +02:00
Wladimir J. van der Laan a6f3e9d843
Merge pull request #5014
41d67c7 tests: fix python test-runner for windows (Cory Fields)
2014-10-01 08:55:34 +02:00
Cory Fields 41d67c78bf tests: fix python test-runner for windows
Windows needed a few fixups to get the tests running:
1. bitcoin-tx needs a file extension in Windows. Take this opportunity to
   add an env file, which pulls variables out of our build config. This can
   be extended as needed, for now it's very simple.
2. After #1, split the args out of the exec key in the test data.
3. Correct the line-endings from windows stdout
2014-09-30 16:26:22 -04:00
Pieter Wuille 8138cbea3c Add automatic script test generation, and actual checksig tests 2014-09-26 21:58:48 +02:00
Pieter Wuille c8589bf99e Add actual signature tests 2014-09-22 19:26:17 +02:00
Pieter Wuille 76ec867796 Use actually valid transactions for script tests 2014-09-22 19:26:17 +02:00
Luke Dashjr a65e320747 bitcoin-util-test: Test bitcoin-tx with null scriptPubKey 2014-09-14 06:28:22 +00:00
Pieter Wuille 6022b5dc6b Make script_{valid,invalid}.json validation flags configurable 2014-09-08 22:38:26 +02:00
Jeff Garzik df4d61e681 Add bitcoin-tx tests
Testing: delin, delout, locktime, and basic createrawtransaction-like
functionality.
2014-08-19 23:15:58 -04:00
Jeff Garzik fb14452c6c bitcoin-tx: Accept input via stdin. Add input handling to tests. 2014-08-19 10:29:10 -04:00
Jeff Garzik d789386371 Add "it works" test for bitcoin-tx 2014-08-19 10:28:58 -04:00