Skip to content

Commit

Permalink
Relax memory safety.
Browse files Browse the repository at this point in the history
Co-authored-by: Moritz Hoffmann <clonker@gmail.com>
  • Loading branch information
ekpyron and clonker committed Jul 4, 2024
1 parent d42f92b commit 2696cff
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/assembly.rst
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,18 @@ of Solidity, you can use a special comment to annotate an assembly block as memo
Note that we will disallow the annotation via comment in a future breaking release; so, if you are not concerned with
backward-compatibility with older compiler versions, prefer using the dialect string.

Advanced Safe Use of Memory
---------------------------

Beyond the strict definition of memory-safety given above, there are cases in which you may want to use more than 64 bytes
of scratch space starting at memory offset ``0``. If you are careful, it can be admissible to use memory up to (and not
including) offset ``0x80`` and still safely declare the assembly block as ``memory-safe``.
This is admissible under either of the following conditions:

- By the end of the assembly block, the free memory pointer at offset ``0x40`` is restored to a sane value (i.e. it is either
restored to its original value or an increment of it due to a manual memory allocation), and the memory word at offset ``0x60``
is restored to a value of zero.

- The assembly block terminates, i.e. execution can never return to high-level Solidity code. This is the case, for example,
if your assembly block unconditionally ends in a ``revert`` statement.

0 comments on commit 2696cff

Please sign in to comment.