Merge pull request #14133 from ethereum/codeTransformPush0

Emit PUSH0 as junk in evm code transform, if available.
This commit is contained in:
Daniel 2023-04-17 17:24:54 +02:00 committed by GitHub
commit 9befe1d456
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 1 deletions

View File

@ -10,6 +10,7 @@ Compiler Features:
* Optimizer: Re-implement simplified version of UnusedAssignEliminator and UnusedStoreEliminator. It can correctly remove some unused assignments in deeply nested loops that were ignored by the old version.
* SMTChecker: Properties that are proved safe are now reported explicitly at the end of the analysis. By default, only the number of safe properties is shown. The CLI option ``--model-checker-show-proved-safe`` and the JSON option ``settings.modelChecker.showProvedSafe`` can be enabled to show the full list of safe properties.
* SMTChecker: Group all messages about unsupported language features in a single warning. The CLI option ``--model-checker-show-unsupported`` and the JSON option ``settings.modelChecker.showUnsupported`` can be enabled to show the full list.
* Yul EVM Code Transform: If available, use ``push0`` instead of ``codesize`` to produce an arbitrary value on stack in order to create equal stack heights between branches.
Bugfixes:

View File

@ -117,6 +117,9 @@ public:
/// Mark this assembly as invalid. Any attempt to request bytecode from it should throw.
virtual void markAsInvalid() = 0;
/// @returns the EVM version the assembly targets.
virtual langutil::EVMVersion evmVersion() const = 0;
};
enum class IdentifierContext { LValue, RValue, VariableDeclaration, NonExternal };

View File

@ -181,6 +181,11 @@ void EthAssemblyAdapter::markAsInvalid()
m_assembly.markAsInvalid();
}
langutil::EVMVersion EthAssemblyAdapter::evmVersion() const
{
return m_assembly.evmVersion();
}
EthAssemblyAdapter::LabelID EthAssemblyAdapter::assemblyTagToIdentifier(evmasm::AssemblyItem const& _tag)
{
u256 id = _tag.data();

View File

@ -67,6 +67,9 @@ public:
void markAsInvalid() override;
langutil::EVMVersion evmVersion() const override;
private:
static LabelID assemblyTagToIdentifier(evmasm::AssemblyItem const& _tag);
void appendJumpInstruction(evmasm::Instruction _instruction, JumpType _jumpType);

View File

@ -77,6 +77,8 @@ public:
void markAsInvalid() override {}
langutil::EVMVersion evmVersion() const override { return m_evmVersion; }
private:
int m_stackHeight = 0;
langutil::EVMVersion m_evmVersion;

View File

@ -351,6 +351,9 @@ void OptimizedEVMCodeTransform::createStackLayout(std::shared_ptr<DebugData cons
[&](JunkSlot const&)
{
// Note: this will always be popped, so we can push anything.
if (m_assembly.evmVersion().hasPush0())
m_assembly.appendConstant(0);
else
m_assembly.appendInstruction(evmasm::Instruction::CODESIZE);
}
}, _slot);