Commit Graph

230 Commits

Author SHA1 Message Date
Dave Collins
1a370d38d6
release: Tidy module files with published versions. 2018-12-12 12:18:11 -06:00
Dave Collins
220d434b6e
release: Bump module versions and deps.
This bumps the various module versions as follows:

- github.com/decred/dcrd/dcrec/secp256k1@v1.0.1
- github.com/decred/dcrd/dcrjson@v1.1.0
- github.com/decred/dcrd/database@v1.0.3
- github.com/decred/dcrd/blockchain/stake@v1.1.0
- github.com/decred/dcrd/mining@v1.1.0
- github.com/decred/dcrd/certgen@v1.0.2
- github.com/decred/dcrd/connmgr@v1.0.2
- github.com/decred/dcrd/mempool@v1.1.0

In addition, it serves as a base for tagging releases of the following
module versions that have previous been bumped since the last release,
but not yet tagged:

- github.com/decred/dcrd/wire@v1.2.0
- github.com/decred/dcrd/chaincfg@v1.2.0
- github.com/decred/dcrd/dcrutil@v1.2.0
- github.com/decred/dcrd/txscript@v1.0.2
- github.com/decred/dcrd/blockchain@v1.1.0
- github.com/decred/dcrd/hdkeychain@v1.1.1
- github.com/decred/dcrd/peer@v1.1.0
- github.com/decred/dcrd/rpcclient@v1.1.0

Finally, it updates all of the dependencies for every module accordingly,
adds a few missing overrides for transitive dependencies, and tidies up
some of the go module sum files.
2018-12-10 11:18:00 -06:00
David Hill
617fca8a93 txscript: Use ScriptBuilder more. 2018-12-04 01:11:20 -06:00
David Hill
5f8081761d multi: Remove unused code. 2018-10-31 21:50:09 -04:00
Dave Collins
6f9b6f1c6e
multi: Use regression test network in unit tests.
This modifies the majority of the tests that make use of chain
parameters and the RPC tests to use the resurrected regression test
network.

It also bumps the affected module versions as follows:

- github.com/decred/dcrd/txscript@v1.0.2
- github.com/decred/dcrd/blockchain/stake@v1.0.3
- github.com/decred/dcrd/mempool@v1.0.2

The blockchain and dcrutil modules are also affected, but since their
version has already been bumped since their last release tags, they are
not bumped again.
2018-10-09 19:40:10 -05:00
Donald Adu-Poku
60cbb70c67 txscript: add stake opcode tests. 2018-09-11 20:21:42 +00:00
Donald Adu-Poku
e0222e383c txscript: add p2sh opcode tests. 2018-09-11 20:14:29 +00:00
Donald Adu-Poku
566bb6625b txscript: group numeric encoding tests with their opcodes.
This also moves some dangling tests to their respective opcode groupings as well as some updates to  test comments.
2018-09-10 17:48:02 -05:00
Dave Collins
36f61d8ebd build: Tidy module sums (go mod tidy). 2018-08-16 20:03:27 -05:00
Dave Collins
9536f0c88f
release: Bump module versions and deps.
This bumps the various module versions as follows:

- github.com/decred/dcrd/addrmgr@v1.0.2
- github.com/decred/dcrd/wire@v1.1.0
- github.com/decred/dcrd/chaincfg@v1.1.1
- github.com/decred/dcrd/connmgr@v1.0.1
- github.com/decred/dcrd/dcrutil@v1.1.1
- github.com/decred/dcrd/database@v1.0.1
- github.com/decred/dcrd/hdkeychain@v1.1.0
- github.com/decred/dcrd/txscript@v1.0.1
- github.com/decred/dcrd/blockchain/stake@v1.0.1
- github.com/decred/dcrd/gcs@v1.0.1
- github.com/decred/dcrd/blockchain@v1.0.1
- github.com/decred/dcrd/mining@v1.0.1
- github.com/decred/dcrd/mempool@v1.0.1
- github.com/decred/dcrd/peer@v1.0.1
- github.com/decred/dcrd/rpcclient@v1.0.1

It also updates all of the dependencies for every module accordingly and
adds a few missing overrides for transitive dependencies.
2018-08-09 14:30:22 -05:00
Dave Collins
96a1a8546d
multi: Reduce testnet2 refs in unit tests.
This modifies the test code for several unit tests to prefer using
another network, such as mainnet or simnet, when not specifically
testing something that requires testnet.

In the cases where where testnet is required, it also now prefers a
local reference over directly accessing the testnet parameters directly
from the chaincfg package.

This is being done because the test network undergoes periodic resets
and by reducing the number of direct references, it simplifies the
process of resetting it.
2018-08-08 06:41:50 -05:00
Dave Collins
295179fc0d
build: Refine build module support.
This further refines the modules to add the following new modules
instead of depending on the entire dcrd module:

- github.com/decred/dcrd/dcrjson@v1.0.0
- github.com/decred/dcrd/blockchain@v1.0.0
- github.com/decred/dcrd/blockchain/stake@v1.0.0
- github.com/decred/dcrd/gcs@v1.0.0
- github.com/decred/dcrd/mining@v1.0.0
- github.com/decred/dcrd/mempool@v1.0.0
- github.com/decred/dcrd/peer@v1.0.0
- github.com/decred/dcrd/rpcclient@v1.0.0

Also, it ensures modules that rely on other modules within the repo are
provided replacements to the latest repo code to ensure builds against
master and continuous integration use the latest code.

- github.com/decred/dcrd/addrmgr
- github.com/decred/dcrd/blockchain
- github.com/decred/dcrd/blockchain/stake
- github.com/decred/dcrd/chaincfg
- github.com/decred/dcrd/connmgr
- github.com/decred/dcrd/database
- github.com/decred/dcrd/dcrec/secp256k1
- github.com/decred/dcrd/dcrjson
- github.com/decred/dcrd/dcrutil
- github.com/decred/dcrd/gcs
- github.com/decred/dcrd/hdkeychain
- github.com/decred/dcrd/mempool
- github.com/decred/dcrd/mining
- github.com/decred/dcrd/peer
- github.com/decred/dcrd/rpcclient
- github.com/decred/dcrd/txscript
- github.com/decred/dcrd/wire
2018-08-05 20:45:45 -05:00
Donald Adu-Poku
3978c40b50 txscript: add/group crypto related op code tests. 2018-07-29 23:06:54 -05:00
Donald Adu-Poku
4fcdfab3c2 txscript: group reserved op code tests.
this groups reserved op codes and moves some dangling tests to their respective groups.
2018-07-29 22:46:55 -05:00
Donald Adu-Poku
1ce290d979 txscript: add/group numeric related opcode tests. 2018-07-29 21:10:59 -05:00
Donald Adu-Poku
315e0a9acd txscript: add/group bitwise logic, comparison & rotation op code tests. 2018-07-27 21:24:28 +00:00
Donald Adu-Poku
245c82557c txscript: group splice opcode tests. 2018-07-26 16:30:02 -05:00
Donald Adu-Poku
34a33e1e57 txscript: add/group stack op code tests. 2018-07-25 23:28:45 -05:00
Donald Adu-Poku
59cc2a447e txscript: add/group control op code tests. 2018-07-24 23:02:25 -05:00
Donald Adu-Poku
fb18a45553 txscript: add additional data push op code tests.
This adds tests for OP_DATA_[1...75], OP_1NEGATE, OP_RESERVED, OP_TRUE, OP_[1...16], OP_PUSHDATA1 and OP_PUSHDATA2.
2018-07-23 20:49:48 -05:00
Dave Collins
4a3343f2f1
txscript: Refine go build module support.
Now that the chaincfg, chainhash, dcrec, edwards, secp256k1, dcrutil,
wire, and slog modules have been defined, update the txscript module to
only depend on them instead of the entire dcrd module.
2018-07-21 14:40:32 -05:00
Dave Collins
d052898731
txscript: Update comments for removal of flags.
This updates various comments to accurately reflect reality now that
several script verification flags have been removed.
2018-07-06 11:56:47 -05:00
Dave Collins
d3199d2aa9
multi: Remove unused secp256k1 sig parse parameter.
This removes the unused curve parameter from the ParseSignature and
ParseDERSignature functions of the secp256k1 package and updates all
callers in the repository accordingly.
2018-07-04 12:27:34 -05:00
David Hill
01316e20f3 multi: Continue conversion from chainec to dcrec. 2018-07-04 11:21:43 -04:00
Dave Collins
370d0daba5
txscript: Make PeekInt consistent with PopInt.
This modifies the PeekInt function of the stack to accept a maximum
script number length to mirror PopInt for consistency.  It also updates
the two callers CLTV and CSV) which were manually performing the same
task with 5 bytes due to PeekInt enforcing 4-byte script nums to use the
modified version accordingly.

It also adds some stack tests for 5-byte encodings on both PopInt and
PeekInt.
2018-07-02 12:14:37 -05:00
Dave Collins
84b65d049b
txscript: Remove script num require minimal flag.
This removes the flag to require minimal encoding when create script
numbers since since all callers now call the function with true due to
the recent removal of the minimal data script verification flag from the
script engine and updates the tests accordingly.
2018-07-02 12:14:15 -05:00
Dave Collins
535e4adb04
txscript: Remove MINIMALDATA flag from test data.
This removes the MINIMALDATA script verify flag from the various
reference test data since it is now a noop due to the corresponding flag
being removed from the script engine.
2018-07-02 12:04:30 -05:00
Dave Collins
f5dc86e9cc
txscript: Remove verify minimal data flag.
This removes the ScriptVerifyMinimalData flag from the txscript package,
changes the default semantics to always enforce its behavior, and
updates all callers in the repository accordingly.

This change is being made to simplify the script engine code since the
flag has always been active and required by consensus in Decred, so
there is no need to require a flag to conditionally toggle it.

It should be noted that the tests removed from script_tests.json
specifically dealt with ensuring equivalency of different ways to encode
the same numbers when the ScriptVerifyMinimalData flag is not set.
Therefore, they are no longer necessary.

A few tests which dealt with equivalency that did not already have
expected failing counterparts were converted to expected failure.

Also, several of the tests which dealt with ensuring the specific
encoding of numeric opcodes is being used have been converted to use
hashes since the minimal data requirements specifically prevent
alternate ways of pushing the same encoding which is necessary for
directly checking equality of the raw bytes.

Finally, the MINIMALDATA indicator to enable the flag in the test data
has been retained for now in order to isolate the logic changes as much
as possible.
2018-07-02 12:02:59 -05:00
Dave Collins
a8e9a63684
txscript: Remove DERSIG flag from test data.
This removes the DERSIG script verify flag from the various reference
test data since it is now a noop due to the corresponding flag being
removed from the script engine.
2018-07-02 12:02:41 -05:00
Dave Collins
98e0b27dd8
txscript: Remove DER signature verification flag.
This removes the ScriptVerifyDERSignatures flag from the txscript
package, changes the default semantics to always enforce its behavior
and updates all callers in the repository accordingly.

This change is being made to simplify the script engine code since the
flag has always been active and required by consensus in Decred, so
there is no need to require a flag to conditionally toggle it.

It should be noted that the tests removed from script_tests.json
specifically dealt with ensuring non-DER-compliant signatures were
handled properly when the ScriptVerifyDERSignatures flag was not set.
Therefore, they are no longer necessary.

Finally, the DERSIG indicator to enable the flag in the test data has
been retained for now in order to keep the logic changes separate.
2018-07-02 12:02:28 -05:00
Dave Collins
d12e172fee
txscript: Remove P2SH flag from test data.
This removes the P2SH script verify flag from the various reference test
data since it is now a noop due to the corresponding flag being removed
from the script engine.
2018-07-02 12:02:14 -05:00
Dave Collins
2157079165
txscript: Remove pay-to-script-hash flag.
This removes the ScriptBip16 flag from the txscript package, changes the
default semantics to always enforce its behavior, and updates all
callers in the repository accordingly.

This change is being made to simplify the script engine code since the
flag has always been active and required by consensus in Decred, so there is
no need to require a flag to conditionally toggle it.

Also, since it is no longer possible to invoke the script engine without
the flag with the clean stack flag, it removes the now unused
ErrInvalidFlags error and associated tests.

It should be noted that the test removed from script_tests.json
specifically dealt with ensuring a signature script that contained
non-data-pushing opcodes was successful when neither the ScriptBip16 or
ScriptVerifySigPushOnly flags were set.  Therefore, it is no longer
necessary.

Finally, the P2SH indicator to enable the flag in the test data has been
retained for now in order to keep the logic changes separate.
2018-07-02 12:01:42 -05:00
Dave Collins
c0be0be19a
txscript: Convert reference tests to new format.
This updates the data driven transaction script tests to combine the
previously separate valid and invalid test data files into a single file
and adds a field for the expected result.  This is a nice improvement
since it means tests can now ensure script failures are due to a
specific expected reason as opposed to only generically detecting
failure as the previous format required.

Since it is possible that the script engine might return more fine
grained errors than that test data expects, the test adapter handles
this by allowing expected errors in the test data to be mapped to
multiple txscript errors.

While performing the conversion, it also adds several tests for the
following areas:

- The test harness itself to ensure the parsing logic, particularly for
  the recently added repetition syntax, is working as intended
- All of the opcodes which were converted to NOPs in Decred
  to ensure they are also discouraged from use
- All of the reserved opcodes in Decred
2018-07-02 11:59:13 -05:00
Dave Collins
d8306ee602
txscript: Significantly improve errors.
This converts the majority of script errors from generic errors created
via errors.New and fmt.Errorf to use a concrete type that implements the
error interface with an error code and description.

This allows callers to programmatically detect the type of error via
type assertions and an error code while still allowing the errors to
provide more context.

For example, instead of just having an error the reads "disabled opcode"
as would happen prior to these changes when a disabled opcode is
encountered, the error will now read "attempt to execute disabled opcode
OP_FOO".

While it was previously possible to programmatically detect many errors
due to them being exported, they provided no additional context and
there were also various instances that were just returning errors
created on the spot which callers could not reliably detect without
resorting to looking at the actual error message, which is nearly always
bad practice.

Also, while here, export the MaxStackSize and MaxScriptSize constants
since they can be useful for consumers of the package and perform some
minor cleanup of some of the tests.
2018-07-01 15:04:59 -05:00
Dave Collins
dd0bfb639c
txscript: Cleanup P2SH and stake opcode handling.
This slightly cleans up the handling for pay-to-script-hash scripts and
related stake opcode checking as follows:

- Move the isScriptHash and isAnyKindOfScriptHash functions to script.go
  since they are required by consensus and therefore do not belong in
  standard.go which is reserved for standardness only rules
- Introduce a new function named isStakeOpcode and use it throughout
  versus repeating the specific logic in multiple places
- Use the stake opcode constants instead of magic numbers in the
  aforementioned new function
- Introduce a new function named isStakeScriptHash which specifically
  determines if a script is of the special stake p2sh form
- Update isAnyKindOfScriptHash to make use of the original isScriptHash
  function instead of repeating the logic and the newly introduced
  isStakeScriptHash function
2018-07-01 14:58:16 -05:00
Dave Collins
d70581c8f0
txscript: Cleanup plus tests for checksig opcodes.
This cleans up the code for handling the checksig and checkmultisig
opcodes to explicitly call out any semantics that are likely not
obvious, correct some comments, and improve readability.

It also adds several tests to the reference script tests which exercise
the semantics of the check[multi]sig opcodes including both positive and
negative tests.

Finally, it corrects nearly all of the negative tests related to
signature checking of the script tests which were not properly updated
for the differences introduced by Decred so that they fail for the
intended reasons.

The malformed signatures in the tests were very carefully crafted to be
valid except for the very specific condition being tested.  The majority
of the negative tests modified and added can be manually verified by
commenting out the relevant checks in the script engine, although a few
of them will pass because they fail for other reasons.  In those cases,
prints can be added to ensure the expected failure path is being hit.
2018-06-29 11:15:24 -05:00
Dave Collins
d3731898e9
txscript: Remove STRICTENC flag from test data.
This removes the STRICTENC script verify flag from the various test data
since it is now a noop due to the corresponding flag being removed from
the script engine.
2018-06-22 00:30:02 -05:00
Dave Collins
c9ca59bf66
txscript: Remove strict encoding verification flag.
This removes the ScriptVerifyStrictEncoding flag from the txscript
package, changes the default semantics to always enforce its behavior
and updates all callers in the repository accordingly.

This change is being made to simplify the script engine code since the
flag has always been active and required by consensus in Decred, so
there is no need to require a flag to conditionally toggle it.

It should be noted that the tests removed from script_valid.json
specifically dealt with ensuring signatures not compliant with DER
encoding did not cause execution to halt early on invalid signatures
when neither of the ScriptVerifyStrictEncoding or
ScriptVerifyDERSignatures flags were set.  Therefore, they are no longer
necessary.

For nearly the same reason, the tx test related to the empty pubkey
tx_valid.json was moved to tx_invalid.json.  In particular, an empty
pubkey without ScriptVerifyStrictEncoding simply failed the signature
check and continued execution, while the same condition with the flag
halts execution.  Thus, without the flag the final NOT in the script
would allow the script to succeed, while it does not under the strict
encoding rules.

Finally, the STRICTENC indicator to enable the flag in the test data has
been retained for now in order to keep the logic changes separate.
2018-06-22 00:29:46 -05:00
Dave Collins
3aa1930845
txscript: Remove unused old sig hash type.
This removes the SigHashOld definition from the txscript package since
it both has never been used in Decred and it has also always been
invalid to use due to the fact that strict encoding has always been
active and required by consensus in Decred.
2018-06-22 00:29:33 -05:00
Dave Collins
7815f0c851
txscript: Remove low S verification flag.
This removes the ScriptVerifyLowS flag from the txscript package,
changes the default semantics to always enforce its behavior and updates
all callers in the repository accordingly.

This change is being made to simplify the script engine code since the
flag has always been active and required by consensus in Decred, so
there is no need to require a flag to conditionally toggle it.
2018-06-22 00:28:54 -05:00
Donald Adu-Poku
b105a9ef49 multi: add valueIn parameter to wire.NewTxIn.
This adds the valueIn parameter to wire.NewTxIn. Call sites and associated tests have also been updated.
2018-06-15 19:13:41 -05:00
Dave Collins
39be89d2eb
txscript: Improve and correct some script tests.
This corrects some of the script tests which were not properly updated
for the differences introduced by Decred as well as adds some additional
tests for some updated semantics.

Namely:

- Correct the redeem script hash of several tests so they fail for the
  intended reason instead of due to having an invalid script hash
- Correct multisig tests to remove the dummy parameter which is not
  needed by Decred
- Change the tests for previously reserved opcodes to discouraged
  upgradable NOP tests to match their new semantics
- Add tests to ensure all discourage NOPs are allowed when in an
  unexecuted branch
- Add tests to ensure all reserved opcodes that are not always illegal
  are allowed when in an unexecuted branch
2018-06-15 13:18:14 -05:00
Dave Collins
3608e8ab74
txscript: Allow multi opcode test data repeat.
This expands upon the recently added ability to specify repeated
raw and quoted data in the test data short script form syntax to also
add syntax to allow repeated sequences of opcodes and updates several
tests to make use of it.

While here, it also corrects a few tests to actually test what they were
originally intended to test but were not updated correctly for Decred
limit changes.  In particular, the following tests were corrected:

- The negative test that ensures exceeding the max opcode limit via
  CHECKMULTISIG and CHECKMULTISIGVERIFY results in failure
- The positive test that ensures hitting the max opcode limit via
  CHECKMULTISIG and CHECKMULTISIGVERIFY with and without keys succeeds
2018-06-15 12:11:02 -05:00
Dave Collins
9e23c8e8ea
txscript: Introduce repeated syntax to test data.
This improves the test data short script form syntax to allow repeated
raw and quoted data and updates several tests to make use of it.

While here, it also corrects a few tests to actually test what they were
originally intended to test but were not updated correctly for Decred
limit changes.  In particular, the following tests were corrected:

- The negative test that ensures to exceeding the maximum allowed script
  size results in failure
- The positive test that ensures a fully maxed out script (max script
  size, max element size push, max opcodes, and max stack items)
  succeeds
- The positive test that ensures OP_RESERVED does not count towards the
  opcode limit
2018-06-14 16:48:04 -05:00
Dave Collins
543ebff573
txscript: Update CSV to match tests in DCP0003. 2018-06-14 10:10:39 -05:00
Dave Collins
ca7eeee6af
txscript: Cleanup and add tests for mod opcode.
This cleans up the code for handling the mod opcode to explicitly call
out its semantics which are likely not otherwise obvious as well as
improve its readability.

It also adds several tests to the reference script tests which exercise
the semantics of the div opcode including both positive and negative
tests.
2018-06-13 16:53:40 -05:00
Dave Collins
1080a9709a
txscript: Cleanup and add tests for div opcode.
This cleans up the code for handling the div opcode to explicitly call
out its semantics which are likely not otherwise obvious as well as
improve its readability.

It also adds several tests to the reference script tests which exercise
the semantics of the div opcode including both positive and negative
tests.
2018-06-13 16:53:24 -05:00
Dave Collins
0ee1468f40
txscript: Cleanup and add tests for rshift opcode.
This cleans up the code for handling the right shift opcode to
explicitly call out its semantics which are likely not otherwise obvious
as well as improve its readability.

It also adds several tests to the reference script tests which exercise
the semantics of the right shift opcode including both positive and
negative tests.
2018-06-13 16:52:36 -05:00
Dave Collins
f8d8dbcd19
txscript: Cleanup and add tests for lshift opcode.
This cleans up the code for handling the left shift opcode to explicitly
call out its semantics which are likely not otherwise obvious as well as
improve its readability.

It also adds several tests to the reference script tests which exercise
the semantics of the left shift opcode including both positive and
negative tests.
2018-06-13 16:51:09 -05:00
Dave Collins
71f86bec32
txscript: Cleanup and add tests for rotl opcode.
This cleans up the code for handling the left rotation opcode to
explicitly call out its semantics which are likely not otherwise obvious
as well as improve its readability.

It also adds several tests to the reference script tests which exercise
the semantics of the left rotation opcode including both positive and
negative tests.
2018-06-13 16:39:44 -05:00