Skip to content

Commit

Permalink
Merge pull request #15542 from ipsilon/verbatim-side-effect-fix
Browse files Browse the repository at this point in the history
Fix verbatim control flow side effects
  • Loading branch information
cameel authored Nov 22, 2024
2 parents 4231717 + 1b3d549 commit 46e1f81
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/yul.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,8 @@ the compiler. Violations of these restrictions can result in
undefined behavior.

- Control-flow should not jump into or out of verbatim blocks,
but it can jump within the same verbatim block.
but it can jump within the same verbatim block. In particular,
reverting or returning from the block is *not* allowed.
- Stack contents apart from the input and output parameters
should not be accessed.
- The stack height difference should be exactly ``m - n``
Expand Down
6 changes: 6 additions & 0 deletions libyul/ControlFlowSideEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ struct ControlFlowSideEffects

return controlFlowSideEffects;
}

/// @returns the worst-case control flow side effects.
static ControlFlowSideEffects worst()
{
return ControlFlowSideEffects{true, true, true};
}
};

}
2 changes: 1 addition & 1 deletion libyul/backends/evm/EVMDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ BuiltinFunctionForEVM EVMDialect::createVerbatimFunction(size_t _arguments, size
1 + _arguments,
_returnVariables,
SideEffects::worst(),
ControlFlowSideEffects{},
ControlFlowSideEffects::worst(), // Worst control flow side effects because verbatim can do anything.
std::vector<std::optional<LiteralKind>>{LiteralKind::String} + std::vector<std::optional<LiteralKind>>(_arguments),
[=](
FunctionCall const& _call,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
let x := 0
let y := 1
sstore(x, y)
// opcodes: PUSH1 0x00 DUP1 RETURN
// SSTORE is not redundant due to the RETURN hidden in the verbatim block. It must not be removed.
verbatim_0i_0o(hex"600080F3")
revert(0,0)
}
// ----
// step: unusedStoreEliminator
//
// {
// {
// let x := 0
// sstore(x, 1)
// verbatim_0i_0o("`\x00\x80\xf3")
// revert(0, 0)
// }
// }

0 comments on commit 46e1f81

Please sign in to comment.