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
txscript: Force extracted addrs to compressed. #775
Conversation
txscript/standard_test.go
Outdated
"b93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5c" + | ||
"b2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b41" + | ||
"2a3")) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra blank line.
rpcserver.go
Outdated
@@ -5737,30 +5737,21 @@ func handleVerifyMessage(s *rpcServer, cmd interface{}, closeChan <-chan struct{ | |||
wire.WriteVarString(&buf, 0, "Decred Signed Message:\n") | |||
wire.WriteVarString(&buf, 0, c.Message) | |||
expectedMessageHash := chainhash.HashB(buf.Bytes()) | |||
pk, wasCompressed, err := chainec.Secp256k1.RecoverCompact(sig, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should be kept the same. Compressed and uncompressed pubkeys result in different addresses and therefore they should not verify.
This was incorrect before due to the hack in NewAddressSecpPubKey
, but now that NewAddressSecpPubKey
has been fixed, this function should be left the way it was so it is correct.
rpcserver.go
Outdated
activeNetParams.Params) | ||
if err != nil { | ||
// Again mirror Bitcoin Core behavior, which treats error in | ||
// public key reconstruction as invalid signature. | ||
return false, nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't remove this newline. If you'll notice in the majority of the code base there is always a newline before a code block with a comment.
mempool/mempool_test.go
Outdated
@@ -313,8 +313,7 @@ func newPoolHarness(chainParams *chaincfg.Params) (*poolHarness, []spendableOutp | |||
|
|||
// Generate associated pay-to-script-hash address and resulting payment | |||
// script. | |||
pubKeyBytes := signPub.SerializeCompressed() | |||
payPubKeyAddr, err := dcrutil.NewAddressSecpPubKey(pubKeyBytes, | |||
payPubKeyAddr, err := dcrutil.NewAddressSecpPubKeyCompressed(signPub, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please leave this the way it was. It is calling the function with the compressed bytes, so it's valid, and I prefer not to churn things that don't need to be churned since it makes upstream merges harder due to unnecessary differences.
rpctest/memwallet.go
Outdated
@@ -553,8 +553,7 @@ func (m *memWallet) ConfirmedBalance() dcrutil.Amount { | |||
// keyToAddr maps the passed private to corresponding p2pkh address. | |||
func keyToAddr(key chainec.PrivateKey, net *chaincfg.Params) (dcrutil.Address, error) { | |||
pubKey := chainec.Secp256k1.NewPublicKey(key.Public()) | |||
serializedKey := pubKey.SerializeCompressed() | |||
pubKeyAddr, err := dcrutil.NewAddressSecpPubKey(serializedKey, net) | |||
pubKeyAddr, err := dcrutil.NewAddressSecpPubKeyCompressed(pubKey, net) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Please leave it as is since It is calling the function with the compressed bytes already.
txscript/standard_test.go
Outdated
p2pkCompressed2Main, err := dcrutil.NewAddressSecpPubKey(decodeHex("03b0bd"+ | ||
"634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e65"), | ||
|
||
pubkey2, err := chainec.Secp256k1.ParsePubKey(decodeHex("03b0bd" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't change this. There is no need since they are specifically being given the compressed bytes.
txscript/standard_test.go
Outdated
|
||
pubkey2, err := chainec.Secp256k1.ParsePubKey(decodeHex("03b0bd" + | ||
"634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e65")) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra blank line.
txscript/standard_test.go
Outdated
@@ -671,27 +698,52 @@ func TestMultiSigScript(t *testing.T) { | |||
t.Parallel() | |||
|
|||
// mainnet p2pk 13CG6SJ3yHUXo4Cr2RY4THLLJrNFuG3gUg | |||
p2pkCompressedMain, err := dcrutil.NewAddressSecpPubKey(decodeHex("02192d7"+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't change this. There is no need since they are specifically being given the compressed bytes.
txscript/standard_test.go
Outdated
&chaincfg.MainNetParams) | ||
if err != nil { | ||
t.Errorf("Unable to create pubkey address (compressed): %v", | ||
err) | ||
return | ||
} | ||
p2pkCompressed2Main, err := dcrutil.NewAddressSecpPubKey(decodeHex("03b0bd"+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't change this. There is no need since they are specifically being given the compressed bytes.
txscript/standard_test.go
Outdated
"b93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5c"+ | ||
"b2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b41"+ | ||
"2a3"), &chaincfg.MainNetParams) | ||
pubkey3, err := chainec.Secp256k1.ParsePubKey(decodeHex("0411d" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, this could just use newAddressPubKey
.
9cde4ba
to
66f0e7b
Compare
txscript/standard_test.go
Outdated
err) | ||
return | ||
} | ||
p2pkUncompressedMain := newAddressPubKey(pubkey.SerializeCompressed()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
txscript/standard_test.go
Outdated
err) | ||
return | ||
} | ||
p2pkUncompressedMain := newAddressPubKey(pubkey.SerializeCompressed()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please Just pass it the decodeHex
result. There is no sense in parsing it just to serialize it and have it reparsed again in the function.
p2pkUncompressedMain := newAddressPubKey(decodeHex("0411db" +
"93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2" +
"e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3"))
txscript/sign_test.go
Outdated
pkBytes := pk.SerializeUncompressed() | ||
|
||
address, err := dcrutil.NewAddressSecpPubKey(pkBytes, | ||
// TODO: this test might have to be removed since consensus rules |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests shouldn't be removed. Instead, the comment should call out that they are required to be compressed currently due to the workaround in ExtractPkScriptAddrs
.
Ultimately, the consensus rules need to be updated so they do not call into a standardness function. Standard rules are intended to be a subset of consensus and invoking them is a mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good now. We'll need to make sure to get the dependent btcutil PR in first and update the glide.yaml
and glide.lock
accordingly before merging.
Please amend the commit title match the PR title so that it properly calls out the package it modifies and conforms to the Model Git Commit Message from the Code Contribution Guidelines. |
525df3a
to
8baee3c
Compare
glide.lock
Outdated
@@ -1,5 +1,5 @@ | |||
hash: 153a3e6a1f31b2b29a113e953098f2b42a645103ee3e10040b5e03727a7b003c | |||
updated: 2017-07-26T12:10:25.6313172-05:00 | |||
hash: bfe9054cc320a713e759ae524d46404f5fa085a62466fa172e1dcb4d8d08acbd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not change since the glide.yaml
didn't change.
83a96b7
to
c85f9d6
Compare
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
c85f9d6
to
2c1e17b
Compare
This requires PR decred/dcrutil#55.Decred's consensus rules require address generation to use a compressed pubkey format, this was hacked
into
btcutil.NewAddressSecpPubKey
. This commit removes the hack and providesbtcutil.NewAddressSecpPubKeyCompressed
to enforce the consensus prerequisite