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

[EVM-Equivalence-YUL] Extcodecopy fix #515

Merged
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
17 changes: 13 additions & 4 deletions system-contracts/contracts/EvmInterpreterFunctions.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ function getIsStaticFromCallFlags() -> isStatic {

// Basically performs an extcodecopy, while returning the length of the bytecode.
function _fetchDeployedCode(addr, _offset, _len) -> codeLen {
codeLen := _fetchDeployedCodeWithDest(addr, 0, _len, _offset)
}

// Basically performs an extcodecopy, while returning the length of the bytecode.
function _fetchDeployedCodeWithDest(addr, _offset, _len, dest) -> codeLen {
let codeHash := _getRawCodeHash(addr)

mstore(0, codeHash)
Expand All @@ -241,7 +246,7 @@ function _fetchDeployedCode(addr, _offset, _len) -> codeLen {
_len := codeLen
}

returndatacopy(_offset, 32, _len)
returndatacopy(dest, add(32,_offset), _len)
}

// Returns the length of the bytecode.
Expand Down Expand Up @@ -1244,15 +1249,19 @@ function performExtCodeCopy(evmGas,oldSp) -> evmGasLeft, sp {

let len_32 := shr(5, len)
for {let i := 0} lt(i, len_32) { i := add(i, 1) } {
mstore(shl(5,i),0)
mstore(add(dest,shl(5,i)),0)
}
let size_32 := shl(5,len_32)
let rest_32 := sub(len, size_32)
for {let i := 0} lt(i, rest_32) { i := add(i, 1) } {
mstore8(add(size_32,i),0)
mstore8(add(dest,add(size_32,i)),0)
}

// Gets the code from the addr
pop(_fetchDeployedCode(addr, add(offset, MEM_OFFSET_INNER()), len))
if iszero(iszero(_getRawCodeHash(addr))) {
pop(_fetchDeployedCodeWithDest(addr, offset, len,add(dest,MEM_OFFSET_INNER())))
}

}

function performCreate(evmGas,oldSp,isStatic) -> evmGasLeft, sp {
Expand Down
34 changes: 26 additions & 8 deletions system-contracts/contracts/EvmInterpreterPreprocessed.yul
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ object "EVMInterpreter" {

// Basically performs an extcodecopy, while returning the length of the bytecode.
function _fetchDeployedCode(addr, _offset, _len) -> codeLen {
codeLen := _fetchDeployedCodeWithDest(addr, 0, _len, _offset)
}

// Basically performs an extcodecopy, while returning the length of the bytecode.
function _fetchDeployedCodeWithDest(addr, _offset, _len, dest) -> codeLen {
let codeHash := _getRawCodeHash(addr)

mstore(0, codeHash)
Expand All @@ -315,7 +320,7 @@ object "EVMInterpreter" {
_len := codeLen
}

returndatacopy(_offset, 32, _len)
returndatacopy(dest, add(32,_offset), _len)
}

// Returns the length of the bytecode.
Expand Down Expand Up @@ -1318,15 +1323,19 @@ object "EVMInterpreter" {

let len_32 := shr(5, len)
for {let i := 0} lt(i, len_32) { i := add(i, 1) } {
mstore(shl(5,i),0)
mstore(add(dest,shl(5,i)),0)
}
let size_32 := shl(5,len_32)
let rest_32 := sub(len, size_32)
for {let i := 0} lt(i, rest_32) { i := add(i, 1) } {
mstore8(add(size_32,i),0)
mstore8(add(dest,add(size_32,i)),0)
}

// Gets the code from the addr
pop(_fetchDeployedCode(addr, add(offset, MEM_OFFSET_INNER()), len))
if iszero(iszero(_getRawCodeHash(addr))) {
pop(_fetchDeployedCodeWithDest(addr, offset, len,add(dest,MEM_OFFSET_INNER())))
}

}

function performCreate(evmGas,oldSp,isStatic) -> evmGasLeft, sp {
Expand Down Expand Up @@ -2919,6 +2928,11 @@ object "EVMInterpreter" {

// Basically performs an extcodecopy, while returning the length of the bytecode.
function _fetchDeployedCode(addr, _offset, _len) -> codeLen {
codeLen := _fetchDeployedCodeWithDest(addr, 0, _len, _offset)
}

// Basically performs an extcodecopy, while returning the length of the bytecode.
function _fetchDeployedCodeWithDest(addr, _offset, _len, dest) -> codeLen {
let codeHash := _getRawCodeHash(addr)

mstore(0, codeHash)
Expand All @@ -2938,7 +2952,7 @@ object "EVMInterpreter" {
_len := codeLen
}

returndatacopy(_offset, 32, _len)
returndatacopy(dest, add(32,_offset), _len)
}

// Returns the length of the bytecode.
Expand Down Expand Up @@ -3941,15 +3955,19 @@ object "EVMInterpreter" {

let len_32 := shr(5, len)
for {let i := 0} lt(i, len_32) { i := add(i, 1) } {
mstore(shl(5,i),0)
mstore(add(dest,shl(5,i)),0)
}
let size_32 := shl(5,len_32)
let rest_32 := sub(len, size_32)
for {let i := 0} lt(i, rest_32) { i := add(i, 1) } {
mstore8(add(size_32,i),0)
mstore8(add(dest,add(size_32,i)),0)
}

// Gets the code from the addr
pop(_fetchDeployedCode(addr, add(offset, MEM_OFFSET_INNER()), len))
if iszero(iszero(_getRawCodeHash(addr))) {
pop(_fetchDeployedCodeWithDest(addr, offset, len,add(dest,MEM_OFFSET_INNER())))
}

}

function performCreate(evmGas,oldSp,isStatic) -> evmGasLeft, sp {
Expand Down