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

fix: [QS-12] prevent setting bad time ranges #286

Merged
merged 1 commit into from
Nov 14, 2024
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
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": "176125",
"Runtime_BatchTransfers": "92985",
"Runtime_Erc20Transfer": "78394",
"Runtime_InstallSessionKey_Case1": "423008",
"Runtime_InstallSessionKey_Case1": "423036",
"Runtime_NativeTransfer": "54543",
"Runtime_UseSessionKey_Case1_Counter": "78606",
"Runtime_UseSessionKey_Case1_Token": "111919",
"UserOp_BatchTransfers": "198306",
"UserOp_Erc20Transfer": "185271",
"UserOp_InstallSessionKey_Case1": "531215",
"UserOp_InstallSessionKey_Case1": "531243",
"UserOp_NativeTransfer": "161528",
"UserOp_UseSessionKey_Case1_Counter": "195233",
"UserOp_UseSessionKey_Case1_Token": "226217",
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": "97745",
"Runtime_BatchTransfers": "88968",
"Runtime_Erc20Transfer": "74425",
"Runtime_InstallSessionKey_Case1": "421557",
"Runtime_InstallSessionKey_Case1": "421585",
"Runtime_NativeTransfer": "50584",
"Runtime_UseSessionKey_Case1_Counter": "78956",
"Runtime_UseSessionKey_Case1_Token": "112269",
"UserOp_BatchTransfers": "193459",
"UserOp_Erc20Transfer": "180495",
"UserOp_InstallSessionKey_Case1": "528735",
"UserOp_InstallSessionKey_Case1": "528763",
"UserOp_NativeTransfer": "156770",
"UserOp_UseSessionKey_Case1_Counter": "195473",
"UserOp_UseSessionKey_Case1_Token": "226457",
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
Loading