Pieter Wuille [ARCHIVE] on Nostr: 📅 Original date posted:2015-01-25 📝 Original message:On Wed, Jan 21, 2015 at ...
📅 Original date posted:2015-01-25
📝 Original message:On Wed, Jan 21, 2015 at 8:32 PM, Rusty Russell <rusty at rustcorp.com.au> wrote:
> One weirdness is the restriction on maximum total length, rather than a
> 32 byte (33 with 0-prepad) limit on signatures themselves.
Glad that you point this out; I believe that's a weakness with more
impact now that this function is used for consensus. Let me clarify.
This function was originally written for Bitcoin Core v0.8.0, where it
was only used to enforce non-standardness, not consensus. In that
setting, there was no need to require a maximum length for the R and S
arguments, as overly-long R or S values (which, because of a further
rule, do not have excessive padding) will always result in integers >=
2^256, which means the encoded signature would never be valid
according to the ECDSA specification. A restriction on the total
length is required however, as BER allows multi-byte length
descriptors, which this function cannot (and shouldn't, as it's not
DER) parse.
However, in the currently proposed soft fork, non-DER results in
immediate script failure, which is distinguishable from invalid
signatures (by negating the result of a CHECKSIG, for example using a
NOT after it). I must admit that having invalid signatures with
overly-long R or S but acceptable R+S size be distinguishable from
invalid signatures where R+S is too large is ugly, and unnecessary.
Adding individual R and S length restrictions (ideally: saying that no
more than 32 bytes, excluding the padding 0 byte in front, is invalid)
would be trivial, but it means deviating slightly from the
standardness rule implementation that has been deployed for a while.
There should not really be much risk in doing so, as there are still
no node implementation releases (apart from the v0.10.0 rc's) that
would mine a CHECKSIG whose result is negated.
So, I think there are two options:
* Just add this R/S length restriction rule as a standardness
requirement, but not make it part of the soft fork. A later softfork
can then add this easily. The same can be done for several other
changes if they are deemed useful, like only allowing 0 (the empty
array) as invalid signature (any other causes failure script
immediately), requiring correct encoding even for non-evaluated
signatures, ...
* Add it to the softfork now, and be done with it.
Opinions?
--
Pieter
Published at
2023-06-07 15:28:57Event JSON
{
"id": "ab5aa80ee574cd2e8169a9819467ca61293daccae58c3c7054c48d73afcc36b7",
"pubkey": "5cb21bf5d7f25a9d46879713cbd32433bbc10e40ef813a3c28fe7355f49854d6",
"created_at": 1686151737,
"kind": 1,
"tags": [
[
"e",
"43498997aaf69cc28c108f60f2a0a9a1eeab544cf4e7f9ece35a133ac15cb4c1",
"",
"root"
],
[
"e",
"f9fa4ea721d81b763be5237280557b71a49431015e733cb593a76a92dd37077b",
"",
"reply"
],
[
"p",
"5cb21bf5d7f25a9d46879713cbd32433bbc10e40ef813a3c28fe7355f49854d6"
]
],
"content": "📅 Original date posted:2015-01-25\n📝 Original message:On Wed, Jan 21, 2015 at 8:32 PM, Rusty Russell \u003crusty at rustcorp.com.au\u003e wrote:\n\u003e One weirdness is the restriction on maximum total length, rather than a\n\u003e 32 byte (33 with 0-prepad) limit on signatures themselves.\n\nGlad that you point this out; I believe that's a weakness with more\nimpact now that this function is used for consensus. Let me clarify.\n\nThis function was originally written for Bitcoin Core v0.8.0, where it\nwas only used to enforce non-standardness, not consensus. In that\nsetting, there was no need to require a maximum length for the R and S\narguments, as overly-long R or S values (which, because of a further\nrule, do not have excessive padding) will always result in integers \u003e=\n2^256, which means the encoded signature would never be valid\naccording to the ECDSA specification. A restriction on the total\nlength is required however, as BER allows multi-byte length\ndescriptors, which this function cannot (and shouldn't, as it's not\nDER) parse.\n\nHowever, in the currently proposed soft fork, non-DER results in\nimmediate script failure, which is distinguishable from invalid\nsignatures (by negating the result of a CHECKSIG, for example using a\nNOT after it). I must admit that having invalid signatures with\noverly-long R or S but acceptable R+S size be distinguishable from\ninvalid signatures where R+S is too large is ugly, and unnecessary.\n\nAdding individual R and S length restrictions (ideally: saying that no\nmore than 32 bytes, excluding the padding 0 byte in front, is invalid)\nwould be trivial, but it means deviating slightly from the\nstandardness rule implementation that has been deployed for a while.\nThere should not really be much risk in doing so, as there are still\nno node implementation releases (apart from the v0.10.0 rc's) that\nwould mine a CHECKSIG whose result is negated.\n\nSo, I think there are two options:\n* Just add this R/S length restriction rule as a standardness\nrequirement, but not make it part of the soft fork. A later softfork\ncan then add this easily. The same can be done for several other\nchanges if they are deemed useful, like only allowing 0 (the empty\narray) as invalid signature (any other causes failure script\nimmediately), requiring correct encoding even for non-evaluated\nsignatures, ...\n* Add it to the softfork now, and be done with it.\n\nOpinions?\n\n-- \nPieter",
"sig": "4330b53f349c18b266cb12dec723b2ff90a224008716b2f994a27a8eaecb984fbacfbf633708a2405b47b3f3d0143acd7b261eaac4386698d927e7019f0a631c"
}