mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix literal arguments in interpreter.
This commit is contained in:
@@ -430,28 +430,46 @@ u256 EVMInstructionInterpreter::eval(
|
||||
return 0;
|
||||
}
|
||||
|
||||
u256 EVMInstructionInterpreter::evalBuiltin(BuiltinFunctionForEVM const& _fun, const std::vector<u256>& _arguments)
|
||||
u256 EVMInstructionInterpreter::evalBuiltin(
|
||||
BuiltinFunctionForEVM const& _fun,
|
||||
vector<Expression> const& _arguments,
|
||||
vector<u256> const& _evaluatedArguments
|
||||
)
|
||||
{
|
||||
if (_fun.instruction)
|
||||
return eval(*_fun.instruction, _arguments);
|
||||
else if (_fun.name == "datasize"_yulstring)
|
||||
return u256(keccak256(h256(_arguments.at(0)))) & 0xfff;
|
||||
else if (_fun.name == "dataoffset"_yulstring)
|
||||
return u256(keccak256(h256(_arguments.at(0) + 2))) & 0xfff;
|
||||
else if (_fun.name == "datacopy"_yulstring)
|
||||
return eval(*_fun.instruction, _evaluatedArguments);
|
||||
|
||||
string fun = _fun.name.str();
|
||||
// Evaluate datasize/offset/copy instructions
|
||||
if (fun == "datasize" || fun == "dataoffset")
|
||||
{
|
||||
string arg = std::get<Literal>(_arguments.at(0)).value.str();
|
||||
if (arg.length() < 32)
|
||||
arg.resize(32, 0);
|
||||
if (fun == "datasize")
|
||||
return u256(keccak256(arg)) & 0xfff;
|
||||
else
|
||||
{
|
||||
// Force different value than for datasize
|
||||
arg[31] += 2;
|
||||
return u256(keccak256(arg)) & 0xfff;
|
||||
}
|
||||
}
|
||||
else if (fun == "datacopy")
|
||||
{
|
||||
// This is identical to codecopy.
|
||||
if (accessMemory(_arguments.at(0), _arguments.at(2)))
|
||||
if (accessMemory(_evaluatedArguments.at(0), _evaluatedArguments.at(2)))
|
||||
copyZeroExtended(
|
||||
m_state.memory,
|
||||
m_state.code,
|
||||
size_t(_arguments.at(0)),
|
||||
size_t(_arguments.at(1) & numeric_limits<size_t>::max()),
|
||||
size_t(_arguments.at(2))
|
||||
size_t(_evaluatedArguments.at(0)),
|
||||
size_t(_evaluatedArguments.at(1) & numeric_limits<size_t>::max()),
|
||||
size_t(_evaluatedArguments.at(2))
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
yulAssert(false, "Unknown builtin: " + _fun.name.str());
|
||||
yulAssert(false, "Unknown builtin: " + fun);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user