Skip to content

Conversation

@jl2012
Copy link
Contributor

@jl2012 jl2012 commented May 31, 2018

This makes using SIGHASH_SINGLE without a matching output non-standard. Signature of this form is insecure, as it commits to no output while users might think it commits to one. It is even worse in non-segwit scripts, which is effectively NOINPUT|NONE, so any UTXO of the same key could be stolen.

This is one of the earliest unintended consensus behavior which could be fixed with a softfork. The first step is to make it non-standard.

Copy link
Member

Choose a reason for hiding this comment

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

SCRIPT_VERIFY_SECURE_SIGHASH_SINGLE since it's making sure it's secure, not that it's insecure, and to make it self-evident what it is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@jl2012 jl2012 force-pushed the insecure_single branch 2 times, most recently from 2ce4d80 to 146cf12 Compare May 31, 2018 16:13
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove reference to const bool?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@jl2012 jl2012 force-pushed the insecure_single branch from 146cf12 to afe08aa Compare June 5, 2018 20:32
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just pass unsigned int flags into CheckSig? It seems like there might be flags in the future we want to check for as well, so why not bite the bullet and just pass in the flags?

Copy link
Contributor

Choose a reason for hiding this comment

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

I could go either way, but as is this avoids an internal dependency in CheckSig on flags' implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is also used in sign.cpp so I'd like to avoid using flags

@Christewart
Copy link
Contributor

strong concept ACK.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I would lead with require_secure_single since it's a feature flipper

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is ranked by rarity. The use if SIGHASH_SINGLE is rare. If it is not used, the remaining conditions will not be inspected.

@jl2012
Copy link
Contributor Author

jl2012 commented Jul 13, 2018

rebased

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 7, 2018

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #13533 ([tests] Reduced number of validations in tx_validationcache_tests by lucash-dev)
  • #13266 ([moveonly] privatize SignatureExtractorChecker by Empact)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

{
public:
virtual bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const
virtual bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion, const bool require_secure_single) const
Copy link
Contributor

@practicalswift practicalswift Sep 26, 2018

Choose a reason for hiding this comment

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

Should require_secure_single be an unnamed parameter since it is not used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just for consistency?

@NicolasDorier
Copy link
Contributor

NicolasDorier commented Sep 26, 2018

which is effectively NOINPUT|NONE, so any UTXO of the same key could be stolen.

Just being pedantic (and maybe out of topic), but NOINPUT|NONE is not equivalent to giving a key. NOINPUT|NONE works well with OP_CODESEPARATOR to select which path of the script the signer wants to execute.

EDIT:

I'm wrong, NOINPUT says scriptCode of the input is set to an empty script.

@jl2012
Copy link
Contributor Author

jl2012 commented Feb 5, 2019

This patch must be used with the NULLFAIL rule. Otherwise, it would be a hardfork as one may use a script CHECKSIG NOT with an out-of-bound SIGHASH_SINGLE signature. The script will fail before this patch, and pass after this patch.

NULLFAIL will fix the problem as the script will fail after the patch, due to the use of invalid signature

Another option is to throw an exception, instead of return false in GenericTransactionSignatureChecker(). It will be reported as SCRIPT_ERR_UNKNOWN_ERROR, unless #15074 is adopted.

@DrahtBot DrahtBot closed this May 7, 2019
@DrahtBot
Copy link
Contributor

DrahtBot commented May 7, 2019

The last travis run for this pull request was 241 days ago and is thus outdated. To trigger a fresh travis build, this pull request should be closed and re-opened.

@DrahtBot DrahtBot reopened this May 7, 2019
@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 2, 2019

Needs rebase

@adamjonas
Copy link
Member

@jl2012 Rebased after #13266 and #18422 at master...adamjonas:pr/13360 if there is interest in continuing to work on this.

@maflcko
Copy link
Member

maflcko commented Aug 13, 2020

Closing for now. Let me know when you want to work on this again

@maflcko maflcko closed this Aug 13, 2020
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants