-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Optimize Clones assembly #3640
Optimize Clones assembly #3640
Conversation
Can you quantify the improvement to the clone functions from using the scratch space? The suggested method for |
@frangio Ok, understand. Changed the implementation of Saves a tiny bit of gas during deployment, and makes the deployer bytecode a little smaller. |
For the record, I looked at defining a helper like below that we could reuse in all places. Unfortunately Solidity doesn't inline the call so I don't think it's worth it. function _getInitCode(address implementation) internal pure returns (bytes32 w0, bytes32 w1) {
/// @solidity memory-safe-assembly
assembly {
w0 := or(0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000, shr(0xe8, shl(0x60, implementation)))
// Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
w1 := or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3)
}
} |
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.
LGTM
Resolved the |
For reference here's the memory layout in
|
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Brb, i’m outside right now. |
@Vectorized Any hints on how to create the equivalent of I tried a lot but nothing seems to result in the correct address, maybe the optimizations and using the proxy prefix + suffix bytes makes it not straightforward to replicate it on JavaScript? References: Thank you in advance! :) |
|
@Amxx Thanks, I ended up doing a tiny JS library to solve the issue so I don't have to deal with it again! Haha So that allowed me to finish this other one: |
Changes:
predictDeterministicAddress
to use lesser operations, while maintaining the same memory expansion costs.Gas Before:
Gas After:
PR Checklist