Skip to content

Commit

Permalink
Emit PUSH0 as junk in evm code transform, if available.
Browse files Browse the repository at this point in the history
  • Loading branch information
ekpyron committed Apr 17, 2023
1 parent 6bc6ae9 commit 3458da9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions libyul/backends/evm/AbstractAssembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ class AbstractAssembly

/// 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 };
Expand Down
5 changes: 5 additions & 0 deletions libyul/backends/evm/EthAssemblyAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions libyul/backends/evm/EthAssemblyAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class EthAssemblyAdapter: public AbstractAssembly

void markAsInvalid() override;

langutil::EVMVersion evmVersion() const override;


private:
static LabelID assemblyTagToIdentifier(evmasm::AssemblyItem const& _tag);
void appendJumpInstruction(evmasm::Instruction _instruction, JumpType _jumpType);
Expand Down
2 changes: 2 additions & 0 deletions libyul/backends/evm/NoOutputAssembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class NoOutputAssembly: public AbstractAssembly

void markAsInvalid() override {}

langutil::EVMVersion evmVersion() const override { return m_evmVersion; }

private:
int m_stackHeight = 0;
langutil::EVMVersion m_evmVersion;
Expand Down
5 changes: 4 additions & 1 deletion libyul/backends/evm/OptimizedEVMCodeTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,10 @@ void OptimizedEVMCodeTransform::createStackLayout(std::shared_ptr<DebugData cons
[&](JunkSlot const&)
{
// Note: this will always be popped, so we can push anything.
m_assembly.appendInstruction(evmasm::Instruction::CODESIZE);
if (m_assembly.evmVersion().hasPush0())
m_assembly.appendConstant(0);
else
m_assembly.appendInstruction(evmasm::Instruction::CODESIZE);
}
}, _slot);
},
Expand Down

0 comments on commit 3458da9

Please sign in to comment.