Commit Graph

396 Commits

Author SHA1 Message Date
Dave Collins
7f1da3bc07
txscript: Deprecate GetMultisigMandN.
This deprecates the GetMultisigMandN function which should never have
been added since the CalcMultiSigStats function already existed for this
purpose.

While here, redefine the function in terms of CalcMultiSigStats.
2019-03-26 14:50:53 -05:00
Dave Collins
b1b64d9228
txscript: Deprecate IsStakeOutput.
This function is only useful for internal consensus purposes within the
script engine and as such should not be exported.

While here, also add a comment to specify to the script version
semantics.
2019-03-26 14:50:53 -05:00
Dave Collins
60d41d1230
txscript: Deprecate HasP2SHScriptSigStakeOpCodes.
This function is only useful for internal consensus purposes within the
script engine and as such should not be exported.
2019-03-26 14:50:52 -05:00
VcTT
8695142d02 txscript: Add stake tx remove opcode tests.
txscript: Add stake tx remove opcode tests.
2019-03-26 14:49:15 -05:00
David Hill
3d2d557614 multi: deprecate DisableLog 2019-03-18 11:16:35 -05:00
David Hill
69bac3189f multi: drop init and just set default log 2019-03-18 11:16:35 -05:00
Dave Collins
0f50fd5f8c
multi: Add go 1.11 directive to all modules.
This adds the go 1.11 directive to all of the modules in order to
clearly mark they build and work with that version.  Go 1.12 modified
the tools such that tidy will automatically add the new version to
modules that do not already have a directive and that would prevent
builds on Go 1.11 through Go 1.11.3 which is not desirable.
2019-03-18 02:02:35 -05:00
Dave Collins
8c477528f1
txscript: Introduce constant for max CSV bytes.
As is already well commented in the code, the sequence number parameter
of the CHECKSEQUENCEVERIFY opcode requires 5 bytes instead of the
standard 4 bytes allowed by math opcodes.  This introduces a constant
for the value instead of hardcoding 5 to increase readability and
potentially allow the value to be exported in the future.
2019-03-12 10:26:04 -05:00
Dave Collins
b19842a4c4
txscript: Introduce constant for max CLTV bytes.
As is already well commented in the code, the locktime parameter of the
CHECKLOCKTIMEVERIFY opcode requires 5 bytes instead of the standard 4
bytes allowed by math opcodes.  This introduces a constant for the value
instead of hardcoding 5 to increase readability and potentially allow
the value to be exported in the future.
2019-03-12 10:13:06 -05:00
Dave Collins
a729ce27e0
txscript: Tighten standardness pubkey checks.
This tightens the multisig and pay-to-pubkey standard script
identification functions to use the same strict pubkey requirements as
the consensus rules since standardness rules are generally intended to
be more restrictive than the consensus rules which implies they are at a
minimum at least as restrictive.

The tests are also updated to deal with the additional restriction
accordingly.
2019-03-11 19:33:27 -05:00
Dave Collins
03c9bbf1e5
txscript: Consistent checksigaltverify handling.
This introduces a new error named ErrCheckSigAltVerify and modifies the
opcodeCheckSigAltVerify handler to use the abstractVerify function along
with the new error.  This makes the handling consistent with all other
signature checking verification opcode handlers and ensures the error
both can be programmatically detected as well as be uniquely identified
as compared to a generic verify failure.
2019-03-08 20:36:04 -06:00
Dave Collins
c0124570cd
txscript: Rename p2sh indicator to isP2SH.
This renames the flag that indicates whether or not the script engine is
executing a pay-to-script-hash script pair to a name that more
accurately describes its behavior.
2019-02-14 16:35:30 -06:00
Dave Collins
1f5abadc08
txscript: Add remove signature reference test.
An important (and easy for implementations to miss) aspect of the
CHECKSIG opcodes is that the full signature (signature plus hash type)
that is being checked is first removed from the script prior to
calculating the signature hash against which the signature is verified.

It appears the test in the upstream btcsuite code for this was removed
during the initial Decred port instead of being converted as it should
have been.

Consequently, this converts the relevant test so it is correct for
Decred and adds it to the reference tests.  Note that the first of the
two added tests is to ensure the original signature is valid prior to
testing the actual removal condition.
2019-02-14 14:10:12 -06:00
David Hill
85443cafa9 multi: cleanup linter warnings 2019-02-13 08:38:25 -05:00
Dave Collins
e052b9cbf2
multi: Remove non-root module replacements.
This modifies all of the modules, with the exception of the root module,
to remove all replacement directives from their go.mod files and update
the requirements and module sums accordingly.

While it is nice to be able to build and test directly from each module
directory and have it pull in the latest untagged changes when
developing, having all of the overrides in each module makes it
infeasible to use the module tools to help maintain the modules and thus
makes it quite difficult to ensure they are all independently accurate
for external consumers.

By maintaining all of the overrides in the root module and invoking all
builds and tests from it, the overrides will apply to ensure the latest
code is being built and tested.

This also modifies the tests script used with in CI to run all of the
tests from the root module accordingly.
2019-02-08 18:01:43 -06:00
David Hill
b1bbf8091b txscript: code cleanup
- switch if-else to switch/case for readability
- remove unused params
2019-02-08 09:18:53 -05:00
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
Dave Collins
9644ec433e
txscript: Cleanup and add tests for rotr opcode.
This cleans up the code for handling the right 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 right rotation opcode including both positive and
negative tests.
2018-06-13 16:30:38 -05:00
Dave Collins
e84ee743d2
txscript: Cleanup and add tests for the cat opcode.
This cleans up the code for handling the cat opcode to more closely
match the style used by the rest of the code and improves its test
coverage by adding several tests to the reference script tests which
exercise its semantics including both positive and negative tests.
2018-06-12 12:43:30 -05:00
Dave Collins
549aae93ce
txscript: Cleanup and add tests for right opcode.
This cleans up the code for handling the right 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 opcode including both positive and negative
tests.
2018-06-12 12:42:49 -05:00
Dave Collins
dc7849061c
txscript: Cleanup and add tests for left opcode.
This cleans up the code for handling the left 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 opcode including both positive and negative
tests.
2018-06-12 00:22:14 -05:00
Donald Adu-Poku
900e5964db txscript: export canonicalDataSize.
This is needed in determining signed input
script sizes of multisig outputs.
2018-06-06 18:26:24 +00:00
Dave Collins
c476afa931
txscript: Cleanup code for the substr opcode.
This cleans up the code for handling the substr opcode to explicitly
call out its semantics which are likely not otherwise obvious as well as
improve its readability.
2018-05-25 20:28:57 -05:00
Dave Collins
45e313e6d2
multi: Define vgo modules.
This adds module support for the versioned go toolchain.  In particular,
the following packages are defined as modules:

* addrmgr
* blockchain
* certgen
* chaincfg
* connmgr
* database
* dcrjson
* dcrutil
* gcs
* hdkeychain
* mempool
* mining
* peer
* rpcclient
* txscript
* wire

It does not update the travis build environment or README since it is
experimental at this point.
2018-05-25 15:38:16 -05:00
Dave Collins
678ff1efdd
multi: Replace btclog with slog.
This modifies all packages within the repository to the use the Decred
fork of btclog which has been renamed to slog and updates the dependency
files accordingly.
2018-05-23 14:22:10 -05:00
Dave Collins
3a81a21ec9
txscript: Improve substr opcode test coverage.
This adds several tests to the reference script tests which exercise the
semantics of the substr opcode including both positive and negative
tests.
2018-05-15 03:38:18 -05:00
Dave Collins
f54fb6ce67
txscript: Remove unused strict multisig flag.
This removes the ScriptStrictMultiSig flag from the txscript package
since it is not used or needed by Decred.

The flag is a holdover from the upstream code which was used to address
a bug that does not exist in Decred.
2018-05-15 02:34:22 -05:00
Dave Collins
66f5acc9aa
multi: Correct typos found by misspell. 2018-05-08 21:29:33 -05:00
Dave Collins
75432b3c96
multi: Break coinbase dep on standardness rules.
Standardness rules are not the same as consensus rules and it is
important to keep clear separation between them, because standardness
rules can and do change, while the consensus rules must not change
without a specific vote, and even then, the old rules must be kept
around for validation of all blocks prior to any changes introduced by a
successful vote.

Prior to this commit, the blockchain code which enforces the consensus
rule that requires the second output of the coinbase transaction to
contain the height of the block in a provably pruneable nulldata script
push was relying on code in txscript/standard.go, which, as the name of
the file suggests, is specifically intended for code related to
standardness checks.

This introduces a new function in the txscript package named
ExtractCoinbaseNullData which does not rely on any of the code related
to standardness checks and modifies the blockchain code accordingly to
make use of the new function instead.  It also removes the
standardness-dependent GetNullDataContent function which is no longer
used by anything.

Finally, it adds tests in the txscript package to ensure the new
function has the required semantics.
2018-05-08 12:49:40 -05:00
Dave Collins
5717411882
txscript: Decouple and optimize sighash calc.
This modifies the signature hash calculation logic to completely
decouple it from the wire transaction serialization and significantly
optimizes it in the process.  It also significantly improves the
comments to specifically call out the semantics.

This change is highly desirable because it has several beneficial
properties:

- The signature hash semantics are much clearer and specific
- There is no longer a need to copy the entire transaction and modify
  the relevant portions since the necessary substitutions are made on
  the fly
- Allows much faster calculation by serializing directly into byte
  slices and avoiding all of the additional error handling logic
  dedicated to handling network streams
- Provides the possibility of changing the wire format without breaking
  signature hash calculation
  - Note that the caching portion still relies on the wire format, but
    that can be addressed in future commits since it is merely an
    optimization that can also be decoupled

The following is a before and after comparison of signature hash
calculation for both speed and memory allocations for a transaction with
many inputs:

benchmark                old ns/op     new ns/op     delta
------------------------------------------------------------
BenchmarkCalcSigHash     6299714       1551740       -75.37%

benchmark                old allocs    new allocs    delta
------------------------------------------------------------
BenchmarkCalcSigHash     18601         1691          -90.91%
2018-05-01 08:51:41 -05:00
Dave Collins
b51a3bb396
txscript: Add benchmark for sighash calculation. 2018-05-01 08:51:38 -05:00
Dave Collins
a068101639
txscript: Correct JSON-based signature hash tests.
This updates the recently-added JSON-based signature hash test data to
actually test the SigHashAnyOneCanPay flag in the non-fuzzer
transactions as intended.

The flag is 0x80, but the JSON test data specifies the signature hash
type in decimal, so SigHashAll|SigHashAnyOneCanPay, which is 0x81,
should've been specified as 129 decimal instead of 81 decimal.  The same
applies to all combinations with the SigHashAnyOneCanPay flag.
2018-04-30 18:18:18 -05:00
Dave Collins
47cbc26b93
txscript: Add JSON-based signature hash tests.
This adds a significant number of JSON-based tests with various
transactions, scripts, and hash types, to ensure the signature hash
calculated generates the expected hash in each case.

It specifically tests some specialized transactions such as coinbase,
ticket purchase, vote, and revocation.  It also includes carefully
created tests for all combinations of defined hash types along with
triggering an error due to improper use of SigHashSingle.

Finally, it also includes fuzz testing by providing a selection of 100
regular transactions with various numbers of inputs and outputs along
with randomly generated (including undefined) signature hash types and
input indexes.  Due to the way that masking of the signature hash type
works, a couple of the fuzzer tests also hit the improper use of
SigHashSingle.

The test data was generated as JSON in order to make it easier for
developers of software in other languages and platforms that need to
deal with generating signature hashes to consume and prove correctness
of their implementation as well.
2018-04-30 12:14:14 -05:00
Dave Collins
2cb2d9a22a
txscript: Consolidate tests into txscript package.
Putting the test code in the same package makes it easier for forks
since they don't have to change the import paths as much and it also
gets rid of the need for internal_test.go to bridge.

Also, do some light cleanup on a few tests while here.
2018-04-30 10:34:59 -05:00
Dave Collins
6fe33fc277
txscript: Remove SigHashAllValue.
This removes the SigHashAllValue signature hash type.  This is being
done because it is not currently usable without a consensus change due
to a consensus rule which enforces strict signature encoding disallowing
the hash type.

While it would be possible to change the consensus rule in question to
include SigHashAllValue, that would obviously require a consensus vote
since it constitutes a change to the consensus rules.  Given that a vote
is required to make any changes in regards to this, it is ideal to
completely change the algorithm altogether to not only address this
issue, but also to address other shortcomings in regards to efficiency
and complexity of the current algorithm in addition to committing to all
input amounts per the aforementioned description.
2018-04-30 09:10:02 -05:00
Dave Collins
f6be618a1b
txscript: Move sig hash logic to separate file.
This moves the logic to calculate the signature hash and the associated
test to separate files.  Since there will ultimately be a new signature
algorithm, it makes sense to separate all logic related to signature
hashes for better code organization.

It contains no functional changes.
2018-04-30 08:54:07 -05:00
Josh Rickmar
e944badc9b chainec/dcrec: Remove hybrid pubkey support
This is a follow-up to a previous change which removed the ability to
create a dcrutil.Address from a hybrid pubkey.  It removes all
secp256k1 hybrid pubkey support from the chainec/dcrec packages since
these pubkeys are not usable when evaluated by OP_CHECKSIG or
OP_CHECKMULTISIG.

While ParsePubKey is called by consensus code and its behavior has
been changed to error when encountering a hybrid secp256k1 pubkey,
this is not a consensus change as every use of ParsePubKey in
consensus code either checks beforehand that the pubkey is compressed
or uncompressed, requires a parsed address to be P2PKH or P2SH, or
checks an address string against the premine ledger (which only
contains P2PKH addresses).
2018-03-20 17:45:09 -04:00
Markus Richter
1e42b8524d multi: Properly capitalize Decred.
Decred is inconsistencly capitalized in the code base,
change all occurences of decred to Decred.
2018-03-01 17:41:35 -06:00
David Hill
5fc31ca578 multi: fix misspell linter warnings 2018-02-18 12:26:52 -06:00
Josh Rickmar
5eb3296508 Require atomic swap contracts to specify the secret size.
This allows redeeming parties to audit the secret size and ensure it
will be usable once revealed.
2018-02-16 15:14:27 -06:00
David Hill
393a95c079 multi: fix some maligned linter warnings 2018-02-13 14:50:33 -06:00
David Hill
e45c34fbfc multi: release the mutex earlier 2018-02-13 13:55:02 -06:00
David Hill
dce7e3f161 multi: various cleanups 2018-02-02 14:18:41 -06:00
Donald Adu-Poku
e5828813c0 txscript: Remove OP_SMALLDATA 2017-12-29 19:57:26 +00:00
Donald Adu-Poku
29aa087e97 txscript: enforce MaxDataCarrierSize for GenerateProvablyPruneableOut 2017-12-23 01:36:12 +00:00
Donald Adu-Poku
106f979fa7 txscript: Cleanup and improve NullDataScript tests.
This modifies the recently-added NullDataScript function in several
ways in an effort to make them more consistent with the tests in the
rest of the code base and improve/correct the logic:

- Use the hexToBytes and mustParseShortForm functions
- Consistently format the test errors
- Replace the valid bool flag with an expected error and test against it
- Ensure the returned script type is the expected type in all cases
2017-12-22 00:58:54 +00:00
Dave Collins
1ca1017813
txscript: Allow external signature hash calc.
This modifies the exported CalcSignatureHash function to accept a script
as bytes instead of an array of parsed opcodes which are not available
to callers outside of the package.

While here, it also adds a proper comment for the exported function
since it is intended for more than testing as the previous comment
claimed.

Finally, it updates the tests to use a valid script instead of the
previous impossible to achieve constructed series of parsed opcodes.
2017-12-21 14:28:22 -06:00
David Hill
fc31a0b39e multi: remove unused funcs and vars 2017-12-07 21:46:25 -06:00
David Hill
b13f5dfbda travis: add ineffassign linter 2017-12-01 09:14:04 -05:00
Donald Adu-Poku
2d0d42401c txscript: Correct nulldata standardness check. 2017-12-01 01:24:17 +00:00
Josh Rickmar
238bef1c80 txscript: Require SHA256 secret hashes for atomic swaps 2017-11-28 10:03:42 -05:00
David Hill
20686cd775 travis: add gosimple linter 2017-11-20 18:49:55 -06:00
Josh Rickmar
6842aa006d Merge remaining dcrutil code into a dcrd package.
This merge commit adds the following code from the
github.com/decred/dcrutil package into a new
github.com/decred/dcrd/dcrutil package:

* Address handling
* Amount type
* AppDataDir func
* bitflags functions
* Block wrapper type
* Hash160 func
* Tx wrapper type
* WIF type

as well as all tests for this code.

The old github.com/decred/dcrutil/hdkeychain package has also been
merged and moved to github.com/decred/dcrd/dcrutil/hdkeychain.

dcrd packages have been updated to use the new packages and the dep
files have been updated for this change.
2017-10-11 22:06:36 -04:00
Dave Collins
ee5b56ba72
txscript: Implement CheckSequenceVerify
This modifies the script engine to replace OP_NOP3 with
OP_CHECKSEQUENCEVERIFY and adds a flag to selectively enable its
enforcement.

The new opcode examines the top item on the stack and compares it
against the sequence number of the associated transaction input in order
to allow scripts to conditionally enforce the inclusion of relative time
locks to the transaction.

The following is an overview of the changes:

- Introduce a new flag named ScriptVerifyCheckSequenceVerify to
  provide conditional enforcement of the new opcode
- Introduce a constant named OP_CHECKSEQUENCEVERIFY which has the same
  value as OP_NOP3 since it is replacing it
  - Update opcode to name mappings accordingly
- Abstract the logic that deals with time lock verification since it is
  the same for both the new opcode and OP_CHECKLOCKTIMEVERIFY
- Implement the required opcode semantics
- Add tests to ensure the opcode works as expected including when used
  both correctly and incorrectly
2017-09-21 15:58:48 -05:00
Dave Collins
bd78208c37
txscript: Revert upstream CSV merge.
This reverts the changes related to the CheckSequenceVerify opcode that
were merged from upstream since additional changes are needed and it's
much cleaner to implement all of code related to the sequence locks in
the same PR which will be referenced by the DCP as opposed to being
split up in multiple.
2017-09-21 11:17:58 -05:00
Josh Rickmar
5cb9a722a3 Add txscript API to parse atomic swap contracts. 2017-09-19 17:44:29 -04:00
Dave Collins
1955bb1bf1
multi: Abstract standard verification flags.
This modifies the way standard verification flags are handled so that it
is possible to selectively enable them based on the result of agenda
votes.

First, it moves the StandardVerifyFlags constant from the txscript
package to the mempool/policy code and rename it to
BaseStandardVerifyFlags.  As the TODO in the comment of the moved
constant indicated, these flags are policy related and thus really
belong in policy.  Ideally there would be a completely separate policy
package, but since the policy code currently lives in mempool/policy.go,
the constant has been moved there.

Next, it introduces a new function named standardScriptVerifyFlags,
which accepts the chain as an argument and, for now, just returns the
BaseStandardVerifyFlags along with a nil error.  This will allow
additional flags to be selectively enabled depending on the result of an
agenda vote.

Finally, it updates the mempool policy struct to require a closure for
obtaining the flags so it can remain decoupled from the chain which in
turn allows easier and more robust unit testing of mempool functionality
since it allows a mocks to be used.
2017-09-15 12:58:21 -05:00
Dave Collins
11ae59977a
txscript: Introduce OP_SHA256.
This modifies the script engine to replace OP_UNKNOWN192 with OP_SHA256
along with a flag named ScriptVerifySHA256 to selectively enable its
enforcement.

The new opcode consumes the top item from the data stack, computes its
SHA-256, and pushes the resulting digest back to the data stack.

Since it requires an item on the data stack, execution will terminate
with an error when the stack is empty.  This behavior differs from
OP_UNKNOWN192 which does not consume any elements from the data stack
and therefore makes this is hard-forking change when interpreted with
the new semantics due to the ScriptVerifySHA256 flag being set.  Code to
selectively enable the opcode based on the result of an agenda vote will
be added in a separate commit.

This also includes tests to ensure the opcode works as expected
including when used both correctly and incorrectly.
2017-09-14 11:33:48 -05:00
Dave Collins
7c3ff8279e
txscript: Rename OP_SHA256 to OP_BLAKE256.
Decred updated the semantics of this opcode to use blake256, but did not
rename the opcode to reflect that.  This renames the opcode so that it
is clear that a blake256 hash is produced instead of a sha256 hash.
2017-09-08 12:40:39 -05:00
Jean-Christophe Mincke
5115a422f0 multi: Error descriptions are in lower case.
Functions fmt.Error(), errors.New() are inspected.

Files under the dcrd/vendor directory are ignored.
2017-09-08 18:03:59 +02:00
Dave Collins
c47ee87673
txscript: Implement CheckSequenceVerify
Upstream commit a6bf1d9850.

The merge commit modifies all of the encoded transactions in the test
data to use Decred native format and contains some other minor
modifications necessary to integrate with Decred.
2017-08-28 12:23:34 -05:00
David Hill
64119dfabb txscript: remove unneeded API 2017-08-17 15:42:04 -04:00
Dave Collins
fce24223cd
multi: Separate tx serialization type from version.
Decred's serialized format for transactions split the 32-bit version
field into two 16-bit components such that the upper bits are used to
encode a serialization type and the lower 16 bits are the actual
transaction version.

Unfortunately, when this was done, the in-memory transaction struct was
not also updated to hide this complexity, which means that callers
currently have to understand and take special care when dealing with the
version field of the transaction.

Since the main purpose of the wire package is precisely to hide these
details, this remedies the situation by introducing a new field on the
in-memory transaction struct named SerType which houses the
serialization type and changes the Version field back to having the
desired semantics of actually being the real transaction version.  Also,
since the maximum version can only be a 16-bit value, the Version field
has been changed to a uint16 to properly reflect this.

The serialization and deserialization functions now deal with properly
converting to and from these fields to the actual serialized format as
intended.

Finally, these changes also include a fairly significant amount of
related code cleanup and optimization along with some bug fixes in order
to allow the transaction version to be bumped as intended.

The following is an overview of all changes:
- Introduce new SerType field to MsgTx to specify the serialization type
- Change MsgTx.Version to a uint16 to properly reflect its maximum
  allowed value
- Change the semantics of MsgTx.Version to be the actual transaction
  version as intended
- Update all callers that had special code to deal with the previous
  Version field semantics to use the new semantics
- Switch all of the code that deals with encoding and decoding the
  serialized version field to use more efficient masks and shifts
  instead of binary writes into buffers which cause allocations
- Correct several issues that would prevent producing expected
  serializations for transactions with actual transaction versions that
  are not 1
- Simplify the various serialize functions to use a single func which
  accepts the serialization type to reduce code duplication
- Make serialization type switch usage more consistent with the rest of
  the code base
- Update the utxoview and related code to use uint16s for the
  transaction version as well since it should not care about the
  serialization type due to using its own
- Make code more consistent in how it uses bytes.Buffer
- Clean up several of the comments regarding hashes and add some new
  comments to better describe the serialization types
2017-08-07 14:10:27 -05:00
Dave Collins
9a7132a56b
txscript: Cleanup reference test code.
This cleans up the reference test file to remove references to bitcoin
since it no longer applies to decred and remove a TODO that was recently
completed.
2017-08-04 03:05:42 -05:00
Dave Collins
fdb25c2f43
txscript: Use native encoding in json test data.
This modifies the valid and invalid JSON transaction test data to use
natively-encoded transactions instead of the legacy Bitcoin format.
2017-08-03 23:43:37 -05:00
Dave Collins
5baa16baa3
txscript: Update signatures in json test data.
This modifies the signatures of all the transactions in the invalid
transaction data which involve checking signatures to ensure that they
are not failing for the wrong reason.

In order to make it easier for future updates, it introduces three
well-known private keys, 1, 2, and 3, that are used for signing all of
the transactions and adds them to the comments in the test data.  The
first one is used for regular CHECKSIG while all three are used for
CHECKMULTISIG.
2017-08-03 23:43:00 -05:00
Dave Collins
3a243c6bc1
txscript: Remove max money from json test data.
This removes the tests related to max money checks since txscript does
not do sanity checking on the monetary amounts as that is done by the
consensus rules in blockchain.

While here, update dcrscript -> txscript in the comments to reflect
reality.

As an aside, the existing tests were invalid anyways since the
signatures were invalid and thus the tests were failing for the wrong
reason.
2017-08-03 22:31:22 -05:00
Dave Collins
6a0c530a46
txscript: Remove multisigdummy from json test data.
This removes the test for the original Bitcoin bug in CHECKMULTISIG that
required an additional argument since that has been fixed in Decred and
the test therefore no longer applies.

As an aside, the existing test was invalid anyways since the signature
was invalid and thus the test would've failed for the wrong reason.
2017-08-03 20:30:09 -05:00
Dave Collins
4acee5b61a
txscript: Replace CODESEPARATOR json test data.
This replaces the tests for CODESEPARATOR in the invalid transaction
JSON data to be correct for Decred.  It is always invalid to pass over
the CODESEPARATOR opcode in Decred as opposed to the Bitcoin behavior
where it changes what is hashed for the signature hash calculation.

As an aside, the previous tests were invalid anyways since they included
a signature that was invalid so the test would've failed for the wrong
reason.  For all of these tests it's important for them to pass other
than the specific failure condition they are intended to trigger.
2017-08-03 16:39:29 -05:00
Dave Collins
c11117aa77
txscript: Correct p2sh hashes in json test data.
This corrects the hashes for the p2sh scripts in the invalid transaction
JSON data.  This helps ensure the transactions are failing for the
intended reason as opposed to the p2sh script never being run because
the script hashes don't match.
2017-08-03 11:21:09 -05:00
Donald Adu-Poku
2c1e17b424 txscript: Force extracted addrs to compressed.
decred's consensus rules require address generation
to use a compressed pubkey format, this was hacked
into NewAddressSecpPubKey. This commit removes the
hack and provides NewAddressSecpPubKeyCompressed to
enforce the consensus prerequisite
2017-08-02 00:34:35 +00:00
Donald Adu-Poku
db727aeeb6 multi: Update DecodeAddress function signature 2017-07-21 23:41:24 -05:00
David Hill
a9234850e7 remove deadcode 2017-07-17 15:06:47 -05:00
Josh Rickmar
ce4b77d3d9 all: Remove seelog logger.
The btclog package has been changed to defining its own logging
interface (rather than seelog's) and provides a default implementation
for callers to use.

There are two primary advantages to the new logger implementation.

First, all log messages are created before the call returns.  Compared
to seelog, this prevents data races when mutable variables are logged.

Second, the new logger does not implement any kind of artifical rate
limiting (what seelog refers to as "adaptive logging").  Log messages
are outputted as soon as possible and the application will appear to
perform much better when watching standard output.

Because log rotation is not a feature of the btclog logging
implementation, it is handled by the main package by importing a file
rotation package that provides an io.Reader interface for creating
output to a rotating file output.  The rotator has been configured
with the same defaults that btcd previously used in the seelog config
(10MB file limits with maximum of 3 rolls) but now compresses newly
created roll files.  Due to the high compressibility of log text, the
compressed files typically reduce to around 15-30% of the original
10MB file.
2017-06-20 10:58:10 -04:00
John C. Vernaleo
e7b128a672 multi: Update markdown in README files to match change in github parser.
This borrows a lot from btcsuite/btcd 9918e2a56196fb6b1b2837a9e7fb84f3454098fd
2017-05-26 12:06:19 -04:00
David Hill
99d04eea40 Preallocate the exact number of bytes if known. 2017-03-20 21:46:33 -05:00
Dave Collins
8644a8c732
txscript: Update signing tests to use params var.
This updates the script signing test code to use a single chain params
variable instead of repeatedly referring to a specific network.  This
makes it much easier to change in the future such as future testnet
resets.
2017-03-16 19:46:03 -05:00
John C. Vernaleo
ef71103c95 Remove variables for testnet v1. 2017-03-16 20:19:07 -04:00
David Hill
caa57df468 travis: enable gometalinter (#603)
* Hook up gometalinter

* travis: enable unconvert

* travis: enable gosimple
2017-03-08 15:44:15 -05:00
John C. Vernaleo
72673d94d3 Switch to upstream golang.org/x/crypto (#608)
* Switch to upstream golang.org/x/crypto

* Update dcrutil to move to upstream crypto there too
2017-03-08 11:22:02 -05:00
Dave Collins
6cce15fe9e
txscript: Expose AddOps on ScriptBuilder.
Upstream commit cee207c64c.
2016-11-18 12:58:00 -06:00
Dave Collins
c162fbde71
multi: Upstream chainhash abstraction sync
Contains the following commits:

- 711f33450c
- b6b1e55d1e
  - Reverted because Travis is already at a more recent version
- bd4e64d1d4

Also, the merge commit contains the necessary decred-specific
alterations, converts all other references to sha to hash to keep with
the spirit of the merged commits, and various other cleanup intended to
bring the code bases more in line with one another.
2016-11-16 12:48:40 -06:00
David Hill
4494f0f852 txscript: Remove OP_SMALLDATA 2016-10-21 15:18:42 -04:00
Dave Collins
0731f2ddc9 txscript: Cleanup and improve NullDataScript tests.
This modifies the recently-added NullDataScript function in several
ways in an effort to make them more consistent with the tests in the
rest of the code base and improve/correct the logic:

- Use the hexToBytes and mustParseShortForm functions
- Consistently format the test errors
- Replace the valid bool flag with an expected error and test against it
- Ensure the returned script type is the expected type in all cases
2016-10-21 10:26:09 -05:00
DanielKrawisz
b77654f8d4 txscript: Add null data script creator
This adds a new function named NullDataScript to the txscript package that returns a provably-pruneable  OP_RETURN script with the provided data.  The function will return an error if the provided data is larger than the maximum allowed length for a nulldata script to be be considered standard.
2016-10-21 09:37:48 -05:00
Dave Collins
59a3fc2f66 txscript: Consolidate tests into txscript package.
Putting the test code in the same package makes it easier for forks
since they don't have to change the import paths as much and it also
gets rid of the need for internal_test.go to bridge.

Also, do some light cleanup on a few tests while here.
2016-10-20 09:28:33 -05:00
Dave Collins
b60e3547d2 txscript: Correct nulldata standardness check.
This corrects the isNullData standard transaction type test to work
properly with canonically-encoded data pushes.  In particular, single
byte data pushes that are small integers (0-16) are converted to the
equivalent numeric opcodes when canonically encoded and the code failed
to detect them properly.

It also adds several tests to ensure that both canonical and
non-canonical nulldata scripts are recognized properly and modifies the
test failure print to include the script that failed.

This does not affect consensus since it is just a standardness check.
2016-10-20 01:44:58 -05:00
David Hill
a6bf1d9850 txscript: Implement CheckSequenceVerify (BIP0112) 2016-10-19 12:06:44 -04:00
cjepson
c323abbc10 Merge in btcd '7f07fb1093dd80105d36d61c8fb8a16f6e9d9b29'
Merge in btcd commit 7f07fb1093.
2016-09-23 14:40:27 -04:00
cjepson
2889b79b0e Merge btcd commit '644570487f379e9856ae4025181ecc6293d86711'
Merges in btcd commit 644570487f.
2016-09-23 12:11:31 -04:00
cjepson
02bb5123d6 Merge in btcd commit '3b39edcaa1e867efc4223d95ca1496aaadf8eca3'
Merges in 3b39edcaa1 from btcd.
2016-09-22 15:52:37 -04:00
Dave Collins
b6d426241d blockchain: Rework to use new db interface.
This commit is the first stage of several that are planned to convert
the blockchain package into a concurrent safe package that will
ultimately allow support for multi-peer download and concurrent chain
processing.  The goal is to update btcd proper after each step so it can
take advantage of the enhancements as they are developed.

In addition to the aforementioned benefit, this staged approach has been
chosen since it is absolutely critical to maintain consensus.
Separating the changes into several stages makes it easier for reviewers
to logically follow what is happening and therefore helps prevent
consensus bugs.  Naturally there are significant automated tests to help
prevent consensus issues as well.

The main focus of this stage is to convert the blockchain package to use
the new database interface and implement the chain-related functionality
which it no longer handles.  It also aims to improve efficiency in
various areas by making use of the new database and chain capabilities.

The following is an overview of the chain changes:

- Update to use the new database interface
- Add chain-related functionality that the old database used to handle
  - Main chain structure and state
  - Transaction spend tracking
- Implement a new pruned unspent transaction output (utxo) set
  - Provides efficient direct access to the unspent transaction outputs
  - Uses a domain specific compression algorithm that understands the
    standard transaction scripts in order to significantly compress them
  - Removes reliance on the transaction index and paves the way toward
    eventually enabling block pruning
- Modify the New function to accept a Config struct instead of
  inidividual parameters
- Replace the old TxStore type with a new UtxoViewpoint type that makes
  use of the new pruned utxo set
- Convert code to treat the new UtxoViewpoint as a rolling view that is
  used between connects and disconnects to improve efficiency
- Make best chain state always set when the chain instance is created
  - Remove now unnecessary logic for dealing with unset best state
- Make all exported functions concurrent safe
  - Currently using a single chain state lock as it provides a straight
    forward and easy to review path forward however this can be improved
    with more fine grained locking
- Optimize various cases where full blocks were being loaded when only
  the header is needed to help reduce the I/O load
- Add the ability for callers to get a snapshot of the current best
  chain stats in a concurrent safe fashion
  - Does not block callers while new blocks are being processed
- Make error messages that reference transaction outputs consistently
  use <transaction hash>:<output index>
- Introduce a new AssertError type an convert internal consistency
  checks to use it
- Update tests and examples to reflect the changes
- Add a full suite of tests to ensure correct functionality of the new
  code

The following is an overview of the btcd changes:

- Update to use the new database and chain interfaces
- Temporarily remove all code related to the transaction index
- Temporarily remove all code related to the address index
- Convert all code that uses transaction stores to use the new utxo
  view
- Rework several calls that required the block manager for safe
  concurrency to use the chain package directly now that it is
  concurrent safe
- Change all calls to obtain the best hash to use the new best state
  snapshot capability from the chain package
- Remove workaround for limits on fetching height ranges since the new
  database interface no longer imposes them
- Correct the gettxout RPC handler to return the best chain hash as
  opposed the hash the txout was found in
- Optimize various RPC handlers:
  - Change several of the RPC handlers to use the new chain snapshot
    capability to avoid needlessly loading data
  - Update several handlers to use new functionality to avoid accessing
    the block manager so they are able to return the data without
    blocking when the server is busy processing blocks
  - Update non-verbose getblock to avoid deserialization and
    serialization overhead
  - Update getblockheader to request the block height directly from
    chain and only load the header
  - Update getdifficulty to use the new cached data from chain
  - Update getmininginfo to use the new cached data from chain
  - Update non-verbose getrawtransaction to avoid deserialization and
    serialization overhead
  - Update gettxout to use the new utxo store versus loading
    full transactions using the transaction index

The following is an overview of the utility changes:
- Update addblock to use the new database and chain interfaces
- Update findcheckpoint to use the new database and chain interfaces
- Remove the dropafter utility which is no longer supported

NOTE: The transaction index and address index will be reimplemented in
another commit.
2016-08-18 15:42:18 -04:00
Dave Collins
cee207c64c txscript: Expose AddOps on ScriptBuilder. (#734)
This exposes a new function on the ScriptBuilder type named AddOps that
allows multiple opcodes to be added via a single call and adds tests to
exercise the new function.

Finally, it updates a couple of places in the signing code that were
abusing the interface by setting its private script directly to use the
new public function instead.
2016-08-12 19:29:28 -05:00
Dave Collins
bd4e64d1d4 chainhash: Abstract hash logic to new package. (#729)
This is mostly a backport of some of the same modifications made in
Decred along with a few additional things cleaned up.  In particular,
this updates the code to make use of the new chainhash package.

Also, since this required API changes anyways and the hash algorithm is
no longer tied specifically to SHA, all other functions throughout the
code base which had "Sha" in their name have been changed to Hash so
they are not incorrectly implying the hash algorithm.

The following is an overview of the changes:

- Remove the wire.ShaHash type
- Update all references to wire.ShaHash to the new chainhash.Hash type
- Rename the following functions and update all references:
  - wire.BlockHeader.BlockSha -> BlockHash
  - wire.MsgBlock.BlockSha -> BlockHash
  - wire.MsgBlock.TxShas -> TxHashes
  - wire.MsgTx.TxSha -> TxHash
  - blockchain.ShaHashToBig -> HashToBig
  - peer.ShaFunc -> peer.HashFunc
- Rename all variables that included sha in their name to include hash
  instead
- Update for function name changes in other dependent packages such as
  btcutil
- Update copyright dates on all modified files
- Update glide.lock file to use the required version of btcutil
2016-08-08 14:04:33 -05:00
Dave Collins
9b3e7d70ef txscript: Correct comments on alt stack methods.
Upstream commit 5ff5fc5fa2.
2016-06-01 14:57:09 -05:00
Dave Collins
d3ef588608 multi: Update with result of gofmt -s.
Contains the following upstream commits:
- d4852101d4
  - This commit has already been independently applied so it is mostly a
    NOOP
- f389742b39

In addition, gofmt -s has been run again to simplify the new additions
to Decred and and all simplifications are included in the merge commit.
2016-05-30 12:40:44 -05:00
Dave Collins
2030b4d057 multi: Fix several misspellings in the comments.
Contains the following upstream commits:
- ef9c50be57
- eb882f39f8

In addition to merging the fixes in the commits, this also fixes a few
more misspellings that were introduced in the new Decred code.
2016-05-30 12:24:21 -05:00
Dave Collins
7d4646cbc7 txscript: Comment improvements and fixes
Contains the following upstream commits:
- d272bfebb7
  - This commit was originally cherry picked from Decred and is a NOOP
- 9abc2c0e19
2016-05-27 23:54:59 -05:00
Dave Collins
18e35febe5 dcrjson/txscript: Merge arm-specific test updates.
Contains the following upstream commits:
- 3c2c858888
- c7e6c1e88f
2016-05-27 09:48:01 -05:00
Dave Collins
3117ae7683 txscript: Fix typo in README
Upstream commit 528ddaf23e.
2016-05-27 01:01:18 -05:00
Dave Collins
fe65e81af0 Apply various upstream comment fixes.
Contains the following upstream commits:
- 87182a2ddf
  - This commit does not apply to Decred so it has been reverted
- 89af747603
  - This commit has already been cherry picked and is a NOOP
- d0cdd53720
  - This commit has already been cherry picked and is a NOOP
- df20c1074c
- ff0c787237
- 6e133b58da
- 34a94b7d0b
- 14ccab80e7
2016-05-27 00:35:06 -05:00
Mawueli Kofi Adzoe
7f07fb1093 txscript: Fix typo. (#700)
* Fix tiny typo. Bump copyright year.
* Clarify documentation.
2016-05-22 23:23:20 -05:00
Dave Collins
40d778dd2d docs: Make various README.md files consistent.
Upstream commit 3942a116e4

This merge also includes a few Decred specific modifications and
corrects some old btcjson references that should have been updated to
dcrjson.
2016-05-20 16:00:12 -05:00
Dave Collins
e310d1dac5 Integrate a valid ECDSA signature cache
Upstream commit 0029905d43
2016-05-18 13:37:06 -05:00
Dave Collins
4e14b549b0 txscript: Sync upstream makeScriptNum tests.
Upstream commit ce22159fb2
2016-05-17 16:34:03 -05:00
Dave Collins
28f5ce5e44 Sync upstream through Sep 28, 2015.
This sync includes a new service flag named SFNodeBloom that a node is
required to use to indicate that it supports bloom filtering.  This
includes a protocol version bump to 2 and a wire version bump to 0.1.0.

dcrd:
The SFNodeBloom flag is set by default.  A new configuration option
--nopeerbloomfilters has been added to to disable bloom filtering.

Also, it corrects an issue with the mining state message where it was
using the network protocol version instead of having its own version.
2016-05-17 14:01:54 -05:00
Dave Collins
885070a4df Sync upstream through Sep 2, 2015. 2016-05-17 12:15:10 -05:00
cjepson
653e13db0e Waste less memory if sighash optimizations are on
Legacy transaction deep copy code mandated by the Bitcoin protocol
caused large amounts of data to be copied needlessly. If the
optimization for SigHashAll is set in chaincfg/params.go, these
extra copies are avoided by directly writing the pkScript and
decorations to a buffer and then hashing to get a witness hash,
while using the cached hash for the prefix.

Fixes #126.
2016-05-16 16:18:04 -04:00
Jonathan Gillham
1da28450c9 txscript: Make error strings idiomatic. 2016-05-12 14:43:13 -05:00
Jonathan Gillham
7384c88e2d Make PubKey variable names consistent. 2016-05-12 14:43:13 -05:00
Jonathan Gillham
c24785e90b txscript: Remove unneeded signature hash copies
These copies were likely left over from when MsgTx had no deep copy
functionality.
2016-05-12 14:43:09 -05:00
Bruno
901fafc201 switch maxDataCarrierSize to public const 2016-05-11 13:36:19 -05:00
Jonathan Gillham
ed9d1948cd Fixed erroneous txscript.KeyClosure documentation. 2016-05-11 13:33:20 -05:00
Dave Collins
644570487f txscript: Reduce script parse opcode allocs. (#677)
This changes the script template parsing function to use a pointer into
the constant global opcode array for parsed opcodes as opposed to making
a copy of the opcode entries which causes unnecessary allocations.

Profiling showed that after roughly 48 hours of operation, this
copy was the culprit of 207 million unnecessary allocations.
2016-04-25 16:17:07 -05:00
Olaoluwa Osuntokun
3b39edcaa1 txscript: optimize sigcache lookup (#598)
Profiles discovered that lookups into the signature cache included an
expensive comparison to the stored `sigInfo` struct. This lookup had the
potential to be more expensive than directly verifying the signature
itself!

In addition, evictions were rather expensive because they involved
reading from /dev/urandom, or equivalent, for each eviction once the
signature cache was full as well as potentially iterating over every
item in the cache in the worst-case.

To remedy this poor performance several changes have been made:
* Change the lookup key to the fixed sized 32-byte signature hash
* Perform a full equality check only if there is a cache hit which
    results in a significant  speed up for both insertions and existence
checks
* Override entries in the case of a colliding hash on insert Add an
* .IsEqual() method to the Signature and PublicKey types in the
  btcec package to facilitate easy equivalence testing
* Allocate the signature cache map with the max number of entries in
  order to avoid unnecessary map re-sizes/allocations
* Optimize evictions from the signature cache Delete the first entry
* seen which is safe from manipulation due to
    the pre image resistance of the hash function
* Double the default maximum number of entries within the signature
  cache due to the reduction in the size of a cache entry
  * With this eviction scheme, removals are effectively O(1)

Fixes #575.
2016-04-13 21:56:10 -05:00
Dave Collins
5ff5fc5fa2 txscript: Correct comments on alt stack methods. (#657) 2016-04-11 14:22:25 -05:00
David Hill
5fcef8aa56 txscript: New function IsUnspendable
IsUnspendable takes a public key script and returns whether it is
spendable.

Additionally, hook this into the mempool isDust function, since
unspendable outputs can't be spent.

This mimics Bitcoin Core commit 0aad1f13b2430165062bf9436036c1222a8724da
2016-03-22 11:34:32 -04:00
cjepson
c017ba6b60 Correct the expected number of inputs for stake P2SH outputs
The required number of inputs for a stake P2SH output were incorrectly
estimated by CalcScriptInfo. Now the sub class for any given output is
also checked for whether or not it is P2SH.
2016-03-09 11:46:16 -05:00
cjepson
df701d8cdf Revert sync merge
The sync merge does not build and needs further testing. It is
being reverted.
2016-03-08 22:16:06 -05:00
Alex Yocom-Piatt
cb9566911c Update comment to match code 2016-03-07 13:39:50 -06:00
Alex Yocom-Piatt
7e2c687295 Fix build/test errors from merge 2016-03-07 11:42:51 -06:00
Alex Yocom-Piatt
5b2b97e858 Sync to upstream 0280fa0264
Conflicts:
	blockchain/chain.go
	blockchain/checkpoints.go
	blockchain/difficulty.go
	blockchain/internal_test.go
	blockchain/txlookup.go
	blockchain/validate.go
	blockchain/validate_test.go
	blockmanager.go
	chaincfg/params.go
	cmd/dropafter/dropafter.go
	cpuminer.go
	database/db.go
	database/interface_test.go
	database/ldb/block.go
	database/ldb/insertremove_test.go
	database/ldb/leveldb.go
	database/ldb/operational_test.go
	database/ldb/tx.go
	database/memdb/memdb.go
	database/reorg_test.go
	dcrjson/walletsvrcmds.go
	docs/README.md
	docs/json_rpc_api.md
	mempool.go
	mining.go
	peer.go
	rpcserver.go
	rpcserverhelp.go
	rpcwebsocket.go
	sample-dcrd.conf
	txscript/consensus.go
	txscript/script_test.go
	txscript/sign.go
	txscript/standard.go
	wire/blockheader_test.go
	wire/msgtx_test.go
2016-03-07 11:35:24 -06:00
Dave Collins
f389742b39 multi: Update with result of gofmt -s.
This commit updates the code to make use of the most recent simplified
output from gofmt.
2016-02-25 13:02:54 -06:00
Dave Collins
eb882f39f8 multi: Fix several misspellings in the comments.
This commit corrects several typos in the comments found by misspell.
2016-02-25 11:17:12 -06:00
John C. Vernaleo
14769a741b Resolve all remaining issues caught by goclean.sh 2016-02-15 11:24:00 -05:00
John C. Vernaleo
1954bf24bb Work on improving the use of analysis tools in goclean.sh
Corrected or added many comments.

Update test code to follow format go vet wants.

The code doesn't pass the checks 100% yet.  That will come in a later
commit but these all seemed related so I'd rather get them in now.
2016-02-12 15:24:32 -05:00
Kefkius
7e1e205c70 Fix documentation for opcodeInvalid
Change 'opcodeReserved' to 'opcodeInvalid'
2016-02-12 09:11:49 -05:00
Dave Collins
9abc2c0e19 txscript: Comment improvements and fixes
This commit improves and corrects a few comments in txscript to ensure
they match reality.
2016-02-11 21:43:32 -06:00
Kefkius
d272bfebb7 Fix documentation for opcodeInvalid
Change 'opcodeReserved' to 'opcodeInvalid'
2016-02-11 20:42:41 -06:00
Kefkius
d759d1d3df Remove duplicate stack tests. 2016-02-09 11:17:04 -06:00
Kefkius
4d5ee10d66
Remove duplicate stack tests 2016-02-09 11:54:44 -05:00
John C. Vernaleo
acf973c2a6 Fix a test to match commit cb112a8 2016-02-08 17:33:40 -05:00
cjepson
cb112a81e6 Fix bug causing multisignature failure on IsStandard check
An off by one bug caused by inheritance from Bitcoin caused
multisignature transactions that were fully signed to be rejected
due to the number of stack items. The off-by-one bug has been fixed.
2016-02-08 10:02:33 -05:00
John C. Vernaleo
5076a00512 Initial Decred Commit.
Includes work by cjepson, ay-p, jolan, and jcv.

Initial conceptual framework by tacotime.
2016-02-07 14:00:12 -05:00
Dave Collins
c7e6c1e88f txscript: Correct JSON float conversions in tests.
This modifies the conversion of the output index from the JSON-based
test data for valid and invalid transactions as well as the signature
hash type for signature hash tests to first convert to a signed int and
then to an unsigned int.  This is necessary because the result of a
direct conversion of a float to an unsigned int is implementation
dependent and doesn't result in the expected value on all platforms.

Also, while here, change the function names in the error prints to match
the actual names.

Fixes #600.
2016-02-03 13:38:35 -06:00
Chris Shepherd
528ddaf23e txscript: Fix typo in README 2016-01-29 12:39:11 -08:00
Mawuli Adzoe
14ccab80e7 Review and fix typos in SigCache code. 2015-12-30 11:57:15 -07:00
David Hill
34a94b7d0b txscript: sync Bitcoin Core script tests 2015-12-30 09:38:16 -05:00
Mawuli Adzoe
6e133b58da txscript: Fix docs to match function.
Changed the order of return values described in the docs to be
consistent with the function’s actual return value signature.
2015-12-29 11:42:03 -07:00
Rune T. Aune
b691a222d5 Add signature hash calculation tests from Bitcoin Core.
500 tests with various transactions and scripts, verifying that
calcSignatureHash generates the expected hash in each case.

This requires changing SigHashType to uint32; that won't affect the
standard use-cases, but will make calcSignatureHash behave more like the
Core counterpart for non-standard SigHashType settings, like those in
some of these tests.
2015-11-15 16:39:00 -05:00
Dave Collins
3942a116e4 docs: Make various README.md files consistent.
First, it removes the documentation section from all the README.md files
and instead puts a web-based godoc badge and link at the top with the
other badges.  This is being done since the local godoc tool no longer
ships with Go by default, so the instructions no longer work without
first installing godoc. Due to this, pretty much everyone uses the
web-based godoc these days anyways.  Anyone who has manually installed
godoc won't need instructions.

Second, it makes sure the ISC license badge is at the top with the other
badges and removes the textual reference in the overview section.

Finally, it's modifies the Installation section to Installation and
Updating and adds a '-u' to the 'go get' command since it works for both
and thus is simpler.
2015-10-23 14:51:36 -05:00
David Hill
2e6e896aa6 txscript: Sync Bitcoin Core tests. 2015-10-22 16:10:29 -04:00
David Hill
3fa416a7ef txscript: fix isMultiSig bug.
isMultiSig was not verifying the number of pubkeys specified matched
the number of pubkeys provided.  This caused certain non-standard
scripts to be considered multisig scripts.

However, the script still would have failed during execution.

NOTE: This only affects whether or not the script is considered
standard and does NOT affect consensus.

Also, add a test for this check.
2015-10-22 15:55:34 -04:00
David Hill
4c3ad4987b txscript: Implement CheckLockTimeVerify (BIP0065)
See https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki for
more information.

This commit mimics Bitcoin Core commit bc60b2b4b401f0adff5b8b9678903ff8feb5867b
and includes additional tests from Bitcoin Core commit
cb54d17355864fa08826d6511a0d7692b21ef2c9
2015-10-14 13:19:49 -04:00
David Hill
0f57a41ed8 txscript: Add ScriptVerifyLowS to the standard flags
We've already been generating lowS sigs for quite a while.  This removes
the malleability vector.

This mimics Bitcoin Core commit 49dd5c629df0a08cf3b1ea8085c03312d1a81696
2015-10-09 15:30:12 -04:00
Olaoluwa Osuntokun
0029905d43 Integrate a valid ECDSA signature cache into btcd
Introduce an ECDSA signature verification into btcd in order to
mitigate a certain DoS attack and as a performance optimization.

The benefits of SigCache are two fold. Firstly, usage of SigCache
mitigates a DoS attack wherein an attacker causes a victim's client to
hang due to worst-case behavior triggered while processing attacker
crafted invalid transactions. A detailed description of the mitigated
DoS attack can be found here: https://bitslog.wordpress.com/2013/01/23/fixed-bitcoin-vulnerability-explanation-why-the-signature-cache-is-a-dos-protection/
Secondly, usage of the SigCache introduces a signature verification
optimization which speeds up the validation of transactions within a
block, if they've already been seen and verified within the mempool.

The server itself manages the sigCache instance. The blockManager and
txMempool respectively now receive pointers to the created sigCache
instance. All read (sig triplet existence) operations on the sigCache
will not block unless a separate goroutine is adding an entry (writing)
to the sigCache. GetBlockTemplate generation now also utilizes the
sigCache in order to avoid unnecessarily double checking signatures
when generating a template after previously accepting a txn to the
mempool. Consequently, the CPU miner now also employs the same
optimization.

The maximum number of entries for the sigCache has been introduced as a
config parameter in order to allow users to configure the amount of
memory consumed by this new additional caching.
2015-10-08 17:31:42 -07:00
David Hill
ce22159fb2 txscript: Change makeScriptNum to take a length argument
While current existing numeric opcodes are limited to 4 bytes, new
opcodes may need different limits.

This mimics Bitcoin Core commit 99088d60d8a7747c6d1a7fd5d8cd388be1b3e138
2015-10-05 19:48:55 -04:00
Dave Collins
064cc8e7c3 txscript: Optimize DisasmString function.
This commit modifies the DisasmString function to use a bytes buffer for
constructing the disassembled string instead of naive string
concatenation.  This makes a huge difference when disassembling scripts
with large numbers of opcodes.
2015-09-28 12:57:53 -05:00
Jonathan Gillham
27f7f82355 txscript: Make error strings idiomatic. 2015-08-09 14:06:36 +01:00
David Hill
3331d6098b txscript: New function IsUnspendable
IsUnspendable takes a public key script and returns whether it is
spendable.

Additionally, hook this into the mempool isDust function, since
unspendable outputs can't be spent.

This mimics Bitcoin Core commit 0aad1f13b2430165062bf9436036c1222a8724da
2015-08-03 10:10:23 -04:00
Jonathan Gillham
b448a2b6bc Make PubKey variable names consistent. 2015-08-02 22:21:27 +01:00