48 Commits

Author SHA1 Message Date
Ori Newman
a4bb070722
[NOD-754] Fix staticcheck errors (#627)
* [NOD-754] Fix staticcheck errors

* [NOD-754] Remove some unused exported functions

* [NOD-754] Fix staticcheck errors

* [NOD-754] Don't panic if out/in close fails

* [NOD-754] Wrap outside errors with custom message
2020-02-18 16:56:38 +02:00
stasatdaglabs
03b7af9a13 [NOD-532] Replace "chain" with "DAG" where appropriate (#537)
* [NOD-532] Change chain to DAG in the root package.

* [NOD-532] Change chain to DAG in checkpoints.go.

* [NOD-532] Change chain to DAG in blockdag.

* [NOD-532] Change chain to DAG in cmd.

* [NOD-532] Change chain to DAG in dagconfig.

* [NOD-532] Change chain to DAG in database.

* [NOD-532] Change chain to DAG in mempool.

* [NOD-532] Change chain to DAG in mempool.

* [NOD-532] Change chain to DAG in netsync.

* [NOD-532] Change chain to DAG in rpcclient.

* [NOD-532] Change chain to DAG in server.

* [NOD-532] Change chain to DAG in txscript.

* [NOD-532] Change chain to DAG in util.

* [NOD-532] Change chain to DAG in wire.

* [NOD-532] Remove block heights in dagio.go examples.

* [NOD-532] Rename fakeChain to fakeDAG.

* [NOD-532] Fix comments, remove unused EnableBCInfoHacks flag.

* [NOD-532] Fix comments and variable names.

* [NOD-532] Fix comments.

* [NOD-532] Fix merge errors.

* [NOD-532] Formatted project.
2019-12-17 13:40:03 +02:00
stasatdaglabs
f46dec449d [NOD-510] Change all references to Bitcoin to Kaspa (#531)
* [NOD-510] Change coinbase flags to kaspad.

* [NOD-510] Removed superfluous spaces after periods in comments.

* [NOD-510] Rename btcd -> kaspad in the root folder.

* [NOD-510] Rename BtcEncode -> KaspaEncode and BtcDecode -> KaspaDecode.

* [NOD-510] Rename BtcEncode -> KaspaEncode and BtcDecode -> KaspaDecode.

* [NOD-510] Continue renaming btcd -> kaspad.

* [NOD-510] Rename btcjson -> kaspajson.

* [NOD-510] Rename file names inside kaspajson.

* [NOD-510] Rename kaspajson -> jsonrpc.

* [NOD-510] Finish renaming in addrmgr.

* [NOD-510] Rename package btcec to ecc.

* [NOD-510] Finish renaming stuff in blockdag.

* [NOD-510] Rename stuff in cmd.

* [NOD-510] Rename stuff in config.

* [NOD-510] Rename stuff in connmgr.

* [NOD-510] Rename stuff in dagconfig.

* [NOD-510] Rename stuff in database.

* [NOD-510] Rename stuff in docker.

* [NOD-510] Rename stuff in integration.

* [NOD-510] Rename jsonrpc to rpcmodel.

* [NOD-510] Rename stuff in limits.

* [NOD-510] Rename stuff in logger.

* [NOD-510] Rename stuff in mempool.

* [NOD-510] Rename stuff in mining.

* [NOD-510] Rename stuff in netsync.

* [NOD-510] Rename stuff in peer.

* [NOD-510] Rename stuff in release.

* [NOD-510] Rename stuff in rpcclient.

* [NOD-510] Rename stuff in server.

* [NOD-510] Rename stuff in signal.

* [NOD-510] Rename stuff in txscript.

* [NOD-510] Rename stuff in util.

* [NOD-510] Rename stuff in wire.

* [NOD-510] Fix failing tests.

* [NOD-510] Fix merge errors.

* [NOD-510] Fix go vet errors.

* [NOD-510] Remove merged file that's no longer relevant.

* [NOD-510] Add a comment above Op0.

* [NOD-510] Fix some comments referencing Bitcoin Core.

* [NOD-510] Fix some more comments referencing Bitcoin Core.

* [NOD-510] Fix bitcoin -> kaspa.

* [NOD-510] Fix more bitcoin -> kaspa.

* [NOD-510] Fix comments, remove DisconnectBlock in addrindex.

* [NOD-510] Rename KSPD to KASD.

* [NOD-510] Fix comments and user agent.
2019-12-12 15:21:41 +02:00
Svarog
369ec449a8 [NOD-509] Change organization name to kaspanet (#524)
* [NOD-509] Change organization name to kaspanet

* [NOD-509] Reorganize imports
2019-12-08 17:33:42 +02:00
Svarog
f4c6859e51 [NOD-509] Updated repository and imports to github.com/daglabs/kaspad (#521) 2019-12-08 16:28:53 +02:00
Ori Newman
c88fa1492e [NOD-375] Move to pkg/errors (#447)
* [NOD-375] Move to pkg/errors

* [NOD-375] Fix tests

* [NOD-375] Make AreErrorsEqual a shared function
2019-11-04 11:24:12 +02:00
Ori Newman
7371120481 [NOD-333] Make ExtractScriptPubKeyAddrs return single address (#415)
* [NOD-333] Make ExtractScriptPubKeyAddrs return single address

* [NOD-333] Remove reference to required signatures from ExtractScriptPubKeyAddrs
2019-09-19 11:19:51 +03:00
Ori Newman
a789680db1 [NOD-314] change pkscript to scriptpubkey (#400)
* [NOD-314] Change everywhere PkScript to ScriptPubKey

* [NOD-314] Change everywhere PkScript to ScriptPubKey

* [NOD-314] Rename pkPops -> scriptPubKeyPops
2019-09-15 11:09:36 +03:00
Ori Newman
c14c64d534 [NOD-224] Make P2PK and raw Multisig non-standard (#332) 2019-06-27 12:44:22 +03:00
Svarog
0c5f3d72bd [NOD-223] Removed Nulldata as standard tx type (#329)
* [NOD-223] Removed Nulldata as standard tx type

* [NOD-223] Removed redundant space
2019-06-16 16:31:38 +03:00
Ori Newman
aa51b5f071 [NOD-179] Added ECMH-Multiset to all UTXO structs (#304)
* [NOD-172] Port EMCH from bchd

* [NOD-172] Fix hdkeychain.TestErrors and add btcec.TestRecoverCompact

* [NOD-172] Make ECMH immutable

* [NOD-172] Fix gofmt errors

* [NOD-172] Add TestMultiset_NewMultisetFromDataSlice and fix Point to be immutable

* [NOD-172] Fix gofmt errors

* [NOD-172] Add test for checking that the Union of a multiset and its inverse is zero

* [NOD-179] Add ECMH Point to all UTXO-structs

* [NOD-179] Fix utxo set tests

* [NOD-179] Fix mempool tests

* [NOD-179] Remove RemoveTxOuts

* [NOD-179] Move serializeBlockUTXODiffData to the top of the file

* [NOD-179] Fix serializeBlockUTXODiffData comment format

* [NOD-179] Fix AddTx comment and name return values
2019-05-23 15:11:42 +03:00
Ori Newman
1cd82fcd3b [DEV-91] Ensure 100% coverage in mempool package (#60)
* [DEV-91] add tests for RemoveOrphansByTag

* [DEV-91] Add tests for orphan tx expiration

* [DEV-91] add TestDoubleSpends

* [DEV-91] add TestFetchTransaction

* [DEV-91] added a test for MinHighPriority

* [DEV-91] test unparsable scripts

* [DEV-91] test MaxOrphanTxs=0

* [DEV-91] add TestRemoveTransaction

* [DEV-105] use utxodiff in mempool instead of utxoview

* [DEV-105] get rid of utxoview

* [DEV-105] fix tests to use utxoset

* [DEV-105] remove utxoview type

* [DEV-105] move DagSetup to test_utils.go

* [DEV-105] add comments and add blockdag/test_utils_test.go

* [DEV-105] change checkPoolDoubleSpend to check utxodiff

* [DEV-105] add restoreInputs arg to removeTransaction

* [DEV-91] add restoreInputs arg to removeTransaction in unit tests

* [DEV-105] add restoreInputs arg to removeTransaction

* [DEV-105] give more descriptive names to vars

* [DEV-115] close txChan outside of HandleNewBlock

* [DEV-105] rename DagSetup -> DAGSetup

* [DEV-91] remove IsSpentInDiff

* [DEV-91] fix comment

* [DEV-91] Make IsPushOnlyScript return an error if the script cannot be parsed

* [DEV-91] add more tests for IsPushOnlyScript

* [DEV-91] fix comments
2018-09-27 12:09:19 +03:00
stasatdaglabs
6dd3b815c1 [DEV-17] Move Bech32Prefix-related code from btcd/chaincfg/params.go to btcdutil (#62)
* [DEV-17] Moved Bech32 stuff from params.go to address.go.

* [DEV-17] Removed dagconfig dependency from address_test.go.

* [DEV-17] Removed dagconfig dependency from builder_test.go.

* [DEV-17] Removed dagconfig dependency from internal_test.go.

* [DEV-17] Removed dagconfig dependency from wif.go.

* [DEV-17] Removed dagconfig dependency from externdedkey.go.

* [DEV-17] Fixed compilation errors outside of hdkeychain.

* [DEV-17] Resolved circular dependencies.

* [DEV-17] Fixed failing tests.

* [DEV-17] Renamed DagXxx to Bech32PrefixDAGXxx

* [DEV-17] Fixed register_test.go.

* [DEV-17] Renamed HDKeyIDPairXxxNet to XxxNetHDKeyPair.

* [DEV-17] Renamed IsForNet to IsForPrefix.
2018-09-23 15:49:50 +03:00
Ori Newman
b4b71eec01 [DEV-98] Move script flags from relay rules to consensus (#49)
* [DEV-98] Move script flags from relay rules to consensus

* [DEV-98] remove flags from script_tests.json

* [DEV-98] fix multisig and remove test that assume no minimal data rule

* [DEV-98] rename bip16 bool to isP2sh

* [DEV-98] add sighash type to overly long signature in script_tests.json

* [DEV-98] add test for NUMEQUAL for non equal numbers script_tests.json

* [DEV-98] remove debugging if

* [DEV-98] remove ErrCleanStack from EVAL_FALSE

* [DEV-98] change isP2sh to isP2SH to comply with Go style

* [DEV-98] add ScriptNoFlags to explictly indicate for empty ScriptFlags

* [DEV-98] rename ErrPubKeyType -> ErrPubKeyFormat

* [DEV-98] rename PUBKEYTYPE -> PUBKEYFORMAT
2018-08-23 17:45:49 +03:00
stasatdaglabs
c65d9aa168 [DEV-97] Combine btcd and btcutil repositories (#51)
* [DEV-97] Moved github.com/daglabs/btcutil into github.com/daglabs/btcd/btcutil.

* [DEV-97] Updated Gopkg.toml to no longer refer to btcutil.

* [DEV-97] Renamed btcutil to util.
2018-08-23 16:54:16 +03:00
Ori Newman
d9abfa0fd3 [DEV-68] Revert block version to 1 everywhere
* revert block version to 1

* [DEV-68] remove dersig flag

* [DEV-68] get rid of vbLegacyBlockVersion

* [DEV-68] remove isBIP0030Node
2018-08-13 12:35:20 +03:00
Ori Newman
29f1b2baff [DEV-31] Regenrate block databases and genesis blocks in order to be compatiable with the new structure (uint64 timestamps) 2018-07-19 19:04:00 +03:00
Ori Newman
0878f98d1e [DEV-31] Convert all timestamp to uint64 2018-07-17 13:04:29 +03:00
Ori Newman
d472600155 [DEV-18] Remove CSV and CLTV soft fork logic - convert to base protocol (#26)
* [DEV-18] changed CSV/CLTV to be regular op codes, and returned nop2 and nop3 to be regular nops

* [DEV-18] remove csv/cltv flags - part 1

* [DEV-18] remove csv/cltv flags - part 2

* [DEV-18] remove csv/cltv activation rules

* [DEV-18] remove csv/cltv activation rules

* [DEV-18] csv_fork_test fixes

* [DEV-18] readd chain params

* [DEV-18] readd chain params and remove csv activation rules

* [DEV-18] returned build flags to integration test

* [DEV-18] make csv/cltv to pop the the first element of the stack instead of peeking it

* [DEV-18] fix comments related to CSV/CLTV to remove any reference to soft fork

* [DEV-18] fix comments related to CSV/CLTV to remove any reference to soft fork

* [DEV-18] rename csv_fork_test.go to csv_fork.go

* [DEV-18] change mTx location

* [DEV-18] remove BIP0065Height

* [DEV-18] add function isUpgradableNop for readability
2018-07-15 13:56:34 +03:00
Mike Zak
1631998091 Merge remote-tracking branch 'origin/master' into dev-20-primitive-blockdag 2018-07-12 16:23:55 +03:00
Svarog
4d099d51cb [DEV-50] Remove the Multisig bug requiring a dummy push
* [DEV-50] Remove the Multisig bug requiring a dummy push

* [DEV-50] Removed redundant comment, since dummy bug was fixed

* [DEV-50] Removed some more dummy-related comments and error message
2018-07-03 11:21:16 +03:00
Mike Zak
d92690f7e5 Merge remote-tracking branch 'origin/master' into dev-20-primitive-blockdag 2018-07-01 15:58:02 +03:00
Svarog
8195acd0bb
[DEV-49] Renamed all opcodes consts to be CamelCase (#16) 2018-07-01 15:52:05 +03:00
Stas Boutenko
a26fd21ae7 [DEV-32] Renamed chaincfg to dagconfig and chainhash to daghash. 2018-06-19 18:19:54 +03:00
Mike Zak
e14712c99e Merge remote-tracking branch 'origin/master' into remove-segwit 2018-06-14 10:49:10 +03:00
Stas Boutenko
6924403653 [DEV-13] Removed netID magic numbers. 2018-06-11 11:13:16 +03:00
Mike Zak
e3079c7e79 [DEV-14] Removed SegWit from txscript package! 2018-06-11 09:58:48 +03:00
Stas Boutenko
2901d302f3 Updated references. 2018-06-03 18:34:09 +03:00
Josh Rickmar
1cd648d784 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 16:18:43 -05:00
Josh Rickmar
2e60448ffc txscript: Require SHA256 secret hashes for atomic swaps 2017-11-28 10:07:13 -05:00
Josh Rickmar
4803a8291c txscript: Add API to parse atomic swap contracts. 2017-09-20 12:44:35 -05:00
Olaoluwa Osuntokun
ff6cb25e89 txscript: convert all new segwit error types to ErrorCode's 2017-08-13 23:17:40 -05:00
Olaoluwa Osuntokun
80dd96ac5d txscript: add new post segwit policies to standard script flags 2017-08-13 23:17:40 -05:00
Olaoluwa Osuntokun
9054ef8354 BIP 147: enforce NULLDUMMY w/ segwit verification
This commit implements the flag activation portion of BIP 0147. The
verification behavior triggered by the NULLDUMMY script verification
flag has been present within btcd for some time, however it wasn’t
activated by default.

With this commit, once segwit has activated, the ScriptStrictMultiSig
will also be activated within the Script VM. Additionally, the
ScriptStrictMultiSig is now a standard script verification flag which
is used unconditionally within the mempool.
2017-08-13 23:17:40 -05:00
Olaoluwa Osuntokun
aaf187427e BIP0141+txscript: implement witness program validation
This commit implements full witness program validation for the
currently defined version 0 witness programs. This includes validation
logic for nested p2sh, p2wsh, and p2wkh. Additionally, when in witness
validation mode, an additional set of constrains are enforced such as
using the new sighash digest algorithm and enforcing clean stack
behavior within witness programs.
2017-08-13 23:17:40 -05:00
Olaoluwa Osuntokun
469e53ca27 BIP0141+txscript: awareness of new standard script templates, add helper funcs
This commit introduces a series of internal and external helper
functions which enable the txscript package to be aware of the new
standard script templates introduced as part of BIP0141. The two new
standard script templates recognized are pay-to-witness-key-hash
(P2WKH) and pay-to-witness-script-hash (P2WSH).
2017-08-13 23:17:40 -05:00
David Hill
0efea24aa6 txscript: Implement ScriptVerifyNullFail
ScriptVerifyNullFail defines that signatures must be empty if a
CHECKSIG or CHECKMULTISIG operation fails.

This commit also enables ScriptVerifyNullFail at the mempool policy
level.
2017-01-13 14:19:11 -05:00
Dave Collins
fdc2bc867b
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.
2017-01-12 13:12:39 -06: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
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
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
Bruno
4335ce828c switch maxDataCarrierSize to public const 2015-07-20 14:26:05 +08:00
Dave Collins
927a0e9c37 txscript: Test consistency and cleanup.
- Move reference tests to test package since they are intended to
  exercise the engine as callers would
- Improve the short form script parsing to allow additional opcodes:
  DATA_#, OP_#, FALSE, TRUE
- Make use of a function to decode hex strings rather than manually
  defining byte slices
- Update the tests to make use of the short form script parsing logic
  rather than manually defining byte slices
- Consistently replace all []byte{} and [][]byte{} with nil
- Define tests only used in a specific function inside that func
- Move invalid flag combination test to engine_test since that is what
  it is testing
- Remove all redundant script tests in favor of the JSON-based tests in
  the data directory.
- Move several functions from internal_test.go to the test files
  associated with what the tests are checking
2015-05-04 16:04:29 -05:00
Dave Collins
005b540895 txscript: Separate code for standard scripts.
This commit moves all code related to standard scripts into a separate
file named standard.go as well as the associated tests into
standard_test.go.  Since the code in address.go and address_test.go is
only related to standard scripts, it has been combined into the new
files and the old files deleted.

The intent here is to make it clear that the code in standard.go is not
related to consensus.
2015-05-01 15:20:48 -05:00