-
Notifications
You must be signed in to change notification settings - Fork 10
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
check and update two slots #87
Merged
livingrockrises
merged 6 commits into
dev
from
feat/manage-multiple-implementation-slots
Jun 2, 2024
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
26d92e5
check and update two slots
livingrockrises 9a91b01
respond to PR comments
livingrockrises 32d5bd9
Merge branch 'dev' into feat/manage-multiple-implementation-slots
Aboudjem ef7c414
negative test cases
livingrockrises 3a2a610
Merge branch 'feat/manage-multiple-implementation-slots' of https://g…
livingrockrises 2fc766e
negative test + refactor
livingrockrises File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,6 +237,20 @@ | |
return IValidator(validator).isValidSignatureWithSender(msg.sender, computeHash, truncatedSignature); | ||
} | ||
|
||
/// @notice Retrieves the address of the current implementation from the EIP-1967 slot. | ||
/// @notice Checks the 1967 implementation slot, if not found then checks the slot defined by address (Biconomy V2 smart account) | ||
/// @return implementation The address of the current contract implementation. | ||
function getImplementation() external view returns (address implementation) { | ||
assembly { | ||
implementation := sload(_ERC1967_IMPLEMENTATION_SLOT) | ||
} | ||
if(implementation == address(0)) { | ||
assembly { | ||
implementation := sload(address()) | ||
} | ||
} | ||
} | ||
|
||
/// @notice Checks if a specific module type is supported by this smart account. | ||
/// @param moduleTypeId The identifier of the module type to check. | ||
/// @return True if the module type is supported, false otherwise. | ||
|
@@ -285,9 +299,20 @@ | |
} | ||
|
||
/// Upgrades the contract to a new implementation and calls a function on the new contract. | ||
/// @notice Updates two slots 1. 1967 slot and 2. address() slot in case if it's upgraded earlier from Biconomy V2 account. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...as Biconomy v2 Account (proxy) reads implementation from the slot that is defined by its address. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
/// @param newImplementation The address of the new contract implementation. | ||
/// @param data The calldata to be sent to the new implementation. | ||
function upgradeToAndCall(address newImplementation, bytes calldata data) public payable virtual override { | ||
function upgradeToAndCall(address newImplementation, bytes calldata data) public payable virtual override onlyEntryPointOrSelf { | ||
if(newImplementation == address(0)) revert InvalidImplementationAddress(); | ||
bool res; | ||
assembly { | ||
res := gt(extcodesize(newImplementation), 0) | ||
} | ||
if(res == false) revert InvalidImplementationAddress(); | ||
// update the address() storage slot as well. | ||
assembly { | ||
sstore(address(), newImplementation) | ||
} | ||
UUPSUpgradeable.upgradeToAndCall(newImplementation, data); | ||
} | ||
|
||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
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.
what is this magic?
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.
which line?
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.
address()
opcode returns the same asaddress(this)
so the contract's address is used as number of the storage slot (it is converted to bytes32) to store the address of the implementation
so this line loads it from storage using the opcode to obtain the slot where the implementation address is stored.
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.
yup,
https://github.com/bcnmy/scw-contracts/blob/main/contracts/smart-account/Proxy.sol#L23