mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Resolving Keccak-256: check if arguments are identifiers early.
Previously, the check on whether the optimization was useful gas wise was done before checking if the keccak256 opcode had identifier as arguments. Since the gas meter crashes when encountering certain Yul opcodes (create, dataoffset, etc.), this optimizer step crashed.
This commit is contained in:
@@ -97,6 +97,13 @@ void LoadResolver::tryEvaluateKeccak(
|
||||
std::vector<Expression> const& _arguments
|
||||
)
|
||||
{
|
||||
yulAssert(_arguments.size() == 2, "");
|
||||
Identifier const* memoryKey = std::get_if<Identifier>(&_arguments.at(0));
|
||||
Identifier const* length = std::get_if<Identifier>(&_arguments.at(1));
|
||||
|
||||
if (!memoryKey || !length)
|
||||
return;
|
||||
|
||||
// The costs are only correct for hashes of 32 bytes or 1 word (when rounded up).
|
||||
GasMeter gasMeter{
|
||||
dynamic_cast<EVMDialect const&>(m_dialect),
|
||||
@@ -122,13 +129,6 @@ void LoadResolver::tryEvaluateKeccak(
|
||||
if (costOfLiteral > costOfKeccak)
|
||||
return;
|
||||
|
||||
yulAssert(_arguments.size() == 2, "");
|
||||
Identifier const* memoryKey = std::get_if<Identifier>(&_arguments.at(0));
|
||||
Identifier const* length = std::get_if<Identifier>(&_arguments.at(1));
|
||||
|
||||
if (!memoryKey || !length)
|
||||
return;
|
||||
|
||||
auto memoryValue = util::valueOrNullptr(m_memory, memoryKey->name);
|
||||
if (memoryValue && inScope(*memoryValue))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user