Skip to content

Commit

Permalink
Merge branch 'main' into int-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MexicanAce authored Dec 19, 2024
2 parents 94c65c2 + 7923945 commit 7d24cf8
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 89 deletions.
2 changes: 1 addition & 1 deletion src/SsoAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ contract SsoAccount is Initializable, HookManager, ERC1271Handler, TokenCallback
// If there is not enough balance for the transaction, the account should reject it
// on the validation step to prevent paying fees for revertable transactions.
if (_transaction.totalRequiredBalance() > address(this).balance) {
revert Errors.INSUFFICIENT_FUNDS();
revert Errors.INSUFFICIENT_FUNDS(_transaction.totalRequiredBalance(), address(this).balance);
}

// While the suggested signed hash is usually provided, it is generally
Expand Down
2 changes: 1 addition & 1 deletion src/auth/BootloaderAuth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Errors } from "../libraries/Errors.sol";
abstract contract BootloaderAuth {
modifier onlyBootloader() {
if (msg.sender != BOOTLOADER_FORMAL_ADDRESS) {
revert Errors.NOT_FROM_BOOTLOADER();
revert Errors.NOT_FROM_BOOTLOADER(msg.sender);
}
_;
}
Expand Down
2 changes: 1 addition & 1 deletion src/auth/HookAuth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract contract HookAuth {

modifier onlyHook() {
if (!_isHook(msg.sender)) {
revert Errors.NOT_FROM_HOOK();
revert Errors.NOT_FROM_HOOK(msg.sender);
}
_;
}
Expand Down
2 changes: 1 addition & 1 deletion src/auth/SelfAuth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Errors } from "../libraries/Errors.sol";
abstract contract SelfAuth {
modifier onlySelf() {
if (msg.sender != address(this)) {
revert Errors.NOT_FROM_SELF();
revert Errors.NOT_FROM_SELF(msg.sender);
}
_;
}
Expand Down
4 changes: 2 additions & 2 deletions src/batch/BatchCaller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ abstract contract BatchCaller is SelfAuth {
}

if (!_calls[i].allowFailure && !success) {
revert Errors.CALL_FAILED();
revert Errors.CALL_FAILED(i);
}
}

if (totalValue != msg.value) {
revert Errors.MsgValueMismatch(msg.value, totalValue);
revert Errors.MSG_VALUE_MISMATCH(msg.value, totalValue);
}
}
}
51 changes: 18 additions & 33 deletions src/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,66 +6,51 @@ library Errors {
ACCOUNT
//////////////////////////////////////////////////////////////*/

error INSUFFICIENT_FUNDS();
error INSUFFICIENT_FUNDS(uint256 required, uint256 available);
error FEE_PAYMENT_FAILED();
error METHOD_NOT_IMPLEMENTED();

/*//////////////////////////////////////////////////////////////
LINKED LIST
//////////////////////////////////////////////////////////////*/

error INVALID_PREV();
error INVALID_PREV_BYTES(bytes prevValue, bytes oldValue);
error INVALID_PREV_ADDR(address prevValue, address oldValue);
// Bytes
error INVALID_BYTES();
error BYTES_ALREADY_EXISTS();
error BYTES_NOT_EXISTS();
error INVALID_BYTES(uint256 length);
error BYTES_ALREADY_EXISTS(bytes length);
error BYTES_NOT_EXISTS(bytes lookup);
// Address
error INVALID_ADDRESS();
error ADDRESS_ALREADY_EXISTS();
error ADDRESS_NOT_EXISTS();

/*//////////////////////////////////////////////////////////////
OWNER MANAGER
//////////////////////////////////////////////////////////////*/

error INVALID_PUBKEY_LENGTH();
error INVALID_ADDRESS(address valid);
error ADDRESS_ALREADY_EXISTS(address exists);
error ADDRESS_NOT_EXISTS(address notExists);

/*//////////////////////////////////////////////////////////////
VALIDATOR MANAGER
//////////////////////////////////////////////////////////////*/

error VALIDATOR_ERC165_FAIL();
error VALIDATOR_ERC165_FAIL(address validator);

/*//////////////////////////////////////////////////////////////
HOOK MANAGER
//////////////////////////////////////////////////////////////*/

error EMPTY_HOOK_ADDRESS();
error HOOK_ERC165_FAIL();
error INVALID_KEY();

/*//////////////////////////////////////////////////////////////
MODULE MANAGER
//////////////////////////////////////////////////////////////*/

error EMPTY_MODULE_ADDRESS();
error RECURSIVE_MODULE_CALL();
error MODULE_ERC165_FAIL();
error EMPTY_HOOK_ADDRESS(uint256 hookAndDataLength);
error HOOK_ERC165_FAIL(address hookAddress, bool isValidation);
error INVALID_KEY(bytes32 key);

/*//////////////////////////////////////////////////////////////
AUTH
//////////////////////////////////////////////////////////////*/

error NOT_FROM_BOOTLOADER();
error NOT_FROM_MODULE();
error NOT_FROM_HOOK();
error NOT_FROM_SELF();
error NOT_FROM_SELF_OR_MODULE();
error NOT_FROM_BOOTLOADER(address notBootloader);
error NOT_FROM_HOOK(address notHook);
error NOT_FROM_SELF(address notSelf);

/*//////////////////////////////////////////////////////////////
BatchCaller
//////////////////////////////////////////////////////////////*/

error CALL_FAILED();
error MsgValueMismatch(uint256 actualValue, uint256 expectedValue);
error CALL_FAILED(uint256 batchCallIndex);
error MSG_VALUE_MISMATCH(uint256 actualValue, uint256 expectedValue);
}
17 changes: 0 additions & 17 deletions src/libraries/JsmnSolLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -334,23 +334,6 @@ library JsmnSolLib {
return mint;
}
function uint2str(uint256 i) internal pure returns (string memory) {
if (i == 0) return "0";
uint256 j = i;
uint256 len;
while (j != 0) {
len++;
j /= 10;
}
bytes memory bstr = new bytes(len);
uint256 k = len - 1;
while (i != 0) {
bstr[k--] = bytes1(uint8(48 + (i % 10)));
i /= 10;
}
return string(bstr);
}
function parseBool(string memory _a) internal pure returns (bool) {
if (strCompare(_a, "true") == 0) {
return true;
Expand Down
40 changes: 20 additions & 20 deletions src/libraries/LinkedList.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ library BytesLinkedList {

modifier validBytes(bytes calldata value) {
if (value.length <= SENTINEL_LENGTH) {
revert Errors.INVALID_BYTES();
revert Errors.INVALID_BYTES(value.length);
}
_;
}

function add(mapping(bytes => bytes) storage self, bytes calldata value) internal validBytes(value) {
if (self[value].length != 0) {
revert Errors.BYTES_ALREADY_EXISTS();
revert Errors.BYTES_ALREADY_EXISTS(self[value]);
}

bytes memory prev = self[SENTINEL_BYTES];
Expand All @@ -36,10 +36,10 @@ library BytesLinkedList {

function replace(mapping(bytes => bytes) storage self, bytes calldata oldValue, bytes calldata newValue) internal {
if (!exists(self, oldValue)) {
revert Errors.BYTES_NOT_EXISTS();
revert Errors.BYTES_NOT_EXISTS(oldValue);
}
if (exists(self, newValue)) {
revert Errors.BYTES_ALREADY_EXISTS();
revert Errors.BYTES_ALREADY_EXISTS(newValue);
}

bytes memory cursor = SENTINEL_BYTES;
Expand All @@ -63,13 +63,13 @@ library BytesLinkedList {
bytes calldata newValue
) internal {
if (!exists(self, oldValue)) {
revert Errors.BYTES_NOT_EXISTS();
revert Errors.BYTES_NOT_EXISTS(oldValue);
}
if (exists(self, newValue)) {
revert Errors.BYTES_ALREADY_EXISTS();
revert Errors.BYTES_ALREADY_EXISTS(newValue);
}
if (!equals(self[prevValue], oldValue)) {
revert Errors.INVALID_PREV();
revert Errors.INVALID_PREV_BYTES(self[prevValue], oldValue);
}

self[newValue] = self[oldValue];
Expand All @@ -79,7 +79,7 @@ library BytesLinkedList {

function remove(mapping(bytes => bytes) storage self, bytes calldata value) internal {
if (!exists(self, value)) {
revert Errors.BYTES_NOT_EXISTS();
revert Errors.BYTES_NOT_EXISTS(value);
}

bytes memory cursor = SENTINEL_BYTES;
Expand All @@ -101,10 +101,10 @@ library BytesLinkedList {
bytes calldata value
) internal {
if (!exists(self, value)) {
revert Errors.BYTES_NOT_EXISTS();
revert Errors.BYTES_NOT_EXISTS(value);
}
if (!equals(self[prevValue], value)) {
revert Errors.INVALID_PREV();
revert Errors.INVALID_PREV_BYTES(self[prevValue], value);
}

self[prevValue] = self[value];
Expand Down Expand Up @@ -175,14 +175,14 @@ library AddressLinkedList {

modifier validAddress(address value) {
if (value <= SENTINEL_ADDRESS) {
revert Errors.INVALID_ADDRESS();
revert Errors.INVALID_ADDRESS(value);
}
_;
}

function add(mapping(address => address) storage self, address value) internal validAddress(value) {
if (self[value] != address(0)) {
revert Errors.ADDRESS_ALREADY_EXISTS();
revert Errors.ADDRESS_ALREADY_EXISTS(value);
}

address prev = self[SENTINEL_ADDRESS];
Expand All @@ -197,10 +197,10 @@ library AddressLinkedList {

function replace(mapping(address => address) storage self, address oldValue, address newValue) internal {
if (!exists(self, oldValue)) {
revert Errors.ADDRESS_NOT_EXISTS();
revert Errors.ADDRESS_NOT_EXISTS(oldValue);
}
if (exists(self, newValue)) {
revert Errors.ADDRESS_ALREADY_EXISTS();
revert Errors.ADDRESS_ALREADY_EXISTS(newValue);
}

address cursor = SENTINEL_ADDRESS;
Expand All @@ -224,13 +224,13 @@ library AddressLinkedList {
address newValue
) internal {
if (!exists(self, oldValue)) {
revert Errors.ADDRESS_NOT_EXISTS();
revert Errors.ADDRESS_NOT_EXISTS(oldValue);
}
if (exists(self, newValue)) {
revert Errors.ADDRESS_ALREADY_EXISTS();
revert Errors.ADDRESS_ALREADY_EXISTS(newValue);
}
if (self[prevValue] != oldValue) {
revert Errors.INVALID_PREV();
revert Errors.INVALID_PREV_ADDR(self[prevValue], oldValue);
}

self[newValue] = self[oldValue];
Expand All @@ -240,7 +240,7 @@ library AddressLinkedList {

function remove(mapping(address => address) storage self, address value) internal {
if (!exists(self, value)) {
revert Errors.ADDRESS_NOT_EXISTS();
revert Errors.ADDRESS_NOT_EXISTS(value);
}

address cursor = SENTINEL_ADDRESS;
Expand All @@ -258,10 +258,10 @@ library AddressLinkedList {

function removeUsingPrev(mapping(address => address) storage self, address prevValue, address value) internal {
if (!exists(self, value)) {
revert Errors.ADDRESS_NOT_EXISTS();
revert Errors.ADDRESS_NOT_EXISTS(value);
}
if (self[prevValue] != value) {
revert Errors.INVALID_PREV();
revert Errors.INVALID_PREV_ADDR(self[prevValue], value);
}

self[prevValue] = self[value];
Expand Down
6 changes: 3 additions & 3 deletions src/managers/HookManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ abstract contract HookManager is IHookManager, Auth {
/// @inheritdoc IHookManager
function setHookData(bytes32 key, bytes calldata data) external override onlyHook {
if (key == CONTEXT_KEY) {
revert Errors.INVALID_KEY();
revert Errors.INVALID_KEY(key);
}

_hookDataStore()[msg.sender][key] = data;
Expand Down Expand Up @@ -161,7 +161,7 @@ abstract contract HookManager is IHookManager, Auth {

function _addHook(bytes calldata hookAndData, bool isValidation) internal {
if (hookAndData.length < 20) {
revert Errors.EMPTY_HOOK_ADDRESS();
revert Errors.EMPTY_HOOK_ADDRESS(hookAndData.length);
}

address hookAddress = address(bytes20(hookAndData[0:20]));
Expand All @@ -173,7 +173,7 @@ abstract contract HookManager is IHookManager, Auth {

function _installHook(address hookAddress, bytes memory initData, bool isValidation) internal {
if (!_supportsHook(hookAddress, isValidation)) {
revert Errors.HOOK_ERC165_FAIL();
revert Errors.HOOK_ERC165_FAIL(hookAddress, isValidation);
}

if (isValidation) {
Expand Down
2 changes: 1 addition & 1 deletion src/managers/ValidatorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ abstract contract ValidatorManager is IValidatorManager, Auth {

function _addModuleValidator(address validator, bytes memory accountValidationKey) internal {
if (!_supportsModuleValidator(validator)) {
revert Errors.VALIDATOR_ERC165_FAIL();
revert Errors.VALIDATOR_ERC165_FAIL(validator);
}

_moduleValidatorsLinkedList().add(validator);
Expand Down
Loading

0 comments on commit 7d24cf8

Please sign in to comment.