Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(EVM): Fix calls to contract being created #1093

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading