-
Notifications
You must be signed in to change notification settings - Fork 7
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: update storage layout of signer #36
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
42f2bb9
feat: update storage layout of signer
r0ohafza e6ac5c1
fix: minor fixes
r0ohafza 1d0ad85
fix: minor fixes
r0ohafza 02b441a
fix: address comments
r0ohafza aeb1ace
fix: address comments
r0ohafza f327640
fix: using MultiSignerLib
r0ohafza aedd881
fix: use global and remove unneeded private functions
r0ohafza de78d0f
fix: use $.isValidSignature
r0ohafza 4b3f279
fix: update isPasskey logic
r0ohafza 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity ^0.8.23; | ||
|
||
/** | ||
* @notice An EOA or Passkey signer. | ||
* | ||
* @dev For a Signer to be valid it has to be either an EOA or a Passkey signer. | ||
* - EOA -> slot2 has to be empty and slot1 has to be a valid address. | ||
* - Passkey -> both slot1 and slot2 have to be non empty. | ||
*/ | ||
struct Signer { | ||
r0ohafza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bytes32 slot1; | ||
bytes32 slot2; | ||
} | ||
|
||
function createSigner(address signer_) pure returns (Signer memory) { | ||
return Signer(bytes32(uint256(uint160(signer_))), bytes32(0)); | ||
} | ||
|
||
function createSigner(uint256 x_, uint256 y_) pure returns (Signer memory) { | ||
return Signer(bytes32(x_), bytes32(y_)); | ||
} | ||
|
||
using SignerLib for Signer global; | ||
|
||
library SignerLib { | ||
/* -------------------------------------------------------------------------- */ | ||
/* CONSTANTS */ | ||
/* -------------------------------------------------------------------------- */ | ||
|
||
bytes32 constant ZERO = bytes32(0); | ||
|
||
/* -------------------------------------------------------------------------- */ | ||
/* FUNCTIONS */ | ||
/* -------------------------------------------------------------------------- */ | ||
|
||
function isEOA(Signer calldata signer_) internal pure returns (bool) { | ||
uint256 slot1 = uint256(bytes32(signer_.slot1)); | ||
return signer_.slot2 == ZERO && slot1 <= type(uint160).max && slot1 > 0; | ||
} | ||
|
||
function isPasskey(Signer calldata signer_) internal pure returns (bool) { | ||
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. According to this Stack Exchange answer the |
||
return signer_.slot1 != ZERO && signer_.slot2 != ZERO; | ||
} | ||
|
||
function isPasskeyMem(Signer memory signer_) internal pure returns (bool) { | ||
return signer_.slot1 != ZERO && signer_.slot2 != ZERO; | ||
} | ||
|
||
function isValid(Signer calldata signer_) internal pure returns (bool) { | ||
r0ohafza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return isEOA(signer_) || isPasskey(signer_); | ||
} | ||
|
||
function isEmpty(Signer calldata signer_) internal pure returns (bool) { | ||
return signer_.slot1 == ZERO && signer_.slot2 == ZERO; | ||
} | ||
|
||
function isEmptyMem(Signer memory signer_) internal pure returns (bool) { | ||
return signer_.slot1 == ZERO && signer_.slot2 == ZERO; | ||
} | ||
} |
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.
According to ERC-7201, the annotation
@custom:storage-location
below this line is ignored when outside of a contract:(Inside the library like it was before it would also be ignored.)
The practical consequence is that tools like OpenZeppelin Upgrades will not consider this struct when analyzing the storage layout of a vault.
A good way to fix this IMO would be to keep the struct here but remove the annotation, and define a new struct specifically for the layout inside the
MultiSigner
contract.The names may need to be reviewed. I see this library as another kind of signer so it may belong in
src/signers/MultiSigner.sol
. As for the contract it could becontract MultiSignerAuth
?