Skip to content

Conversation

@odudex
Copy link
Collaborator

@odudex odudex commented Jul 29, 2025

Some consider assert suitable only for debugging because, as when a Python script is executed with the -O (optimize) flag, all assert statements are stripped from the code at runtime.

This is particularly relevant in Android environments, where Buildozer, by default, runs with the -O flag enabled. As a result, important validation checks implemented with assert would be skipped entirely.

We have already been using these changes in the Krux Android app for some time, and we believe adopting this approach more broadly would be beneficial.

@qlrd
Copy link

qlrd commented Jul 29, 2025

cACK, i will do some tests to it.

assert num_bytes <= 64
assert num_bytes >= 16
if num_bytes > 64:
raise ValueError("Number of bytes must be less than 64")
Copy link

@jdlcdl jdlcdl Jul 29, 2025

Choose a reason for hiding this comment

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

"... must not exceed 64"
or if not 16 <= num_bytes <= 64: raise ValueError("Number of bytes must be between 16 and 64") ?

@jdlcdl
Copy link

jdlcdl commented Jul 29, 2025

I've carefully reviewed these changes.

I didn't catch any logic errors in this pr, seems to be doing the same thing as before (except specific exceptions rather than AssertionError (maybe some projects catch these?))

I noted one wording change, where "less than 64" might better be "less than or equal to 64".

odudex and others added 3 commits July 29, 2025 17:00
In order to test the replace assertions with conditional error raising,
specifically, in bip85 code, was added a test for `derive_entropy`
method as well the failure cases described in `derive_mnemonic` and
`derive_hex`.
@odudex
Copy link
Collaborator Author

odudex commented Jul 30, 2025

Commits from this PR were merged to develop branch

@odudex
Copy link
Collaborator Author

odudex commented Jul 30, 2025

The last commit (which I had forgotten to add when opening the PR) is the most important, as the removed assert would disrupt the descriptor parsing logic when Embit is run with the -O flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants