Skip to content

Commit b676944

Browse files
lukehutchLeo Alt
authored andcommitted
Update security-considerations.rst
Explained Checks-Effects-Interactions and added info on Checks-Effects-Events-Interactions
1 parent e048ba4 commit b676944

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

docs/security-considerations.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ as it uses ``call`` which forwards all remaining gas by default:
9898
}
9999
100100
To avoid re-entrancy, you can use the Checks-Effects-Interactions pattern as
101-
outlined further below:
101+
demonstrated below:
102102

103103
.. code-block:: solidity
104104
@@ -116,6 +116,13 @@ outlined further below:
116116
}
117117
}
118118
119+
The Checks-Effects-Interactions pattern ensures that all code paths through a contract complete all required checks
120+
of the supplied parameters before modifying the contract's state (Checks); only then it makes any changes to the state (Effects);
121+
it may make calls to functions in other contracts *after* all planned state changes have been written to
122+
storage (Interactions). This is a common foolproof way to prevent *re-entrancy attacks*, where an externally called
123+
malicious contract is able to double-spend an allowance, double-withdraw a balance, among other things, by using logic that calls back into the
124+
original contract before it has finalized its transaction.
125+
119126
Note that re-entrancy is not only an effect of Ether transfer but of any
120127
function call on another contract. Furthermore, you also have to take
121128
multi-contract situations into account. A called contract could modify the

0 commit comments

Comments
 (0)