Skip to content

Commit

Permalink
Call createEVM instead of createEVMInternal
Browse files Browse the repository at this point in the history
  • Loading branch information
jrchatruc committed Aug 28, 2024
1 parent 87863a3 commit 78fc58a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 100 deletions.
8 changes: 7 additions & 1 deletion system-contracts/contracts/ContractDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 5 additions & 33 deletions system-contracts/contracts/EvmInterpreterFunctions.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
76 changes: 10 additions & 66 deletions system-contracts/contracts/EvmInterpreterPreprocessed.yul
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 78fc58a

Please sign in to comment.