diff --git a/system-contracts/contracts/EvmEmulator.yul b/system-contracts/contracts/EvmEmulator.yul index 52b579962..e00ddba6a 100644 --- a/system-contracts/contracts/EvmEmulator.yul +++ b/system-contracts/contracts/EvmEmulator.yul @@ -415,9 +415,14 @@ object "EvmEmulator" { let success := staticcall(gas(), CODE_ORACLE_SYSTEM_CONTRACT(), 0, 32, 0, 0) // it fails if we don't have any code deployed at this address if success { - // The true length of the bytecode is encoded in bytecode hash + // The length of the bytecode is encoded in versioned bytecode hash let codeLen := and(shr(224, rawCodeHash), 0xffff) + if eq(shr(248, rawCodeHash), 1) { + // For native zkVM contracts length encoded in words, not bytes + codeLen := shl(5, codeLen) // * 32 + } + if gt(len, codeLen) { len := codeLen } @@ -3539,9 +3544,14 @@ object "EvmEmulator" { let success := staticcall(gas(), CODE_ORACLE_SYSTEM_CONTRACT(), 0, 32, 0, 0) // it fails if we don't have any code deployed at this address if success { - // The true length of the bytecode is encoded in bytecode hash + // The length of the bytecode is encoded in versioned bytecode hash let codeLen := and(shr(224, rawCodeHash), 0xffff) + if eq(shr(248, rawCodeHash), 1) { + // For native zkVM contracts length encoded in words, not bytes + codeLen := shl(5, codeLen) // * 32 + } + if gt(len, codeLen) { len := codeLen } diff --git a/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul b/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul index be1e0f1d3..61feb9235 100644 --- a/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul +++ b/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul @@ -355,9 +355,14 @@ function fetchDeployedCode(addr, dstOffset, srcOffset, len) -> copiedLen { let success := staticcall(gas(), CODE_ORACLE_SYSTEM_CONTRACT(), 0, 32, 0, 0) // it fails if we don't have any code deployed at this address if success { - // The true length of the bytecode is encoded in bytecode hash + // The length of the bytecode is encoded in versioned bytecode hash let codeLen := and(shr(224, rawCodeHash), 0xffff) + if eq(shr(248, rawCodeHash), 1) { + // For native zkVM contracts length encoded in words, not bytes + codeLen := shl(5, codeLen) // * 32 + } + if gt(len, codeLen) { len := codeLen }