aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2017-03-10 00:03:53 +0800
committerchriseth <c@ethdev.com>2017-03-14 21:21:33 +0800
commit47cd8964b8617e5c7e93232719224c8334a4c764 (patch)
treeea29137b7c499b0ddbef1e62bb8a4d401c694224 /docs
parent9aab3b8639afa6e30e866e052a412b6f39c6ef6c (diff)
downloaddexon-solidity-47cd8964b8617e5c7e93232719224c8334a4c764.tar
dexon-solidity-47cd8964b8617e5c7e93232719224c8334a4c764.tar.gz
dexon-solidity-47cd8964b8617e5c7e93232719224c8334a4c764.tar.bz2
dexon-solidity-47cd8964b8617e5c7e93232719224c8334a4c764.tar.lz
dexon-solidity-47cd8964b8617e5c7e93232719224c8334a4c764.tar.xz
dexon-solidity-47cd8964b8617e5c7e93232719224c8334a4c764.tar.zst
dexon-solidity-47cd8964b8617e5c7e93232719224c8334a4c764.zip
Require and Assert.
Diffstat (limited to 'docs')
-rw-r--r--docs/control-structures.rst11
-rw-r--r--docs/miscellaneous.rst4
2 files changed, 12 insertions, 3 deletions
diff --git a/docs/control-structures.rst b/docs/control-structures.rst
index 83d3eac9..25bf203b 100644
--- a/docs/control-structures.rst
+++ b/docs/control-structures.rst
@@ -396,12 +396,19 @@ Currently, Solidity automatically generates a runtime exception in the following
#. If your contract receives Ether via a public getter function.
#. If you call a zero-initialized variable of internal function type.
#. If a ``.transfer()`` fails.
+#. If you call ``assert`` with an argument that evaluates to false.
While a user-provided exception is generated in the following situations:
#. Calling ``throw``.
+#. Calling ``require`` with an argument that evaluates to ``false``.
-Internally, Solidity performs a revert operation (instruction ``0xfd``) when a user-provided exception is thrown. In contrast, it performs an invalid operation
-(instruction ``0xfe``) if a runtime exception is encountered. In both cases, this causes
+Internally, Solidity performs a revert operation (instruction ``0xfd``) when a user-provided exception is thrown or the condition of
+a ``require`` call is not met. In contrast, it performs an invalid operation
+(instruction ``0xfe``) if a runtime exception is encountered or the condition of an ``assert`` call is not met. In both cases, this causes
the EVM to revert all changes made to the state. The reason for this is that there is no safe way to continue execution, because an expected effect
did not occur. Because we want to retain the atomicity of transactions, the safest thing to do is to revert all changes and make the whole transaction
(or at least call) without effect.
+
+If contracts are written so that ``assert`` is only used to test internal conditions and ``require``
+is used in case of malformed input, a formal analysis tool that verifies that the invalid
+opcode can never be reached can be used to check for the absence of errors assuming valid inputs. \ No newline at end of file
diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst
index e3ec0efb..2865d884 100644
--- a/docs/miscellaneous.rst
+++ b/docs/miscellaneous.rst
@@ -435,7 +435,7 @@ The following is the order of precedence for operators, listed in order of evalu
| *16* | Comma operator | ``,`` |
+------------+-------------------------------------+--------------------------------------------+
-.. index:: block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin, revert, keccak256, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send
+.. index:: assert, block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin, revert, require, keccak256, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send
Global Variables
================
@@ -453,6 +453,8 @@ Global Variables
- ``now`` (``uint``): current block timestamp (alias for ``block.timestamp``)
- ``tx.gasprice`` (``uint``): gas price of the transaction
- ``tx.origin`` (``address``): sender of the transaction (full call chain)
+- ``assert(bool condition)``: abort execution and revert state changes if condition is ``false`` (use for internal error)
+- ``require(bool condition)``: abort execution and revert state changes if condition is ``false`` (use for malformed input)
- ``revert()``: abort execution and revert state changes
- ``keccak256(...) returns (bytes32)``: compute the Ethereum-SHA-3 (Keccak-256) hash of the (tightly packed) arguments
- ``sha3(...) returns (bytes32)``: an alias to `keccak256()`