Skip to content

Commit f5f0f0a

Browse files
committed
add gas limit range
1 parent 9af1ffa commit f5f0f0a

File tree

2 files changed

+84
-4
lines changed

2 files changed

+84
-4
lines changed

src/Router.sol

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ contract Router is
6060
// Default gas limit for withdraw operations
6161
uint256 private constant DEFAULT_WITHDRAW_GAS_LIMIT = 400000;
6262

63+
// Min and max gas limits for withdraw operations
64+
uint256 private constant MIN_WITHDRAW_GAS_LIMIT = 100000;
65+
uint256 private constant MAX_WITHDRAW_GAS_LIMIT = 10000000;
66+
6367
// Current gas limit for withdraw operations (can be modified by admin)
6468
uint256 public withdrawGasLimit;
6569

@@ -687,7 +691,8 @@ contract Router is
687691
* @param newGasLimit The new gas limit to set
688692
*/
689693
function setWithdrawGasLimit(uint256 newGasLimit) public onlyRole(DEFAULT_ADMIN_ROLE) {
690-
require(newGasLimit > 0, "Gas limit cannot be zero");
694+
require(newGasLimit >= MIN_WITHDRAW_GAS_LIMIT, "Gas limit below minimum");
695+
require(newGasLimit <= MAX_WITHDRAW_GAS_LIMIT, "Gas limit above maximum");
691696
emit WithdrawGasLimitUpdated(withdrawGasLimit, newGasLimit);
692697
withdrawGasLimit = newGasLimit;
693698
}
@@ -698,7 +703,8 @@ contract Router is
698703
* @param gasLimit The gas limit to set
699704
*/
700705
function setChainWithdrawGasLimit(uint256 chainId, uint256 gasLimit) public onlyRole(DEFAULT_ADMIN_ROLE) {
701-
require(gasLimit > 0, "Gas limit cannot be zero");
706+
require(gasLimit >= MIN_WITHDRAW_GAS_LIMIT, "Gas limit below minimum");
707+
require(gasLimit <= MAX_WITHDRAW_GAS_LIMIT, "Gas limit above maximum");
702708
chainWithdrawGasLimits[chainId] = gasLimit;
703709
emit ChainWithdrawGasLimitSet(chainId, gasLimit);
704710
}

test/Router.t.sol

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,44 @@ contract RouterTest is Test {
508508

509509
function test_SetWithdrawGasLimit_ZeroValueReverts() public {
510510
uint256 zeroGasLimit = 0;
511-
vm.expectRevert("Gas limit cannot be zero");
511+
vm.expectRevert("Gas limit below minimum");
512512
router.setWithdrawGasLimit(zeroGasLimit);
513513
}
514514

515+
function test_SetWithdrawGasLimit_BelowMinimumReverts() public {
516+
uint256 tooLowGasLimit = 99999; // Just below minimum of 100000
517+
518+
vm.expectRevert("Gas limit below minimum");
519+
router.setWithdrawGasLimit(tooLowGasLimit);
520+
}
521+
522+
function test_SetWithdrawGasLimit_AboveMaximumReverts() public {
523+
uint256 tooHighGasLimit = 10000001; // Just above maximum of 10000000
524+
525+
vm.expectRevert("Gas limit above maximum");
526+
router.setWithdrawGasLimit(tooHighGasLimit);
527+
}
528+
529+
function test_SetWithdrawGasLimit_AtMinimum() public {
530+
uint256 minimumGasLimit = 100000; // Exactly at minimum
531+
532+
// Set at minimum should work
533+
router.setWithdrawGasLimit(minimumGasLimit);
534+
535+
// Verify the gas limit was set
536+
assertEq(router.withdrawGasLimit(), minimumGasLimit);
537+
}
538+
539+
function test_SetWithdrawGasLimit_AtMaximum() public {
540+
uint256 maximumGasLimit = 10000000; // Exactly at maximum
541+
542+
// Set at maximum should work
543+
router.setWithdrawGasLimit(maximumGasLimit);
544+
545+
// Verify the gas limit was set
546+
assertEq(router.withdrawGasLimit(), maximumGasLimit);
547+
}
548+
515549
function test_SetWithdrawGasLimit_NonAdminReverts() public {
516550
uint256 newGasLimit = 200000;
517551
vm.prank(user1);
@@ -1094,10 +1128,50 @@ contract RouterTest is Test {
10941128
uint256 zeroGasLimit = 0;
10951129

10961130
// Attempt to set a zero gas limit
1097-
vm.expectRevert("Gas limit cannot be zero");
1131+
vm.expectRevert("Gas limit below minimum");
10981132
router.setChainWithdrawGasLimit(chainId, zeroGasLimit);
10991133
}
11001134

1135+
function test_SetChainWithdrawGasLimit_BelowMinimumReverts() public {
1136+
uint256 chainId = 42161; // Arbitrum chain ID
1137+
uint256 tooLowGasLimit = 99999; // Just below minimum of 100000
1138+
1139+
// Attempt to set a gas limit below the minimum
1140+
vm.expectRevert("Gas limit below minimum");
1141+
router.setChainWithdrawGasLimit(chainId, tooLowGasLimit);
1142+
}
1143+
1144+
function test_SetChainWithdrawGasLimit_AboveMaximumReverts() public {
1145+
uint256 chainId = 42161; // Arbitrum chain ID
1146+
uint256 tooHighGasLimit = 10000001; // Just above maximum of 10000000
1147+
1148+
// Attempt to set a gas limit above the maximum
1149+
vm.expectRevert("Gas limit above maximum");
1150+
router.setChainWithdrawGasLimit(chainId, tooHighGasLimit);
1151+
}
1152+
1153+
function test_SetChainWithdrawGasLimit_AtMinimum() public {
1154+
uint256 chainId = 42161; // Arbitrum chain ID
1155+
uint256 minimumGasLimit = 100000; // Exactly at minimum
1156+
1157+
// Set at minimum should work
1158+
router.setChainWithdrawGasLimit(chainId, minimumGasLimit);
1159+
1160+
// Verify the custom gas limit was set
1161+
assertEq(router.chainWithdrawGasLimits(chainId), minimumGasLimit);
1162+
}
1163+
1164+
function test_SetChainWithdrawGasLimit_AtMaximum() public {
1165+
uint256 chainId = 42161; // Arbitrum chain ID
1166+
uint256 maximumGasLimit = 10000000; // Exactly at maximum
1167+
1168+
// Set at maximum should work
1169+
router.setChainWithdrawGasLimit(chainId, maximumGasLimit);
1170+
1171+
// Verify the custom gas limit was set
1172+
assertEq(router.chainWithdrawGasLimits(chainId), maximumGasLimit);
1173+
}
1174+
11011175
function test_SetChainWithdrawGasLimit_NonAdminReverts() public {
11021176
uint256 chainId = 42161; // Arbitrum chain ID
11031177
uint256 customGasLimit = 500000;

0 commit comments

Comments
 (0)