You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Changelog.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,10 @@
1
1
### 0.5.0 (unreleased)
2
2
3
+
How to update your code:
4
+
* Change every ``.call()`` to a ``.call("")`` and every ``.call(signature, a, b, c)`` to use ``.call(abi.encodeWithSignature(signature, a, b, c))`` (the last one only works for value types).
5
+
* Change every ``keccak256(a, b, c)`` to ``keccak256(abi.encodePacked(a, b, c))``.
6
+
7
+
3
8
Breaking Changes:
4
9
* ABI Encoder: Properly pad data from calldata (``msg.data`` and external function parameters). Use ``abi.encodePacked`` for unpadded encoding.
5
10
* Code Generator: Signed right shift uses proper arithmetic shift, i.e. rounding towards negative infinity. Warning: this may silently change the semantics of existing code!
@@ -22,6 +27,7 @@ Breaking Changes:
22
27
* Parser: Disallow trailing dots that are not followed by a number.
23
28
* Type Checker: Disallow arithmetic operations for boolean variables.
24
29
* Type Checker: Disallow conversions between ``bytesX`` and ``uintY`` of different size.
30
+
* Type Checker: Only accept a single ``bytes`` type for ``.call()`` (and family), ``keccak256()``, ``sha256()`` and ``ripemd160()``.
25
31
* Remove obsolete ``std`` directory from the Solidity repository. This means accessing ``https://github.com/ethereum/soldity/blob/develop/std/*.sol`` (or ``https://github.com/ethereum/solidity/std/*.sol`` in Remix) will not be possible.
26
32
* Syntax Checker: Named return values in function types are an error.
Copy file name to clipboardExpand all lines: docs/miscellaneous.rst
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -322,7 +322,7 @@ Global Variables
322
322
- ``abi.encodePacked(...) returns (bytes)``: Performes :ref:`packed encoding <abi_packed_mode>` of the given arguments
323
323
- ``abi.encodeWithSelector(bytes4 selector, ...) returns (bytes)``: :ref:`ABI <ABI>`-encodes the given arguments
324
324
starting from the second and prepends the given four-byte selector
325
-
- ``abi.encodeWithSignature(string signature, ...) returns (bytes)``: Equivalent to ``abi.encodeWithSelector(bytes4(keccak256(signature), ...)```
325
+
- ``abi.encodeWithSignature(string signature, ...) returns (bytes)``: Equivalent to ``abi.encodeWithSelector(bytes4(keccak256(bytes(signature)), ...)```
326
326
- ``block.blockhash(uint blockNumber) returns (bytes32)``: hash of the given block - only works for 256 most recent, excluding current, blocks - deprecated in version 0.4.22 and replaced by ``blockhash(uint blockNumber)``.
327
327
- ``block.coinbase`` (``address``): current block miner's address
328
328
- ``block.difficulty`` (``uint``): current block difficulty
@@ -343,10 +343,10 @@ Global Variables
343
343
- ``revert()``: abort execution and revert state changes
344
344
- ``revert(string message)``: abort execution and revert state changes providing an explanatory string
345
345
- ``blockhash(uint blockNumber) returns (bytes32)``: hash of the given block - only works for 256 most recent blocks
346
-
- ``keccak256(...) returns (bytes32)``: compute the Ethereum-SHA-3 (Keccak-256) hash of the :ref:`(tightly packed) arguments <abi_packed_mode>`
347
-
- ``sha3(...) returns (bytes32)``: an alias to ``keccak256``
348
-
- ``sha256(...) returns (bytes32)``: compute the SHA-256 hash of the :ref:`(tightly packed) arguments <abi_packed_mode>`
349
-
- ``ripemd160(...) returns (bytes20)``: compute the RIPEMD-160 hash of the :ref:`(tightly packed) arguments <abi_packed_mode>`
346
+
- ``keccak256(bytes memory) returns (bytes32)``: compute the Ethereum-SHA-3 (Keccak-256) hash of the input
347
+
- ``sha3(bytes memory) returns (bytes32)``: an alias to ``keccak256``
348
+
- ``sha256(bytes memory) returns (bytes32)``: compute the SHA-256 hash of the input
349
+
- ``ripemd160(bytes memory) returns (bytes20)``: compute the RIPEMD-160 hash of the input
350
350
- ``ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address)``: recover address associated with the public key from elliptic curve signature, return zero on error
351
351
- ``addmod(uint x, uint y, uint k) returns (uint)``: compute ``(x + y) % k`` where the addition is performed with arbitrary precision and does not wrap around at ``2**256``. Assert that ``k != 0`` starting from version 0.5.0.
352
352
- ``mulmod(uint x, uint y, uint k) returns (uint)``: compute ``(x * y) % k`` where the multiplication is performed with arbitrary precision and does not wrap around at ``2**256``. Assert that ``k != 0`` starting from version 0.5.0.
Copy file name to clipboardExpand all lines: docs/types.rst
+19-16Lines changed: 19 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -143,27 +143,37 @@ Send is the low-level counterpart of ``transfer``. If the execution fails, the c
143
143
* ``call``, ``callcode`` and ``delegatecall``
144
144
145
145
Furthermore, to interface with contracts that do not adhere to the ABI,
146
-
the function ``call`` is provided which takes an arbitrary number of arguments of any type. These arguments are padded to 32 bytes and concatenated. One exception is the case where the first argument is encoded to exactly four bytes. In this case, it is not padded to allow the use of function signatures here.
146
+
or to get more direct control over the encoding,
147
+
the function ``call`` is provided which takes a single byte array as input.
148
+
The functions ``abi.encode``, ``abi.encodePacked``, ``abi.encodeWithSelector``
149
+
and ``abi.encodeWithSignature`` can be used to encode structured data.
147
150
148
-
::
151
+
.. warning::
152
+
All these functions are low-level functions and should be used with care.
153
+
Specifically, any unknown contract might be malicious and if you call it, you
154
+
hand over control to that contract which could in turn call back into
155
+
your contract, so be prepared for changes to your state variables
156
+
when the call returns. The regular way to interact with other contracts
157
+
is to call a function on a contract object (``x.f()``).
Previous versions of Solidity allowed these functions to receive
161
+
arbitrary arguments and would also handle a first argument of type
162
+
``bytes4`` differently. These edge cases were removed in version 0.5.0.
153
163
154
-
``call`` returns a boolean indicating whether the invoked function terminated (``true``) or caused an EVM exception (``false``). It is not possible to access the actual data returned (for this we would need to know the encoding and size in advance).
164
+
``call`` returns a boolean indicating whether the invoked function terminated (``true``) or caused an EVM exception (``false``). It is not possible to access the actual data returned with plain Solidity. However, using inline assembly it is possible to make a raw ``call`` and access the actual data returned with the ``returndatacopy`` instruction.
155
165
156
166
It is possible to adjust the supplied gas with the ``.gas()`` modifier::
Copy file name to clipboardExpand all lines: docs/units-and-global-variables.rst
+18-34Lines changed: 18 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -100,16 +100,16 @@ ABI Encoding Functions
100
100
----------------------
101
101
102
102
- ``abi.encode(...) returns (bytes)``: ABI-encodes the given arguments
103
-
- ``abi.encodePacked(...) returns (bytes)``: Performes packed encoding of the given arguments
103
+
- ``abi.encodePacked(...) returns (bytes)``: Performes :ref:`packed encoding<abi_packed_mode>` of the given arguments
104
104
- ``abi.encodeWithSelector(bytes4 selector, ...) returns (bytes)``: ABI-encodes the given arguments
105
105
starting from the second and prepends the given four-byte selector
106
-
- ``abi.encodeWithSignature(string signature, ...) returns (bytes)``: Equivalent to ``abi.encodeWithSelector(bytes4(keccak256(signature), ...)```
106
+
- ``abi.encodeWithSignature(string signature, ...) returns (bytes)``: Equivalent to ``abi.encodeWithSelector(bytes4(keccak256(bytes(signature)), ...)```
107
107
108
108
.. note::
109
109
These encoding functions can be used to craft data for function calls without actually
110
-
calling a function. Furthermore, ``keccak256(abi.encodePacked(a, b))`` is a more
111
-
explicit way to compute ``keccak256(a, b)``, which will be deprecated in future
112
-
versions.
110
+
calling a function. Furthermore, ``keccak256(abi.encodePacked(a, b))`` is a way
111
+
to compute the hash of structured data (although be aware that it is possible to
112
+
craft a "hash collision" using different inputs types).
113
113
114
114
See the documentation about the :ref:`ABI <ABI>` and the
115
115
:ref:`tightly packed encoding <abi_packed_mode>` for details about the encoding.
@@ -139,34 +139,18 @@ Mathematical and Cryptographic Functions
139
139
compute ``(x + y) % k`` where the addition is performed with arbitrary precision and does not wrap around at ``2**256``. Assert that ``k != 0`` starting from version 0.5.0.
140
140
``mulmod(uint x, uint y, uint k) returns (uint)``:
141
141
compute ``(x * y) % k`` where the multiplication is performed with arbitrary precision and does not wrap around at ``2**256``. Assert that ``k != 0`` starting from version 0.5.0.
142
-
``keccak256(...) returns (bytes32)``:
143
-
compute the Ethereum-SHA-3 (Keccak-256) hash of the :ref:`(tightly packed) arguments <abi_packed_mode>`
144
-
``sha256(...) returns (bytes32)``:
145
-
compute the SHA-256 hash of the :ref:`(tightly packed) arguments <abi_packed_mode>`
146
-
``sha3(...) returns (bytes32)``:
142
+
``keccak256(bytes memory) returns (bytes32)``:
143
+
compute the Ethereum-SHA-3 (Keccak-256) hash of the input
144
+
``sha256(bytes memory) returns (bytes32)``:
145
+
compute the SHA-256 hash of the input
146
+
``sha3(bytes memory) returns (bytes32)``:
147
147
alias to ``keccak256``
148
-
``ripemd160(...) returns (bytes20)``:
149
-
compute RIPEMD-160 hash of the :ref:`(tightly packed) arguments <abi_packed_mode>`
It might be that you run into Out-of-Gas for ``sha256``, ``ripemd160`` or ``ecrecover`` on a *private blockchain*. The reason for this is that those are implemented as so-called precompiled contracts and these contracts only really exist after they received the first message (although their contract code is hardcoded). Messages to non-existing contracts are more expensive and thus the execution runs into an Out-of-Gas error. A workaround for this problem is to first send e.g. 1 Wei to each of the contracts before you use them in your actual contracts. This is not an issue on the official or test net.
0 commit comments