-
Notifications
You must be signed in to change notification settings - Fork 213
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
Use malloc instead of dynamic allocation on-stack in pairing functions #20
Conversation
I think it's a good idea, but relic library doesn't use malloc almost anywhere, it seems like it's a design decision? Have you run the benchmarks/tests with this, does everything run properly? What about valgrind? |
Will run the tests later with valgrind and then report back |
Benchmark and tests run without errors. Valgrind also reported no issues. I created an issue in relic to clarify if this would be allowed in upstream. |
contrib/relic/src/pp/relic_pp_map.c
Outdated
bn_t n; | ||
int i, j; | ||
|
||
bn_null(n); | ||
|
||
_p = malloc(sizeof(ep_t) * m); | ||
_q = malloc(sizeof(ep_t) * m); | ||
t = malloc(sizeof(ep2_t) * m); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t should be ep_t and _q should be ep2_t
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Fixed
When these are called with thousands of pairings, dynamic allocation on the stack results in stack overflows, leading to crashes. Better to use heap allocation here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, perhaps better to put both statements either inside TRY block or outside of it?
…e` (Chia-Network#20) * src: Add ExtendedPublicKey, ExtendedPrivateKey and ChainCode * test: Add "Legacy HD" keys tests * Convert seeds to Bytes Co-authored-by: UdjinM6 <[email protected]>
Description from commit:
If this is merged into this repo, I'll also create a PR into the relic project.