Skip to content

Commit

Permalink
refactor: [v0.8-develop] 6900 iteration setup (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-alchemy authored Apr 16, 2024
1 parent f6e335c commit cf5355a
Show file tree
Hide file tree
Showing 17 changed files with 1,824 additions and 1,801 deletions.
4 changes: 3 additions & 1 deletion .solhint-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"modifier-name-mixedcase": ["error"],
"private-vars-leading-underscore": ["error"],
"no-inline-assembly": "off",
"avoid-low-level-calls": "off"
"avoid-low-level-calls": "off",
"one-contract-per-file": "off",
"no-empty-blocks": "off"
}
}

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"scripts": {
"lint": "pnpm lint:src && pnpm lint:test",
"lint:src": "solhint -c .solhint-src.json ./src/**/*.sol",
"lint:test": "solhint -c .solhint-test.json ./test/**/*.sol"
"lint:src": "solhint -c .solhint-src.json './src/**/*.sol'",
"lint:test": "solhint -c .solhint-test.json './test/**/*.sol'"
}
}
1,020 changes: 516 additions & 504 deletions src/libraries/AssociatedLinkedListSetLib.sol

Large diffs are not rendered by default.

103 changes: 53 additions & 50 deletions src/libraries/PluginStorageLib.sol
Original file line number Diff line number Diff line change
@@ -1,59 +1,62 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

type StoragePointer is bytes32;
// type StoragePointer is bytes32;

/// @title Plugin Storage Library
/// @notice Library for allocating and accessing ERC-4337 address-associated storage within plugins.
library PluginStorageLib {
/// @notice Allocates a memory buffer for an associated storage key, and sets the associated address and batch
/// index.
/// @param addr The address to associate with the storage key.
/// @param batchIndex The batch index to associate with the storage key.
/// @param keySize The size of the key in words, where each word is 32 bytes. Not inclusive of the address and
/// batch index.
/// @return key The allocated memory buffer.
function allocateAssociatedStorageKey(address addr, uint256 batchIndex, uint8 keySize)
internal
pure
returns (bytes memory key)
{
assembly ("memory-safe") {
// Clear any dirty upper bits of keySize to prevent overflow
keySize := and(keySize, 0xff)
// /// @title Plugin Storage Library
// /// @notice Library for allocating and accessing ERC-4337 address-associated storage within plugins.
// library PluginStorageLib {
// /// @notice Allocates a memory buffer for an associated storage key, and sets the associated address and
// batch
// /// index.
// /// @param addr The address to associate with the storage key.
// /// @param batchIndex The batch index to associate with the storage key.
// /// @param keySize The size of the key in words, where each word is 32 bytes. Not inclusive of the address
// and
// /// batch index.
// /// @return key The allocated memory buffer.
// function allocateAssociatedStorageKey(address addr, uint256 batchIndex, uint8 keySize)
// internal
// pure
// returns (bytes memory key)
// {
// assembly ("memory-safe") {
// // Clear any dirty upper bits of keySize to prevent overflow
// keySize := and(keySize, 0xff)

// compute the total size of the buffer, include the address and batch index
let totalSize := add(64, mul(32, keySize))
// // compute the total size of the buffer, include the address and batch index
// let totalSize := add(64, mul(32, keySize))

// Allocate memory for the key
key := mload(0x40)
mstore(0x40, add(add(key, totalSize), 32))
mstore(key, totalSize)
// // Allocate memory for the key
// key := mload(0x40)
// mstore(0x40, add(add(key, totalSize), 32))
// mstore(key, totalSize)

// Clear any dirty upper bits of address
addr := and(addr, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
// Store the address and batch index in the key buffer
mstore(add(key, 32), addr)
mstore(add(key, 64), batchIndex)
}
}
// // Clear any dirty upper bits of address
// addr := and(addr, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
// // Store the address and batch index in the key buffer
// mstore(add(key, 32), addr)
// mstore(add(key, 64), batchIndex)
// }
// }

function associatedStorageLookup(bytes memory key, bytes32 input) internal pure returns (StoragePointer ptr) {
assembly ("memory-safe") {
mstore(add(key, 96), input)
ptr := keccak256(add(key, 32), mload(key))
}
}
// function associatedStorageLookup(bytes memory key, bytes32 input) internal pure returns (StoragePointer ptr)
// {
// assembly ("memory-safe") {
// mstore(add(key, 96), input)
// ptr := keccak256(add(key, 32), mload(key))
// }
// }

function associatedStorageLookup(bytes memory key, bytes32 input1, bytes32 input2)
internal
pure
returns (StoragePointer ptr)
{
assembly ("memory-safe") {
mstore(add(key, 96), input1)
mstore(add(key, 128), input2)
ptr := keccak256(add(key, 32), mload(key))
}
}
}
// function associatedStorageLookup(bytes memory key, bytes32 input1, bytes32 input2)
// internal
// pure
// returns (StoragePointer ptr)
// {
// assembly ("memory-safe") {
// mstore(add(key, 96), input1)
// mstore(add(key, 128), input2)
// ptr := keccak256(add(key, 32), mload(key))
// }
// }
// }
2 changes: 0 additions & 2 deletions src/plugins/owner/ISingleOwnerPlugin.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.19;

import {UserOperation} from "@eth-infinitism/account-abstraction/interfaces/UserOperation.sol";

interface ISingleOwnerPlugin {
enum FunctionId {
VALIDATION_OWNER_OR_SELF
Expand Down
61 changes: 33 additions & 28 deletions src/plugins/owner/SingleOwnerPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,6 @@ contract SingleOwnerPlugin is BasePlugin, ISingleOwnerPlugin, IERC1271 {
_transferOwnership(newOwner);
}

/// @inheritdoc IERC1271
/// @dev The signature is valid if it is signed by the owner's private key
/// (if the owner is an EOA) or if it is a valid ERC-1271 signature from the
/// owner (if the owner is a contract). Note that unlike the signature
/// validation used in `validateUserOp`, this does///*not** wrap the digest in
/// an "Ethereum Signed Message" envelope before checking the signature in
/// the EOA-owner case.
function isValidSignature(bytes32 digest, bytes memory signature) public view override returns (bytes4) {
if (SignatureChecker.isValidSignatureNow(_owners[msg.sender], digest, signature)) {
return _1271_MAGIC_VALUE;
}
return 0xffffffff;
}

/// @inheritdoc ISingleOwnerPlugin
function owner() external view returns (address) {
return _owners[msg.sender];
}

// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ Plugin view functions ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

/// @inheritdoc ISingleOwnerPlugin
function ownerOf(address account) external view returns (address) {
return _owners[account];
}

// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ Plugin interface functions ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
Expand Down Expand Up @@ -136,6 +108,38 @@ contract SingleOwnerPlugin is BasePlugin, ISingleOwnerPlugin, IERC1271 {
revert NotImplemented();
}

// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ Execution view functions ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

/// @inheritdoc IERC1271
/// @dev The signature is valid if it is signed by the owner's private key
/// (if the owner is an EOA) or if it is a valid ERC-1271 signature from the
/// owner (if the owner is a contract). Note that unlike the signature
/// validation used in `validateUserOp`, this does///*not** wrap the digest in
/// an "Ethereum Signed Message" envelope before checking the signature in
/// the EOA-owner case.
function isValidSignature(bytes32 digest, bytes memory signature) external view override returns (bytes4) {
if (SignatureChecker.isValidSignatureNow(_owners[msg.sender], digest, signature)) {
return _1271_MAGIC_VALUE;
}
return 0xffffffff;
}

/// @inheritdoc ISingleOwnerPlugin
function owner() external view returns (address) {
return _owners[msg.sender];
}

// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ Plugin view functions ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

/// @inheritdoc ISingleOwnerPlugin
function ownerOf(address account) external view returns (address) {
return _owners[account];
}

/// @inheritdoc BasePlugin
function pluginManifest() external pure override returns (PluginManifest memory) {
PluginManifest memory manifest;
Expand Down Expand Up @@ -212,6 +216,7 @@ contract SingleOwnerPlugin is BasePlugin, ISingleOwnerPlugin, IERC1271 {

return metadata;
}

// ┏━━━━━━━━━━━━━━━┓
// ┃ EIP-165 ┃
// ┗━━━━━━━━━━━━━━━┛
Expand Down
Loading

0 comments on commit cf5355a

Please sign in to comment.