Skip to content

Commit

Permalink
Cleanup and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
adamegyed committed Mar 14, 2024
1 parent 2896be7 commit beff739
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/LightAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ contract LightAccount is BaseLightAccount, CustomSlotInitializable {

function _getStorage() internal pure returns (LightAccountStorage storage storageStruct) {
bytes32 position = _STORAGE_POSITION;
assembly {
assembly ("memory-safe") {
storageStruct.slot := position
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/LightAccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ contract LightAccountFactory {
);
}

/// @notice Compute the hash of the owner and salt in scratch space memory.
/// @param owner The owner of the account to be created.
/// @param salt A salt, which can be changed to create multiple accounts with the same owner.
/// @return combinedSalt The hash of the owner and salt.
function _getCombinedSalt(address owner, uint256 salt) internal pure returns (bytes32 combinedSalt) {
// Compute the hash of the owner and salt in scratch space memory.
assembly ("memory-safe") {
mstore(0x00, owner)
mstore(0x20, salt)
Expand Down
4 changes: 2 additions & 2 deletions src/MultiOwnerLightAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ contract MultiOwnerLightAccount is BaseLightAccount, CustomSlotInitializable {
returns (bool)
{
(address recovered, ECDSA.RecoverError error,) = derivedHash.tryRecover(trimmedSignature);
return (error == ECDSA.RecoverError.NoError && _getStorage().owners.contains(CastLib.toSetValue(recovered)))
return (error == ECDSA.RecoverError.NoError && _getStorage().owners.contains(recovered.toSetValue()))
|| _isValidERC1271SignatureNow(derivedHash, trimmedSignature);
}

Expand All @@ -193,7 +193,7 @@ contract MultiOwnerLightAccount is BaseLightAccount, CustomSlotInitializable {

function _getStorage() internal pure returns (LightAccountStorage storage storageStruct) {
bytes32 position = _STORAGE_POSITION;
assembly {
assembly ("memory-safe") {
storageStruct.slot := position
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/MultiOwnerLightAccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ contract MultiOwnerLightAccountFactory {
);
}

/// @notice Compute the hash of the owner and salt in scratch space memory.
/// @param owners The owners of the account to be created.
/// @param salt A salt, which can be changed to create multiple accounts with the same owner.
/// @return combinedSalt The hash of the owner and salt.
function _getCombinedSalt(address[] memory owners, uint256 salt) internal pure returns (bytes32) {
return keccak256(abi.encode(owners, salt));
}
Expand Down
3 changes: 1 addition & 2 deletions src/common/BaseLightAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {UUPSUpgradeable} from "../../ext/solady/UUPSUpgradeable.sol";
import {ERC1271} from "./ERC1271.sol";

abstract contract BaseLightAccount is BaseAccount, TokenCallbackHandler, UUPSUpgradeable, ERC1271 {
bytes4 internal constant _1271_MAGIC_VALUE = bytes4(keccak256("isValidSignature(bytes32,bytes)")); // 0x1626ba7e
IEntryPoint internal immutable _ENTRY_POINT;

/// @dev The length of the array does not match the expected length.
Expand Down Expand Up @@ -109,7 +108,7 @@ abstract contract BaseLightAccount is BaseAccount, TokenCallbackHandler, UUPSUpg
function _call(address target, uint256 value, bytes memory data) internal {
(bool success, bytes memory result) = target.call{value: value}(data);
if (!success) {
assembly {
assembly ("memory-safe") {
revert(add(result, 32), mload(result))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/CustomSlotInitializable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ abstract contract CustomSlotInitializable {

function _getInitializableStorage() private view returns (CustomSlotInitializableStorage storage _storage) {
bytes32 position = _storagePosition;
assembly {
assembly ("memory-safe") {
_storage.slot := position
}
}
Expand Down

0 comments on commit beff739

Please sign in to comment.