Skip to content

Commit

Permalink
Merge pull request ethereum#13457 from ethereum/checks
Browse files Browse the repository at this point in the history
Explained Checks-Effects-Interactions
  • Loading branch information
Marenz authored Aug 30, 2022
2 parents b028671 + b676944 commit b2afe9f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion docs/security-considerations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ as it uses ``call`` which forwards all remaining gas by default:
}
To avoid re-entrancy, you can use the Checks-Effects-Interactions pattern as
outlined further below:
demonstrated below:

.. code-block:: solidity
Expand All @@ -116,6 +116,13 @@ outlined further below:
}
}
The Checks-Effects-Interactions pattern ensures that all code paths through a contract complete all required checks
of the supplied parameters before modifying the contract's state (Checks); only then it makes any changes to the state (Effects);
it may make calls to functions in other contracts *after* all planned state changes have been written to
storage (Interactions). This is a common foolproof way to prevent *re-entrancy attacks*, where an externally called
malicious contract is able to double-spend an allowance, double-withdraw a balance, among other things, by using logic that calls back into the
original contract before it has finalized its transaction.

Note that re-entrancy is not only an effect of Ether transfer but of any
function call on another contract. Furthermore, you also have to take
multi-contract situations into account. A called contract could modify the
Expand Down

0 comments on commit b2afe9f

Please sign in to comment.