Skip to content

Commit

Permalink
Bug: invalid G1 and G2 cached in PrivateKey (Chia-Network#289)
Browse files Browse the repository at this point in the history
* QA: test cache invalidation for PrivateKey copy assignment operator

* BugFix: Invalidate caches in PrivateKey copy assignment operator
  • Loading branch information
random-zebra authored and UdjinM6 committed Dec 1, 2021
1 parent c237ae8 commit 9d1be94
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/privatekey.cpp
Expand Up @@ -88,6 +88,7 @@ PrivateKey& PrivateKey::operator=(const PrivateKey& other)
{
CheckKeyData();
other.CheckKeyData();
InvalidateCaches();
bn_copy(keydata, other.keydata);
return *this;
}
Expand Down
4 changes: 4 additions & 0 deletions src/test.cpp
Expand Up @@ -65,8 +65,12 @@ TEST_CASE("class PrivateKey") {
REQUIRE(!pk3.IsZero());
REQUIRE(pk1 != pk2);
REQUIRE(pk3 == pk2);
REQUIRE(pk2.GetG1Element().IsValid()); // cache previous g1
REQUIRE(pk2.GetG2Element().IsValid()); // cache previous g2
pk2 = pk1;
REQUIRE(pk1 == pk2);
REQUIRE(pk1.GetG1Element() == pk2.GetG1Element());
REQUIRE(pk1.GetG2Element() == pk2.GetG2Element());
REQUIRE(pk3 != pk2);
}
SECTION("Move {constructor|assignment operator}") {
Expand Down

0 comments on commit 9d1be94

Please sign in to comment.