-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: [v0.8-develop] 6900 iteration setup (#43)
- Loading branch information
1 parent
f6e335c
commit cf5355a
Showing
17 changed files
with
1,824 additions
and
1,801 deletions.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -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)) | ||
// } | ||
// } | ||
// } |
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.