Skip to content

Commit

Permalink
Fix calls to contract being created
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov committed Nov 27, 2024
1 parent 348e84a commit 2856203
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 @@ -393,6 +393,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 @@ -802,7 +809,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 @@ -3441,6 +3448,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 @@ -3850,7 +3864,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 @@ -331,6 +331,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 @@ -740,7 +747,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 2856203

Please sign in to comment.