mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Allow stack limit evasion in system yul routines during old code generation.
This commit is contained in:
@@ -484,7 +484,7 @@ void CompilerContext::appendInlineAssembly(
|
||||
obj.code = parserResult;
|
||||
obj.analysisInfo = make_shared<yul::AsmAnalysisInfo>(analysisInfo);
|
||||
|
||||
optimizeYul(obj, dialect, _optimiserSettings, externallyUsedIdentifiers);
|
||||
optimizeYul(obj, dialect, _optimiserSettings, externallyUsedIdentifiers, _system);
|
||||
|
||||
if (_system)
|
||||
{
|
||||
@@ -531,7 +531,13 @@ void CompilerContext::appendInlineAssembly(
|
||||
}
|
||||
|
||||
|
||||
void CompilerContext::optimizeYul(yul::Object& _object, yul::EVMDialect const& _dialect, OptimiserSettings const& _optimiserSettings, std::set<yul::YulString> const& _externalIdentifiers)
|
||||
void CompilerContext::optimizeYul(
|
||||
yul::Object& _object,
|
||||
yul::EVMDialect const& _dialect,
|
||||
OptimiserSettings const& _optimiserSettings,
|
||||
std::set<yul::YulString> const& _externalIdentifiers,
|
||||
bool _system
|
||||
)
|
||||
{
|
||||
#ifdef SOL_OUTPUT_ASM
|
||||
cout << yul::AsmPrinter(*dialect)(*_object.code) << endl;
|
||||
@@ -539,6 +545,7 @@ void CompilerContext::optimizeYul(yul::Object& _object, yul::EVMDialect const& _
|
||||
|
||||
bool const isCreation = runtimeContext() != nullptr;
|
||||
yul::GasMeter meter(_dialect, isCreation, _optimiserSettings.expectedExecutionsPerDeployment);
|
||||
solAssert(m_freeMemoryInitPush, "");
|
||||
yul::OptimiserSuite::run(
|
||||
_dialect,
|
||||
&meter,
|
||||
@@ -546,7 +553,8 @@ void CompilerContext::optimizeYul(yul::Object& _object, yul::EVMDialect const& _
|
||||
_optimiserSettings.optimizeStackAllocation,
|
||||
_optimiserSettings.yulOptimiserSteps,
|
||||
isCreation? nullopt : make_optional(_optimiserSettings.expectedExecutionsPerDeployment),
|
||||
_externalIdentifiers
|
||||
_externalIdentifiers,
|
||||
_system ? m_freeMemoryInitPush : shared_ptr<u256>{}
|
||||
);
|
||||
|
||||
#ifdef SOL_OUTPUT_ASM
|
||||
|
||||
@@ -276,7 +276,13 @@ public:
|
||||
/// Otherwise returns "revert(0, 0)".
|
||||
std::string revertReasonIfDebug(std::string const& _message = "");
|
||||
|
||||
void optimizeYul(yul::Object& _object, yul::EVMDialect const& _dialect, OptimiserSettings const& _optimiserSetting, std::set<yul::YulString> const& _externalIdentifiers = {});
|
||||
void optimizeYul(
|
||||
yul::Object& _object,
|
||||
yul::EVMDialect const& _dialect,
|
||||
OptimiserSettings const& _optimiserSetting,
|
||||
std::set<yul::YulString> const& _externalIdentifiers = {},
|
||||
bool _system = false
|
||||
);
|
||||
|
||||
/// Appends arbitrary data to the end of the bytecode.
|
||||
void appendToAuxiliaryData(bytes const& _data) { m_asm->appendToAuxiliaryData(_data); }
|
||||
@@ -309,6 +315,12 @@ public:
|
||||
|
||||
RevertStrings revertStrings() const { return m_revertStrings; }
|
||||
|
||||
evmasm::AssemblyItem makeFreeMemoryInitPush(u256 _value)
|
||||
{
|
||||
m_freeMemoryInitPush = std::make_shared<u256>(_value);
|
||||
return evmasm::AssemblyItem(m_freeMemoryInitPush);
|
||||
}
|
||||
|
||||
private:
|
||||
/// Updates source location set in the assembly.
|
||||
void updateSourceLocation();
|
||||
@@ -394,6 +406,8 @@ private:
|
||||
std::queue<std::tuple<std::string, unsigned, unsigned, std::function<void(CompilerContext&)>>> m_lowLevelFunctionGenerationQueue;
|
||||
/// Flag to check that appendYulUtilityFunctions() was called exactly once
|
||||
bool m_appendYulUtilityFunctionsRan = false;
|
||||
/// The assembly item that pushes the initial value of the free memory pointer.
|
||||
std::shared_ptr<u256> m_freeMemoryInitPush;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ void CompilerUtils::initialiseFreeMemoryPointer()
|
||||
{
|
||||
size_t reservedMemory = m_context.reservedMemory();
|
||||
solAssert(bigint(generalPurposeMemoryStart) + bigint(reservedMemory) < bigint(1) << 63, "");
|
||||
m_context << (u256(generalPurposeMemoryStart) + reservedMemory);
|
||||
m_context << m_context.makeFreeMemoryInitPush((u256(generalPurposeMemoryStart) + reservedMemory));
|
||||
storeFreeMemoryPointer();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user