guix: backport oscrypto PBKDF2 timing fix #36838

Manually merged
Sjors merged 1 commit from 2026/11/guix-oscrypto-timing into master 2026-12-01 16:19:12 +00:00 AGit
Sjors commented 2026-11-11 14:59:02 +00:00 (Migrated from github.com)

With substitutes disabled, guix-codesign can fail when building oscrypto 1.3.0. The test_dump_private test raises ZeroDivisionError.

The Guix time-machine bump in bitcoin/bitcoin#36233 (merged after the 32.x branch-off) pulls in OpenSSL 3.5.5, which can finish oscrypto's initial PBKDF2 benchmark in under a millisecond. oscrypto truncates this duration to zero and then divides by it. This was fixed upstream in wbond/oscrypto@144c121950

This PR adds the fix to contrib/guix/patches. It can be dropped once a new oscrypto release includes the fix and a Guix time machine bump includes it.

With substitutes disabled, `guix-codesign` can fail when building [oscrypto](https://pypi.org/project/oscrypto/) 1.3.0. The `test_dump_private` test raises `ZeroDivisionError`. The Guix time-machine bump in bitcoin/bitcoin#36233 (merged after the 32.x branch-off) pulls in OpenSSL 3.5.5, which can finish oscrypto's initial PBKDF2 benchmark in under a millisecond. oscrypto truncates this duration to zero and then divides by it. This was fixed upstream in wbond/oscrypto@144c12195001b08b9ccecb8a3fd041d22ae24474 This PR adds the fix to `contrib/guix/patches`. It can be dropped once a new oscrypto release includes the fix and a Guix time machine bump includes it.
DrahtBot commented 2026-11-11 14:59:13 +00:00 (Migrated from github.com)

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

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK fanquake

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36838 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36838.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36838#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [fanquake](https://github.com/bitcoin/bitcoin/pull/36838#issuecomment-7317262880) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--5faf32d7da4f0f540f40219e4f7537a3-->
Sjors commented 2026-11-11 15:05:03 +00:00 (Migrated from github.com)

I ran into this while making a new release for sv2-tp, which backports most recent tool-changes from here.

I used local-file instead of search-our-patches. I can add a commit to drop that helper entirely if people want: github.com/Sjors/bitcoin@95098e4587

I ran into this while making a [new release for sv2-tp](https://github.com/stratum-mining/sv2-tp/releases/tag/v1.1.3), which backports most recent tool-changes from here. I used `local-file` instead of `search-our-patches`. I can add a commit to drop that helper entirely if people want: https://github.com/Sjors/bitcoin/commit/95098e4587ebb158881b180b4a1aa0468a6bc6ce
First-time contributor

No findings were published from this review.

Review coverage was incomplete.


Reviewed: 1575462b22b8 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:312ddb2095238aa2ca395a9cc39b05ab5a38a7177afbdb0d69098df9c3e0bef9:9a7f127b15c6116c267953d38288a9f17ec7c7bcd3a975fb71a2db8bfd974dbf --> <!-- ralph-base:2e5d7540a1da07a7e448f339d54cfb40a78dddbc --> <!-- ralph-head:1575462b22b8584a49103eee7ad5a7ccf3289c4b --> <!-- ralph-case:430cc127bb42c68181a4dfae35b1885b8e1707ed523b5fa2131e91d62db2daf8 --> No findings were published from this review. Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`1575462b22b8`](<https://git.fish.foo/bitcoin/bitcoin/commit/1575462b22b8584a49103eee7ad5a7ccf3289c4b>) · [Review report](<https://review.fish.foo/report/36838-1575462b22b8584a49103eee7ad5a7ccf3289c4b-3401-2.html>) · [Previous reports](<https://review.fish.foo/traces/36838/>) [permalink](<https://review.fish.foo/report/36838-1575462b22b8584a49103eee7ad5a7ccf3289c4b-3401-2.html>)
fanquake commented 2026-11-26 11:47:48 +00:00 (Migrated from github.com)

Concept ACK - We can fix this now, but going forward, I'm looking at a more robust/maintainable set of deps.

once a new oscrypto release includes the fix

Can you upstream this patch to Guix in the interim? (can you link to upstream if you already did)

I used local-file instead of search-our-patches. I can add a commit to drop that helper entirely if people want: github.com/Sjors/bitcoin@95098e4587

Can you PR this separately?

Concept ACK - We can fix this now, but going forward, I'm looking at a more robust/maintainable set of deps. > once a new oscrypto release includes the fix Can you upstream this patch to Guix in the interim? (can you link to upstream if you already did) > I used local-file instead of search-our-patches. I can add a commit to drop that helper entirely if people want: https://github.com/Sjors/bitcoin/commit/95098e4587ebb158881b180b4a1aa0468a6bc6ce Can you PR this separately?
Sjors commented 2026-11-26 14:14:13 +00:00 (Migrated from github.com)

I'm looking at a more robust/maintainable set of deps.

I see oscrypto hasn't had a new release since 2022, so that might be a good idea.

Can you upstream this patch to Guix in the interim?

I opened an issue, since they have a somewhat silly LLM policy: https://codeberg.org/guix/guix/issues/12817

Can you PR this separately?

Done in https://github.com/bitcoin/bitcoin/pull/36988

> I'm looking at a more robust/maintainable set of deps. I see oscrypto hasn't had a new release since 2022, so that might be a good idea. > Can you upstream this patch to Guix in the interim? I opened an issue, since they have a somewhat silly LLM policy: https://codeberg.org/guix/guix/issues/12817 > Can you PR this separately? Done in https://github.com/bitcoin/bitcoin/pull/36988
fanquake commented 2026-11-27 15:29:10 +00:00 (Migrated from github.com)

I opened an issue,

Maybe @hebasto can land the patch upstream then?

> I opened an issue, Maybe @hebasto can land the patch upstream then?
hebasto commented 2026-11-28 12:27:38 +00:00 (Migrated from github.com)
> > I opened an issue, > > Maybe [@hebasto](https://github.com/hebasto) can land the patch upstream then? Please see https://codeberg.org/guix/guix/pulls/12888.
fanquake (Migrated from github.com) reviewed 2026-12-01 14:57:03 +00:00
fanquake (Migrated from github.com) left a comment

ACK a97c4b0289 recreated the no subs fail:

Listing '/gnu/store/adv57p9hz2g6kx3462rlma3nqfmyr0p4-python-oscrypto-1.3.0/lib/python3.12/site-packages/oscrypto-1.3.0.dist-info'...
Listing '/gnu/store/adv57p9hz2g6kx3462rlma3nqfmyr0p4-python-oscrypto-1.3.0/lib/python3.12/site-packages/oscrypto-1.3.0.dist-info/licenses'...
phase `compile-bytecode' succeeded after 0.1 seconds
starting phase `set-envs'
phase `set-envs' succeeded after 0.0 seconds
starting phase `check'
Using custom
Working dir: /tmp/guix-build-python-oscrypto-1.3.0.drv-0/source
Python 3.12.15 (main, Jan  1 1970, 00:00:01) [GCC 14.3.0]

asn1crypto: 1.5.1, /gnu/store/8k6i5smd0rl8lrm5dx1qd75ycd6wjxvx-python-asn1crypto-1.5.1-0.b763a75/lib/python3.12/site-packages/asn1crypto
oscrypto: 1.3.0, openssl (3.5.9) backend, /tmp/guix-build-python-oscrypto-1.3.0.drv-0/source/oscrypto
...........................................................................E.................................................................
======================================================================
ERROR: test_dump_private (tests.test_asymmetric.AsymmetricTests.test_dump_private)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/guix-build-python-oscrypto-1.3.0.drv-0/source/tests/test_asymmetric.py", line 131, in test_dump_private
    do_run()
  File "/tmp/guix-build-python-oscrypto-1.3.0.drv-0/source/tests/test_asymmetric.py", line 118, in do_run
    pem_serialized = asymmetric.dump_private_key(private, password, target_ms=20)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/guix-build-python-oscrypto-1.3.0.drv-0/source/oscrypto/asymmetric.py", line 327, in dump_private_key
    iterations = pbkdf2_iteration_calculator(kdf_hmac, key_length, target_ms=target_ms, quiet=True)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/guix-build-python-oscrypto-1.3.0.drv-0/source/oscrypto/kdf.py", line 145, in pbkdf2_iteration_calculator
    iterations = int(iterations / fraction / 2.0)
                     ~~~~~~~~~~~^~~~~~~~~~
ZeroDivisionError: float division by zero

----------------------------------------------------------------------
Ran 141 tests in 0.334s

FAILED (errors=1)
error: in phase 'check': uncaught exception:
%exception #<&invoke-error program: "python" arguments: ("run.py" "use_openssl=/gnu/store/xfzy3rq2lyi4h9jj342az01mc73mjc6y-openssl-3.5.9/lib/libcrypto.so,/gnu/store/xfzy3rq2lyi4h9jj342az01mc73mjc6y-openssl-3.5.9/lib/libssl.so" "skip_internet=true" "tests") exit-status: 1 term-signal: #f stop-signal: #f> 
phase `check' failed after 0.4 seconds
ACK a97c4b0289208711a49ada2aed4a65ed078a5b8f recreated the no subs fail: ```bash Listing '/gnu/store/adv57p9hz2g6kx3462rlma3nqfmyr0p4-python-oscrypto-1.3.0/lib/python3.12/site-packages/oscrypto-1.3.0.dist-info'... Listing '/gnu/store/adv57p9hz2g6kx3462rlma3nqfmyr0p4-python-oscrypto-1.3.0/lib/python3.12/site-packages/oscrypto-1.3.0.dist-info/licenses'... phase `compile-bytecode' succeeded after 0.1 seconds starting phase `set-envs' phase `set-envs' succeeded after 0.0 seconds starting phase `check' Using custom Working dir: /tmp/guix-build-python-oscrypto-1.3.0.drv-0/source Python 3.12.15 (main, Jan 1 1970, 00:00:01) [GCC 14.3.0] asn1crypto: 1.5.1, /gnu/store/8k6i5smd0rl8lrm5dx1qd75ycd6wjxvx-python-asn1crypto-1.5.1-0.b763a75/lib/python3.12/site-packages/asn1crypto oscrypto: 1.3.0, openssl (3.5.9) backend, /tmp/guix-build-python-oscrypto-1.3.0.drv-0/source/oscrypto ...........................................................................E................................................................. ====================================================================== ERROR: test_dump_private (tests.test_asymmetric.AsymmetricTests.test_dump_private) ---------------------------------------------------------------------- Traceback (most recent call last): File "/tmp/guix-build-python-oscrypto-1.3.0.drv-0/source/tests/test_asymmetric.py", line 131, in test_dump_private do_run() File "/tmp/guix-build-python-oscrypto-1.3.0.drv-0/source/tests/test_asymmetric.py", line 118, in do_run pem_serialized = asymmetric.dump_private_key(private, password, target_ms=20) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/guix-build-python-oscrypto-1.3.0.drv-0/source/oscrypto/asymmetric.py", line 327, in dump_private_key iterations = pbkdf2_iteration_calculator(kdf_hmac, key_length, target_ms=target_ms, quiet=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/guix-build-python-oscrypto-1.3.0.drv-0/source/oscrypto/kdf.py", line 145, in pbkdf2_iteration_calculator iterations = int(iterations / fraction / 2.0) ~~~~~~~~~~~^~~~~~~~~~ ZeroDivisionError: float division by zero ---------------------------------------------------------------------- Ran 141 tests in 0.334s FAILED (errors=1) error: in phase 'check': uncaught exception: %exception #<&invoke-error program: "python" arguments: ("run.py" "use_openssl=/gnu/store/xfzy3rq2lyi4h9jj342az01mc73mjc6y-openssl-3.5.9/lib/libcrypto.so,/gnu/store/xfzy3rq2lyi4h9jj342az01mc73mjc6y-openssl-3.5.9/lib/libssl.so" "skip_internet=true" "tests") exit-status: 1 term-signal: #f stop-signal: #f> phase `check' failed after 0.4 seconds ```
fanquake (Migrated from github.com) commented 2026-12-01 14:56:38 +00:00

nit:

             ((guix gexp) #:select (local-file))
nit: ```suggestion ((guix gexp) #:select (local-file)) ```
Sjors commented 2026-12-01 15:59:09 +00:00 (Migrated from github.com)

I took the nit in https://github.com/bitcoin/bitcoin/pull/36838#discussion_r4756038378 and rebased after #36988 for clarity (there's no conflict).

On x86_64:

bash -c '
source contrib/guix/libexec/prelude.bash; JOBS=$(nproc)
HOST=arm64-apple-darwin time-machine build --no-substitutes -m contrib/guix/manifest_codesign.scm > /dev/null
time-machine build --no-substitutes --check /gnu/store/wz7ykdpszagk2mk5r65nw09k0iqrg1ns-python-oscrypto-1.3.0.drv
expected=8ba09493d5ce007cdbfce32ea7137019e44f0b0cacab6517c77e62bcb9bce406
actual=$(time-machine hash -S nar -H sha256 -f hex /gnu/store/9s5j78g9279xp1596jym6m3anv5y4dly-python-oscrypto-1.3.0)
[ "$actual" = "$expected" ] && echo "OK: $actual" || { echo "MISMATCH: expected $expected, got $actual"; exit 1; }
'
I took the nit in https://github.com/bitcoin/bitcoin/pull/36838#discussion_r4756038378 and rebased after #36988 for clarity (there's no conflict). On x86_64: ``` bash -c ' source contrib/guix/libexec/prelude.bash; JOBS=$(nproc) HOST=arm64-apple-darwin time-machine build --no-substitutes -m contrib/guix/manifest_codesign.scm > /dev/null time-machine build --no-substitutes --check /gnu/store/wz7ykdpszagk2mk5r65nw09k0iqrg1ns-python-oscrypto-1.3.0.drv expected=8ba09493d5ce007cdbfce32ea7137019e44f0b0cacab6517c77e62bcb9bce406 actual=$(time-machine hash -S nar -H sha256 -f hex /gnu/store/9s5j78g9279xp1596jym6m3anv5y4dly-python-oscrypto-1.3.0) [ "$actual" = "$expected" ] && echo "OK: $actual" || { echo "MISMATCH: expected $expected, got $actual"; exit 1; } ' ```
fanquake commented 2026-12-01 16:14:13 +00:00 (Migrated from github.com)
ACK 1575462b22b8584a49103eee7ad5a7ccf3289c4b
hebasto (Migrated from github.com) approved these changes 2026-12-01 17:27:43 +00:00
hebasto (Migrated from github.com) left a comment

Post-merge ACK 1575462b22.

Post-merge ACK 1575462b22b8584a49103eee7ad5a7ccf3289c4b.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36838
No description provided.