Skip to content

Commit

Permalink
Handle zkVM contracts in EXTCODECOPY
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov committed Dec 19, 2024
1 parent 0d2ce5a commit c3174be
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
14 changes: 12 additions & 2 deletions system-contracts/contracts/EvmEmulator.yul
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit c3174be

Please sign in to comment.