Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btcec: set curve name in CurveParams #1565

Merged
merged 2 commits into from
Sep 8, 2020
Merged

Conversation

hallazzang
Copy link
Contributor

Set curve name(secp256k1) in KoblitzCurve.CurveParams

Fixes #1564

Copy link
Contributor

@onyb onyb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a comment to indicate the naming convention to follow? The list on SafeCurves would be a good example.

@hallazzang
Copy link
Contributor Author

@onyb I chose the name secp256k1 from that list. Is it worth adding comment like this?

// Curve name taken from https://safecurves.cr.yp.to/.
secp256k1.Name = "secp256k1"

@onyb
Copy link
Contributor

onyb commented May 5, 2020

@hallazzang That seems fine to me. The idea for the comment was to justify why we use secp256k1, vs S256.

@Rjected
Copy link
Contributor

Rjected commented Jul 17, 2020

Hi, do you mind rebasing this?

Set curve name(secp256k1) in KoblitzCurve.CurveParams

Fixes btcsuite#1564
@hallazzang
Copy link
Contributor Author

@Rjected updated.

@onyb onyb added this to the 0.22.0 milestone Sep 7, 2020
@onyb onyb added the btcec label Sep 7, 2020
Copy link
Member

@jcvernaleo jcvernaleo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@jcvernaleo jcvernaleo merged commit 7cbf956 into btcsuite:master Sep 8, 2020
marni pushed a commit to decfi/btcd that referenced this pull request Oct 5, 2021
* Improve error message about non-active segwit on simnet

I started playing with simnet and was confronted with error message:

```
[ERR] FNDG: Unable to broadcast funding tx for ChannelPoint(<point>:0):
-22: TX rejected: transaction <tx> has witness data, but segwit isn't active yet
```

I wasn't aware of the activation period so I got quite puzzled.
Google helped. But I think the message could mention likely cause.

Newly it optionally prints something like:

```
(The threshold for segwit activation is 300 blocks on simnet, current best height is 113)
```

* btcctl: add regtest mode to btcctl

* build: replace travis-ci with github actions.

test go 1.14
use golangci-lint

* build: update deps

* build: clean linter warnings

* btcjson: change getblock default verbosity to 1

This change makes btcd's getblock command match bitcoind's. Previously
the default verbosity was 0, which caused errors when using the
rpcclient library to connect to a bitcoind node - getblock would
unmarshall incorrectly since it didn't expect a verbosity=1 result when
it did not specify verbosity.

* rpcclient: send legacy GetBlock request for backwards compatibility

Without this, users of this library wouldn't be able to issue GetBlock
requests to nodes which haven't updated to support the latest request
format, namely the use of a single `int` parameter to denote verbosity
instead of two `bool`s.

* rpcclient: Add cookie auth

Based on Hugo Landau's cookie auth implementation for Namecoin's ncdns.

Fixes btcsuite#1054

* rpcclient: Refactor cookie caching

* rpcclient: Try user+pass auth before cookie auth

* rpcclient: Read first line of cookie instead of trimming space

* rpcclient: serialize nil inputs to empty list

* Improve chain state init efficiency

Remove unnecessary slice of all block indexes and
remove DB iteration over all block indexes that
used to determined the size of the slice.

* Add blockchain.NewUtxoEntry() to directly create entries for UtxoViewpoint

The current methods to add to a UtxoViewpoint don't allow for a situation where
we have only UTXO data but not a whole transaction.  This commit allows
contstruction of a UtxoEntry without requiring a full MsgTx.

AddTxOut() and AddTxOuts() both require a whole transaction, including the inputs,
which are only used in order to calculate the txid.  In some situations, such as
with use of the utreexo accumulator, we only have the utxo data but not the
transaction which created it.

For reference, utreexo's initial usage of the blockchain.NewUtxoEntry() function is at
https://github.com/mit-dci/utreexo/pull/135/files#diff-3f7b8f9991ea957f1f4ad9f5a95415f0R96

* Add getchaintxstats JSON-RPC client command

* Add fundrawtransaction RPC call

* Add getbalances RPC client command

* rpcclient: Add GetTransactionWatchOnly method

* peer: knownInventory, sentNonces - use generic lru

While here, also rename and generalize limitMap and apply to
other maps which need to be bounded.

* btcec: Avoid panic in fieldVal.SetByteSlice for large inputs

The implementation has been adapted from the dcrec module in dcrd. The
bug was initially fixed in decred/dcrd@3d9cda1 while transitioning to a
constant time algorithm. A large set of test vectors were subsequently
added in decred/dcrd@8c6b52d.

The function signature has been preserved for backwards compatibility.
This means that returning whether the value has overflowed, and the
corresponding test vectors have not been backported.

This fixes btcsuite#1170 and closes a previous attempt to fix the bug in btcsuite#1178.

* config+service_windows: add flag to disable win service

To run integration tests with btcd on Windows in non-interactive
environments (such as the Travis build with Windows machines), we
need to make sure we can still spawn a child process instead of only a
windows background service.

* updated docs for getblock-verbosity fixes

* Update json_rpc_api.md

Corrections suggested by @onyb btcsuite#1608 (comment)

* netsync: handle notfound messages from peers

backport from decred/dcrd#2253

When a peer sends a notfound message, remove the hash from requested
map.  Also increase notfound ban score and return early if it
disconnects the peer.

* release: update release script path

* release: remove old scripts and update process doc

- remove prep_release.sh and notes.sample
- update license in release.sh
- add notes for maintainers on the release process
- mention CHANGES file modifications

* Update CHANGES file for 0.21.0 release

Also updated changes for 0.20.1, and added a small note about changes
since 0.12.0.

* btcd: bump version to v0.21.0-beta

* blockchain: remove unknown block version warning

* Add rpclient implementation of getdescriptorinfo RPC

* peer: prevent last block height going backwards

This modifies the UpdateLastBlockHeight function to ensure the new
height is after the existing height before updating it in order to
prevent it from going backwards so it properly matches the intent of the
function which is to report the latest known block height for the peer.

Without this change, the value will properly start out at the latest
known block height reported by the peer during version negotiation,
however, it will be set to lower values when syncing from the peer due
to requesting old blocks and blindly updating the height.

It also adds a test to ensure proper functionality.

This is a backport of decred/dcrd#1747

* Fix monetary unit

* rpcserver: add parity with bitcoind for validateaddress

Updated the rpcserver handler for validateaddress JSON-RPC command to
have parity with the bitcoind 0.20.0 interface.

The new fields included are - isscript, iswitness, witness_version, and
witness_program. The scriptPubKey field has been left out since it
requires wallet access.

This update has no impact on the rpcclient.ValidateAddress method,
which uses the btcjson.ValidateAddressWalletResult type for modelling
the response from bitcoind.

* Add getblockfilter JSON-RPC client command

Add type for second getblockfilter param

* Implement signmessagewithprivkey JSON-RPC command

Reuse the Bitcoin message signature header const
also in verifymessage.

* rpcclient: Implement importmulti JSON-RPC client command

* Add Dockerfile to build and run btcd on Docker.

* btcd: fix conversion of int to string failing in Go 1.15

* btcjson,wire: fix invalid use of string(x) to convert byte value

* Major rework on documentation to make it compatible to readthedocs.org

* Added symlink to index.md for github readme preview.

* btcd+netsync: support witness tx and block in notfound msg

* btcec: set curve name in CurveParams

Set curve name(secp256k1) in KoblitzCurve.CurveParams

Fixes btcsuite#1564

* btcec: add a comment indicating where curve name taken from

Related with btcsuite#1565

* rpcclient: support listtransactions RPC with watchonly argument

Co-authored-by: Gert-Jaap Glasbergen <gertjaap@decoscrypto.com>

* blockchain: Remove unnecessary tx hash

* btcjson: update ListTransactionsResult for Bitcoin 0.20.0

This only adds new fields as optional, in order to make this change
backwards compatible with older versions of Bitcoin Core.

* chaincfg: Add RegisterHDKeyID func to populate HD key ID pairs

Currently, the only way to register HD version bytes is by initializing
chaincfg.Params struct, and registering it during package init.
RegisterHDKeyID provides a way to populate custom HD version bytes,
without having to create new chaincfg.Params instances. This is useful
for library packages who want to use non-standard version bytes for
serializing extended keys, such as the ones documented in SLIP-0132.

This function is complementary to HDPrivateKeyToPublicKeyID, which is
used to lookup previously registered key IDs.

* Nullable optional JSON-RPC parameters

Fix command marshalling dropping params following params with nil value.

btcsuite#1591 Allow specifying null parameter value from command line.

* GitHub Actions: Enable Go Race detector and code coverage

This modifies the goclean.sh script to run tests with the
race detector enabled. It also enables code coverage, and
uploads the results to coveralls.io.

Running tests with -race and -cover flags was disabled in
6487ba1 and 6788df7 respectively, due to some limits on
time/goroutines being hit on Travis CI. Since we have
migrated to GitHub Actions, it is desirable to bring them
back.

* rpc: Add getnodeaddresses JSON-RPC support

Add NodeAddresses function to rpcserverConnManager
interface for fetching known node addresses.

* btcjson,rpcclient: add support for PSBT commands to rpcclient

* Added ListSinceBlockMinConfWatchOnly method.

* wire: add proper types for flag field and improve docs

Summary of changes:

- Add a new const TxFlagMarker to indicate the flag prefix byte.
- Add a new TxFlag type to enumerate the flags supported by the
  tx parser.

  This allows us to avoid hardcoded magics, and will make it easier
  to support new flags in future.
- Improve code comments.

Closes btcsuite#1598.

* removed unnecessary GOMAXPROCS function calls

* rpcclient: add deriveaddresses RPC command

* ci: add go 1.15 to tests

* sample-btcd.conf: fix typo

* btcjson: add test for null params in searchrawtransactions

Closes PR btcsuite#1476.

* GetBlockTemplate RPC client implementation (btcsuite#1629)

* GetBlockTemplate RPC client implementation

* Txid added to the getblocktemplate result

* Omitempty for TxID and improved comment for GetBlockTemplate 'rules' field

* rpcclient: implement getaddressinfo command

Fields such as label, and labelspurpose are not included, since they
are deprecated, and will be removed in Bitcoin Core 0.21.

* Fix link to using bootstrap.dat

* rpcclient: implement getwalletinfo command

* rpcserver: add txid to getblocktemplate response

* rpc: add signrawtransactionwithwallet interface

Adds interface for issuing a signrawtransactionwithwallet command.
Note that this does not add functionality for the btcd rpc server
itself, it simply assumes that the RPC client has this ability and gives
an API for interacting with the RPC client.

rpc: add signrawtransactionwithwallet interface

* rpcclient: implement gettxoutsetinfo command

* Unmarshal hashes/second as float in GetMiningInfoResult

* rpcclient: add more wallet commands

Implement backupwallet, dumpwallet, loadwallet and unloadwallet.

* btcjson: add new JSON-RPC errors and document them

* rpcclient: implement createwallet with functional options

* rpcclient: fix documentation typos

* integration: allow setting custom btcd exe path

To allow using a custom btcd executable, we allow specifying a path to a
file. If the path is empty, the harness will fall back to compiling one
from scratch.

* integration: allow overwriting address generator

* integration: allow specifying connection behavior

* integration/rpctest: randomizes port in rpctest.New to reduce collisions

* btcjson+rpcserverhelp: restore bitcoind compatibility

The PR btcsuite#1594 introduced a change that made the order of parameters
relevant, if one of them is nil. This makes it harder to be backward
compatible with the same JSON message if an existing parameter in
bitcoind was re-purposed to have a different meaning.

* simplify s[:] to s where s is a slice

Found using https://go-critic.github.io/overview#unslice-ref

* rpcclient: add ExtraHeaders in ConnConfig

* Add support for receiving sendaddrv2 message from a peer

* fixed broken link

* Add support for arm32v7 in Dockerfile

* Fixes btcsuite#1653

* btcjson: Update fields in GetBlockChainInfoResult

Update the fields of GetBlockChainInfoResult to reflect the current state of
the RPC returned by other full-node implementations.

 * InitialBlockDownload - Node is in Initial Block Download mode if True.
 * SizeOnDisk - The estimated size of the block and undo files on disk.

* txscript: add benchmark for IsUnspendable

 - create benchmarks to measure allocations
 - add test for benchmark input
 - create a low alloc parseScriptTemplate
 - refactor parsing logic for a single opcode

* txscript/hashcache_test: always add inputs during getTxn

TestHashCacheAddContainsHashes flakes fairly regularly when rebasing
PR btcsuite#1684 with:
    txid <txid> wasn't inserted into cache but was found.

With probabilty 1/10^2 there will be no inputs on the transaction. This
reduces the entropy in the txid, and I belive is the primary cause of
the flake.

* txscript/hashcache_test: call rand.Seed once in init

This resolves the more fundamental flake in the unit tests noted in the
prior commit.

Because multiple unit tests call rand.Seed in parallel, it's possible
they can be executed with the same unix timestamp (in seconds). If the
second call happens between generating the hash cache and checking that
the cache doesn't contain a random txn, the random transaction is in
fact a duplicate of one generated earlier since the RNG state was reset.

To remedy, we initialize rand.Seed once in the init function.

* btcec: validate R and S signature components in RecoverCompact

* Add Batch JSON-RPC support (rpc client & server)

* Fix error message returned by EstimateFee

When you provide an argument to EstimateFee(numblocks uint32) that exceeds the estimateFeeDepth (which is set to 25), you get an error message that says "can only estimate fees for up to 100 blocks from now".  The variable used in the if condition and the variable used for creating the error message should be the same.

* docs: update shields

* rpcserver: Fix Error message returned by processRequest

When processRequest can't find a rpc command, standardCmdResult returns
a `btcjson.ErrRPCMethodNotFound` but it gets ignored and a
`btcjson.ErrRPCInvalidRequest` is returned instead.

This makes processRequest return the right error message.

* peer: allow external testing of peer.Peer

The previous use of allowSelfConns prevented this, as users aren't able
to invoke peer.TstAllowSelfConns themselves due to being part of a test
file, which aren't exported at the library level, leading to a
"disconnecting peer connected to self" error upon establishing a mock
connection between two peers. By including the option at the config
level instead (false by default, prevents connections to self) we enable
users of the peer library to properly test the behavior of the peer.Peer
struct externally.

* addrmgr: Use RLock/RUnlock when possible

* build: update btcutil dependency

* rpcclient: fix documentation typo

* btcjson: Updated TxRawResult.Version from int32 to uint32

* wire+chaincfg: add signet params

This commit adds all necessary chain parameters for connecting to the
public signet network.
Reference: bitcoin/bitcoin#18267

* config+params: add signet config option

This commit adds the --signet command line flag (or signet config
option) for starting btcd in signet mode.

* rpcserver: add taproot deployment to getblockchaininfo

* btcctl: add signet param

This commit adds the --signet command line flag to the btcctl utility.

* mining: extract witness commitment add into method

* rpctest: add witness commitment when calling CreateBlock

If we tried to include transactions having witnesses, the block would be
invalid since the witness commitment was not added.

* Don't reference the readme that we don't produce

* chaincfg: fix deployment bit numbers

On signet all previous soft forks and also taproot are always activated,
meaning the version is always 0x20000000 for all blocks. To make sure
they activate properly in `btcd` we therefore need to use the correct
bit to mask the version.
This means that on any custom signet there would need to be 2016 blocks
mined before SegWit or Taproot can be used.

* mempool: add additional test case for inherited RBF replacement

In this commit, we add an additional test case for inherited RBF
replacement. This test case asserts that if a parent is marked as being
replaceable, but the child isn't, then the child can still be replaced
as according to BIP 125 it shoudl _inhreit_ the replaceability of its
parent.

The addition of this test case was prompted by the recently discovered
Bitcoin Core "CVE" [1]. It turns out that bitcoind doesn't properly
implement BIP 125. Namely it fails to allow a child to "inherit"
replaceability if its parent is also replaceable. Our implementation
makes this trait rather explicit due to its recursive implementation.
Kudos to the original implementer @wpaulino for getting this correct.

[1]: https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-May/018893.html.

* Update CHANGES file for 0.22.0 release

* btcd: bump version to v0.22.0-beta

* Update release date for v0.22.0-beta in CHANGES file

* remove duplicate command

Co-authored-by: Antonin Hildebrand <antonin@hildebrand.cz>
Co-authored-by: Dan Cline <kidscline01@gmail.com>
Co-authored-by: David Hill <dhill@mindcry.org>
Co-authored-by: Henry <henry.wfisher@gmail.com>
Co-authored-by: Wilmer Paulino <wilmer.paulino@gmail.com>
Co-authored-by: Olaoluwa Osuntokun <laolu32@gmail.com>
Co-authored-by: JeremyRand <jeremyrand@airmail.cc>
Co-authored-by: Torkel Rogstad <torkel@rogstad.io>
Co-authored-by: Mikael Lindlof <mikuz.dev@gmail.com>
Co-authored-by: adiabat <rx@awsomnet.org>
Co-authored-by: Federico Bond <federicobond@gmail.com>
Co-authored-by: Anirudha Bose <anirudha.bose@ledger.fr>
Co-authored-by: Javed Khan <tuxcanfly@gmail.com>
Co-authored-by: Anirudha Bose <anirudha.bose@alumni.cern>
Co-authored-by: Oliver Gugger <gugger@gmail.com>
Co-authored-by: qqjettkgjzhxmwj <37233887+JettScythe@users.noreply.github.com>
Co-authored-by: Dan Cline <dan@dancline.net>
Co-authored-by: John C. Vernaleo <jcv@netpurgatory.com>
Co-authored-by: wakiyamap <wakiyamap@gmail.com>
Co-authored-by: Christian Lehmann <info@legacycode.org>
Co-authored-by: yyforyongyu <yy2452@columbia.edu>
Co-authored-by: Hanjun Kim <hallazzang@gmail.com>
Co-authored-by: Gert-Jaap Glasbergen <gertjaap@decoscrypto.com>
Co-authored-by: Calvin Kim <calvin@kcalvinalvin.info>
Co-authored-by: Andrew Tugarinov <nalcheg@gmail.com>
Co-authored-by: ipriver <g1ran1q@gmail.com>
Co-authored-by: Jake Sylvestre <jakesyl@gmail.com>
Co-authored-by: Tristyn <tristynstimpson@gmail.com>
Co-authored-by: Elliott Minns <elliott.minns@me.com>
Co-authored-by: Friedger Müffke <friedger@gmail.com>
Co-authored-by: David Mazary <dmaz@vt.edu>
Co-authored-by: Armando Ochoa <armando.o.j@gmail.com>
Co-authored-by: Liran Sharir <lsharir@paxos.com>
Co-authored-by: Iskander Sharipov <quasilyte@gmail.com>
Co-authored-by: 10gic <2391796+10gic@users.noreply.github.com>
Co-authored-by: Yaacov Akiba Slama <ya@slamail.org>
Co-authored-by: ebiiim <mail@ebiiim.com>
Co-authored-by: Victor Lavaud <victor.lavaud@gmail.com>
Co-authored-by: Vinayak Borkar <vinayakb@gmail.com>
Co-authored-by: Steven Kreuzer <skreuzer@FreeBSD.org>
Co-authored-by: Conner Fromknecht <conner@lightning.engineering>
Co-authored-by: Appelberg-s <Appelberg-s@users.noreply.github.com>
Co-authored-by: Gustavo Chain <gchain@pm.me>
Co-authored-by: Aurèle Oulès <aurele@oules.com>
Co-authored-by: Johan T. Halseth <johanth@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set curve name for KoblitzCurve
4 participants