Skip to content

Commit ab18b6d

Browse files
authored
Merge pull request argotorg#14787 from ethereum/fuzz-mcopy
Yul proto fuzzer: Add mcopy builtin to generator.
2 parents fd73bce + 9d80e0e commit ab18b6d

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

test/tools/ossfuzz/protoToYul.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,10 @@ void ProtoConverter::visit(CopyFunc const& _x)
796796
if (type == CopyFunc::RETURNDATA && !m_evmVersion.supportsReturndata())
797797
return;
798798

799+
// Bail out if MCOPY is not supported for fuzzed EVM version
800+
if (type == CopyFunc::MEMORY && !m_evmVersion.hasMcopy())
801+
return;
802+
799803
// Code copy may change state if e.g., some byte of code
800804
// is stored to storage via a sequence of mload and sstore.
801805
if (m_filterStatefulInstructions && type == CopyFunc::CODE)
@@ -816,13 +820,22 @@ void ProtoConverter::visit(CopyFunc const& _x)
816820
case CopyFunc::DATA:
817821
m_output << "datacopy";
818822
break;
823+
case CopyFunc::MEMORY:
824+
m_output << "mcopy";
819825
}
820826
m_output << "(";
821827
m_output << "mod(";
822828
visit(_x.target());
823829
m_output << ", " << to_string(s_maxMemory - s_maxSize) << ")";
824830
m_output << ", ";
825-
visit(_x.source());
831+
if (type == CopyFunc::MEMORY)
832+
{
833+
m_output << "mod(";
834+
visit(_x.source());
835+
m_output << ", " << to_string(s_maxMemory - s_maxSize) << ")";
836+
}
837+
else
838+
visit(_x.source());
826839
m_output << ", ";
827840
m_output << "mod(";
828841
visit(_x.size());

test/tools/ossfuzz/protoToYul.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,9 @@ class ProtoConverter
346346
static auto constexpr s_dataIdentifier = "datablock";
347347
/// Upper bound on memory writes is 64KB in order to
348348
/// preserve semantic equivalence in the presence of
349-
/// memory guard
349+
/// memory guard. Note that s_maxMemory must be much larger
350+
/// than s_maxSize to create tests without significant overlap
351+
/// of I/O memory regions.
350352
static unsigned constexpr s_maxMemory = 65536;
351353
/// Upper bound on size for range copy functions
352354
static unsigned constexpr s_maxSize = 32768;

test/tools/ossfuzz/yulProto.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ message CopyFunc {
186186
CODE = 1;
187187
RETURNDATA = 2;
188188
DATA = 3;
189+
MEMORY = 4;
189190
}
190191
required CopyType ct = 1;
191192
required Expression target = 2;

0 commit comments

Comments
 (0)