diff --git a/system-contracts/contracts/ContractDeployer.sol b/system-contracts/contracts/ContractDeployer.sol index 852baba6c..fb3f7256d 100644 --- a/system-contracts/contracts/ContractDeployer.sol +++ b/system-contracts/contracts/ContractDeployer.sol @@ -194,9 +194,15 @@ contract ContractDeployer is IContractDeployer, ISystemContract { function createEVM(bytes calldata _initCode) external payable override returns (address) { // If the account is an EOA, use the min nonce. If it's a contract, use deployment nonce // Subtract 1 for EOA since the nonce has already been incremented for this transaction + + uint256 deploymentNonce = NONCE_HOLDER_SYSTEM_CONTRACT.getDeploymentNonce(msg.sender); + if (deploymentNonce == 0) { + NONCE_HOLDER_SYSTEM_CONTRACT.incrementDeploymentNonce(msg.sender); + } + uint256 senderNonce = msg.sender == tx.origin ? NONCE_HOLDER_SYSTEM_CONTRACT.getMinNonce(msg.sender) - 1 - : NONCE_HOLDER_SYSTEM_CONTRACT.incrementDeploymentNonce(msg.sender) + 1; + : NONCE_HOLDER_SYSTEM_CONTRACT.incrementDeploymentNonce(msg.sender); address newAddress = Utils.getNewAddressCreateEVM(msg.sender, senderNonce); _evmDeployOnAddress(newAddress, _initCode); return newAddress; diff --git a/system-contracts/contracts/EvmInterpreterFunctions.template.yul b/system-contracts/contracts/EvmInterpreterFunctions.template.yul index 8b53d3ea7..af89a9867 100644 --- a/system-contracts/contracts/EvmInterpreterFunctions.template.yul +++ b/system-contracts/contracts/EvmInterpreterFunctions.template.yul @@ -1349,31 +1349,15 @@ function $llvm_NoInline_llvm$_genericCreate(addr, offset, size, sp, value, evmGa _pushEVMFrame(gasForTheCall, false) - // Selector - mstore(sub(offset, 0x80), 0x5b16a23c) - // Arg1: address - mstore(sub(offset, 0x60), addr) - // Arg2: init code - // Where the arg starts (third word) - mstore(sub(offset, 0x40), 0x40) + // CreateEVM selector + mstore(sub(offset, 0x60), 0xff311601) + // Where the arg starts (second word) + mstore(sub(offset, 0x40), 0x20) // Length of the init code mstore(sub(offset, 0x20), size) - let farCallAbi := getFarCallABI( - 0, - 0, - sub(offset, 0x64), - add(size, 0x64), - INF_PASS_GAS(), - // Only rollup is supported for now - 0, - 0, - 0, - 1 - ) - let to := DEPLOYER_SYSTEM_CONTRACT() - result := verbatim_6i_1o("system_call", to, farCallAbi, 0, 0, 0, 0) + result := call(gas(), DEPLOYER_SYSTEM_CONTRACT(), value, sub(offset, 0x44), add(size, 0x44), 0, 32) let gasLeft switch result @@ -1389,18 +1373,6 @@ function $llvm_NoInline_llvm$_genericCreate(addr, offset, size, sp, value, evmGa _popEVMFrame() - switch result - case 1 { - incrementNonce(address()) - } - default { - switch isEOA(address()) - case 1 { - incrementNonce(address()) - } - default {} - } - let back // skipping check since we pushed exactly 4 items earlier diff --git a/system-contracts/contracts/EvmInterpreterPreprocessed.yul b/system-contracts/contracts/EvmInterpreterPreprocessed.yul index b33b96e42..31bb9e6de 100644 --- a/system-contracts/contracts/EvmInterpreterPreprocessed.yul +++ b/system-contracts/contracts/EvmInterpreterPreprocessed.yul @@ -1431,31 +1431,15 @@ object "EVMInterpreter" { _pushEVMFrame(gasForTheCall, false) - // Selector - mstore(sub(offset, 0x80), 0x5b16a23c) - // Arg1: address - mstore(sub(offset, 0x60), addr) - // Arg2: init code - // Where the arg starts (third word) - mstore(sub(offset, 0x40), 0x40) + // CreateEVM selector + mstore(sub(offset, 0x60), 0xff311601) + // Where the arg starts (second word) + mstore(sub(offset, 0x40), 0x20) // Length of the init code mstore(sub(offset, 0x20), size) - let farCallAbi := getFarCallABI( - 0, - 0, - sub(offset, 0x64), - add(size, 0x64), - INF_PASS_GAS(), - // Only rollup is supported for now - 0, - 0, - 0, - 1 - ) - let to := DEPLOYER_SYSTEM_CONTRACT() - result := verbatim_6i_1o("system_call", to, farCallAbi, 0, 0, 0, 0) + result := call(gas(), DEPLOYER_SYSTEM_CONTRACT(), value, sub(offset, 0x44), add(size, 0x44), 0, 32) let gasLeft switch result @@ -1471,18 +1455,6 @@ object "EVMInterpreter" { _popEVMFrame() - switch result - case 1 { - incrementNonce(address()) - } - default { - switch isEOA(address()) - case 1 { - incrementNonce(address()) - } - default {} - } - let back // skipping check since we pushed exactly 4 items earlier @@ -4521,31 +4493,15 @@ object "EVMInterpreter" { _pushEVMFrame(gasForTheCall, false) - // Selector - mstore(sub(offset, 0x80), 0x5b16a23c) - // Arg1: address - mstore(sub(offset, 0x60), addr) - // Arg2: init code - // Where the arg starts (third word) - mstore(sub(offset, 0x40), 0x40) + // CreateEVM selector + mstore(sub(offset, 0x60), 0xff311601) + // Where the arg starts (second word) + mstore(sub(offset, 0x40), 0x20) // Length of the init code mstore(sub(offset, 0x20), size) - let farCallAbi := getFarCallABI( - 0, - 0, - sub(offset, 0x64), - add(size, 0x64), - INF_PASS_GAS(), - // Only rollup is supported for now - 0, - 0, - 0, - 1 - ) - let to := DEPLOYER_SYSTEM_CONTRACT() - result := verbatim_6i_1o("system_call", to, farCallAbi, 0, 0, 0, 0) + result := call(gas(), DEPLOYER_SYSTEM_CONTRACT(), value, sub(offset, 0x44), add(size, 0x44), 0, 32) let gasLeft switch result @@ -4561,18 +4517,6 @@ object "EVMInterpreter" { _popEVMFrame() - switch result - case 1 { - incrementNonce(address()) - } - default { - switch isEOA(address()) - case 1 { - incrementNonce(address()) - } - default {} - } - let back // skipping check since we pushed exactly 4 items earlier