Skip to content

Commit

Permalink
Unify modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
gianbelinche committed Aug 27, 2024
1 parent b3446e6 commit 87863a3
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 11 deletions.
8 changes: 6 additions & 2 deletions system-contracts/contracts/ContractDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
Expand Down Expand Up @@ -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);
}

Expand Down
12 changes: 9 additions & 3 deletions system-contracts/contracts/EvmGasManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"
);
_;
}

Expand Down Expand Up @@ -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];
Expand All @@ -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();
}
}
33 changes: 31 additions & 2 deletions system-contracts/contracts/EvmInterpreterFunctions.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}

Expand Down
66 changes: 62 additions & 4 deletions system-contracts/contracts/EvmInterpreterPreprocessed.yul
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 87863a3

Please sign in to comment.