Skip to content

Commit

Permalink
Optimize extcodecopy
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov committed Oct 29, 2024
1 parent df1c554 commit 8e0ec51
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
38 changes: 24 additions & 14 deletions system-contracts/contracts/EvmEmulator.yul
Original file line number Diff line number Diff line change
Expand Up @@ -1656,14 +1656,19 @@ object "EvmEmulator" {
}

evmGasLeft := chargeGas(evmGasLeft, dynamicGas)

$llvm_AlwaysInline_llvm$_memsetToZero(dstOffset, len)

// Gets the code from the addr
if and(iszero(iszero(getRawCodeHash(addr))), gt(len, 0)) {
pop(fetchDeployedCode(addr, add(dstOffset, MEM_OFFSET()), srcOffset, len))
}

if gt(len, 0) {
let realCodeLen
if getRawCodeHash(addr) {
// Gets the code from the addr
realCodeLen := fetchDeployedCode(addr, add(dstOffset, MEM_OFFSET()), srcOffset, len)
}

if lt(realCodeLen, len) {
$llvm_AlwaysInline_llvm$_memsetToZero(add(dstOffset, realCodeLen), sub(len, realCodeLen))
}
}

ip := add(ip, 1)
}
case 0x3D { // OP_RETURNDATASIZE
Expand Down Expand Up @@ -4653,14 +4658,19 @@ object "EvmEmulator" {
}

evmGasLeft := chargeGas(evmGasLeft, dynamicGas)

$llvm_AlwaysInline_llvm$_memsetToZero(dstOffset, len)

// Gets the code from the addr
if and(iszero(iszero(getRawCodeHash(addr))), gt(len, 0)) {
pop(fetchDeployedCode(addr, add(dstOffset, MEM_OFFSET()), srcOffset, len))
}

if gt(len, 0) {
let realCodeLen
if getRawCodeHash(addr) {
// Gets the code from the addr
realCodeLen := fetchDeployedCode(addr, add(dstOffset, MEM_OFFSET()), srcOffset, len)
}

if lt(realCodeLen, len) {
$llvm_AlwaysInline_llvm$_memsetToZero(add(dstOffset, realCodeLen), sub(len, realCodeLen))
}
}

ip := add(ip, 1)
}
case 0x3D { // OP_RETURNDATASIZE
Expand Down
19 changes: 12 additions & 7 deletions system-contracts/evm-emulator/EvmEmulatorLoop.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -456,14 +456,19 @@ for { } true { } {
}

evmGasLeft := chargeGas(evmGasLeft, dynamicGas)

$llvm_AlwaysInline_llvm$_memsetToZero(dstOffset, len)

// Gets the code from the addr
if and(iszero(iszero(getRawCodeHash(addr))), gt(len, 0)) {
pop(fetchDeployedCode(addr, add(dstOffset, MEM_OFFSET()), srcOffset, len))
}

if gt(len, 0) {
let realCodeLen
if getRawCodeHash(addr) {
// Gets the code from the addr
realCodeLen := fetchDeployedCode(addr, add(dstOffset, MEM_OFFSET()), srcOffset, len)
}

if lt(realCodeLen, len) {
$llvm_AlwaysInline_llvm$_memsetToZero(add(dstOffset, realCodeLen), sub(len, realCodeLen))
}
}

ip := add(ip, 1)
}
case 0x3D { // OP_RETURNDATASIZE
Expand Down

0 comments on commit 8e0ec51

Please sign in to comment.