From 87863a3ab3d2ba96338fa68f497efd7e65657100 Mon Sep 17 00:00:00 2001 From: Gianbelinche <39842759+gianbelinche@users.noreply.github.com> Date: Tue, 27 Aug 2024 14:50:13 -0300 Subject: [PATCH] Unify modifiers --- .../contracts/ContractDeployer.sol | 8 ++- system-contracts/contracts/EvmGasManager.sol | 12 +++- .../EvmInterpreterFunctions.template.yul | 33 +++++++++- .../contracts/EvmInterpreterPreprocessed.yul | 66 +++++++++++++++++-- 4 files changed, 108 insertions(+), 11 deletions(-) diff --git a/system-contracts/contracts/ContractDeployer.sol b/system-contracts/contracts/ContractDeployer.sol index e958cb057..852baba6c 100644 --- a/system-contracts/contracts/ContractDeployer.sol +++ b/system-contracts/contracts/ContractDeployer.sol @@ -39,10 +39,14 @@ contract ContractDeployer is IContractDeployer, ISystemContract { modifier onlySystemEvm() { require(ACCOUNT_CODE_STORAGE_SYSTEM_CONTRACT.isAccountEVM(msg.sender), "only system evm"); + require( + SystemContractHelper.isSystemCall() || SystemContractHelper.isSystemContract(msg.sender), + "This method require system call flag" + ); _; } - function setDeployedCode(uint256 constructorGasLeft, bytes calldata paddedNewDeployedCode) onlySystemCall onlySystemEvm external { + function setDeployedCode(uint256 constructorGasLeft, bytes calldata paddedNewDeployedCode) onlySystemEvm external { require(ACCOUNT_CODE_STORAGE_SYSTEM_CONTRACT.isAccountEVM(msg.sender)); uint256 bytecodeLen = uint256(bytes32(paddedNewDeployedCode[:32])); @@ -214,7 +218,7 @@ contract ContractDeployer is IContractDeployer, ISystemContract { return newAddress; } - function createEVMInternal(address _newAddress, bytes calldata _initCode) onlySystemCall onlySystemEvm external payable { + function createEVMInternal(address _newAddress, bytes calldata _initCode) onlySystemEvm external payable { _evmDeployOnAddress(_newAddress, _initCode); } diff --git a/system-contracts/contracts/EvmGasManager.sol b/system-contracts/contracts/EvmGasManager.sol index 44f4dc920..f150fa222 100644 --- a/system-contracts/contracts/EvmGasManager.sol +++ b/system-contracts/contracts/EvmGasManager.sol @@ -5,6 +5,8 @@ import "./EvmConstants.sol"; import {ACCOUNT_CODE_STORAGE_SYSTEM_CONTRACT} from "./Constants.sol"; import {ISystemContract} from "./interfaces/ISystemContract.sol"; +import {SystemContractHelper} from "./libraries/SystemContractHelper.sol"; + // We consider all the contracts (including system ones) as warm. uint160 constant PRECOMPILES_END = 0xffff; @@ -80,6 +82,10 @@ contract EvmGasManager is ISystemContract { modifier onlySystemEvm() { require(ACCOUNT_CODE_STORAGE_SYSTEM_CONTRACT.isAccountEVM(msg.sender), "only system evm"); + require( + SystemContractHelper.isSystemCall() || SystemContractHelper.isSystemContract(msg.sender), + "This method require system call flag" + ); _; } @@ -124,13 +130,13 @@ contract EvmGasManager is ISystemContract { */ - function pushEVMFrame(uint256 _passGas, bool _isStatic) onlySystemCall onlySystemEvm external { + function pushEVMFrame(uint256 _passGas, bool _isStatic) onlySystemEvm external { EVMStackFrameInfo memory frame = EVMStackFrameInfo({passGas: _passGas, isStatic: _isStatic}); evmStackFrames.push(frame); } - function consumeEvmFrame() onlySystemCall onlySystemEvm external returns (uint256 passGas, bool isStatic) { + function consumeEvmFrame() onlySystemEvm external returns (uint256 passGas, bool isStatic) { if (evmStackFrames.length == 0) return (INF_PASS_GAS, false); EVMStackFrameInfo memory frameInfo = evmStackFrames[evmStackFrames.length - 1]; @@ -142,7 +148,7 @@ contract EvmGasManager is ISystemContract { evmStackFrames[evmStackFrames.length - 1].passGas = INF_PASS_GAS; } - function popEVMFrame() onlySystemCall onlySystemEvm external { + function popEVMFrame() onlySystemEvm external { evmStackFrames.pop(); } } diff --git a/system-contracts/contracts/EvmInterpreterFunctions.template.yul b/system-contracts/contracts/EvmInterpreterFunctions.template.yul index 088140087..8b53d3ea7 100644 --- a/system-contracts/contracts/EvmInterpreterFunctions.template.yul +++ b/system-contracts/contracts/EvmInterpreterFunctions.template.yul @@ -581,13 +581,28 @@ function warmSlot(key,currentValue) -> isWarm, originalValue { mstore(4, key) mstore(36,currentValue) - let success := call(gas(), EVM_GAS_MANAGER_CONTRACT(), 0, 0, 68, 0, 64) + let farCallAbi := getFarCallABI( + 0, + 0, + 0, + 68, + gas(), + // Only rollup is supported for now + 0, + 0, + 0, + 1 + ) + let to := EVM_GAS_MANAGER_CONTRACT() + let success := verbatim_6i_1o("system_call", to, farCallAbi, 0, 0, 0, 0) if iszero(success) { // This error should never happen revert(0, 0) } + returndatacopy(0, 0, 64) + isWarm := mload(0) originalValue := mload(32) } @@ -745,13 +760,27 @@ function $llvm_AlwaysInline_llvm$_warmAddress(addr) -> isWarm { mstore(0, 0x8DB2BA7800000000000000000000000000000000000000000000000000000000) mstore(4, addr) - let success := call(gas(), EVM_GAS_MANAGER_CONTRACT(), 0, 0, 36, 0, 32) + let farCallAbi := getFarCallABI( + 0, + 0, + 0, + 36, + gas(), + // Only rollup is supported for now + 0, + 0, + 0, + 1 + ) + let to := EVM_GAS_MANAGER_CONTRACT() + let success := verbatim_6i_1o("system_call", to, farCallAbi, 0, 0, 0, 0) if iszero(success) { // This error should never happen revert(0, 0) } + returndatacopy(0, 0, 32) isWarm := mload(0) } diff --git a/system-contracts/contracts/EvmInterpreterPreprocessed.yul b/system-contracts/contracts/EvmInterpreterPreprocessed.yul index bb46e2e33..b33b96e42 100644 --- a/system-contracts/contracts/EvmInterpreterPreprocessed.yul +++ b/system-contracts/contracts/EvmInterpreterPreprocessed.yul @@ -663,13 +663,28 @@ object "EVMInterpreter" { mstore(4, key) mstore(36,currentValue) - let success := call(gas(), EVM_GAS_MANAGER_CONTRACT(), 0, 0, 68, 0, 64) + let farCallAbi := getFarCallABI( + 0, + 0, + 0, + 68, + gas(), + // Only rollup is supported for now + 0, + 0, + 0, + 1 + ) + let to := EVM_GAS_MANAGER_CONTRACT() + let success := verbatim_6i_1o("system_call", to, farCallAbi, 0, 0, 0, 0) if iszero(success) { // This error should never happen revert(0, 0) } + returndatacopy(0, 0, 64) + isWarm := mload(0) originalValue := mload(32) } @@ -827,13 +842,27 @@ object "EVMInterpreter" { mstore(0, 0x8DB2BA7800000000000000000000000000000000000000000000000000000000) mstore(4, addr) - let success := call(gas(), EVM_GAS_MANAGER_CONTRACT(), 0, 0, 36, 0, 32) + let farCallAbi := getFarCallABI( + 0, + 0, + 0, + 36, + gas(), + // Only rollup is supported for now + 0, + 0, + 0, + 1 + ) + let to := EVM_GAS_MANAGER_CONTRACT() + let success := verbatim_6i_1o("system_call", to, farCallAbi, 0, 0, 0, 0) if iszero(success) { // This error should never happen revert(0, 0) } + returndatacopy(0, 0, 32) isWarm := mload(0) } @@ -3724,13 +3753,28 @@ object "EVMInterpreter" { mstore(4, key) mstore(36,currentValue) - let success := call(gas(), EVM_GAS_MANAGER_CONTRACT(), 0, 0, 68, 0, 64) + let farCallAbi := getFarCallABI( + 0, + 0, + 0, + 68, + gas(), + // Only rollup is supported for now + 0, + 0, + 0, + 1 + ) + let to := EVM_GAS_MANAGER_CONTRACT() + let success := verbatim_6i_1o("system_call", to, farCallAbi, 0, 0, 0, 0) if iszero(success) { // This error should never happen revert(0, 0) } + returndatacopy(0, 0, 64) + isWarm := mload(0) originalValue := mload(32) } @@ -3888,13 +3932,27 @@ object "EVMInterpreter" { mstore(0, 0x8DB2BA7800000000000000000000000000000000000000000000000000000000) mstore(4, addr) - let success := call(gas(), EVM_GAS_MANAGER_CONTRACT(), 0, 0, 36, 0, 32) + let farCallAbi := getFarCallABI( + 0, + 0, + 0, + 36, + gas(), + // Only rollup is supported for now + 0, + 0, + 0, + 1 + ) + let to := EVM_GAS_MANAGER_CONTRACT() + let success := verbatim_6i_1o("system_call", to, farCallAbi, 0, 0, 0, 0) if iszero(success) { // This error should never happen revert(0, 0) } + returndatacopy(0, 0, 32) isWarm := mload(0) }