-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Optimize auth
module for bytecode size and gas usage
#7096
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
Merged
Merged
Conversation
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
xunilrj
reviewed
Apr 17, 2025
bitzoic
previously approved these changes
Apr 18, 2025
bitzoic
approved these changes
Apr 18, 2025
xunilrj
approved these changes
Apr 19, 2025
8 tasks
ironcev
added a commit
that referenced
this pull request
May 7, 2025
## Description This PR optimizes the `std::crypto` module for bytecode size and gas cost by using optimization techniques similar to those used in #7087, #7092, and #7096. The optimized public functions are listed in the below code snippet. **The bytecode size of that code got reduced from 46104 bytes to 44288 bytes.** We actually expect a bigger gain here. At one point in the optimization, the bytecode size went down to 33896 bytes. Bouncing back to ~44600 is related to the issue described in #7150. Once that issue is solved, we expect even smaller bytcode sizes. ```sway script; use std::crypto::ed25519::*; use std::crypto::point2d::*; use std::crypto::public_key::*; use std::crypto::scalar::*; use std::crypto::secp256k1::*; use std::crypto::secp256r1::*; use std::crypto::signature::*; use std::vm::evm::evm_address::EvmAddress; fn main() { let ed25519 = std::crypto::ed25519::Ed25519::new(); let _ = ed25519 == ed25519; let point2d = std::crypto::point2d::Point2D::new(); let _ = point2d == point2d; let public_key = std::crypto::public_key::PublicKey::new(); let _ = public_key == public_key; let _ = public_key.is_zero(); let scalar = std::crypto::scalar::Scalar::new(); let _ = scalar == scalar; let message = std::crypto::message::Message::new(); let secp256k1 = std::crypto::secp256k1::Secp256k1::new(); let _ = secp256k1 == secp256k1; let _ = secp256k1.address(message); let _ = secp256k1.evm_address(message); let _ = secp256k1.verify(public_key, message); let _ = secp256k1.verify_address(Address::zero(), message); let _ = secp256k1.verify_evm_address(EvmAddress::zero(), message); let secp256r1 = std::crypto::secp256r1::Secp256r1::new(); let _ = secp256r1 == secp256r1; let _ = secp256r1.address(message); let _ = secp256r1.evm_address(message); let _ = secp256r1.verify(public_key, message); let _ = secp256r1.verify_address(Address::zero(), message); let _ = secp256r1.verify_evm_address(EvmAddress::zero(), message); } ``` ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [ ] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
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.
Description
This PR optimizes the
std::auth
module for bytecode size and gas cost by using optimization techniques similar to those used in #7087 and #7092.The optimized public functions are listed in the below code snippet. The bytecode size of that code got reduced from 2480 bytes to 1200 bytes.
Checklist
Breaking*
orNew Feature
labels where relevant.