Skip to content

Commit 2cedb42

Browse files
committed
Merge bitcoin#29252: kernel: Remove key module from kernel library
96378fe Refactor: Remove ECC_Start and ECC_Stop from key header (TheCharlatan) 41eba5b kernel: Remove key module from kernel library (TheCharlatan) a08d2b3 tools: Use ECC_Context helper in bitcoin-tx and bitcoin-wallet tools (Ryan Ofsky) 28905c1 test: Use ECC_Context helper in bench and fuzz tests (Ryan Ofsky) 538fedd common: Add ECC_Context RAII wrapper for ECC_Start/ECC_Stop (Ryan Ofsky) Pull request description: The key module's functionality is not used by the kernel library, but currently kernel users are still required to initialize the key module's `secp256k1_context_sign` global as part of the `kernel::Context` through `ECC_Start`. So move the `ECC_Start` call to the `NodeContext` ctor instead to completely remove the key module from the kernel library. The gui tests currently keep multiple `NodeContext` objects in memory, so call `ECC_Stop` manually to avoid triggering an assertion on `ECC_Start`. --- This PR is part of the [libbitcoinkernel project](bitcoin#27587). It removes a module from the kernel library. ACKs for top commit: achow101: ACK 96378fe ryanofsky: Code review ACK 96378fe. Just suggested comment changes since last review. theuni: utACK 96378fe Tree-SHA512: 40be427e8e2c920c0e3ce64a9bdd90551be27a89af11440bfb6ab0dd3a1d1ccb7cf1f82383cd782818cd1bb44d5ae5d2161cf4d78d3127ce4987342007090bab
2 parents 7066980 + 96378fe commit 2cedb42

33 files changed

+79
-71
lines changed

src/Makefile.am

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,6 @@ libbitcoinkernel_la_SOURCES = \
945945
kernel/disconnected_transactions.cpp \
946946
kernel/mempool_persist.cpp \
947947
kernel/mempool_removal_reason.cpp \
948-
key.cpp \
949948
logging.cpp \
950949
node/blockstorage.cpp \
951950
node/chainstate.cpp \

src/bench/bip324_ecdh.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
static void BIP324_ECDH(benchmark::Bench& bench)
1616
{
17-
ECC_Start();
17+
ECC_Context ecc_context{};
1818
FastRandomContext rng;
1919

2020
std::array<std::byte, 32> key_data;
@@ -44,8 +44,6 @@ static void BIP324_ECDH(benchmark::Bench& bench)
4444
// - Copy 16 bytes from the resulting shared secret into the middle of their ellswift key.
4545
std::copy(ret.begin() + 16, ret.end(), their_ellswift_data.begin() + 24);
4646
});
47-
48-
ECC_Stop();
4947
}
5048

5149
BENCHMARK(BIP324_ECDH, benchmark::PriorityLevel::HIGH);

src/bench/ccoins_caching.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484)
1919
static void CCoinsCaching(benchmark::Bench& bench)
2020
{
21-
ECC_Start();
21+
ECC_Context ecc_context{};
2222

2323
FillableSigningProvider keystore;
2424
CCoinsView coinsDummy;
@@ -47,7 +47,6 @@ static void CCoinsCaching(benchmark::Bench& bench)
4747
bool success{AreInputsStandard(tx_1, coins)};
4848
assert(success);
4949
});
50-
ECC_Stop();
5150
}
5251

5352
BENCHMARK(CCoinsCaching, benchmark::PriorityLevel::HIGH);

src/bench/checkqueue.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench)
2525
// We shouldn't ever be running with the checkqueue on a single core machine.
2626
if (GetNumCores() <= 1) return;
2727

28-
ECC_Start();
28+
ECC_Context ecc_context{};
2929

3030
struct PrevectorJob {
3131
prevector<PREVECTOR_SIZE, uint8_t> p;
@@ -62,6 +62,5 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench)
6262
// it is done explicitly here for clarity
6363
control.Wait();
6464
});
65-
ECC_Stop();
6665
}
6766
BENCHMARK(CCheckQueueSpeedPrevectorJob, benchmark::PriorityLevel::HIGH);

src/bench/descriptors.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
static void ExpandDescriptor(benchmark::Bench& bench)
1414
{
15-
ECC_Start();
15+
ECC_Context ecc_context{};
1616

1717
const auto desc_str = "sh(wsh(multi(16,03669b8afcec803a0d323e9a17f3ea8e68e8abe5a278020a929adbec52421adbd0,0260b2003c386519fc9eadf2b5cf124dd8eea4c4e68d5e154050a9346ea98ce600,0362a74e399c39ed5593852a30147f2959b56bb827dfa3e60e464b02ccf87dc5e8,0261345b53de74a4d721ef877c255429961b7e43714171ac06168d7e08c542a8b8,02da72e8b46901a65d4374fe6315538d8f368557dda3a1dcf9ea903f3afe7314c8,0318c82dd0b53fd3a932d16e0ba9e278fcc937c582d5781be626ff16e201f72286,0297ccef1ef99f9d73dec9ad37476ddb232f1238aff877af19e72ba04493361009,02e502cfd5c3f972fe9a3e2a18827820638f96b6f347e54d63deb839011fd5765d,03e687710f0e3ebe81c1037074da939d409c0025f17eb86adb9427d28f0f7ae0e9,02c04d3a5274952acdbc76987f3184b346a483d43be40874624b29e3692c1df5af,02ed06e0f418b5b43a7ec01d1d7d27290fa15f75771cb69b642a51471c29c84acd,036d46073cbb9ffee90473f3da429abc8de7f8751199da44485682a989a4bebb24,02f5d1ff7c9029a80a4e36b9a5497027ef7f3e73384a4a94fbfe7c4e9164eec8bc,02e41deffd1b7cce11cde209a781adcffdabd1b91c0ba0375857a2bfd9302419f3,02d76625f7956a7fc505ab02556c23ee72d832f1bac391bcd2d3abce5710a13d06,0399eb0a5487515802dc14544cf10b3666623762fbed2ec38a3975716e2c29c232)))";
1818
const std::pair<int64_t, int64_t> range = {0, 1000};
@@ -27,8 +27,6 @@ static void ExpandDescriptor(benchmark::Bench& bench)
2727
assert(success);
2828
}
2929
});
30-
31-
ECC_Stop();
3230
}
3331

3432
BENCHMARK(ExpandDescriptor, benchmark::PriorityLevel::HIGH);

src/bench/ellswift.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
static void EllSwiftCreate(benchmark::Bench& bench)
1111
{
12-
ECC_Start();
12+
ECC_Context ecc_context{};
1313

1414
CKey key = GenerateRandomKey();
1515
uint256 entropy = GetRandHash();
@@ -22,8 +22,6 @@ static void EllSwiftCreate(benchmark::Bench& bench)
2222
/* Use the last 32 bytes of the ellswift encoded public key as next entropy. */
2323
std::copy(ret.begin() + 32, ret.begin() + 64, MakeWritableByteSpan(entropy).begin());
2424
});
25-
26-
ECC_Stop();
2725
}
2826

2927
BENCHMARK(EllSwiftCreate, benchmark::PriorityLevel::HIGH);

src/bench/verify_script.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// modified to measure performance of other types of scripts.
1616
static void VerifyScriptBench(benchmark::Bench& bench)
1717
{
18-
ECC_Start();
18+
ECC_Context ecc_context{};
1919

2020
const uint32_t flags{SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_P2SH};
2121
const int witnessversion = 0;
@@ -57,7 +57,6 @@ static void VerifyScriptBench(benchmark::Bench& bench)
5757
assert(err == SCRIPT_ERR_OK);
5858
assert(success);
5959
});
60-
ECC_Stop();
6160
}
6261

6362
static void VerifyNestedIfScript(benchmark::Bench& bench)

src/bitcoin-chainstate.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <script/sigcache.h>
2727
#include <util/chaintype.h>
2828
#include <util/fs.h>
29+
#include <util/signalinterrupt.h>
2930
#include <util/task_runner.h>
3031
#include <validation.h>
3132
#include <validationinterface.h>

src/bitcoin-tx.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -692,21 +692,10 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
692692
tx = mergedTx;
693693
}
694694

695-
class Secp256k1Init
696-
{
697-
public:
698-
Secp256k1Init() {
699-
ECC_Start();
700-
}
701-
~Secp256k1Init() {
702-
ECC_Stop();
703-
}
704-
};
705-
706695
static void MutateTx(CMutableTransaction& tx, const std::string& command,
707696
const std::string& commandVal)
708697
{
709-
std::unique_ptr<Secp256k1Init> ecc;
698+
std::unique_ptr<ECC_Context> ecc;
710699

711700
if (command == "nversion")
712701
MutateTxVersion(tx, commandVal);
@@ -726,18 +715,18 @@ static void MutateTx(CMutableTransaction& tx, const std::string& command,
726715
else if (command == "outaddr")
727716
MutateTxAddOutAddr(tx, commandVal);
728717
else if (command == "outpubkey") {
729-
ecc.reset(new Secp256k1Init());
718+
ecc.reset(new ECC_Context());
730719
MutateTxAddOutPubKey(tx, commandVal);
731720
} else if (command == "outmultisig") {
732-
ecc.reset(new Secp256k1Init());
721+
ecc.reset(new ECC_Context());
733722
MutateTxAddOutMultiSig(tx, commandVal);
734723
} else if (command == "outscript")
735724
MutateTxAddOutScript(tx, commandVal);
736725
else if (command == "outdata")
737726
MutateTxAddOutData(tx, commandVal);
738727

739728
else if (command == "sign") {
740-
ecc.reset(new Secp256k1Init());
729+
ecc.reset(new ECC_Context());
741730
MutateTxSign(tx, commandVal);
742731
}
743732

src/bitcoin-wallet.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,9 @@ MAIN_FUNCTION
128128
return EXIT_FAILURE;
129129
}
130130

131-
ECC_Start();
131+
ECC_Context ecc_context{};
132132
if (!wallet::WalletTool::ExecuteWalletToolFunc(args, command->command)) {
133133
return EXIT_FAILURE;
134134
}
135-
ECC_Stop();
136135
return EXIT_SUCCESS;
137136
}

0 commit comments

Comments
 (0)