diff --git a/system-contracts/contracts/EvmInterpreterFunctions.template.yul b/system-contracts/contracts/EvmInterpreterFunctions.template.yul index 1a1395895..483293281 100644 --- a/system-contracts/contracts/EvmInterpreterFunctions.template.yul +++ b/system-contracts/contracts/EvmInterpreterFunctions.template.yul @@ -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) @@ -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. @@ -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 { diff --git a/system-contracts/contracts/EvmInterpreterPreprocessed.yul b/system-contracts/contracts/EvmInterpreterPreprocessed.yul index 28b920add..902c784bf 100644 --- a/system-contracts/contracts/EvmInterpreterPreprocessed.yul +++ b/system-contracts/contracts/EvmInterpreterPreprocessed.yul @@ -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) @@ -315,7 +320,7 @@ object "EVMInterpreter" { _len := codeLen } - returndatacopy(_offset, 32, _len) + returndatacopy(dest, add(32,_offset), _len) } // Returns the length of the bytecode. @@ -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 { @@ -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) @@ -2938,7 +2952,7 @@ object "EVMInterpreter" { _len := codeLen } - returndatacopy(_offset, 32, _len) + returndatacopy(dest, add(32,_offset), _len) } // Returns the length of the bytecode. @@ -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 {