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

Use malloc instead of dynamic allocation on-stack in pairing functions #20

Merged
merged 1 commit into from
Sep 21, 2018
Merged

Use malloc instead of dynamic allocation on-stack in pairing functions #20

merged 1 commit into from
Sep 21, 2018

Conversation

codablock
Copy link
Contributor

Description from commit:

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.

If this is merged into this repo, I'll also create a PR into the relic project.

@mariano54
Copy link
Contributor

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?
./src/runbench
./src/runtest
valgrind --leak-check=full --gen-suppressions=yes ./src/runtest

@codablock
Copy link
Contributor Author

Will run the tests later with valgrind and then report back

@codablock
Copy link
Contributor Author

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.

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);
Copy link
Contributor

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

Copy link
Contributor Author

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.
Copy link
Contributor

@jonspock jonspock left a 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?

@mariano54 mariano54 merged commit 6d819eb into Chia-Network:master Sep 21, 2018
@codablock codablock deleted the pr_relic_fixes branch October 19, 2018 13:35
PastaPastaPasta pushed a commit to PastaPastaPasta/bls-signatures that referenced this pull request Oct 22, 2021
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants