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

Revert fetch deployed code len optimization #31

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
52 changes: 34 additions & 18 deletions system-contracts/contracts/EvmInterpreter.yul
Original file line number Diff line number Diff line change
Expand Up @@ -346,16 +346,22 @@ object "EVMInterpreter" {
function _fetchDeployedCodeLen(addr) -> codeLen {
let codeHash := _getRawCodeHash(addr)

switch shr(248, codeHash)
mstore(0, codeHash)

let success := staticcall(gas(), CODE_ORACLE_SYSTEM_CONTRACT(), 0, 32, 0, 0)

switch iszero(success)
case 1 {
// EraVM
let codeLengthInWords := and(shr(224, codeHash), 0xffff)
codeLen := shl(5, codeLengthInWords) // codeLengthInWords * 32
// The code oracle call can only fail in the case where the contract
// we are querying is the current one executing and it has not yet been
// deployed, i.e., if someone calls codesize (or extcodesize(address()))
// inside the constructor. In that case, code length is zero.
codeLen := 0
}
case 2 {
// EVM
let codeLengthInBytes := and(shr(224, codeHash), 0xffff)
codeLen := codeLengthInBytes
default {
// The first word is the true length of the bytecode
returndatacopy(0, 0, 32)
codeLen := mload(0)
}
}

Expand Down Expand Up @@ -2040,7 +2046,9 @@ object "EVMInterpreter" {
evmGasLeft := chargeGas(evmGasLeft, 2500)
}

sp := pushStackItemWithoutCheck(sp, _fetchDeployedCodeLen(addr))
switch _isEVM(addr)
case 0 { sp := pushStackItemWithoutCheck(sp, extcodesize(addr)) }
default { sp := pushStackItemWithoutCheck(sp, _fetchDeployedCodeLen(addr)) }
ip := add(ip, 1)
}
case 0x3C { // OP_EXTCODECOPY
Expand Down Expand Up @@ -3320,16 +3328,22 @@ object "EVMInterpreter" {
function _fetchDeployedCodeLen(addr) -> codeLen {
let codeHash := _getRawCodeHash(addr)

switch shr(248, codeHash)
mstore(0, codeHash)

let success := staticcall(gas(), CODE_ORACLE_SYSTEM_CONTRACT(), 0, 32, 0, 0)

switch iszero(success)
case 1 {
// EraVM
let codeLengthInWords := and(shr(224, codeHash), 0xffff)
codeLen := shl(5, codeLengthInWords) // codeLengthInWords * 32
// The code oracle call can only fail in the case where the contract
// we are querying is the current one executing and it has not yet been
// deployed, i.e., if someone calls codesize (or extcodesize(address()))
// inside the constructor. In that case, code length is zero.
codeLen := 0
}
case 2 {
// EVM
let codeLengthInBytes := and(shr(224, codeHash), 0xffff)
codeLen := codeLengthInBytes
default {
// The first word is the true length of the bytecode
returndatacopy(0, 0, 32)
codeLen := mload(0)
}
}

Expand Down Expand Up @@ -5014,7 +5028,9 @@ object "EVMInterpreter" {
evmGasLeft := chargeGas(evmGasLeft, 2500)
}

sp := pushStackItemWithoutCheck(sp, _fetchDeployedCodeLen(addr))
switch _isEVM(addr)
case 0 { sp := pushStackItemWithoutCheck(sp, extcodesize(addr)) }
default { sp := pushStackItemWithoutCheck(sp, _fetchDeployedCodeLen(addr)) }
ip := add(ip, 1)
}
case 0x3C { // OP_EXTCODECOPY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,22 @@ function _fetchDeployedCodeWithDest(addr, _offset, _len, dest) -> codeLen {
function _fetchDeployedCodeLen(addr) -> codeLen {
let codeHash := _getRawCodeHash(addr)

switch shr(248, codeHash)
mstore(0, codeHash)

let success := staticcall(gas(), CODE_ORACLE_SYSTEM_CONTRACT(), 0, 32, 0, 0)

switch iszero(success)
case 1 {
// EraVM
let codeLengthInWords := and(shr(224, codeHash), 0xffff)
codeLen := shl(5, codeLengthInWords) // codeLengthInWords * 32
}
case 2 {
// EVM
let codeLengthInBytes := and(shr(224, codeHash), 0xffff)
codeLen := codeLengthInBytes
// The code oracle call can only fail in the case where the contract
// we are querying is the current one executing and it has not yet been
// deployed, i.e., if someone calls codesize (or extcodesize(address()))
// inside the constructor. In that case, code length is zero.
codeLen := 0
}
default {
// The first word is the true length of the bytecode
returndatacopy(0, 0, 32)
codeLen := mload(0)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,9 @@ for { } true { } {
evmGasLeft := chargeGas(evmGasLeft, 2500)
}

sp := pushStackItemWithoutCheck(sp, _fetchDeployedCodeLen(addr))
switch _isEVM(addr)
case 0 { sp := pushStackItemWithoutCheck(sp, extcodesize(addr)) }
default { sp := pushStackItemWithoutCheck(sp, _fetchDeployedCodeLen(addr)) }
ip := add(ip, 1)
}
case 0x3C { // OP_EXTCODECOPY
Expand Down
Loading