Merge pull request #9489 from ethereum/fixStackLit

Fix handling of long literal arguments in the stack compressor.
This commit is contained in:
chriseth 2020-07-23 16:49:39 +02:00 committed by GitHub
commit 95c8f41ddf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 4 deletions

View File

@ -163,14 +163,21 @@ NoOutputEVMDialect::NoOutputEVMDialect(EVMDialect const& _copyFrom):
{ {
for (auto& fun: m_functions) for (auto& fun: m_functions)
{ {
size_t parameters = fun.second.parameters.size();
size_t returns = fun.second.returns.size(); size_t returns = fun.second.returns.size();
fun.second.generateCode = [=](FunctionCall const& _call, AbstractAssembly& _assembly, BuiltinContext&, std::function<void(Expression const&)> _visitExpression) fun.second.generateCode = [=](FunctionCall const& _call, AbstractAssembly& _assembly, BuiltinContext&, std::function<void(Expression const&)> _visitExpression)
{ {
for (auto const& arg: _call.arguments | boost::adaptors::reversed) size_t visited = 0;
_visitExpression(arg); for (size_t j = 0; j < _call.arguments.size(); j++)
{
size_t const i = _call.arguments.size() - j - 1;
if (!(fun.second.literalArguments && (*fun.second.literalArguments)[i]))
{
_visitExpression(_call.arguments[i]);
visited++;
}
}
for (size_t i = 0; i < parameters; i++) for (size_t i = 0; i < visited; i++)
_assembly.appendInstruction(evmasm::Instruction::POP); _assembly.appendInstruction(evmasm::Instruction::POP);
for (size_t i = 0; i < returns; i++) for (size_t i = 0; i < returns; i++)

View File

@ -0,0 +1,25 @@
object "t" {
code {
sstore(0, datasize("name_that_is_longer_than_32_bytes_name_that_is_longer_than_32_bytes_name_that_is_longer_than_32_bytes"))
}
object "name_that_is_longer_than_32_bytes_name_that_is_longer_than_32_bytes_name_that_is_longer_than_32_bytes" {
code {}
}
}
// ====
// optimize: true
// ----
// Assembly:
// /* "source":23:147 */
// dataSize(sub_0)
// /* "source":30:31 */
// 0x00
// /* "source":23:147 */
// sstore
// stop
//
// sub_0: assembly {
// }
// Bytecode: 6000600055fe
// Opcodes: PUSH1 0x0 PUSH1 0x0 SSTORE INVALID
// SourceMappings: 23:124:0:-:0;30:1;23:124