Skip to content

Commit

Permalink
fix: prevent setting bad time ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
howydev committed Nov 9, 2024
1 parent cd5433a commit 5af7561
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 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": "175987",
"Runtime_BatchTransfers": "92985",
"Runtime_Erc20Transfer": "78394",
"Runtime_InstallSessionKey_Case1": "422978",
"Runtime_InstallSessionKey_Case1": "423006",
"Runtime_NativeTransfer": "54543",
"Runtime_UseSessionKey_Case1_Counter": "78606",
"Runtime_UseSessionKey_Case1_Token": "111919",
"UserOp_BatchTransfers": "198297",
"UserOp_Erc20Transfer": "185250",
"UserOp_InstallSessionKey_Case1": "531188",
"UserOp_InstallSessionKey_Case1": "531216",
"UserOp_NativeTransfer": "161531",
"UserOp_UseSessionKey_Case1_Counter": "195236",
"UserOp_UseSessionKey_Case1_Token": "226220",
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": "97701",
"Runtime_BatchTransfers": "88968",
"Runtime_Erc20Transfer": "74425",
"Runtime_InstallSessionKey_Case1": "421527",
"Runtime_InstallSessionKey_Case1": "421555",
"Runtime_NativeTransfer": "50584",
"Runtime_UseSessionKey_Case1_Counter": "78956",
"Runtime_UseSessionKey_Case1_Token": "112269",
"UserOp_BatchTransfers": "193462",
"UserOp_Erc20Transfer": "180498",
"UserOp_InstallSessionKey_Case1": "528708",
"UserOp_InstallSessionKey_Case1": "528736",
"UserOp_NativeTransfer": "156773",
"UserOp_UseSessionKey_Case1_Counter": "195464",
"UserOp_UseSessionKey_Case1_Token": "226460",
Expand Down
3 changes: 3 additions & 0 deletions src/modules/permissions/TimeRangeModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ contract TimeRangeModule is IValidationHookModule, ModuleBase {
/// @param validUntil The timestamp until which the time range is valid, inclusive.
/// @param validAfter The timestamp after which the time range is valid, inclusive.
function setTimeRange(uint32 entityId, uint48 validUntil, uint48 validAfter) public {
if (validUntil <= validAfter) {
revert TimeRangeNotValid();
}
timeRanges[entityId][msg.sender] = TimeRange(validUntil, validAfter);
}

Expand Down
29 changes: 23 additions & 6 deletions test/modules/TimeRangeModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,25 @@ contract TimeRangeModuleTest is CustomValidationTestBase {
assertEq(retrievedValidAfter, 0);
}

function testFuzz_timeRangeModule_userOp(uint48 _validUntil, uint48 _validAfter) public {
validUntil = _validUntil;
validAfter = _validAfter;
function test_timeRangeModule_setBadTime() public withSMATest {
validUntil = 1000;
validAfter = 100;

_customValidationSetup();

vm.startPrank(address(account1));
vm.expectRevert(TimeRangeModule.TimeRangeNotValid.selector);
timeRangeModule.setTimeRange(TEST_DEFAULT_VALIDATION_ENTITY_ID, validUntil, validUntil);

vm.expectRevert(TimeRangeModule.TimeRangeNotValid.selector);
timeRangeModule.setTimeRange(TEST_DEFAULT_VALIDATION_ENTITY_ID, validUntil, validUntil + 1);
vm.stopPrank();
}

function testFuzz_timeRangeModule_userOp(uint48 time1, uint48 time2) public {
vm.assume(time1 != time2);
validUntil = time1 > time2 ? time1 : time2;
validAfter = time1 < time2 ? time1 : time2;

_customValidationSetup();

Expand Down Expand Up @@ -140,9 +156,10 @@ contract TimeRangeModuleTest is CustomValidationTestBase {
);
}

function testFuzz_timeRangeModule_userOp_fail(uint48 _validUntil, uint48 _validAfter) public {
validUntil = _validUntil;
validAfter = _validAfter;
function testFuzz_timeRangeModule_userOp_fail(uint48 time1, uint48 time2) public {
vm.assume(time1 != time2);
validUntil = time1 > time2 ? time1 : time2;
validAfter = time1 < time2 ? time1 : time2;

_customValidationSetup();

Expand Down

0 comments on commit 5af7561

Please sign in to comment.