mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
parent
d454cec1bd
commit
eb92d5f760
@ -279,13 +279,13 @@ All together, the encoding is (newline after function selector and each 32-bytes
|
|||||||
|
|
||||||
Let us apply the same principle to encode the data for a function with a signature ``g(uint[][],string[])`` with values ``([[1, 2], [3]], ["one", "two", "three"])`` but start from the most atomic parts of the encoding:
|
Let us apply the same principle to encode the data for a function with a signature ``g(uint[][],string[])`` with values ``([[1, 2], [3]], ["one", "two", "three"])`` but start from the most atomic parts of the encoding:
|
||||||
|
|
||||||
First we encode the length and data of the first embeded dynamic array ``[1, 2]`` of the first root array ``[[1, 2], [3]]``:
|
First we encode the length and data of the first embedded dynamic array ``[1, 2]`` of the first root array ``[[1, 2], [3]]``:
|
||||||
|
|
||||||
- ``0x0000000000000000000000000000000000000000000000000000000000000002`` (number of elements in the first array, 2; the elements themselves are ``1`` and ``2``)
|
- ``0x0000000000000000000000000000000000000000000000000000000000000002`` (number of elements in the first array, 2; the elements themselves are ``1`` and ``2``)
|
||||||
- ``0x0000000000000000000000000000000000000000000000000000000000000001`` (first element)
|
- ``0x0000000000000000000000000000000000000000000000000000000000000001`` (first element)
|
||||||
- ``0x0000000000000000000000000000000000000000000000000000000000000002`` (second element)
|
- ``0x0000000000000000000000000000000000000000000000000000000000000002`` (second element)
|
||||||
|
|
||||||
Then we encode the length and data of the second embeded dynamic array ``[3]`` of the first root array ``[[1, 2], [3]]``:
|
Then we encode the length and data of the second embedded dynamic array ``[3]`` of the first root array ``[[1, 2], [3]]``:
|
||||||
|
|
||||||
- ``0x0000000000000000000000000000000000000000000000000000000000000001`` (number of elements in the second array, 1; the element is ``3``)
|
- ``0x0000000000000000000000000000000000000000000000000000000000000001`` (number of elements in the second array, 1; the element is ``3``)
|
||||||
- ``0x0000000000000000000000000000000000000000000000000000000000000003`` (first element)
|
- ``0x0000000000000000000000000000000000000000000000000000000000000003`` (first element)
|
||||||
@ -307,7 +307,7 @@ Offset ``a`` points to the start of the content of the array ``[1, 2]`` which is
|
|||||||
Offset ``b`` points to the start of the content of the array ``[3]`` which is line 5 (160 bytes); thus ``b = 0x00000000000000000000000000000000000000000000000000000000000000a0``.
|
Offset ``b`` points to the start of the content of the array ``[3]`` which is line 5 (160 bytes); thus ``b = 0x00000000000000000000000000000000000000000000000000000000000000a0``.
|
||||||
|
|
||||||
|
|
||||||
Then we encode the embeded strings of the second root array:
|
Then we encode the embedded strings of the second root array:
|
||||||
|
|
||||||
- ``0x0000000000000000000000000000000000000000000000000000000000000003`` (number of characters in word ``"one"``)
|
- ``0x0000000000000000000000000000000000000000000000000000000000000003`` (number of characters in word ``"one"``)
|
||||||
- ``0x6f6e650000000000000000000000000000000000000000000000000000000000`` (utf8 representation of word ``"one"``)
|
- ``0x6f6e650000000000000000000000000000000000000000000000000000000000`` (utf8 representation of word ``"one"``)
|
||||||
@ -337,7 +337,7 @@ Offset ``d`` points to the start of the content of the string ``"two"`` which is
|
|||||||
Offset ``e`` points to the start of the content of the string ``"three"`` which is line 7 (224 bytes); thus ``e = 0x00000000000000000000000000000000000000000000000000000000000000e0``.
|
Offset ``e`` points to the start of the content of the string ``"three"`` which is line 7 (224 bytes); thus ``e = 0x00000000000000000000000000000000000000000000000000000000000000e0``.
|
||||||
|
|
||||||
|
|
||||||
Note that the encodings of the embeded elements of the root arrays are not dependent on each other and have the same encodings for a fuction with a signature ``g(string[],uint[][])``.
|
Note that the encodings of the embedded elements of the root arrays are not dependent on each other and have the same encodings for a function with a signature ``g(string[],uint[][])``.
|
||||||
|
|
||||||
Then we encode the length of the first root array:
|
Then we encode the length of the first root array:
|
||||||
|
|
||||||
|
@ -212,9 +212,9 @@ In the grammar, opcodes are represented as pre-defined identifiers.
|
|||||||
+-------------------------+-----+---+-----------------------------------------------------------------+
|
+-------------------------+-----+---+-----------------------------------------------------------------+
|
||||||
| sar(x, y) | | C | arithmetic shift right y by x bits |
|
| sar(x, y) | | C | arithmetic shift right y by x bits |
|
||||||
+-------------------------+-----+---+-----------------------------------------------------------------+
|
+-------------------------+-----+---+-----------------------------------------------------------------+
|
||||||
| addmod(x, y, m) | | F | (x + y) % m with arbitrary precision arithmetics |
|
| addmod(x, y, m) | | F | (x + y) % m with arbitrary precision arithmetic |
|
||||||
+-------------------------+-----+---+-----------------------------------------------------------------+
|
+-------------------------+-----+---+-----------------------------------------------------------------+
|
||||||
| mulmod(x, y, m) | | F | (x * y) % m with arbitrary precision arithmetics |
|
| mulmod(x, y, m) | | F | (x * y) % m with arbitrary precision arithmetic |
|
||||||
+-------------------------+-----+---+-----------------------------------------------------------------+
|
+-------------------------+-----+---+-----------------------------------------------------------------+
|
||||||
| signextend(i, x) | | F | sign extend from (i*8+7)th bit counting from least significant |
|
| signextend(i, x) | | F | sign extend from (i*8+7)th bit counting from least significant |
|
||||||
+-------------------------+-----+---+-----------------------------------------------------------------+
|
+-------------------------+-----+---+-----------------------------------------------------------------+
|
||||||
@ -228,9 +228,9 @@ In the grammar, opcodes are represented as pre-defined identifiers.
|
|||||||
+-------------------------+-----+---+-----------------------------------------------------------------+
|
+-------------------------+-----+---+-----------------------------------------------------------------+
|
||||||
| pop(x) | `-` | F | remove the element pushed by x |
|
| pop(x) | `-` | F | remove the element pushed by x |
|
||||||
+-------------------------+-----+---+-----------------------------------------------------------------+
|
+-------------------------+-----+---+-----------------------------------------------------------------+
|
||||||
| dup1 ... dup16 | | F | copy ith stack slot to the top (counting from top) |
|
| dup1 ... dup16 | | F | copy nth stack slot to the top (counting from top) |
|
||||||
+-------------------------+-----+---+-----------------------------------------------------------------+
|
+-------------------------+-----+---+-----------------------------------------------------------------+
|
||||||
| swap1 ... swap16 | `*` | F | swap topmost and ith stack slot below it |
|
| swap1 ... swap16 | `*` | F | swap topmost and nth stack slot below it |
|
||||||
+-------------------------+-----+---+-----------------------------------------------------------------+
|
+-------------------------+-----+---+-----------------------------------------------------------------+
|
||||||
| mload(p) | | F | mem[p...(p+32)) |
|
| mload(p) | | F | mem[p...(p+32)) |
|
||||||
+-------------------------+-----+---+-----------------------------------------------------------------+
|
+-------------------------+-----+---+-----------------------------------------------------------------+
|
||||||
|
@ -20,7 +20,7 @@ Contracts can be created "from outside" via Ethereum transactions or from within
|
|||||||
|
|
||||||
IDEs, such as `Remix <https://remix.ethereum.org/>`_, make the creation process seamless using UI elements.
|
IDEs, such as `Remix <https://remix.ethereum.org/>`_, make the creation process seamless using UI elements.
|
||||||
|
|
||||||
Creating contracts programatically on Ethereum is best done via using the JavaScript API `web3.js <https://github.com/ethereum/web3.js>`_.
|
Creating contracts programmatically on Ethereum is best done via using the JavaScript API `web3.js <https://github.com/ethereum/web3.js>`_.
|
||||||
As of today it has a method called `web3.eth.Contract <https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#new-contract>`_
|
As of today it has a method called `web3.eth.Contract <https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#new-contract>`_
|
||||||
to facilitate contract creation.
|
to facilitate contract creation.
|
||||||
|
|
||||||
@ -1042,7 +1042,7 @@ constant and defines the behaviour of the contract or
|
|||||||
describes it. The second way has to be used if the
|
describes it. The second way has to be used if the
|
||||||
constructor arguments of the base depend on those of the
|
constructor arguments of the base depend on those of the
|
||||||
derived contract. Arguments have to be given either in the
|
derived contract. Arguments have to be given either in the
|
||||||
inheritance list or in modifier-style in the derived constuctor.
|
inheritance list or in modifier-style in the derived constructor.
|
||||||
Specifying arguments in both places is an error.
|
Specifying arguments in both places is an error.
|
||||||
|
|
||||||
If a derived contract doesn't specify the arguments to all of its base
|
If a derived contract doesn't specify the arguments to all of its base
|
||||||
|
@ -110,13 +110,13 @@ Example: ``./test/libsolidity/syntaxTests/double_stateVariable_declaration.sol``
|
|||||||
// ----
|
// ----
|
||||||
// DeclarationError: Identifier already declared.
|
// DeclarationError: Identifier already declared.
|
||||||
|
|
||||||
A syntax test must contain at least the contract under test itself, followed by the seperator ``----``. The additional comments above are used to describe the
|
A syntax test must contain at least the contract under test itself, followed by the separator ``----``. The additional comments above are used to describe the
|
||||||
expected compiler errors or warnings. This section can be empty in case that the contract should compile without any errors or warnings.
|
expected compiler errors or warnings. This section can be empty in case that the contract should compile without any errors or warnings.
|
||||||
|
|
||||||
In the above example, the state variable ``variable`` was declared twice, which is not allowed. This will result in a ``DeclarationError`` stating that the identifier was already declared.
|
In the above example, the state variable ``variable`` was declared twice, which is not allowed. This will result in a ``DeclarationError`` stating that the identifier was already declared.
|
||||||
|
|
||||||
The tool that is being used for those tests is called ``isoltest`` and can be found under ``./test/tools/``. It is an interactive tool which allows
|
The tool that is being used for those tests is called ``isoltest`` and can be found under ``./test/tools/``. It is an interactive tool which allows
|
||||||
editing of failing contracts using your prefered text editor. Let's try to break this test by removing the second declaration of ``variable``:
|
editing of failing contracts using your preferred text editor. Let's try to break this test by removing the second declaration of ``variable``:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
@ -237,7 +237,7 @@ Othwerise, upon execution the fuzzer will halt with an error saying binary is no
|
|||||||
Location : check_binary(), afl-fuzz.c:6920
|
Location : check_binary(), afl-fuzz.c:6920
|
||||||
|
|
||||||
|
|
||||||
Next, you need some example source files. This will make it much easer for the fuzzer
|
Next, you need some example source files. This will make it much easier for the fuzzer
|
||||||
to find errors. You can either copy some files from the syntax tests or extract test files
|
to find errors. You can either copy some files from the syntax tests or extract test files
|
||||||
from the documentation or the other tests:
|
from the documentation or the other tests:
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ write::
|
|||||||
pragma solidity ^0.4.16;
|
pragma solidity ^0.4.16;
|
||||||
|
|
||||||
contract Simple {
|
contract Simple {
|
||||||
function arithmetics(uint _a, uint _b)
|
function arithmetic(uint _a, uint _b)
|
||||||
public
|
public
|
||||||
pure
|
pure
|
||||||
returns (uint o_sum, uint o_product)
|
returns (uint o_sum, uint o_product)
|
||||||
|
@ -69,7 +69,7 @@ Can you return an array or a ``string`` from a solidity function call?
|
|||||||
Yes. See `array_receiver_and_returner.sol <https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/60_array_receiver_and_returner.sol>`_.
|
Yes. See `array_receiver_and_returner.sol <https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/60_array_receiver_and_returner.sol>`_.
|
||||||
|
|
||||||
What is problematic, though, is returning any variably-sized data (e.g. a
|
What is problematic, though, is returning any variably-sized data (e.g. a
|
||||||
variably-sized array like ``uint[]``) from a fuction **called from within Solidity**.
|
variably-sized array like ``uint[]``) from a function **called from within Solidity**.
|
||||||
This is a limitation of the EVM and will be solved with the next protocol update.
|
This is a limitation of the EVM and will be solved with the next protocol update.
|
||||||
|
|
||||||
Returning variably-sized data as part of an external transaction or call is fine.
|
Returning variably-sized data as part of an external transaction or call is fine.
|
||||||
|
@ -319,7 +319,7 @@ Global Variables
|
|||||||
================
|
================
|
||||||
|
|
||||||
- ``abi.encode(...) returns (bytes)``: :ref:`ABI <ABI>`-encodes the given arguments
|
- ``abi.encode(...) returns (bytes)``: :ref:`ABI <ABI>`-encodes the given arguments
|
||||||
- ``abi.encodePacked(...) returns (bytes)``: Performes :ref:`packed encoding <abi_packed_mode>` of the given arguments
|
- ``abi.encodePacked(...) returns (bytes)``: Performs :ref:`packed encoding <abi_packed_mode>` of the given arguments
|
||||||
- ``abi.encodeWithSelector(bytes4 selector, ...) returns (bytes)``: :ref:`ABI <ABI>`-encodes the given arguments
|
- ``abi.encodeWithSelector(bytes4 selector, ...) returns (bytes)``: :ref:`ABI <ABI>`-encodes the given arguments
|
||||||
starting from the second and prepends the given four-byte selector
|
starting from the second and prepends the given four-byte selector
|
||||||
- ``abi.encodeWithSignature(string signature, ...) returns (bytes)``: Equivalent to ``abi.encodeWithSelector(bytes4(keccak256(bytes(signature)), ...)```
|
- ``abi.encodeWithSignature(string signature, ...) returns (bytes)``: Equivalent to ``abi.encodeWithSelector(bytes4(keccak256(bytes(signature)), ...)```
|
||||||
|
@ -679,7 +679,7 @@ Creating the signature
|
|||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
Alice does not need to interact with Ethereum network to
|
Alice does not need to interact with Ethereum network to
|
||||||
sign the transaction, the proccess is completely offline.
|
sign the transaction, the process is completely offline.
|
||||||
In this tutorial, we will sign messages in the browser
|
In this tutorial, we will sign messages in the browser
|
||||||
using ``web3.js`` and ``MetaMask``.
|
using ``web3.js`` and ``MetaMask``.
|
||||||
In particular, we will use the standard way described in `EIP-762 <https://github.com/ethereum/EIPs/pull/712>`_,
|
In particular, we will use the standard way described in `EIP-762 <https://github.com/ethereum/EIPs/pull/712>`_,
|
||||||
@ -1034,7 +1034,7 @@ The full contract
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// if the timeout is reached without the recipient closing the channel,
|
/// if the timeout is reached without the recipient closing the channel,
|
||||||
/// then the Ether is realeased back to the sender.
|
/// then the Ether is released back to the sender.
|
||||||
function clainTimeout() public {
|
function clainTimeout() public {
|
||||||
require(now >= expiration);
|
require(now >= expiration);
|
||||||
selfdestruct(sender);
|
selfdestruct(sender);
|
||||||
|
@ -188,8 +188,8 @@ Event Definitions and Event Emitters
|
|||||||
Yes::
|
Yes::
|
||||||
|
|
||||||
event LongAndLotsOfArgs(
|
event LongAndLotsOfArgs(
|
||||||
adress sender,
|
address sender,
|
||||||
adress recipient,
|
address recipient,
|
||||||
uint256 publicKey,
|
uint256 publicKey,
|
||||||
uint256 amount,
|
uint256 amount,
|
||||||
bytes32[] options
|
bytes32[] options
|
||||||
@ -205,8 +205,8 @@ Yes::
|
|||||||
|
|
||||||
No::
|
No::
|
||||||
|
|
||||||
event LongAndLotsOfArgs(adress sender,
|
event LongAndLotsOfArgs(address sender,
|
||||||
adress recipient,
|
address recipient,
|
||||||
uint256 publicKey,
|
uint256 publicKey,
|
||||||
uint256 amount,
|
uint256 amount,
|
||||||
bytes32[] options);
|
bytes32[] options);
|
||||||
@ -830,7 +830,7 @@ The naming recommendations given here are intended to improve the readability,
|
|||||||
and thus they are not rules, but rather guidelines to try and help convey the
|
and thus they are not rules, but rather guidelines to try and help convey the
|
||||||
most information through the names of things.
|
most information through the names of things.
|
||||||
|
|
||||||
Lastly, consistency within a codebase should always supercede any conventions
|
Lastly, consistency within a codebase should always supersede any conventions
|
||||||
outlined in this document.
|
outlined in this document.
|
||||||
|
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ ABI Encoding Functions
|
|||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
- ``abi.encode(...) returns (bytes)``: ABI-encodes the given arguments
|
- ``abi.encode(...) returns (bytes)``: ABI-encodes the given arguments
|
||||||
- ``abi.encodePacked(...) returns (bytes)``: Performes :ref:`packed encoding <abi_packed_mode>` of the given arguments
|
- ``abi.encodePacked(...) returns (bytes)``: Performs :ref:`packed encoding <abi_packed_mode>` of the given arguments
|
||||||
- ``abi.encodeWithSelector(bytes4 selector, ...) returns (bytes)``: ABI-encodes the given arguments
|
- ``abi.encodeWithSelector(bytes4 selector, ...) returns (bytes)``: ABI-encodes the given arguments
|
||||||
starting from the second and prepends the given four-byte selector
|
starting from the second and prepends the given four-byte selector
|
||||||
- ``abi.encodeWithSignature(string signature, ...) returns (bytes)``: Equivalent to ``abi.encodeWithSelector(bytes4(keccak256(bytes(signature)), ...)```
|
- ``abi.encodeWithSignature(string signature, ...) returns (bytes)``: Equivalent to ``abi.encodeWithSelector(bytes4(keccak256(bytes(signature)), ...)```
|
||||||
|
@ -338,7 +338,7 @@ The following functions must be available:
|
|||||||
+---------------------------------------------+-----------------------------------------------------------------+
|
+---------------------------------------------+-----------------------------------------------------------------+
|
||||||
| xor(x:bool, y:bool) -> z:bool | xor |
|
| xor(x:bool, y:bool) -> z:bool | xor |
|
||||||
+---------------------------------------------+-----------------------------------------------------------------+
|
+---------------------------------------------+-----------------------------------------------------------------+
|
||||||
| *Arithmetics* |
|
| *Arithmetic* |
|
||||||
+---------------------------------------------+-----------------------------------------------------------------+
|
+---------------------------------------------+-----------------------------------------------------------------+
|
||||||
| addu256(x:u256, y:u256) -> z:u256 | x + y |
|
| addu256(x:u256, y:u256) -> z:u256 | x + y |
|
||||||
+---------------------------------------------+-----------------------------------------------------------------+
|
+---------------------------------------------+-----------------------------------------------------------------+
|
||||||
@ -358,9 +358,9 @@ The following functions must be available:
|
|||||||
+---------------------------------------------+-----------------------------------------------------------------+
|
+---------------------------------------------+-----------------------------------------------------------------+
|
||||||
| expu256(x:u256, y:u256) -> z:u256 | x to the power of y |
|
| expu256(x:u256, y:u256) -> z:u256 | x to the power of y |
|
||||||
+---------------------------------------------+-----------------------------------------------------------------+
|
+---------------------------------------------+-----------------------------------------------------------------+
|
||||||
| addmodu256(x:u256, y:u256, m:u256) -> z:u256| (x + y) % m with arbitrary precision arithmetics |
|
| addmodu256(x:u256, y:u256, m:u256) -> z:u256| (x + y) % m with arbitrary precision arithmetic |
|
||||||
+---------------------------------------------+-----------------------------------------------------------------+
|
+---------------------------------------------+-----------------------------------------------------------------+
|
||||||
| mulmodu256(x:u256, y:u256, m:u256) -> z:u256| (x * y) % m with arbitrary precision arithmetics |
|
| mulmodu256(x:u256, y:u256, m:u256) -> z:u256| (x * y) % m with arbitrary precision arithmetic |
|
||||||
+---------------------------------------------+-----------------------------------------------------------------+
|
+---------------------------------------------+-----------------------------------------------------------------+
|
||||||
| ltu256(x:u256, y:u256) -> z:bool | true if x < y, false otherwise |
|
| ltu256(x:u256, y:u256) -> z:bool | true if x < y, false otherwise |
|
||||||
+---------------------------------------------+-----------------------------------------------------------------+
|
+---------------------------------------------+-----------------------------------------------------------------+
|
||||||
|
Loading…
Reference in New Issue
Block a user