Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kernel: Remove key module from kernel library #29252

Merged
merged 5 commits into from May 10, 2024

Conversation

TheCharlatan
Copy link
Contributor

@TheCharlatan TheCharlatan commented Jan 15, 2024

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. It removes a module from the kernel library.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 15, 2024

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK ryanofsky, theuni, achow101
Stale ACK maflcko, hebasto

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

@maflcko
Copy link
Member

maflcko commented Jan 16, 2024

The gui tests currently keep multiple NodeContext objects in memory, so relax the secp256k1_context_sign check in ECC_Start to instead return early if it has already been initialized.

An alternative would be to call ECC_Stop in the gui tests instead of modifying key code?

@TheCharlatan
Copy link
Contributor Author

Updated 67058d4 -> 2cb38d9 (kernelRmKey_0 -> kernelRmKey_1, compare)

  • Implemented @maflcko's suggestion, calling ECC_Stop instead of relaxing the ECC_Start check.

src/kernel/checks.cpp Outdated Show resolved Hide resolved
@maflcko
Copy link
Member

maflcko commented Jan 16, 2024

lgtm ACK 2cb38d9 🍂

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: lgtm ACK 2cb38d93a8fea16bf84b072a90ac023ef345134d 🍂
3Z6w9mvDbuK4T+f2+g2HGbUkY+ETKts/CGAUhdhsu/MjBFRcdyVX4GOLme1SMwENKvYIENkhNym7luWlGcHRAw==

@TheCharlatan
Copy link
Contributor Author

Updated 2cb38d9 -> a885a16 (kernelRmKey_1 -> kernelRmKey_2, compare)

@maflcko
Copy link
Member

maflcko commented Jan 17, 2024

lgtm ACK a885a16 🔀

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: lgtm ACK a885a166cec6d84d08600f12b25d912bd28af80e 🔀
MgtL4Gf030oUpUZQHa33bgM/KAIA6X7ogn4k7avoYVc87vxEv1qrxN9wxdvRTYiOZ1Hd8faqpxGbrRFpJIA9DQ==

@fanquake fanquake requested a review from theuni January 17, 2024 10:51
@fanquake fanquake added this to the 28.0 milestone Feb 27, 2024
@achow101 achow101 requested a review from darosior April 9, 2024 15:24
@hebasto
Copy link
Member

hebasto commented May 6, 2024

Concept ACK.

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK a885a16.

src/qt/test/rpcnestedtests.cpp Outdated Show resolved Hide resolved
Copy link
Member

@theuni theuni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice change. ACK a885a16

src/qt/test/rpcnestedtests.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review a885a16. This is a good change, but I think it has a few issues pointed out in comments below. At a high level I think it makes sense to decouple ECC initialization from the kernel context struct, but I don't think it makes sense to couple it so tightly with the node context struct.

Would suggest an approach more like this branch: pr/ecc with commits:

  • c6b4b7c common: Add ECC_Context RAII wrapper for ECC_Start/ECC_Stop
  • 7184d36 test: Use ECC_Context helper in bench and fuzz tests
  • 668e2f8 tools: Use ECC_Context helper in bitcoin-tx and bitcoin-wallet tools
  • 7719001 kernel: Remove key module from kernel library

Feel free to take any of this or do something different.

src/kernel/context.h Outdated Show resolved Hide resolved
src/kernel/context.h Show resolved Hide resolved
src/qt/test/rpcnestedtests.cpp Outdated Show resolved Hide resolved
src/node/context.cpp Outdated Show resolved Hide resolved
@TheCharlatan TheCharlatan marked this pull request as ready for review May 7, 2024 14:53
@theuni
Copy link
Member

theuni commented May 8, 2024

@TheCharlatan Mind adding a commit to fixup the includes as per this conversation?

@TheCharlatan
Copy link
Contributor Author

Thank you for the review @ryanofsky!

a885a16 -> 7dc7938 (kernelRmKey_2 -> kernelRmKey_3, compare)

  • Addressed @ryanofsky's comment, cherry-picked the mentioned commits. Also added another commit for removing the now unused ECC_Start and ECC_Stop from the header.
  • Addressed @theuni's comment, cleaning up some of the includes.

@TheCharlatan
Copy link
Contributor Author

Rebased 7dc7938 -> 65a2051 (kernelRmKey_3 -> kernelRmKey_4, compare)

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK 65a2051

src/key.h Show resolved Hide resolved
@DrahtBot DrahtBot requested a review from maflcko May 9, 2024 13:42
@DrahtBot DrahtBot requested review from theuni and hebasto May 9, 2024 13:42
ryanofsky and others added 5 commits May 9, 2024 15:55
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`.
They are unused outside of the key module now.
@TheCharlatan
Copy link
Contributor Author

Updated 65a2051 -> 96378fe (kernelRmKey_4 -> kernelRmKey_5, compare)

  • Addressed @ryanofsky's comment, moving comments and improving description of ECC_Context.

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK 96378fe. Just suggested comment changes since last review.

Copy link
Member

@theuni theuni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice improvements since my last review. The RAII context is an obvious improvement, thanks @ryanofsky.

I looked for a way to add a virtual lifetime class with on_startup/on_shutdown to replace the .init in fuzz.h, but didn't have any luck because of a (afacs?) missing teardown callback. It seems the static context approach used here is actually what's recommended.

utACK 96378fe

@achow101
Copy link
Member

ACK 96378fe

@hebasto
Copy link
Member

hebasto commented May 20, 2024

Ported to the CMake-based build system in hebasto#202.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done or Closed or Rethinking
Development

Successfully merging this pull request may close these issues.

None yet

8 participants