Skip to content

Commit

Permalink
Add modifier to remaining functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gianbelinche committed Aug 26, 2024
1 parent 0d47c89 commit 61d1b13
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 11 deletions.
10 changes: 7 additions & 3 deletions system-contracts/contracts/ContractDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ contract ContractDeployer is IContractDeployer, ISystemContract {

uint256 public constructorReturnGas;

function setDeployedCode(uint256 constructorGasLeft, bytes calldata paddedNewDeployedCode) external {
modifier onlySystemEvm() {
require(ACCOUNT_CODE_STORAGE_SYSTEM_CONTRACT.isAccountEVM(msg.sender), "only system evm");
_;
}

function setDeployedCode(uint256 constructorGasLeft, bytes calldata paddedNewDeployedCode) onlySystemCall onlySystemEvm external {
require(ACCOUNT_CODE_STORAGE_SYSTEM_CONTRACT.isAccountEVM(msg.sender));

uint256 bytecodeLen = uint256(bytes32(paddedNewDeployedCode[:32]));
Expand Down Expand Up @@ -209,8 +214,7 @@ contract ContractDeployer is IContractDeployer, ISystemContract {
return newAddress;
}

function createEVMInternal(address _newAddress, bytes calldata _initCode) external payable {
require(ACCOUNT_CODE_STORAGE_SYSTEM_CONTRACT.isAccountEVM(msg.sender));
function createEVMInternal(address _newAddress, bytes calldata _initCode) onlySystemCall onlySystemEvm external payable {
_evmDeployOnAddress(_newAddress, _initCode);
}

Expand Down
15 changes: 14 additions & 1 deletion system-contracts/contracts/EvmInterpreter.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,20 @@ object "EVMInterpreter" {
mstore(sub(offset, 64), 0x40)
mstore(sub(offset, 32), len)

let success := call(gas(), DEPLOYER_SYSTEM_CONTRACT(), 0, sub(offset, 100), add(len, 100), 0, 0)
let farCallAbi := getFarCallABI(
0,
0,
sub(offset, 100),
add(len, 100),
gas(),
// Only rollup is supported for now
0,
0,
0,
1
)
let to := DEPLOYER_SYSTEM_CONTRACT()
let success := verbatim_6i_1o("system_call", to, farCallAbi, 0, 0, 0, 0)

if iszero(success) {
// This error should never happen
Expand Down
23 changes: 21 additions & 2 deletions system-contracts/contracts/EvmInterpreterFunctions.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,9 @@ function $llvm_NoInline_llvm$_genericCreate(addr, offset, size, sp, value, evmGa
sp := pushStackItemWithoutCheck(sp, mload(sub(offset, 0x40)))
sp := pushStackItemWithoutCheck(sp, mload(sub(offset, 0x20)))


_pushEVMFrame(gasForTheCall, false)

// Selector
mstore(sub(offset, 0x80), 0x5b16a23c)
// Arg1: address
Expand All @@ -1348,9 +1351,25 @@ function $llvm_NoInline_llvm$_genericCreate(addr, offset, size, sp, value, evmGa
// Length of the init code
mstore(sub(offset, 0x20), size)

_pushEVMFrame(gasForTheCall, false)

result := call(INF_PASS_GAS(), DEPLOYER_SYSTEM_CONTRACT(), value, sub(offset, 0x64), add(size, 0x64), 0, 0)
let farCallAbi := getFarCallABI(
0,
0,
sub(offset, 0x80),
add(size, 0x80),
INF_PASS_GAS(),
// Only rollup is supported for now
0,
0,
0,
1
)
let to := DEPLOYER_SYSTEM_CONTRACT()
printString("PRE VERBATIM CREATE")
let result := verbatim_6i_1o("system_call", to, farCallAbi, 0, 0, 0, 0)

printString("POST VERBATIM CREATE")
printHex(result)

let gasLeft
switch result
Expand Down
61 changes: 56 additions & 5 deletions system-contracts/contracts/EvmInterpreterPreprocessed.yul
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,20 @@ object "EVMInterpreter" {
mstore(sub(offset, 64), 0x40)
mstore(sub(offset, 32), len)

let success := call(gas(), DEPLOYER_SYSTEM_CONTRACT(), 0, sub(offset, 100), add(len, 100), 0, 0)
let farCallAbi := getFarCallABI(
0,
0,
sub(offset, 100),
add(len, 100),
gas(),
// Only rollup is supported for now
0,
0,
0,
1
)
let to := DEPLOYER_SYSTEM_CONTRACT()
let success := verbatim_6i_1o("system_call", to, farCallAbi, 0, 0, 0, 0)

if iszero(success) {
// This error should never happen
Expand Down Expand Up @@ -1407,6 +1420,9 @@ object "EVMInterpreter" {
sp := pushStackItemWithoutCheck(sp, mload(sub(offset, 0x40)))
sp := pushStackItemWithoutCheck(sp, mload(sub(offset, 0x20)))


_pushEVMFrame(gasForTheCall, false)

// Selector
mstore(sub(offset, 0x80), 0x5b16a23c)
// Arg1: address
Expand All @@ -1417,9 +1433,25 @@ object "EVMInterpreter" {
// Length of the init code
mstore(sub(offset, 0x20), size)

_pushEVMFrame(gasForTheCall, false)

result := call(INF_PASS_GAS(), DEPLOYER_SYSTEM_CONTRACT(), value, sub(offset, 0x64), add(size, 0x64), 0, 0)
let farCallAbi := getFarCallABI(
0,
0,
sub(offset, 0x80),
add(size, 0x80),
INF_PASS_GAS(),
// Only rollup is supported for now
0,
0,
0,
1
)
let to := DEPLOYER_SYSTEM_CONTRACT()
printString("PRE VERBATIM CREATE")
let result := verbatim_6i_1o("system_call", to, farCallAbi, 0, 0, 0, 0)

printString("POST VERBATIM CREATE")
printHex(result)

let gasLeft
switch result
Expand Down Expand Up @@ -4474,6 +4506,9 @@ object "EVMInterpreter" {
sp := pushStackItemWithoutCheck(sp, mload(sub(offset, 0x40)))
sp := pushStackItemWithoutCheck(sp, mload(sub(offset, 0x20)))


_pushEVMFrame(gasForTheCall, false)

// Selector
mstore(sub(offset, 0x80), 0x5b16a23c)
// Arg1: address
Expand All @@ -4484,9 +4519,25 @@ object "EVMInterpreter" {
// Length of the init code
mstore(sub(offset, 0x20), size)

_pushEVMFrame(gasForTheCall, false)

result := call(INF_PASS_GAS(), DEPLOYER_SYSTEM_CONTRACT(), value, sub(offset, 0x64), add(size, 0x64), 0, 0)
let farCallAbi := getFarCallABI(
0,
0,
sub(offset, 0x80),
add(size, 0x80),
INF_PASS_GAS(),
// Only rollup is supported for now
0,
0,
0,
1
)
let to := DEPLOYER_SYSTEM_CONTRACT()
printString("PRE VERBATIM CREATE")
let result := verbatim_6i_1o("system_call", to, farCallAbi, 0, 0, 0, 0)

printString("POST VERBATIM CREATE")
printHex(result)

let gasLeft
switch result
Expand Down

0 comments on commit 61d1b13

Please sign in to comment.