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

Make static context a feature and allow dynamic context generation #41

Merged
merged 14 commits into from
Mar 27, 2020

Conversation

sorpaas
Copy link
Member

@sorpaas sorpaas commented Mar 26, 2020

This changes the static contexts to be a feature that can be enabled or disabled, and allow contexts to be dynamically generated. By disabling static contexts, users accomplish much smaller binary size, but the trade-off is then that contexts must be generated dynamically (which is not a cheap operation).

@dvdplm
Copy link
Contributor

dvdplm commented Mar 26, 2020

Can you ELI5 what "static|dynamic context" means in this context?

@sorpaas
Copy link
Member Author

sorpaas commented Mar 26, 2020

@dvdplm It's the pre-computed table used to accelerate various calculations. Previously we only allow storing the table as static variables directly in the library. This PR allows disabling those variables (to reduce binary size, if needed) and generate the tables dynamically.

core/src/ecmult.rs Outdated Show resolved Hide resolved
core/src/ecmult.rs Outdated Show resolved Hide resolved
/// Create a new `ECMultContext`.
pub const fn new(pre_g: [AffineStorage; ECMULT_TABLE_SIZE_G]) -> Self {
/// Create a new `ECMultContext` from raw values.
pub const unsafe fn new_raw(pre_g: [AffineStorage; ECMULT_TABLE_SIZE_G]) -> Self {
Copy link
Member

Choose a reason for hiding this comment

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

what makes it unsafe? is it due to potential misuse in crypto logic and not in rust terms?

Copy link
Member Author

Choose a reason for hiding this comment

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

If the table is not filled in the correct data of pre_g, then usage of it would be invalid. So yeah it's in crypto logic, but also not sure if it will lead to anything panicking.

core/src/ecmult.rs Outdated Show resolved Hide resolved
core/src/ecmult.rs Outdated Show resolved Hide resolved
core/src/ecmult.rs Show resolved Hide resolved
core/src/ecmult.rs Show resolved Hide resolved
core/src/ecmult.rs Outdated Show resolved Hide resolved
core/src/ecmult.rs Outdated Show resolved Hide resolved
core/src/ecmult.rs Outdated Show resolved Hide resolved
core/src/ecmult.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
sorpaas and others added 3 commits March 27, 2020 15:56
@dvdplm
Copy link
Contributor

dvdplm commented Mar 27, 2020

This PR allows disabling those variables (to reduce binary size, if needed) and generate the tables dynamically.

How much bigger is the static vs dynamic build? How much does the table generation cost under normal use?

I think it'd be good to get some of this info into the README to help users decide. :)

@sorpaas
Copy link
Member Author

sorpaas commented Mar 27, 2020

How much bigger is the static vs dynamic build? How much does the table generation cost under normal use?

It is reported to be quite significant -- around 1mb or so. I knew some users were discouraged previously from using libsecp256k1 just because of this. I don't have the exact numbers in hand but we can get it later. :)

@dvdplm
Copy link
Contributor

dvdplm commented Mar 27, 2020

we can get it later

Added #46

@sorpaas sorpaas merged commit 6793ff2 into master Mar 27, 2020
@sorpaas sorpaas deleted the sp-dyngen branch March 27, 2020 15:47
trevor-crypto pushed a commit to monacohq/libsecp256k1 that referenced this pull request May 31, 2022
…aritytech#41)

* Make static context a feature and allow dynamic context generation

* new_box -> new_boxed

* Remove "inputs and outputs must not overlap" comment

Does not apply.

* Update core/src/ecmult.rs

Co-Authored-By: Andronik Ordian <[email protected]>

* Add comment about unsafe block in new_boxed

* Tidy up comments

* More documents about unsafety

* Remove deconstruct_raw

* Add missing docs

* Use vec macro

* in -> on

* Update src/lib.rs

Co-Authored-By: David <[email protected]>

* Update src/lib.rs

Co-Authored-By: David <[email protected]>

Co-authored-by: Andronik Ordian <[email protected]>
Co-authored-by: David <[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