aboutsummaryrefslogtreecommitdiffstats
path: root/docs/contracts.rst
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-11-27 03:10:12 +0800
committerGitHub <noreply@github.com>2018-11-27 03:10:12 +0800
commit5e55cb17299e1c8f9a685637703e9bd956cfc826 (patch)
tree4a8de6091e0d93b5fdf7946e485d265aec774b8d /docs/contracts.rst
parent3adddefaf1fc32da706beeeba6d1445bf5477fdb (diff)
parentae542176e3a8490cb83a42a309208fa6c5fd1589 (diff)
downloaddexon-solidity-5e55cb17299e1c8f9a685637703e9bd956cfc826.tar.gz
dexon-solidity-5e55cb17299e1c8f9a685637703e9bd956cfc826.tar.zst
dexon-solidity-5e55cb17299e1c8f9a685637703e9bd956cfc826.zip
Merge pull request #5277 from ethereum/docs-5175-require-revert
DOCS: Add mention that pure functions can require and revert
Diffstat (limited to 'docs/contracts.rst')
-rw-r--r--docs/contracts.rst23
1 files changed, 16 insertions, 7 deletions
diff --git a/docs/contracts.rst b/docs/contracts.rst
index 9913cfb3..df95883f 100644
--- a/docs/contracts.rst
+++ b/docs/contracts.rst
@@ -671,6 +671,20 @@ In addition to the list of state modifying statements explained above, the follo
}
}
+Pure functions are able to use the `revert()` and `require()` functions to revert
+potential state changes when an :ref:`error occurs <assert-and-require>`.
+
+Reverting a state change is not considered a "state modification", as only changes to the
+state made previously in code that did not have the ``view`` or ``pure`` restriction
+are reverted and that code has the option to catch the ``revert`` and not pass it on.
+
+This behaviour is also in line with the ``STATICCALL`` opcode.
+
+.. warning::
+ It is not possible to prevent functions from reading the state at the level
+ of the EVM, it is only possible to prevent them from writing to the state
+ (i.e. only ``view`` can be enforced at the EVM level, ``pure`` can not).
+
.. note::
Prior to version 0.5.0, the compiler did not use the ``STATICCALL`` opcode
for ``pure`` functions.
@@ -679,13 +693,8 @@ In addition to the list of state modifying statements explained above, the follo
By using ``STATICCALL`` for ``pure`` functions, modifications to the
state are prevented on the level of the EVM.
-.. warning::
- It is not possible to prevent functions from reading the state at the level
- of the EVM, it is only possible to prevent them from writing to the state
- (i.e. only ``view`` can be enforced at the EVM level, ``pure`` can not).
-
-.. warning::
- Before version 0.4.17 the compiler did not enforce that ``pure`` is not reading the state.
+.. note::
+ Prior to version 0.4.17 the compiler did not enforce that ``pure`` is not reading the state.
It is a compile-time type check, which can be circumvented doing invalid explicit conversions
between contract types, because the compiler can verify that the type of the contract does
not do state-changing operations, but it cannot check that the contract that will be called