Repository navigation
Document the ESP stack cost of seeding the DRBG - #70
Conversation
|
Warning Review limit reached
Next review available in: 44 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. WalkthroughThe PR documents ESP-IDF CTR-DRBG stack requirements, initialization behavior, memory usage, measurements, and CI configuration. It also ignores ESP-IDF-generated configuration, lock, and managed component files. ChangesESP-IDF support
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@README.md`:
- Around line 49-50: Update the README guidance to replace nostr_key_generate()
with the exported nostr_keypair_generate() API name, while preserving the
surrounding stack-size and signing-entry-point guidance.
- Line 41: Update the ESP-IDF row in the compatibility table to remove the
completed “✅ Tested” status, describe the coverage as an ESP32-S3 QEMU smoke
test, and explicitly indicate that CI is still pending.
- Around line 50-56: Update the README guidance around the documented caller
stack requirement so it does not present 4 KB as guaranteed safe: either add a
QEMU test covering first-call seeding from a 4 KB task, or revise the affected
requirements to mandate the measured 8 KB stack size used by CI.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f2c9e2d7-7ebf-4519-840c-f0df124e0522
📒 Files selected for processing (2)
.gitignoreREADME.md
|
All three looked at. Two were valid, one had a premise that has since gone stale. Stack guidance (line 50-56), valid and the important one. I wrote "at least 4 KB" having tested only 2 KB (crashes) and 8 KB (passes). 4 KB was an asserted number, not a measured one, which is exactly the habit the rest of this PR was written to avoid. Measured it:
The threshold is between 2 KB and 3 KB on this build. The README now says that, and says 4 KB is recommended for margin above the seed rather than because 3 KB was seen to fail. API name (line 50), valid but not for the stated reason. The comment says Platform table (line 41), premise now stale. The suggestion is to say CI is pending. It is not: #67 merged, and Smoke test restored and passing after the experiments: 11 assertions, |
Summary
Documents the stack requirement the mbedTLS CTR-DRBG introduced on ESP targets, and ignores the build byproducts the QEMU smoke test generates.
The hazard
#63 moved the ESP RNG from
esp_fill_random(), which has no state, onto a cached CTR-DRBG so a failed draw can be reported instead of silently returning zeros. Seeding costs stack in whichever task calls first:ctr_drbg_reseed_internal()puts a 384-byteMBEDTLS_CTR_DRBG_MAX_SEED_INPUTbuffer on the caller's stack, plus the entropy gather.Verified against the ESP-IDF sources rather than quoted from memory:
mbedtls/library/ctr_drbg.c:452declares the buffer, andctr_drbg.hconfirmsMAX_SEED_INPUT 384,MAX_REQUEST 1024,RESEED_INTERVAL 10000.Measured, not estimated
Fixed cost, read from a built ESP32-S3 image with
nm:rng_entropyrng_ctr_drbgrng_initializedMy original estimate on the issue was ~450 B, so this corrects it upward.
Stack behaviour, run under QEMU:
Guru Meditation Error: Core 1 panic’ed (LoadProhibited)app_mainseeding, then 2 KB tasks drawingThat middle row is the point, and it corrected my first experiment. I initially just shrank the smoke test's task stack to 2 KB and it passed, which looked like the hazard was not real. It passed because
app_mainhad already seeded with 8 KB of stack, so the task never paid the seed cost. Re-running with a 2 KB task as the genuine first caller crashes. The hazard is specifically the first caller, which is why the README recommends seeding deliberately from a task whose depth you control..gitignore
Executing action: all (aliases: build)
Running cmake in directory /home/kyle/Documents/GitHub/libnostr-c/build
Executing "cmake -G Ninja -DPYTHON_DEPS_CHECKED=1 -DPYTHON=/home/kyle/.espressif/python_env/idf5.4_py3.12_env/bin/python -DESP_PLATFORM=1 -DCCACHE_ENABLE=0 /home/kyle/Documents/GitHub/libnostr-c"... and the QEMU step generate
sdkconfig,dependencies.lockandmanaged_components/intest/esp-idf. None were ignored, so they were onegit add -Aaway from being committed.sdkconfigin particular is per-developer.sdkconfig.defaultsstays tracked, since that is what CI and a fresh checkout use.Test plan
.bssmeasured from a built ELF, not estimatedsdkconfig.defaultsstill trackedCloses libnostr-c-j31.
Summary by CodeRabbit
Documentation
Chores