Disable mload, msize and functions that call themselves (other forms of recusion are still possible)

This commit is contained in:
Bhargava Shastry 2021-04-15 11:40:09 +02:00
parent 614fe9ea9e
commit 851a21ad37
3 changed files with 11 additions and 7 deletions

View File

@ -321,6 +321,8 @@ YulOptimizerTestCommon::YulOptimizerTestCommon(
}},
{"stackLimitEvader", [&]() {
disambiguate();
FunctionHoister::run(*m_context, *m_ast);
CircularReferencesPruner::run(*m_context, *m_ast);
StackLimitEvader::run(*m_context, *m_object, CompilabilityChecker{
*m_dialect,
*m_object,

View File

@ -129,12 +129,9 @@ DEFINE_PROTO_FUZZER(Program const& _input)
EVMDialect::strictAssemblyForEVMObjects(version)
);
// Run circular references pruner and then stack limit evader.
string step = "circularReferencesPruner";
string step = "stackLimitEvader";
optimizerTest.setStep(step);
shared_ptr<solidity::yul::Block> astBlock = optimizerTest.run();
step = "stackLimitEvader";
optimizerTest.setStep(step);
astBlock = optimizerTest.run();
string optimisedProgram = Whiskers(R"(
object "main" {
code {

View File

@ -573,7 +573,8 @@ void ProtoConverter::visit(UnaryOp const& _x)
op == UnaryOp::EXTCODEHASH ||
op == UnaryOp::EXTCODESIZE ||
op == UnaryOp::BALANCE ||
op == UnaryOp::BLOCKHASH
op == UnaryOp::BLOCKHASH ||
op == UnaryOp::MLOAD
)
)
{
@ -659,7 +660,8 @@ void ProtoConverter::visit(NullaryOp const& _x)
op == NullaryOp::TIMESTAMP ||
op == NullaryOp::NUMBER ||
op == NullaryOp::CHAINID ||
op == NullaryOp::SELFBALANCE
op == NullaryOp::SELFBALANCE ||
op == NullaryOp::MSIZE
)
)
{
@ -1057,6 +1059,9 @@ optional<string> ProtoConverter::functionExists(NumFunctionReturns _numReturns)
void ProtoConverter::visit(FunctionCall const& _x, string const& _functionName, bool _expression)
{
// Disable recursive calls.
if (_functionName == m_currentFunctionName)
return;
yulAssert(m_functionSigMap.count(_functionName), "Proto fuzzer: Invalid function.");
auto ret = m_functionSigMap.at(_functionName);
unsigned numInParams = ret.first;
@ -1721,7 +1726,7 @@ void ProtoConverter::fillFunctionCallInput(unsigned _numInParams)
m_output << "calldataload(" << slot << ")";
break;
case 1:
m_output << "mload(" << slot << ")";
m_output << "sload(" << slot << ")";
break;
case 2:
m_output << "sload(" << slot << ")";