diff --git a/libevmasm/SemanticInformation.cpp b/libevmasm/SemanticInformation.cpp index cd16185c4..8085bbb67 100644 --- a/libevmasm/SemanticInformation.cpp +++ b/libevmasm/SemanticInformation.cpp @@ -268,6 +268,37 @@ SemanticInformation::Effect SemanticInformation::memory(Instruction _instruction } } +bool SemanticInformation::readsMemory(Instruction const _instruction) +{ + switch (_instruction) + { + // Instructions that only read from memory + case Instruction::CREATE: + case Instruction::CREATE2: + case Instruction::KECCAK256: + case Instruction::MLOAD: + case Instruction::MSIZE: + case Instruction::RETURN: + case Instruction::REVERT: + case Instruction::LOG0: + case Instruction::LOG1: + case Instruction::LOG2: + case Instruction::LOG3: + case Instruction::LOG4: + + // Instructions that read and write from memory + case Instruction::CODECOPY: + case Instruction::CALL: + case Instruction::CALLCODE: + case Instruction::DELEGATECALL: + case Instruction::STATICCALL: + return true; + + default: + return false; + } +} + bool SemanticInformation::movableApartFromEffects(Instruction _instruction) { switch (_instruction) diff --git a/libevmasm/SemanticInformation.h b/libevmasm/SemanticInformation.h index 8ba2743c4..c78689638 100644 --- a/libevmasm/SemanticInformation.h +++ b/libevmasm/SemanticInformation.h @@ -79,6 +79,10 @@ struct SemanticInformation /// msize instruction. static bool canBeRemovedIfNoMSize(Instruction _instruction); static Effect memory(Instruction _instruction); + /// Returns `true` if the instruction reads from memory. Different from + /// `SemanticInformation::memory(..) == SideEffects::Read` because some builtins read and write + /// memory at the same time. + static bool readsMemory(Instruction const _instruction); static Effect storage(Instruction _instruction); static Effect otherState(Instruction _instruction); static bool invalidInPureFunctions(Instruction _instruction);