Skip to content

Commit

Permalink
Make setting of signature more robust, 0 R/S is possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Doy-lee committed May 29, 2024
1 parent 3b8069e commit 8241f14
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
3 changes: 1 addition & 2 deletions include/ethyl/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ namespace ethyl
{
struct Signature
{
bool init = false;
uint64_t signatureYParity = 0;
Bytes32 signatureR;
Bytes32 signatureS;

bool isEmpty() const;
void set(ECDSACompactSignature const &signature);
};

Expand Down
10 changes: 2 additions & 8 deletions src/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ std::vector<unsigned char> Transaction::serialize() const {
// Access list not going to use
arr.push_back(std::vector<uint64_t>{});

if (!sig.isEmpty()) {
if (sig.init) {
arr.push_back(sig.signatureYParity);
arr.push_back(oxenc::rlp_big_integer(sig.signatureR));
arr.push_back(oxenc::rlp_big_integer(sig.signatureS));
Expand Down Expand Up @@ -66,17 +66,11 @@ std::string Transaction::hashAsHex() const {
return result;
}

bool Signature::isEmpty() const {
static constexpr Bytes32 zero = {};
bool result =
signatureYParity == 0 && signatureR == zero && signatureS == zero;
return result;
}

void Signature::set(const ECDSACompactSignature& signature) {
assert(signature.max_size() == 65);
std::memcpy(signatureR.data(), &signature[0], 32);
std::memcpy(signatureS.data(), &signature[32], 32);
signatureYParity = static_cast<unsigned char>(signature[signature.max_size() - 1]);
init = true;
}
} // namespace ethyl

0 comments on commit 8241f14

Please sign in to comment.