Skip to content
Closed
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
8 changes: 8 additions & 0 deletions src/compiler/evm_frontend/evm_mir_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4552,6 +4552,10 @@ typename EVMMirBuilder::Operand EVMMirBuilder::handleCodeSize() {
void EVMMirBuilder::handleCodeCopy(Operand DestOffsetComponents,
Operand OffsetComponents,
Operand SizeComponents) {
if (SizeComponents.isConstU64() && SizeComponents.getConstValue()[0] == 0) {
return;
}

const auto &RuntimeFunctions = getRuntimeFunctionTable();
normalizeOffsetWithSize(DestOffsetComponents, SizeComponents);
uint64_t Non64Value = std::numeric_limits<uint64_t>::max();
Expand Down Expand Up @@ -6715,6 +6719,10 @@ MInstruction *EVMMirBuilder::getCurrentInstancePointer() {
void EVMMirBuilder::handleCallDataCopy(Operand DestOffsetComponents,
Operand OffsetComponents,
Operand SizeComponents) {
if (SizeComponents.isConstU64() && SizeComponents.getConstValue()[0] == 0) {
return;
}

const auto &RuntimeFunctions = getRuntimeFunctionTable();
uint64_t Non64Value = std::numeric_limits<uint64_t>::max();
normalizeOperandU64(DestOffsetComponents, &Non64Value);
Expand Down
11 changes: 11 additions & 0 deletions tests/evm_asm/calldatacopy_zero_size.easm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// CALLDATACOPY with size 0 must not access or expand memory
PUSH1 0x2a
PUSH1 0x00
MSTORE
PUSH1 0x00
PUSH32 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
PUSH1 0x00
CALLDATACOPY
PUSH1 0x20
PUSH1 0x00
RETURN
1 change: 1 addition & 0 deletions tests/evm_asm/calldatacopy_zero_size.evm.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
602A60005260007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF60003760206000F3
8 changes: 8 additions & 0 deletions tests/evm_asm/calldatacopy_zero_size.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
status: success
error_code: 0
stack: []
memory: '000000000000000000000000000000000000000000000000000000000000002A'
storage: {}
transient_storage: {}
return: '000000000000000000000000000000000000000000000000000000000000002A'
events: []
Loading