Prevent cached settings footgun in rust bindings#585
Merged
jtraglia merged 7 commits intoethereum:mainfrom Aug 5, 2025
Merged
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
jtraglia
commented
Jul 18, 2025
Comment on lines
42
to
47
| pub fn ethereum_kzg_settings(precompute: u64) -> &'static KzgSettings { | ||
| ethereum_kzg_settings_inner(precompute).as_ref() | ||
| let arc = ethereum_kzg_settings_arc(precompute); | ||
| // Intentionally leak the Arc to create a static reference. | ||
| // This is safe because the settings are cached and meant to live for the program's lifetime. | ||
| // The memory will be cleaned up when the program terminates. | ||
| &*Box::leak(Box::new(arc)) |
Member
Author
There was a problem hiding this comment.
@rakita how do you feel about this function? We don't really like it. Is there a better way to do this? Maybe we could delete this function and only provide the arc'd version (ethereum_kzg_settings_arc); would this work?
Contributor
There was a problem hiding this comment.
Previously we had:
fn ethereum_kzg_settings_inner(precompute: u64) -> &'static Arc<KzgSettings> {
that would allow returning 'static reference. I would try to bring back this fn
Member
Author
There was a problem hiding this comment.
Ah. I didn't realize I changed that function's return type. Good call, thanks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This creates caches for each possible precompute value.
Fixes #584.