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

feat(v2): use solady's minimal ERC-1967 proxy and UUPSUpgradeable #35

Conversation

jaypaik
Copy link
Collaborator

@jaypaik jaypaik commented Mar 11, 2024

Note

This changes the way we generate counterfactuals. I think this is okay, but let me know if you see any problems.

  • Added in LibClone.sol and UUPSUpgradeable.sol from solady under /ext. Chose to do this instead of pulling it in as a git submodule since solady doesn't keep release branches so it's not possible to pin down the version pulled down in CI at the moment.

@jaypaik jaypaik mentioned this pull request Mar 11, 2024
3 tasks
@jaypaik jaypaik force-pushed the 03-10-style_consistent_natspec_style branch from a79c6dc to 8dac3c6 Compare March 12, 2024 14:44
@jaypaik jaypaik force-pushed the 03-10-feat_use_solady_s_minimal_ERC-1967_proxy_and_UUPSUpgradeable branch from 1d1c48d to fa694c6 Compare March 12, 2024 14:44
Copy link
Contributor

@adam-alchemy adam-alchemy left a comment

Choose a reason for hiding this comment

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

Looks good, one small possible optimization and a code comment request.

@@ -0,0 +1,1210 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add a comment (either here or elsewhere in the repo) indicating the commit hash from Solady at which this file was pulled, to reference later?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup, good idea. Will do for all of these.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Cut out a task for this, will address upstack.

@@ -0,0 +1,142 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

Copy link
Contributor

Choose a reason for hiding this comment

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

Same here for the solady commit hash

);
}

function _getCombinedSalt(address owner, uint256 salt) internal pure returns (bytes32) {
return keccak256(abi.encode(owner, salt));
Copy link
Contributor

@adam-alchemy adam-alchemy Mar 12, 2024

Choose a reason for hiding this comment

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

this can be optimized to avoid memory expansion as:

function _getCombinedSalt(address owner, uint256 salt) internal pure returns (bytes32 combinedSalt) {
    assembly ("memory-safe") {
        mstore(0x00, owner)
        mstore(0x20,  salt)
        combinedSalt := keccak256(0x00, 0x40)
    }
}

This will use the scratch space in the first two bytes of memory, rather than allocalte a new bytes buffer for the result of abi.encode.

This will have the caveat that the upper bits of address need to be cleared elsewhere, but that's fine here because we only pass post-sanitization external function parameters.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

🧠

);
}

function _getCombinedSalt(address[] memory owners, uint256 salt) internal pure returns (bytes32) {
return keccak256(abi.encode(owners, salt));
Copy link
Contributor

Choose a reason for hiding this comment

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

For this one, we can't avoid memory expansion without a large refactor.

return LightAccount(payable(addr));
/// @return account The address of either the newly deployed account or an existing account with this owner and salt.
function createAccount(address owner, uint256 salt) public returns (LightAccount account) {
(bool alreadyDeployed, address accountAddress) =
Copy link
Contributor

Choose a reason for hiding this comment

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

Returning (bool alreadyDeployed, address accountAddress) is a very nice DevEx from solady :)

@jaypaik jaypaik force-pushed the 03-10-style_consistent_natspec_style branch from 8dac3c6 to 34d89e9 Compare March 12, 2024 22:03
@jaypaik jaypaik force-pushed the 03-10-feat_use_solady_s_minimal_ERC-1967_proxy_and_UUPSUpgradeable branch from fa694c6 to 9836dde Compare March 12, 2024 22:03
@jaypaik jaypaik force-pushed the 03-10-style_consistent_natspec_style branch from 34d89e9 to f37599d Compare March 12, 2024 22:04
@jaypaik jaypaik force-pushed the 03-10-feat_use_solady_s_minimal_ERC-1967_proxy_and_UUPSUpgradeable branch from 9836dde to 775df0e Compare March 12, 2024 22:04
@jaypaik jaypaik force-pushed the 03-10-style_consistent_natspec_style branch from f37599d to e0cb7cf Compare March 13, 2024 06:06
@jaypaik jaypaik force-pushed the 03-10-feat_use_solady_s_minimal_ERC-1967_proxy_and_UUPSUpgradeable branch from 775df0e to 4774a7f Compare March 13, 2024 06:08
Base automatically changed from 03-10-style_consistent_natspec_style to develop March 14, 2024 19:10
@jaypaik jaypaik force-pushed the 03-10-feat_use_solady_s_minimal_ERC-1967_proxy_and_UUPSUpgradeable branch from ab666c3 to b4f2a46 Compare March 14, 2024 19:12
@jaypaik jaypaik merged commit 0849d56 into develop Mar 14, 2024
2 checks passed
@jaypaik jaypaik deleted the 03-10-feat_use_solady_s_minimal_ERC-1967_proxy_and_UUPSUpgradeable branch March 14, 2024 19:15
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.

2 participants