Skip to content
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

chore: update the repo with the latest changes #66

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
"@openzeppelin/contracts": "5.0.2",
"@openzeppelin/contracts-upgradeable": "5.0.2",
"fcl": "github:rdubois-crypto/FreshCryptoLib#8179e08cac72072bd260796633fec41fdfd5b441",
"forge-std": "github:foundry-rs/forge-std#v1.9.2",
"forge-std": "github:foundry-rs/forge-std#v1.9.5",
"solady": "0.0.243",
"@erc6900/reference-implementation": "github:erc6900/reference-implementation#v0.8.0-rc.6"
"@erc6900/reference-implementation": "github:erc6900/reference-implementation#v0.8.0"
},
"devDependencies": {
"solhint": "^5.0.3"
"solhint": "^5.0.5"
},
"directories": {
"test": "test"
Expand Down
44 changes: 0 additions & 44 deletions script/011_DeployTokenCallbackPlugin.s.sol

This file was deleted.

2 changes: 2 additions & 0 deletions src/common/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ error UnauthorizedCaller();
error InvalidLength();

error Unsupported();

error InvalidPublicKey(uint256 x, uint256 y);
13 changes: 10 additions & 3 deletions src/libs/PublicKeyLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@
pragma solidity 0.8.24;

import {PublicKey} from "../common/CommonStructs.sol";
import {InvalidPublicKey} from "../common/Errors.sol";

/**
* @dev Util functions for public key.
*/
library PublicKeyLib {
error InvalidPublicKey(uint256 x, uint256 y);

function toBytes30(uint256 x, uint256 y) internal pure returns (bytes30) {
// (0, 0) is point at infinity and not on the curve and should therefore be rejected
if (x == 0 && y == 0) {
if (!isValidPublicKey(x, y)) {
revert InvalidPublicKey(x, y);
}
return bytes30(uint240(uint256(keccak256(abi.encode(x, y)))));
Expand All @@ -40,4 +39,12 @@ library PublicKeyLib {
uint256 y = publicKey.y;
return toBytes30(x, y);
}

function isValidPublicKey(uint256 x, uint256 y) internal pure returns (bool) {
return x != 0 || y != 0;
}

function isValidPublicKey(PublicKey memory publicKey) internal pure returns (bool) {
return publicKey.x != 0 || publicKey.y != 0;
}
}
16 changes: 12 additions & 4 deletions src/msca/6900/shared/erc712/BaseERC712CompliantModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,24 @@ abstract contract BaseERC712CompliantModule {
return MessageHashUtils.toTypedDataHash({
domainSeparator: keccak256(
abi.encode(
_DOMAIN_SEPARATOR_TYPEHASH, _getModuleIdHash(), block.chainid, address(this), bytes32(bytes20(account))
_DOMAIN_SEPARATOR_TYPEHASH,
_getModuleNameHash(),
_getModuleVersionHash(),
block.chainid,
address(this),
bytes32(bytes20(account))
)
),
structHash: keccak256(abi.encode(_getModuleTypeHash(), hash))
});
}

/// @dev Returns the module typehash.
/// @dev Returns the module message typehash.
function _getModuleTypeHash() internal pure virtual returns (bytes32);

/// @dev Returns the module id.
function _getModuleIdHash() internal pure virtual returns (bytes32);
/// @dev Returns the module name hash.
function _getModuleNameHash() internal pure virtual returns (bytes32);

// @dev Returns the module version hash.
function _getModuleVersionHash() internal pure virtual returns (bytes32);
}
24 changes: 11 additions & 13 deletions src/msca/6900/shared/libs/AddressDLLLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ library AddressDLLLib {
* @dev Check if an item exists or not. O(1).
*/
function contains(AddressDLL storage dll, address item) internal view returns (bool) {
return getHead(dll) == item || dll.next[item] != address(0) || dll.prev[item] != address(0);
if (item == SENTINEL_ADDRESS) {
// SENTINEL_ADDRESS is not a valid item
return false;
}
return getHead(dll) == item || dll.next[item] != SENTINEL_ADDRESS || dll.prev[item] != SENTINEL_ADDRESS;
}

/**
Expand Down Expand Up @@ -109,7 +113,7 @@ library AddressDLLLib {
}
address[] memory results = new address[](limit);
address current = start;
if (start == address(0)) {
if (start == SENTINEL_ADDRESS) {
current = getHead(dll);
}
uint256 count = 0;
Expand All @@ -131,17 +135,11 @@ library AddressDLLLib {
function getAll(AddressDLL storage dll) internal view returns (address[] memory results) {
uint256 totalCount = size(dll);
results = new address[](totalCount);
uint256 accumulatedCount = 0;
address startAddr = address(0x0);
for (uint256 i = 0; i < totalCount; ++i) {
(address[] memory currentResults, address nextAddr) = getPaginated(dll, startAddr, 10);
for (uint256 j = 0; j < currentResults.length; ++j) {
results[accumulatedCount++] = currentResults[j];
}
if (nextAddr == SENTINEL_ADDRESS) {
break;
}
startAddr = nextAddr;
address current = getHead(dll);
uint256 count = 0;
for (; count < totalCount && uint160(current) > SENTINEL_ADDRESS_UINT; ++count) {
results[count] = current;
current = dll.next[current];
}
return results;
}
Expand Down
20 changes: 9 additions & 11 deletions src/msca/6900/shared/libs/Bytes32DLLLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ library Bytes32DLLLib {
* @dev Check if an item exists or not. O(1).
*/
function contains(Bytes32DLL storage dll, bytes32 item) internal view returns (bool) {
if (item == SENTINEL_BYTES32) {
// SENTINEL_BYTES32 is not a valid item
return false;
}
return getHead(dll) == item || dll.next[item] != SENTINEL_BYTES32 || dll.prev[item] != SENTINEL_BYTES32;
}

Expand Down Expand Up @@ -121,17 +125,11 @@ library Bytes32DLLLib {
function getAll(Bytes32DLL storage dll) internal view returns (bytes32[] memory results) {
uint256 totalCount = size(dll);
results = new bytes32[](totalCount);
uint256 accumulatedCount = 0;
bytes32 start = SENTINEL_BYTES32;
for (uint256 i = 0; i < totalCount; ++i) {
(bytes32[] memory currentResults, bytes32 next) = getPaginated(dll, start, 10);
for (uint256 j = 0; j < currentResults.length; ++j) {
results[accumulatedCount++] = currentResults[j];
}
if (next == SENTINEL_BYTES32) {
break;
}
start = next;
bytes32 current = getHead(dll);
uint256 count = 0;
for (; count < totalCount && current > SENTINEL_BYTES32; ++count) {
results[count] = current;
current = dll.next[current];
}
return results;
}
Expand Down
20 changes: 9 additions & 11 deletions src/msca/6900/shared/libs/Bytes4DLLLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ library Bytes4DLLLib {
* @dev Check if an item exists or not. O(1).
*/
function contains(Bytes4DLL storage dll, bytes4 item) internal view returns (bool) {
if (item == SENTINEL_BYTES4) {
// SENTINEL_BYTES4 is not a valid item
return false;
}
return getHead(dll) == item || dll.next[item] != bytes4(0) || dll.prev[item] != bytes4(0);
}

Expand Down Expand Up @@ -123,17 +127,11 @@ library Bytes4DLLLib {
function getAll(Bytes4DLL storage dll) internal view returns (bytes4[] memory results) {
uint256 totalCount = size(dll);
results = new bytes4[](totalCount);
uint256 accumulatedCount = 0;
bytes4 startVal = bytes4(0x0);
for (uint256 i = 0; i < totalCount; ++i) {
(bytes4[] memory currentResults, bytes4 nextVal) = getPaginated(dll, startVal, 10);
for (uint256 j = 0; j < currentResults.length; ++j) {
results[accumulatedCount++] = currentResults[j];
}
if (nextVal == SENTINEL_BYTES4) {
break;
}
startVal = nextVal;
bytes4 current = getHead(dll);
uint256 count = 0;
for (; count < totalCount && current > SENTINEL_BYTES4; ++count) {
results[count] = current;
current = dll.next[current];
}
return results;
}
Expand Down
26 changes: 21 additions & 5 deletions src/msca/6900/shared/libs/ValidationDataLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ library ValidationDataLib {
error WrongTimeBounds();

/**
* @dev Intercept the time bounds [validAfter, validUntil], as well as signature validation result (favoring the
* failure).
* @dev Intercept the time bounds `[validAfter, validUntil]` and the signature validation result,
* prioritizing the invalid authorizer (`!=0 && !=1`), followed by prioritizing failure (`==1`),
* and finally returning success (`==0`). Please note that both `authorizer(2)` and `authorizer(3)` are invalid,
* and calling this function with `(2, 3)` ensures that only one invalid authorizer will be returned.
* @notice address(0) is a successful validation, address(1) is a failed validation,
* and address(2), address(3) and others are invalid authorizers (also failed).
*/
function _intersectValidationData(ValidationData memory a, uint256 uintb)
internal
Expand All @@ -40,10 +44,16 @@ library ValidationDataLib {
revert WrongTimeBounds();
}
// 0 is successful validation
if (a.authorizer == address(0)) {
if (!_isValidAuthorizer(a.authorizer)) {
validationData.authorizer = a.authorizer;
} else if (!_isValidAuthorizer(b.authorizer)) {
validationData.authorizer = b.authorizer;
} else {
validationData.authorizer = a.authorizer;
if (a.authorizer == address(0)) {
validationData.authorizer = b.authorizer;
} else {
validationData.authorizer = a.authorizer;
}
}
if (a.validAfter > b.validAfter) {
validationData.validAfter = a.validAfter;
Expand All @@ -56,7 +66,9 @@ library ValidationDataLib {
validationData.validUntil = b.validUntil;
}
// make sure the caller (e.g. entryPoint) reverts
if (validationData.validAfter >= validationData.validUntil) {
// set to address(1) if and only if the authorizer is address(0) (successful validation)
// we don't want to set to address(1) if the authorizer is invalid such as address(2)
if (validationData.validAfter >= validationData.validUntil && validationData.authorizer == address(0)) {
validationData.authorizer = address(1);
}
return validationData;
Expand All @@ -82,4 +94,8 @@ library ValidationDataLib {
function _packValidationData(ValidationData memory data) internal pure returns (uint256) {
return uint160(data.authorizer) | (uint256(data.validUntil) << 160) | (uint256(data.validAfter) << (160 + 48));
}

function _isValidAuthorizer(address authorizer) internal pure returns (bool) {
return authorizer == address(0) || authorizer == address(1);
}
}
3 changes: 3 additions & 0 deletions src/msca/6900/v0.7/account/BaseMSCA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ abstract contract BaseMSCA is
/// If there's no plugin associated with this function selector, revert
// solhint-disable-next-line no-complex-fallback
fallback(bytes calldata) external payable returns (bytes memory result) {
if (msg.data.length < 4) {
revert NotFoundSelector();
}
// run runtime validation before we load the executionDetail because validation may update account state
if (msg.sender != address(ENTRY_POINT)) {
// ENTRY_POINT should go through validateUserOp flow which calls userOpValidationFunction
Expand Down
22 changes: 9 additions & 13 deletions src/msca/6900/v0.7/libs/FunctionReferenceDLLLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
pragma solidity 0.8.24;

import {EMPTY_FUNCTION_REFERENCE, SENTINEL_BYTES21} from "../../../../common/Constants.sol";
import {SENTINEL_BYTES21} from "../../../../common/Constants.sol";
import {
InvalidFunctionReference, InvalidLimit, ItemAlreadyExists, ItemDoesNotExist
} from "../../shared/common/Errors.sol";
Expand Down Expand Up @@ -48,6 +48,9 @@ library FunctionReferenceDLLLib {
}

function contains(Bytes21DLL storage dll, bytes21 item) internal view returns (bool) {
if (item == SENTINEL_BYTES21) {
return false;
}
return getHeadWithoutUnpack(dll) == item || dll.next[item] != SENTINEL_BYTES21
|| dll.prev[item] != SENTINEL_BYTES21;
}
Expand Down Expand Up @@ -143,18 +146,11 @@ library FunctionReferenceDLLLib {
function getAll(Bytes21DLL storage dll) internal view returns (FunctionReference[] memory results) {
uint256 totalCount = size(dll);
results = new FunctionReference[](totalCount);
uint256 accumulatedCount = 0;
FunctionReference memory startFR = EMPTY_FUNCTION_REFERENCE.unpack();
for (uint256 i = 0; i < totalCount; ++i) {
(FunctionReference[] memory currentResults, FunctionReference memory nextFR) =
getPaginated(dll, startFR, 10);
for (uint256 j = 0; j < currentResults.length; ++j) {
results[accumulatedCount++] = currentResults[j];
}
if (nextFR.pack() == SENTINEL_BYTES21) {
break;
}
startFR = nextFR;
bytes21 current = getHeadWithoutUnpack(dll);
uint256 count = 0;
for (; count < totalCount && current > SENTINEL_BYTES21; ++count) {
results[count] = current.unpack();
current = dll.next[current];
}
return results;
}
Expand Down
22 changes: 8 additions & 14 deletions src/msca/6900/v0.7/libs/RepeatableFunctionReferenceDLLLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
pragma solidity 0.8.24;

import {EMPTY_FUNCTION_REFERENCE, SENTINEL_BYTES21} from "../../../../common/Constants.sol";
import {SENTINEL_BYTES21} from "../../../../common/Constants.sol";
import {InvalidFunctionReference, InvalidLimit, ItemDoesNotExist} from "../../shared/common/Errors.sol";
import {FunctionReference, RepeatableBytes21DLL} from "../common/Structs.sol";
import {FunctionReferenceLib} from "./FunctionReferenceLib.sol";
Expand Down Expand Up @@ -49,7 +49,8 @@ library RepeatableFunctionReferenceDLLLib {
{
bytes21 item = fr.pack();
if (item == SENTINEL_BYTES21) {
return 1;
// sentinel should not considered as the value of the list
return 0;
}
return dll.counter[item];
}
Expand Down Expand Up @@ -191,18 +192,11 @@ library RepeatableFunctionReferenceDLLLib {
function getAll(RepeatableBytes21DLL storage dll) internal view returns (FunctionReference[] memory results) {
uint256 totalUniqueCount = getUniqueItems(dll);
results = new FunctionReference[](totalUniqueCount);
uint256 accumulatedCount = 0;
FunctionReference memory startFR = EMPTY_FUNCTION_REFERENCE.unpack();
for (uint256 i = 0; i < totalUniqueCount; ++i) {
(FunctionReference[] memory currentResults, FunctionReference memory nextFR) =
getPaginated(dll, startFR, 10);
for (uint256 j = 0; j < currentResults.length; ++j) {
results[accumulatedCount++] = currentResults[j];
}
if (nextFR.pack() == SENTINEL_BYTES21) {
break;
}
startFR = nextFR;
bytes21 current = getHeadWithoutUnpack(dll);
uint256 count = 0;
for (; count < totalUniqueCount && current > SENTINEL_BYTES21; ++count) {
results[count] = current.unpack();
current = dll.next[current];
}
return results;
}
Expand Down
Loading
Loading