From 9d1be94853fe98b068c8fdc85780d97b2158f78a Mon Sep 17 00:00:00 2001 From: "random.zebra" Date: Wed, 10 Nov 2021 20:07:43 +0100 Subject: [PATCH] Bug: invalid G1 and G2 cached in PrivateKey (#289) * QA: test cache invalidation for PrivateKey copy assignment operator * BugFix: Invalidate caches in PrivateKey copy assignment operator --- src/privatekey.cpp | 1 + src/test.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/privatekey.cpp b/src/privatekey.cpp index e8e51aa69..bfd296d7b 100644 --- a/src/privatekey.cpp +++ b/src/privatekey.cpp @@ -88,6 +88,7 @@ PrivateKey& PrivateKey::operator=(const PrivateKey& other) { CheckKeyData(); other.CheckKeyData(); + InvalidateCaches(); bn_copy(keydata, other.keydata); return *this; } diff --git a/src/test.cpp b/src/test.cpp index 5af5ea775..bb9c0edd5 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -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}") {