Skip to content

Commit

Permalink
fix: [ALCHEMY-010] event emissions (006, 007, 008) (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypaik authored Nov 25, 2024
1 parent 74bd948 commit 95c8b99
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 21 deletions.
4 changes: 2 additions & 2 deletions gas-snapshots/ModularAccount.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"Runtime_AccountCreation": "176354",
"Runtime_BatchTransfers": "92886",
"Runtime_Erc20Transfer": "78318",
"Runtime_InstallSessionKey_Case1": "423362",
"Runtime_InstallSessionKey_Case1": "429789",
"Runtime_NativeTransfer": "54467",
"Runtime_UseSessionKey_Case1_Counter": "78531",
"Runtime_UseSessionKey_Case1_Token": "111844",
"UserOp_BatchTransfers": "197706",
"UserOp_Erc20Transfer": "184680",
"UserOp_InstallSessionKey_Case1": "531042",
"UserOp_InstallSessionKey_Case1": "537469",
"UserOp_NativeTransfer": "160925",
"UserOp_UseSessionKey_Case1_Counter": "194415",
"UserOp_UseSessionKey_Case1_Token": "225399",
Expand Down
4 changes: 2 additions & 2 deletions gas-snapshots/SemiModularAccount.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"Runtime_AccountCreation": "97767",
"Runtime_BatchTransfers": "88758",
"Runtime_Erc20Transfer": "74238",
"Runtime_InstallSessionKey_Case1": "421513",
"Runtime_InstallSessionKey_Case1": "427940",
"Runtime_NativeTransfer": "50397",
"Runtime_UseSessionKey_Case1_Counter": "78834",
"Runtime_UseSessionKey_Case1_Token": "112147",
"UserOp_BatchTransfers": "192875",
"UserOp_Erc20Transfer": "179932",
"UserOp_InstallSessionKey_Case1": "528315",
"UserOp_InstallSessionKey_Case1": "534742",
"UserOp_NativeTransfer": "156207",
"UserOp_UseSessionKey_Case1_Counter": "194667",
"UserOp_UseSessionKey_Case1_Token": "225651",
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/ExecutionInstallDelegate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract ExecutionInstallDelegate {

address internal immutable _THIS_ADDRESS;

error Erc4337FunctionNotAllowed(bytes4 selector);
error ERC4337FunctionNotAllowed(bytes4 selector);
error ExecutionFunctionAlreadySet(bytes4 selector);
error ExecutionFunctionNotSet(bytes4 selector);
error ExecutionHookNotSet(HookConfig hookConfig);
Expand Down Expand Up @@ -155,8 +155,8 @@ contract ExecutionInstallDelegate {
// Also make sure it doesn't collide with functions defined by ERC-4337 and called by the entry point. This
// prevents a malicious module from sneaking in a function with the same selector as e.g.
// `validatePaymasterUserOp` and turning the account into their own personal paymaster.
if (KnownSelectorsLib.isErc4337Function(uint32(selector))) {
revert Erc4337FunctionNotAllowed(selector);
if (KnownSelectorsLib.isERC4337Function(uint32(selector))) {
revert ERC4337FunctionNotAllowed(selector);
}

_executionStorage.module = module;
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/KnownSelectorsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ library KnownSelectorsLib {
/// @notice Check if a selector is an ERC-4337 function.
/// @param selector The selector to check.
/// @return True if the selector is an ERC-4337 function, false otherwise.
function isErc4337Function(uint32 selector) internal pure returns (bool) {
function isERC4337Function(uint32 selector) internal pure returns (bool) {
return selector == uint32(IAggregator.validateSignatures.selector)
|| selector == uint32(IAggregator.validateUserOpSignature.selector)
|| selector == uint32(IAggregator.aggregateSignatures.selector)
Expand Down
13 changes: 8 additions & 5 deletions src/modules/permissions/AllowlistModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,20 @@ contract AllowlistModule is IExecutionHookModule, IValidationHookModule, ModuleB
event AddressAllowlistUpdated(
uint32 indexed entityId, address indexed account, address indexed target, AddressAllowlistEntry entry
);
event ERC20SpendLimitUpdated(
uint32 indexed entityId, address indexed account, address indexed token, uint256 newLimit
);
event SelectorAllowlistUpdated(
uint32 indexed entityId, address indexed account, bytes24 indexed targetAndSelector, bool allowed
);

error AddressNotAllowed();
error SelectorNotAllowed();
error NoSelectorSpecified();
error ExceededTokenLimit();
error SpendingRequestNotAllowed(bytes4);
error ERC20NotAllowed(address);
error ExceededTokenLimit();
error InvalidCalldataLength();
error NoSelectorSpecified();
error SelectorNotAllowed();
error SpendingRequestNotAllowed(bytes4);

/// @inheritdoc IModule
/// @dev The `data` parameter is expected to be encoded as `(uint32 entityId, AllowlistInput[] inputs)`.
Expand Down Expand Up @@ -185,9 +188,9 @@ contract AllowlistModule is IExecutionHookModule, IValidationHookModule, ModuleB
if (token == address(0)) {
revert ERC20NotAllowed(address(0));
}

addressAllowlist[entityId][token][msg.sender].hasERC20SpendLimit = hasERC20SpendLimit;
erc20SpendLimits[entityId][token][msg.sender] = newLimit;
emit ERC20SpendLimitUpdated(entityId, msg.sender, token, newLimit);
}

/// @notice update the allowlists for a given entity ID. If the entry for an address or selector exist, it will
Expand Down
5 changes: 5 additions & 0 deletions src/modules/permissions/NativeTokenLimitModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ contract NativeTokenLimitModule is ModuleBase, IExecutionHookModule, IValidation
// paymasters given permissions to pull funds from accounts should be added here
mapping(address paymaster => mapping(address account => bool allowed)) public specialPaymasters;

event NativeTokenSpendLimitUpdated(uint32 indexed entityId, address indexed account, uint256 newLimit);
event SpecialPaymasterUpdated(address indexed account, address indexed paymaster, bool allowed);

error ExceededNativeTokenLimit();
error InvalidPaymaster();

Expand All @@ -52,13 +55,15 @@ contract NativeTokenLimitModule is ModuleBase, IExecutionHookModule, IValidation
/// @param newLimit The new limit
function updateLimits(uint32 entityId, uint256 newLimit) external {
limits[entityId][msg.sender] = newLimit;
emit NativeTokenSpendLimitUpdated(entityId, msg.sender, newLimit);
}

/// @notice Update special paymasters that should still decrease the limit of an account
/// @param paymaster The paymaster address
/// @param allowed Whether the paymaster is allowed to pull funds from the account
function updateSpecialPaymaster(address paymaster, bool allowed) external {
specialPaymasters[paymaster][msg.sender] = allowed;
emit SpecialPaymasterUpdated(msg.sender, paymaster, allowed);
}

/// @inheritdoc IValidationHookModule
Expand Down
4 changes: 3 additions & 1 deletion src/modules/permissions/TimeRangeModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ contract TimeRangeModule is IValidationHookModule, ModuleBase {

mapping(uint32 entityId => mapping(address account => TimeRange)) public timeRanges;

event TimeRangeSet(uint32 indexed entityId, address indexed account, uint48 validUntil, uint48 validAfter);

error TimeRangeNotValid();

/// @inheritdoc IModule
Expand Down Expand Up @@ -120,8 +122,8 @@ contract TimeRangeModule is IValidationHookModule, ModuleBase {
} else if (validUntil <= validAfter) {
revert TimeRangeNotValid();
}

timeRanges[entityId][msg.sender] = TimeRange(validUntil, validAfter);
emit TimeRangeSet(entityId, msg.sender, validUntil, validAfter);
}

/// @inheritdoc IERC165
Expand Down
14 changes: 7 additions & 7 deletions test/libraries/KnownSelectorsLib.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import {Test} from "forge-std/Test.sol";
import {KnownSelectorsLib} from "../../src/libraries/KnownSelectorsLib.sol";

contract KnownSelectorsLibTest is Test {
function test_isErc4337Function() public pure {
assertTrue(KnownSelectorsLib.isErc4337Function(uint32(IAggregator.validateSignatures.selector)));
assertTrue(KnownSelectorsLib.isErc4337Function(uint32(IAggregator.validateUserOpSignature.selector)));
assertTrue(KnownSelectorsLib.isErc4337Function(uint32(IAggregator.aggregateSignatures.selector)));
assertTrue(KnownSelectorsLib.isErc4337Function(uint32(IPaymaster.validatePaymasterUserOp.selector)));
assertTrue(KnownSelectorsLib.isErc4337Function(uint32(IPaymaster.postOp.selector)));
function test_isERC4337Function() public pure {
assertTrue(KnownSelectorsLib.isERC4337Function(uint32(IAggregator.validateSignatures.selector)));
assertTrue(KnownSelectorsLib.isERC4337Function(uint32(IAggregator.validateUserOpSignature.selector)));
assertTrue(KnownSelectorsLib.isERC4337Function(uint32(IAggregator.aggregateSignatures.selector)));
assertTrue(KnownSelectorsLib.isERC4337Function(uint32(IPaymaster.validatePaymasterUserOp.selector)));
assertTrue(KnownSelectorsLib.isERC4337Function(uint32(IPaymaster.postOp.selector)));

assertFalse(KnownSelectorsLib.isErc4337Function(uint32(IAccount.validateUserOp.selector)));
assertFalse(KnownSelectorsLib.isERC4337Function(uint32(IAccount.validateUserOp.selector)));
}

function test_isIModuleFunction() public pure {
Expand Down

0 comments on commit 95c8b99

Please sign in to comment.