The simple signature takes a sighash as argument and verifies a signature and pubkey against it.
It is used in signet (#16411) for verifying blocks and in BIP-322 implementation (#16440) for verifying messages.
The simple signature takes a sighash as argument and verifies a signature and pubkey against it.
It is used in signet (#16411) for verifying blocks and in BIP-322 implementation (#16440) for verifying messages.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Reviewers, this pull request conflicts with the following ones:
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.
This interface, where the caller provides the hash of a message, and then “verifies” that the signature is valid, seems problematic to me at this layer of our code – my understanding is that without knowing the preimage of the hash (ie the message being signed), this doesn’t prove that the signature could only have come from someone with knowledge of the private key.
I know at some layer of our cryptography code we will have verification methods like this, but at this layer it seems inconsistent with all our other signature checkers, which are operating under different assumptions (well, except maybe for the DummySignatureChecker which does not do signature verifications, but hopefully that is clear to any callers). So my initial thought is that this is not a good place to have what is effectively a lower-level API call to a crypto library function.
I’m not very familiar with the broader work this is part of, so if this is in fact necessary or expedient from an implementation perspective, then I’d say at a minimum that we should at least include comments explaining that the assumptions here are different than for the other signature checkers.
Maybe I’m misunderstanding, but I’m not sure if it’s that inconsistent in the end. The “CreateSig” methods right now
This is consistent across all of these, and in fact, the other implementations could become sub-classes of this one (perform step 2 into internal sighash then have master do the rest; edit: I actually tried to do this, but it turns out a bit messy as the checker has to be re-constructed for every CreateSig call).
To pass the preimage rather than the hash itself would only lock this down to using some specific type of hasher, and would have no practical meaning for the actual implementation. The two (current) uses of these are here (#16411):
which gets the hash from
and here (#16440):
which gets the hash from
I made a note that these lack some assumptions that are normally present about the validity of the signature.
161@@ -162,6 +162,18 @@ class BaseSignatureChecker
162 virtual ~BaseSignatureChecker() {}
163 };
164
165+/** A general purpose signature checker. Note that this lacks assumptions about the `sighash`, as the preimage is not known to the signer. */
This should emphasize that the issue about not knowing the hash preimage is for the verifier, not the signer. Perhaps:
0/** A low level signature checker. Note that the caller must verify that the hash passed in relates to a known message (unlike for the other signature checkers). */
utACK 0bd274fe8544c896616268a21edd06b2d927fc0f
An alternative that perhaps @sdaftuar would like more given his reasonings, is having a templated class that will work for any object implementing a GetHash() method. Something like:
0explicit SimpleSignatureChecker(const T& hashable) : hash(hashable.GetHash()) {}
But that would require a wrapper class for signet and another one for the signed messages, I think. And if a comment solves the concerns, that’s certainly easier. Just thinking out loud.
167+private:
168+ uint256 hash;
169+
170+public:
171+ const uint256& GetHash() const { return hash; }
172+ explicit SimpleSignatureChecker(const uint256& hash_in) : hash(hash_in) {}
public
(like for the other class SimpleSignatureCreator
and for most classes in general I’d say)
public:
.
35+class SimpleSignatureCreator : public BaseSignatureCreator
36+{
37+ SimpleSignatureChecker checker;
38+
39+public:
40+ explicit SimpleSignatureCreator(const uint256& hashIn) : BaseSignatureCreator(), checker(hashIn) {};
BaseSignatureCreator()
, while the constructor of SimpleSignatureChecker()
doesn’t?
16+
17+BOOST_FIXTURE_TEST_SUITE(simplesigner_tests, BasicTestingSetup)
18+
19+BOOST_AUTO_TEST_CASE(simplesigner_base_tests)
20+{
21+ uint256 message;
message
is (implicitely) set to all-zero?