Skip to content
This repository

Make IsCanonicalScript() check the hash type more thoroughly #2114

Merged
merged 1 commit into from over 1 year ago

4 participants

Pieter Wuille BitcoinPullTester Peter Todd Gavin Andresen
Pieter Wuille
Collaborator

0 and 128 were previously accepted as standard hash type.

Note that this function is not active in the current verification code.

BitcoinPullTester

Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/87b83f97f3c3293ee1950fa646d3857426625cb4 for binaries and test log.

Peter Todd

Is the specification of the format signatures follow easily available? I assume it's an RFC or the like somewhere, (as well as whatever defines ASN-encoding) but what one? It'd be helpful if IsCanonicalSignature() had a comment directing people to what standard (and part of the standard) we're trying to try to check against. The forum link goes into more detail of course, but it's still not clear as to what standard exactly we're talking about.

I mean, normally it's fine leaving this stuff as "to be understood", but script.cpp is one of the most important things defining what is or isn't Bitcoin, and I'm sure there are a lot of people reading it and trying to understand it in detail. Making that easier to do doesn't hurt.

src/script.cpp
... ... @@ -278,7 +278,8 @@ bool IsCanonicalSignature(const valtype &vchSig) {
278 278 return error("Non-canonical signature: too short");
279 279 if (vchSig.size() > 73)
280 280 return error("Non-canonical signature: too long");
281   - if (vchSig[vchSig.size() - 1] & 0x7C)
  281 + unsigned char nHashType = vchSig[vchSig.size() - 1] & 0x7F;
  282 + if (nHashType < 1 || nHashType > 3)
1
Gavin Andresen Owner

Nit: how about:
if (nHashType < SIGHASH_ALL || nHashType > SIGHASH_SINGLE)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Pieter Wuille sipa Make IsCanonicalScript() check the hash type more thoroughly
0 and 128 were previously accepted as standard hash type.

Note that this function is not active in the current verification
code.
bffc744
BitcoinPullTester

Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/bffc744444c19e25c60c8df999beb83192f96a8a for binaries and test log.

Pieter Wuille
Collaborator

@petertodd Good idea. I'll try to add some references in comments soon.

Gavin Andresen gavinandresen merged commit c429f2b into from
Pieter Wuille sipa deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Dec 22, 2012
Pieter Wuille sipa Make IsCanonicalScript() check the hash type more thoroughly
0 and 128 were previously accepted as standard hash type.

Note that this function is not active in the current verification
code.
bffc744
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 2 additions and 1 deletion. Show diff stats Hide diff stats

  1. +2 1  src/script.cpp
3  src/script.cpp
@@ -278,7 +278,8 @@ bool IsCanonicalSignature(const valtype &vchSig) {
278 278 return error("Non-canonical signature: too short");
279 279 if (vchSig.size() > 73)
280 280 return error("Non-canonical signature: too long");
281   - if (vchSig[vchSig.size() - 1] & 0x7C)
  281 + unsigned char nHashType = vchSig[vchSig.size() - 1] & (~(SIGHASH_ANYONECANPAY));
  282 + if (nHashType < SIGHASH_ALL || nHashType > SIGHASH_SINGLE)
282 283 return error("Non-canonical signature: unknown hashtype byte");
283 284 if (vchSig[0] != 0x30)
284 285 return error("Non-canonical signature: wrong type");

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.