From 49567b3f4c216b3345cd5e6c2f2a9a3b27b54fb6 Mon Sep 17 00:00:00 2001 From: Robbie Ferguson Date: Tue, 27 Feb 2018 21:48:16 +1100 Subject: [PATCH] Update Delegatecall Description in Docs The previous description did not include the fact that the storage locations of the two contracts must align up until the storage variable(s) affected in order for the called contract to successfully write to the caller's storage. If they are misaligned, delegatecall will silently fail. This is difficult to debug without underlying knowledge of how delegatecall works, and clarity in the docs would certainly be helpful. --- docs/units-and-global-variables.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/units-and-global-variables.rst b/docs/units-and-global-variables.rst index 2571f20aa..e7f41ed15 100644 --- a/docs/units-and-global-variables.rst +++ b/docs/units-and-global-variables.rst @@ -168,6 +168,13 @@ For more information, see the section on :ref:`address`. to make safe Ether transfers, always check the return value of ``send``, use ``transfer`` or even better: Use a pattern where the recipient withdraws the money. +.. note:: + If storage variables are accessed via a low-level delegatecall, the storage layout of the two contracts + must align in order for the called contract to correctly access the storage variables of the calling contract by name. + This is of course not the case if storage pointers are passed as function arguments as in the case for + the high-level libraries. + + .. note:: The use of ``callcode`` is discouraged and will be removed in the future.