Skip to content

Commit

Permalink
fix(EVM): Fix calls to contract being created (#1093)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov committed Nov 29, 2024
1 parent b5a3258 commit 19f9c16
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
18 changes: 16 additions & 2 deletions system-contracts/contracts/EvmEmulator.yul
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,13 @@ object "EvmEmulator" {
isEVM := fetchFromSystemContract(ACCOUNT_CODE_STORAGE_SYSTEM_CONTRACT(), 36)
}

function isConstructedEvmContract(addr) -> isConstructedEVM {
let rawCodeHash := getRawCodeHash(addr)
let version := shr(248, rawCodeHash)
let isConstructedFlag := xor(shr(240, rawCodeHash), 1)
isConstructedEVM := and(eq(version, 2), isConstructedFlag)
}

// Basically performs an extcodecopy, while returning the length of the copied bytecode.
function fetchDeployedCode(addr, dstOffset, srcOffset, len) -> copiedLen {
let codeHash := getRawCodeHash(addr)
Expand Down Expand Up @@ -803,7 +810,7 @@ object "EvmEmulator" {
}

function _genericCall(addr, gasToPass, value, argsOffset, argsSize, retOffset, retSize, isStatic) -> success, frameGasLeft {
switch isEvmContract(addr)
switch isConstructedEvmContract(addr)
case 0 {
// zkEVM native call
let precompileCost := getGasForPrecompiles(addr, argsOffset, argsSize)
Expand Down Expand Up @@ -3415,6 +3422,13 @@ object "EvmEmulator" {
isEVM := fetchFromSystemContract(ACCOUNT_CODE_STORAGE_SYSTEM_CONTRACT(), 36)
}

function isConstructedEvmContract(addr) -> isConstructedEVM {
let rawCodeHash := getRawCodeHash(addr)
let version := shr(248, rawCodeHash)
let isConstructedFlag := xor(shr(240, rawCodeHash), 1)
isConstructedEVM := and(eq(version, 2), isConstructedFlag)
}

// Basically performs an extcodecopy, while returning the length of the copied bytecode.
function fetchDeployedCode(addr, dstOffset, srcOffset, len) -> copiedLen {
let codeHash := getRawCodeHash(addr)
Expand Down Expand Up @@ -3828,7 +3842,7 @@ object "EvmEmulator" {
}

function _genericCall(addr, gasToPass, value, argsOffset, argsSize, retOffset, retSize, isStatic) -> success, frameGasLeft {
switch isEvmContract(addr)
switch isConstructedEvmContract(addr)
case 0 {
// zkEVM native call
let precompileCost := getGasForPrecompiles(addr, argsOffset, argsSize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ function isEvmContract(addr) -> isEVM {
isEVM := fetchFromSystemContract(ACCOUNT_CODE_STORAGE_SYSTEM_CONTRACT(), 36)
}

function isConstructedEvmContract(addr) -> isConstructedEVM {
let rawCodeHash := getRawCodeHash(addr)
let version := shr(248, rawCodeHash)
let isConstructedFlag := xor(shr(240, rawCodeHash), 1)
isConstructedEVM := and(eq(version, 2), isConstructedFlag)
}

// Basically performs an extcodecopy, while returning the length of the copied bytecode.
function fetchDeployedCode(addr, dstOffset, srcOffset, len) -> copiedLen {
let codeHash := getRawCodeHash(addr)
Expand Down Expand Up @@ -741,7 +748,7 @@ function performDelegateCall(oldSp, evmGasLeft, isStatic, oldStackHead) -> newGa
}

function _genericCall(addr, gasToPass, value, argsOffset, argsSize, retOffset, retSize, isStatic) -> success, frameGasLeft {
switch isEvmContract(addr)
switch isConstructedEvmContract(addr)
case 0 {
// zkEVM native call
let precompileCost := getGasForPrecompiles(addr, argsOffset, argsSize)
Expand Down

0 comments on commit 19f9c16

Please sign in to comment.