Skip to content

Commit

Permalink
min gas for fallable call
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavBreadless committed Sep 25, 2024
1 parent c2c3dbe commit 6ea2aed
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion l1-contracts/contracts/governance/PermanentRestriction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity 0.8.24;

import {UnsupportedEncodingVersion, CallNotAllowed, ChainZeroAddress, NotAHyperchain, NotAnAdmin, RemovingPermanentRestriction, ZeroAddress, UnallowedImplementation, AlreadyWhitelisted, NotWhitelisted, NotBridgehub, InvalidSelector, InvalidAddress} from "../common/L1ContractErrors.sol";
import {UnsupportedEncodingVersion, CallNotAllowed, ChainZeroAddress, NotAHyperchain, NotAnAdmin, RemovingPermanentRestriction, ZeroAddress, UnallowedImplementation, AlreadyWhitelisted, NotWhitelisted, NotBridgehub, InvalidSelector, InvalidAddress, NotEnoughGas} from "../common/L1ContractErrors.sol";

import {L2TransactionRequestTwoBridgesOuter, BridgehubBurnCTMAssetData} from "../bridgehub/IBridgehub.sol";
import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable-v4/access/Ownable2StepUpgradeable.sol";
Expand All @@ -26,6 +26,11 @@ import {IPermanentRestriction} from "./IPermanentRestriction.sol";
/// @dev To be deployed as a transparent upgradable proxy, owned by a trusted decentralized governance.
/// @dev Once of the instances of such contract is to ensure that a ZkSyncHyperchain is a rollup forever.
contract PermanentRestriction is IRestriction, IPermanentRestriction, Ownable2StepUpgradeable {
/// @notice We use try-catch to test whether some of the conditions should be checked.
/// To avoid attacks based on teh 63/64 gas limitations, we ensure that each such call

Check warning on line 30 in l1-contracts/contracts/governance/PermanentRestriction.sol

View workflow job for this annotation

GitHub Actions / typos

"teh" should be "the".
/// has at least this amount.
uint256 constant MIN_GAS_FOR_FALLABLE_CALL = 5_000_000;

Check failure on line 32 in l1-contracts/contracts/governance/PermanentRestriction.sol

View workflow job for this annotation

GitHub Actions / lint

Explicitly mark visibility of state

Check failure on line 32 in l1-contracts/contracts/governance/PermanentRestriction.sol

View workflow job for this annotation

GitHub Actions / lint

Explicitly mark visibility of state

Check failure on line 32 in l1-contracts/contracts/governance/PermanentRestriction.sol

View workflow job for this annotation

GitHub Actions / lint

Explicitly mark visibility of state

/// @notice The address of the Bridgehub contract.
IBridgehub public immutable BRIDGE_HUB;

Expand Down Expand Up @@ -124,6 +129,7 @@ contract PermanentRestriction is IRestriction, IPermanentRestriction, Ownable2St
/// @dev Note that we do not need to validate the migration to the L1 layer as the admin
/// is not changed in this case.
function _validateMigrationToL2(Call calldata _call) internal view {
_ensureEnoughGas();
try this.tryGetNewAdminFromMigration(_call) returns (address admin) {
if (!whitelistedL2Admins[admin]) {
revert NotWhitelisted(admin);
Expand Down Expand Up @@ -205,6 +211,7 @@ contract PermanentRestriction is IRestriction, IPermanentRestriction, Ownable2St
/// @notice Checks if the `msg.sender` is an admin of a certain ZkSyncHyperchain.
/// @param _chain The address of the chain.
function _isAdminOfAChain(address _chain) internal view returns (bool) {
_ensureEnoughGas();
(bool success, ) = address(this).staticcall(abi.encodeCall(this.tryCompareAdminOfAChain, (_chain, msg.sender)));
return success;
}
Expand Down Expand Up @@ -282,4 +289,10 @@ contract PermanentRestriction is IRestriction, IPermanentRestriction, Ownable2St

return l2Admin;
}

function _ensureEnoughGas() internal view {
if (gasleft() < MIN_GAS_FOR_FALLABLE_CALL) {
revert NotEnoughGas();
}
}
}

0 comments on commit 6ea2aed

Please sign in to comment.