From ffe4ce08912ffdf622e7e9666a875491c2284ac7 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 31 Jan 2017 19:37:55 +0100 Subject: [PATCH 001/234] Version update --- CMakeLists.txt | 2 +- Changelog.md | 2 ++ docs/conf.py | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 68bb71f4a..cea219ff8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ include(EthPolicy) eth_policy() # project name and version should be set after cmake_policy CMP0048 -set(PROJECT_VERSION "0.4.9") +set(PROJECT_VERSION "0.4.10") project(solidity VERSION ${PROJECT_VERSION}) # Let's find our dependencies diff --git a/Changelog.md b/Changelog.md index 03ee21937..be0e83295 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,5 @@ +### 0.4.10 (unreleased) + ### 0.4.9 (2017-01-31) Features: diff --git a/docs/conf.py b/docs/conf.py index e97eff3a6..159cd3eab 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -56,9 +56,9 @@ copyright = '2016-2017, Ethereum' # built documents. # # The short X.Y version. -version = '0.4.9' +version = '0.4.10' # The full version, including alpha/beta/rc tags. -release = '0.4.9-develop' +release = '0.4.10-develop' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. From a39adc44d453e5f3ba9f6124a9b41128f2b37015 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 31 Jan 2017 23:31:25 +0100 Subject: [PATCH 002/234] Integrate missed changes. --- docs/assembly.rst | 42 +++- docs/control-structures.rst | 478 +----------------------------------- 2 files changed, 30 insertions(+), 490 deletions(-) diff --git a/docs/assembly.rst b/docs/assembly.rst index 57c0bf9b3..79137b7e9 100644 --- a/docs/assembly.rst +++ b/docs/assembly.rst @@ -37,8 +37,9 @@ arising when writing manual assembly by the following features: We now want to describe the inline assembly language in detail. .. warning:: - Inline assembly is still a relatively new feature and might change if it does not prove useful, - so please try to keep up to date. + Inline assembly is a way to access the Ethereum Virtual Machine + at a low level. This discards several important safety + features of Solidity. Example ------- @@ -49,6 +50,8 @@ idea is that assembly libraries will be used to enhance the language in such way .. code:: + pragma solidity ^0.4.0; + library GetCode { function at(address _addr) returns (bytes o_code) { assembly { @@ -69,11 +72,13 @@ idea is that assembly libraries will be used to enhance the language in such way Inline assembly could also be beneficial in cases where the optimizer fails to produce efficient code. Please be aware that assembly is much more difficult to write because -the compiler does not perform checks, so you should use it only if +the compiler does not perform checks, so you should use it for complex things only if you really know what you are doing. .. code:: + pragma solidity ^0.4.0; + library VectorSum { // This function is less efficient because the optimizer currently fails to // remove the bounds checks in array access. @@ -104,7 +109,7 @@ these curly braces, the following can be used (see the later sections for more d - literals, i.e. ``0x123``, ``42`` or ``"abc"`` (strings up to 32 characters) - opcodes (in "instruction style"), e.g. ``mload sload dup1 sstore``, for a list see below - - opcode in functional style, e.g. ``add(1, mlod(0))`` + - opcodes in functional style, e.g. ``add(1, mlod(0))`` - labels, e.g. ``name:`` - variable declarations, e.g. ``let x := 7`` or ``let x := add(y, 3)`` - identifiers (labels or assembly-local variables and externals if used as inline assembly), e.g. ``jump(name)``, ``3 x add`` @@ -119,7 +124,7 @@ This document does not want to be a full description of the Ethereum virtual mac following list can be used as a reference of its opcodes. If an opcode takes arguments (always from the top of the stack), they are given in parentheses. -Note that the order of arguments can be seed to be reversed in non-functional style (explained below). +Note that the order of arguments can be seen to be reversed in non-functional style (explained below). Opcodes marked with ``-`` do not push an item onto the stack, those marked with ``*`` are special and all others push exactly one item onte the stack. @@ -185,7 +190,7 @@ In the grammar, opcodes are represented as pre-defined identifiers. +-------------------------+------+-----------------------------------------------------------------+ | pc | | current position in code | +-------------------------+------+-----------------------------------------------------------------+ -| pop | `*` | remove topmost stack slot | +| pop(x) | `-` | remove the element pushed by x | +-------------------------+------+-----------------------------------------------------------------+ | dup1 ... dup16 | | copy ith stack slot to the top (counting from top) | +-------------------------+------+-----------------------------------------------------------------+ @@ -230,19 +235,22 @@ In the grammar, opcodes are represented as pre-defined identifiers. | create(v, p, s) | | create new contract with code mem[p..(p+s)) and send v wei | | | | and return the new address | +-------------------------+------+-----------------------------------------------------------------+ -| call(g, a, v, in, | | call contract at address a with input mem[in..(in+insize)] | +| call(g, a, v, in, | | call contract at address a with input mem[in..(in+insize)) | | insize, out, outsize) | | providing g gas and v wei and output area | -| | | mem[out..(out+outsize)] returting 1 on error (out of gas) | +| | | mem[out..(out+outsize)) returning 0 on error (eg. out of gas) | +| | | and 1 on success | +-------------------------+------+-----------------------------------------------------------------+ -| callcode(g, a, v, in, | | identical to call but only use the code from a and stay | +| callcode(g, a, v, in, | | identical to `call` but only use the code from a and stay | | insize, out, outsize) | | in the context of the current contract otherwise | +-------------------------+------+-----------------------------------------------------------------+ -| delegatecall(g, a, in, | | identical to callcode but also keep ``caller`` | +| delegatecall(g, a, in, | | identical to `callcode` but also keep ``caller`` | | insize, out, outsize) | | and ``callvalue`` | +-------------------------+------+-----------------------------------------------------------------+ -| return(p, s) | `*` | end execution, return data mem[p..(p+s)) | +| return(p, s) | `-` | end execution, return data mem[p..(p+s)) | +-------------------------+------+-----------------------------------------------------------------+ -| selfdestruct(a) | `*` | end execution, destroy current contract and send funds to a | +| selfdestruct(a) | `-` | end execution, destroy current contract and send funds to a | ++-------------------------+------+-----------------------------------------------------------------+ +| invalid | `-` | end execution with invalid instruction | +-------------------------+------+-----------------------------------------------------------------+ | log0(p, s) | `-` | log without topics and data mem[p..(p+s)) | +-------------------------+------+-----------------------------------------------------------------+ @@ -331,6 +339,8 @@ It is planned that the stack height changes can be specified in inline assembly. .. code:: + pragma solidity ^0.4.0; + contract C { uint b; function f(uint x) returns (uint r) { @@ -392,6 +402,10 @@ will have a wrong impression about the stack height at label ``two``: three: } +.. note:: + + ``invalidJumpLabel`` is a pre-defined label. Jumping to this location will always + result in an invalid jump, effectively aborting execution of the code. Declaring Assembly-Local Variables ---------------------------------- @@ -405,6 +419,8 @@ be just ``0``, but it can also be a complex functional-style expression. .. code:: + pragma solidity ^0.4.0; + contract C { function f(uint x) returns (uint b) { assembly { @@ -542,7 +558,7 @@ Conventions in Solidity In contrast to EVM assembly, Solidity knows types which are narrower than 256 bits, e.g. ``uint24``. In order to make them more efficient, most arithmetic operations just -treat them as 256 bit numbers and the higher-order bits are only cleaned at the +treat them as 256-bit numbers and the higher-order bits are only cleaned at the point where it is necessary, i.e. just shortly before they are written to memory or before comparisons are performed. This means that if you access such a variable from within inline assembly, you might have to manually clean the higher order bits diff --git a/docs/control-structures.rst b/docs/control-structures.rst index c83d654e7..757988cca 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -400,480 +400,4 @@ Internally, Solidity performs an "invalid jump" when a user-provided exception i (instruction ``0xfe``) if a runtime exception is encountered. In both cases, this causes the EVM to revert all changes made to the state. The reason for this is that there is no safe way to continue execution, because an expected effect did not occur. Because we want to retain the atomicity of transactions, the safest thing to do is to revert all changes and make the whole transaction -(or at least call) without effect. - -.. index:: ! assembly, ! asm, ! evmasm - -Inline Assembly -=============== - -For more fine-grained control especially in order to enhance the language by writing libraries, -it is possible to interleave Solidity statements with inline assembly in a language close -to the one of the virtual machine. Due to the fact that the EVM is a stack machine, it is -often hard to address the correct stack slot and provide arguments to opcodes at the correct -point on the stack. Solidity's inline assembly tries to facilitate that and other issues -arising when writing manual assembly by the following features: - -* functional-style opcodes: ``mul(1, add(2, 3))`` instead of ``push1 3 push1 2 add push1 1 mul`` -* assembly-local variables: ``let x := add(2, 3) let y := mload(0x40) x := add(x, y)`` -* access to external variables: ``function f(uint x) { assembly { x := sub(x, 1) } }`` -* labels: ``let x := 10 repeat: x := sub(x, 1) jumpi(repeat, eq(x, 0))`` - -We now want to describe the inline assembly language in detail. - -.. warning:: - Inline assembly is a way to access the Ethereum Virtual Machine - at a low level. This discards several important safety - features of Solidity. - -Example -------- - -The following example provides library code to access the code of another contract and -load it into a ``bytes`` variable. This is not possible at all with "plain Solidity" and the -idea is that assembly libraries will be used to enhance the language in such ways. - -.. code:: - - pragma solidity ^0.4.0; - - library GetCode { - function at(address _addr) returns (bytes o_code) { - assembly { - // retrieve the size of the code, this needs assembly - let size := extcodesize(_addr) - // allocate output byte array - this could also be done without assembly - // by using o_code = new bytes(size) - o_code := mload(0x40) - // new "memory end" including padding - mstore(0x40, add(o_code, and(add(add(size, 0x20), 0x1f), not(0x1f)))) - // store length in memory - mstore(o_code, size) - // actually retrieve the code, this needs assembly - extcodecopy(_addr, add(o_code, 0x20), 0, size) - } - } - } - -Inline assembly could also be beneficial in cases where the optimizer fails to produce -efficient code. Please be aware that assembly is much more difficult to write because -the compiler does not perform checks, so you should use it for complex things only if -you really know what you are doing. - -.. code:: - - pragma solidity ^0.4.0; - - library VectorSum { - // This function is less efficient because the optimizer currently fails to - // remove the bounds checks in array access. - function sumSolidity(uint[] _data) returns (uint o_sum) { - for (uint i = 0; i < _data.length; ++i) - o_sum += _data[i]; - } - - // We know that we only access the array in bounds, so we can avoid the check. - // 0x20 needs to be added to an array because the first slot contains the - // array length. - function sumAsm(uint[] _data) returns (uint o_sum) { - for (uint i = 0; i < _data.length; ++i) { - assembly { - o_sum := mload(add(add(_data, 0x20), i)) - } - } - } - } - -Syntax ------- - -Inline assembly parses comments, literals and identifiers exactly as Solidity, so you can use the -usual ``//`` and ``/* */`` comments. Inline assembly is initiated by ``assembly { ... }`` and inside -these curly braces, the following can be used (see the later sections for more details) - - - literals, e.g. ``0x123``, ``42`` or ``"abc"`` (strings up to 32 characters) - - opcodes (in "instruction style"), e.g. ``mload sload dup1 sstore``, for a list see below - - opcodes in functional style, e.g. ``add(1, mload(0))`` - - labels, e.g. ``name:`` - - variable declarations, e.g. ``let x := 7`` or ``let x := add(y, 3)`` - - identifiers (externals, labels or assembly-local variables), e.g. ``jump(name)``, ``3 x add`` - - assignments (in "instruction style"), e.g. ``3 =: x`` - - assignments in functional style, e.g. ``x := add(y, 3)`` - - blocks where local variables are scoped inside, e.g. ``{ let x := 3 { let y := add(x, 1) } }`` - -Opcodes -------- - -This document does not want to be a full description of the Ethereum virtual machine, but the -following list can be used as a reference of its opcodes. - -If an opcode takes arguments (always from the top of the stack), they are given in parentheses. -Note that the order of arguments can be seen as being reversed compared to the instructional style (explained below). -Opcodes marked with ``-`` do not push an item onto the stack, those marked with ``*`` are -special and all others push exactly one item onte the stack. - -In the following, ``mem[a...b)`` signifies the bytes of memory starting at position ``a`` up to -(excluding) position ``b`` and ``storage[p]`` signifies the storage contents at position ``p``. - -The opcodes ``pushi`` and ``jumpdest`` cannot be used directly. - -+-------------------------+------+-----------------------------------------------------------------+ -| stop + `-` | stop execution, identical to return(0,0) | -+-------------------------+------+-----------------------------------------------------------------+ -| add(x, y) | | x + y | -+-------------------------+------+-----------------------------------------------------------------+ -| sub(x, y) | | x - y | -+-------------------------+------+-----------------------------------------------------------------+ -| mul(x, y) | | x * y | -+-------------------------+------+-----------------------------------------------------------------+ -| div(x, y) | | x / y | -+-------------------------+------+-----------------------------------------------------------------+ -| sdiv(x, y) | | x / y, for signed numbers in two's complement | -+-------------------------+------+-----------------------------------------------------------------+ -| mod(x, y) | | x % y | -+-------------------------+------+-----------------------------------------------------------------+ -| smod(x, y) | | x % y, for signed numbers in two's complement | -+-------------------------+------+-----------------------------------------------------------------+ -| exp(x, y) | | x to the power of y | -+-------------------------+------+-----------------------------------------------------------------+ -| not(x) | | ~x, every bit of x is negated | -+-------------------------+------+-----------------------------------------------------------------+ -| lt(x, y) | | 1 if x < y, 0 otherwise | -+-------------------------+------+-----------------------------------------------------------------+ -| gt(x, y) | | 1 if x > y, 0 otherwise | -+-------------------------+------+-----------------------------------------------------------------+ -| slt(x, y) | | 1 if x < y, 0 otherwise, for signed numbers in two's complement | -+-------------------------+------+-----------------------------------------------------------------+ -| sgt(x, y) | | 1 if x > y, 0 otherwise, for signed numbers in two's complement | -+-------------------------+------+-----------------------------------------------------------------+ -| eq(x, y) | | 1 if x == y, 0 otherwise | -+-------------------------+------+-----------------------------------------------------------------+ -| iszero(x) | | 1 if x == 0, 0 otherwise | -+-------------------------+------+-----------------------------------------------------------------+ -| and(x, y) | | bitwise and of x and y | -+-------------------------+------+-----------------------------------------------------------------+ -| or(x, y) | | bitwise or of x and y | -+-------------------------+------+-----------------------------------------------------------------+ -| xor(x, y) | | bitwise xor of x and y | -+-------------------------+------+-----------------------------------------------------------------+ -| byte(n, x) | | nth byte of x, where the most significant byte is the 0th byte | -+-------------------------+------+-----------------------------------------------------------------+ -| addmod(x, y, m) | | (x + y) % m with arbitrary precision arithmetics | -+-------------------------+------+-----------------------------------------------------------------+ -| mulmod(x, y, m) | | (x * y) % m with arbitrary precision arithmetics | -+-------------------------+------+-----------------------------------------------------------------+ -| signextend(i, x) | | sign extend from (i*8+7)th bit counting from least significant | -+-------------------------+------+-----------------------------------------------------------------+ -| sha3(p, n) | | keccak(mem[p...(p+n))) | -+-------------------------+------+-----------------------------------------------------------------+ -| jump(label) | `-` | jump to label / code position | -+-------------------------+------+-----------------------------------------------------------------+ -| jumpi(label, cond) | `-` | jump to label if cond is nonzero | -+-------------------------+------+-----------------------------------------------------------------+ -| pc | | current position in code | -+-------------------------+------+-----------------------------------------------------------------+ -| pop(x) | `-` | remove the element pushed by x | -+-------------------------+------+-----------------------------------------------------------------+ -| dup1 ... dup16 | | copy ith stack slot to the top (counting from top) | -+-------------------------+------+-----------------------------------------------------------------+ -| swap1 ... swap16 | `*` | swap topmost and ith stack slot below it | -+-------------------------+------+-----------------------------------------------------------------+ -| mload(p) | | mem[p..(p+32)) | -+-------------------------+------+-----------------------------------------------------------------+ -| mstore(p, v) | `-` | mem[p..(p+32)) := v | -+-------------------------+------+-----------------------------------------------------------------+ -| mstore8(p, v) | `-` | mem[p] := v & 0xff - only modifies a single byte | -+-------------------------+------+-----------------------------------------------------------------+ -| sload(p) | | storage[p] | -+-------------------------+------+-----------------------------------------------------------------+ -| sstore(p, v) | `-` | storage[p] := v | -+-------------------------+------+-----------------------------------------------------------------+ -| msize | | size of memory, i.e. largest accessed memory index | -+-------------------------+------+-----------------------------------------------------------------+ -| gas | | gas still available to execution | -+-------------------------+------+-----------------------------------------------------------------+ -| address | | address of the current contract / execution context | -+-------------------------+------+-----------------------------------------------------------------+ -| balance(a) | | wei balance at address a | -+-------------------------+------+-----------------------------------------------------------------+ -| caller | | call sender (excluding delegatecall) | -+-------------------------+------+-----------------------------------------------------------------+ -| callvalue | | wei sent together with the current call | -+-------------------------+------+-----------------------------------------------------------------+ -| calldataload(p) | | calldata starting from position p (32 bytes) | -+-------------------------+------+-----------------------------------------------------------------+ -| calldatasize | | size of calldata in bytes | -+-------------------------+------+-----------------------------------------------------------------+ -| calldatacopy(t, f, s) | `-` | copy s bytes from calldata at position f to mem at position t | -+-------------------------+------+-----------------------------------------------------------------+ -| codesize | | size of the code of the current contract / execution context | -+-------------------------+------+-----------------------------------------------------------------+ -| codecopy(t, f, s) | `-` | copy s bytes from code at position f to mem at position t | -+-------------------------+------+-----------------------------------------------------------------+ -| extcodesize(a) | | size of the code at address a | -+-------------------------+------+-----------------------------------------------------------------+ -| extcodecopy(a, t, f, s) | `-` | like codecopy(t, f, s) but take code at address a | -+-------------------------+------+-----------------------------------------------------------------+ -| create(v, p, s) | | create new contract with code mem[p..(p+s)) and send v wei | -| | | and return the new address | -+-------------------------+------+-----------------------------------------------------------------+ -| call(g, a, v, in, | | call contract at address a with input mem[in..(in+insize)) | -| insize, out, outsize) | | providing g gas and v wei and output area | -| | | mem[out..(out+outsize)) returning 0 on error (eg. out of gas) | -| | | and 1 on success | -+-------------------------+------+-----------------------------------------------------------------+ -| callcode(g, a, v, in, | | identical to `call` but only use the code from a and stay | -| insize, out, outsize) | | in the context of the current contract otherwise | -+-------------------------+------+-----------------------------------------------------------------+ -| delegatecall(g, a, in, | | identical to `callcode` but also keep ``caller`` | -| insize, out, outsize) | | and ``callvalue`` | -+-------------------------+------+-----------------------------------------------------------------+ -| return(p, s) | `-` | end execution, return data mem[p..(p+s)) | -+-------------------------+------+-----------------------------------------------------------------+ -| selfdestruct(a) | `-` | end execution, destroy current contract and send funds to a | -+-------------------------+------+-----------------------------------------------------------------+ -| invalid | `-` | end execution with invalid instruction | -+-------------------------+------+-----------------------------------------------------------------+ -| log0(p, s) | `-` | log without topics and data mem[p..(p+s)) | -+-------------------------+------+-----------------------------------------------------------------+ -| log1(p, s, t1) | `-` | log with topic t1 and data mem[p..(p+s)) | -+-------------------------+------+-----------------------------------------------------------------+ -| log2(p, s, t1, t2) | `-` | log with topics t1, t2 and data mem[p..(p+s)) | -+-------------------------+------+-----------------------------------------------------------------+ -| log3(p, s, t1, t2, t3) | `-` | log with topics t1, t2, t3 and data mem[p..(p+s)) | -+-------------------------+------+-----------------------------------------------------------------+ -| log4(p, s, t1, t2, t3, | `-` | log with topics t1, t2, t3, t4 and data mem[p..(p+s)) | -| t4) | | | -+-------------------------+------+-----------------------------------------------------------------+ -| origin | | transaction sender | -+-------------------------+------+-----------------------------------------------------------------+ -| gasprice | | gas price of the transaction | -+-------------------------+------+-----------------------------------------------------------------+ -| blockhash(b) | | hash of block nr b - only for last 256 blocks excluding current | -+-------------------------+------+-----------------------------------------------------------------+ -| coinbase | | current mining beneficiary | -+-------------------------+------+-----------------------------------------------------------------+ -| timestamp | | timestamp of the current block in seconds since the epoch | -+-------------------------+------+-----------------------------------------------------------------+ -| number | | current block number | -+-------------------------+------+-----------------------------------------------------------------+ -| difficulty | | difficulty of the current block | -+-------------------------+------+-----------------------------------------------------------------+ -| gaslimit | | block gas limit of the current block | -+-------------------------+------+-----------------------------------------------------------------+ - -Literals --------- - -You can use integer constants by typing them in decimal or hexadecimal notation and an -appropriate ``PUSHi`` instruction will automatically be generated. The following creates code -to add 2 and 3 resulting in 5 and then computes the bitwise and with the string "abc". -Strings are stored left-aligned and cannot be longer than 32 bytes. - -.. code:: - - assembly { 2 3 add "abc" and } - -Functional Style ------------------ - -You can type opcode after opcode in the same way they will end up in bytecode. For example -adding ``3`` to the contents in memory at position ``0x80`` would be - -.. code:: - - 3 0x80 mload add 0x80 mstore - -As it is often hard to see what the actual arguments for certain opcodes are, -Solidity inline assembly also provides a "functional style" notation where the same code -would be written as follows - -.. code:: - - mstore(0x80, add(mload(0x80), 3)) - -Functional style and instructional style can be mixed, but any opcode inside a -functional style expression has to return exactly one stack slot (most of the opcodes do). - -Note that the order of arguments is reversed in functional-style as opposed to the instruction-style -way. If you use functional-style, the first argument will end up on the stack top. - - -Access to External Variables and Functions ------------------------------------------- - -Solidity variables and other identifiers can be accessed by simply using their name. -For storage and memory variables, this will push the address and not the value onto the -stack. Also note that non-struct and non-array storage variable addresses occupy two slots -on the stack: One for the address and one for the byte offset inside the storage slot. -In assignments (see below), we can even use local Solidity variables to assign to. - -Functions external to inline assembly can also be accessed: The assembly will -push their entry label (with virtual function resolution applied). The calling semantics -in solidity are: - - - the caller pushes return label, arg1, arg2, ..., argn - - the call returns with ret1, ret2, ..., retn - -This feature is still a bit cumbersome to use, because the stack offset essentially -changes during the call, and thus references to local variables will be wrong. -It is planned that the stack height changes can be specified in inline assembly. - -.. code:: - - pragma solidity ^0.4.0; - - contract C { - uint b; - function f(uint x) returns (uint r) { - assembly { - b pop // remove the offset, we know it is zero - sload - x - mul - =: r // assign to return variable r - } - } - } - -Labels ------- - -Another problem in EVM assembly is that ``jump`` and ``jumpi`` use absolute addresses -which can change easily. Solidity inline assembly provides labels to make the use of -jumps easier. The following code computes an element in the Fibonacci series. - -.. code:: - - { - let n := calldataload(4) - let a := 1 - let b := a - loop: - jumpi(loopend, eq(n, 0)) - a add swap1 - n := sub(n, 1) - jump(loop) - loopend: - mstore(0, a) - return(0, 0x20) - } - -Please note that automatically accessing stack variables can only work if the -assembler knows the current stack height. This fails to work if the jump source -and target have different stack heights. It is still fine to use such jumps, -you should just not access any stack variables (even assembly variables) in that case. - -Furthermore, the stack height analyser goes through the code opcode by opcode -(and not according to control flow), so in the following case, the assembler -will have a wrong impression about the stack height at label ``two``: - -.. code:: - - { - jump(two) - one: - // Here the stack height is 1 (because we pushed 7), - // but the assembler thinks it is 0 because it reads - // from top to bottom. - // Accessing stack variables here will lead to errors. - jump(three) - two: - 7 // push something onto the stack - jump(one) - three: - } - -.. note:: - - ``invalidJumpLabel`` is a pre-defined label. Jumping to this location will always - result in an invalid jump, effectively aborting execution of the code. - -Declaring Assembly-Local Variables ----------------------------------- - -You can use the ``let`` keyword to declare variables that are only visible in -inline assembly and actually only in the current ``{...}``-block. What happens -is that the ``let`` instruction will create a new stack slot that is reserved -for the variable and automatically removed again when the end of the block -is reached. You need to provide an initial value for the variable which can -be just ``0``, but it can also be a complex functional-style expression. - -.. code:: - - pragma solidity ^0.4.0; - - contract C { - function f(uint x) returns (uint b) { - assembly { - let v := add(x, 1) - mstore(0x80, v) - { - let y := add(sload(v), 1) - b := y - } // y is "deallocated" here - b := add(b, v) - } // v is "deallocated" here - } - } - - -Assignments ------------ - -Assignments are possible to assembly-local variables and to function-local -variables. Take care that when you assign to variables that point to -memory or storage, you will only change the pointer and not the data. - -There are two kinds of assignments: Functional-style and instruction-style. -For functional-style assignments (``variable := value``), you need to provide a value in a -functional-style expression that results in exactly one stack value -and for instruction-style (``=: variable``), the value is just taken from the stack top. -For both ways, the colon points to the name of the variable. - -.. code:: - - assembly { - let v := 0 // functional-style assignment as part of variable declaration - let g := add(v, 2) - sload(10) - =: v // instruction style assignment, puts the result of sload(10) into v - } - - -Things to Avoid ---------------- - -Inline assembly might have a quite high-level look, but it actually is extremely -low-level. The only thing the assembler does for you is re-arranging -functional-style opcodes, managing jump labels, counting stack height for -variable access and removing stack slots for assembly-local variables when the end -of their block is reached. Especially for those two last cases, it is important -to know that the assembler only counts stack height from top to bottom, not -necessarily following control flow. Furthermore, operations like swap will only -swap the contents of the stack but not the location of variables. - -Conventions in Solidity ------------------------ - -In contrast to EVM assembly, Solidity knows types which are narrower than 256 bits, -e.g. ``uint24``. In order to make them more efficient, most arithmetic operations just -treat them as 256-bit numbers and the higher-order bits are only cleaned at the -point where it is necessary, i.e. just shortly before they are written to memory -or before comparisons are performed. This means that if you access such a variable -from within inline assembly, you might have to manually clean the higher order bits -first. - -Solidity manages memory in a very simple way: There is a "free memory pointer" -at position ``0x40`` in memory. If you want to allocate memory, just use the memory -from that point on and update the pointer accordingly. - -Elements in memory arrays in Solidity always occupy multiples of 32 bytes (yes, this is -even true for ``byte[]``, but not for ``bytes`` and ``string``). Multi-dimensional memory -arrays are pointers to memory arrays. The length of a dynamic array is stored at the -first slot of the array and then only the array elements follow. - -.. warning:: - Statically-sized memory arrays do not have a length field, but it will be added soon - to allow better convertibility between statically- and dynamically-sized arrays, so - please do not rely on that. +(or at least call) without effect. \ No newline at end of file From 767ec1d670808cd479ac74780bff51a1f1900f04 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 1 Dec 2016 12:12:10 +0000 Subject: [PATCH 003/234] Support explicit conversion of external function type to address --- libsolidity/ast/Types.cpp | 11 +++++++++++ libsolidity/ast/Types.h | 1 + libsolidity/codegen/CompilerUtils.cpp | 12 ++++++++++++ libsolidity/codegen/ContractCompiler.cpp | 2 +- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index dbabc8db5..4a64b4c81 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -2158,6 +2158,17 @@ bool FunctionType::operator==(Type const& _other) const return true; } +bool FunctionType::isExplicitlyConvertibleTo(Type const& _convertTo) const +{ + if (m_location == Location::External && _convertTo.category() == Category::Integer) + { + IntegerType const& convertTo = dynamic_cast(_convertTo); + if (convertTo.isAddress()) + return true; + } + return _convertTo.category() == category(); +} + TypePointer FunctionType::unaryOperatorResult(Token::Value _operator) const { if (_operator == Token::Value::Delete) diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index a5147f176..3917dca21 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -922,6 +922,7 @@ public: virtual std::string identifier() const override; virtual bool operator==(Type const& _other) const override; + virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override; virtual TypePointer unaryOperatorResult(Token::Value _operator) const override; virtual std::string canonicalName(bool /*_addDataLocation*/) const override; virtual std::string toString(bool _short) const override; diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 477f021a8..469bd0edf 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -787,6 +787,18 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp if (_cleanupNeeded) m_context << Instruction::ISZERO << Instruction::ISZERO; break; + case Type::Category::Function: + { + solAssert(targetTypeCategory == Type::Category::Integer, "Invalid conversion for function type."); + IntegerType const& targetType = dynamic_cast(_targetType); + solAssert(targetType.isAddress(), "Function type can only be converted to address."); + FunctionType const& typeOnStack = dynamic_cast(_typeOnStack); + solAssert(typeOnStack.location() == FunctionType::Location::External, "Only external function type can be converted."); + + // stack:
+ m_context << Instruction::POP; + break; + } default: // All other types should not be convertible to non-equal types. solAssert(_typeOnStack == _targetType, "Invalid type conversion requested."); diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index 4d33927db..f42799064 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -42,7 +42,7 @@ class StackHeightChecker public: StackHeightChecker(CompilerContext const& _context): m_context(_context), stackHeight(m_context.stackHeight()) {} - void check() { solAssert(m_context.stackHeight() == stackHeight, "I sense a disturbance in the stack."); } + void check() { solAssert(m_context.stackHeight() == stackHeight, "I sense a disturbance in the stack. "); } private: CompilerContext const& m_context; unsigned stackHeight; From ce62c7c01c01c859f6b310309a186a966e835d77 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 2 Dec 2016 13:58:14 +0000 Subject: [PATCH 004/234] Be more verbose on the stack-mismatch errors --- libsolidity/codegen/ContractCompiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index f42799064..9d6129a36 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -42,7 +42,7 @@ class StackHeightChecker public: StackHeightChecker(CompilerContext const& _context): m_context(_context), stackHeight(m_context.stackHeight()) {} - void check() { solAssert(m_context.stackHeight() == stackHeight, "I sense a disturbance in the stack. "); } + void check() { solAssert(m_context.stackHeight() == stackHeight, std::string("I sense a disturbance in the stack: ") + std::to_string(m_context.stackHeight()) + " vs " + std::to_string(stackHeight)); } private: CompilerContext const& m_context; unsigned stackHeight; From ef7add8c2bfacea43aa32455c80ac9575aa46a67 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 2 Dec 2016 21:53:36 +0000 Subject: [PATCH 005/234] Add tests for explicity fuction type to address casting --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 472067ecd..1aca7ab98 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -4725,6 +4725,18 @@ BOOST_AUTO_TEST_CASE(delete_external_function_type_invalid) CHECK_ERROR(text, TypeError, ""); } +BOOST_AUTO_TEST_CASE(external_function_type_to_address) +{ + char const* text = R"( + contract C { + function f() return (address) { + return address(this.f); + } + } + )"; + CHECK_SUCCESS(text); +} + BOOST_AUTO_TEST_CASE(invalid_fixed_point_literal) { char const* text = R"( From 0b61f13c7f83667c524197fcfd53f04ab7645e1e Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 27 Jan 2017 11:46:36 +0000 Subject: [PATCH 006/234] Add more tests for function type conversion --- test/libsolidity/SolidityEndToEndTest.cpp | 19 +++++++++++++++++++ .../SolidityNameAndTypeResolution.cpp | 14 +++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 4075a0160..4924b55d0 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -8462,6 +8462,25 @@ BOOST_AUTO_TEST_CASE(function_array_cross_calls) BOOST_CHECK(callContractFunction("test()") == encodeArgs(u256(5), u256(6), u256(7))); } +BOOST_AUTO_TEST_CASE(external_function_to_address) +{ + char const* sourceCode = R"( + contract C { + function f() returns (bool) { + return address(this.f) == address(this); + } + function g(function() external cb) returns (address) { + return address(cb); + } + } + )"; + + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("f()") == encodeArgs(true)); + BOOST_CHECK(callContractFunction("g(function)", fromHex("00000000000000000000000000000000000004226121ff00000000000000000")) == encodeArgs(u160(0x42))); +} + + BOOST_AUTO_TEST_CASE(copy_internal_function_array_to_storage) { char const* sourceCode = R"( diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 1aca7ab98..587f10751 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -4729,7 +4729,7 @@ BOOST_AUTO_TEST_CASE(external_function_type_to_address) { char const* text = R"( contract C { - function f() return (address) { + function f() returns (address) { return address(this.f); } } @@ -4737,6 +4737,18 @@ BOOST_AUTO_TEST_CASE(external_function_type_to_address) CHECK_SUCCESS(text); } +BOOST_AUTO_TEST_CASE(internal_function_type_to_address) +{ + char const* text = R"( + contract C { + function f() returns (address) { + return address(f); + } + } + )"; + CHECK_ERROR(text, TypeError, ""); +} + BOOST_AUTO_TEST_CASE(invalid_fixed_point_literal) { char const* text = R"( From 4361797ddca240dc55c9f88c6579383eb558b309 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 1 Feb 2017 12:22:14 +0000 Subject: [PATCH 007/234] Only capture function type to address conversion --- libsolidity/codegen/CompilerUtils.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 469bd0edf..9f019d279 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -789,15 +789,17 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp break; case Type::Category::Function: { - solAssert(targetTypeCategory == Type::Category::Integer, "Invalid conversion for function type."); - IntegerType const& targetType = dynamic_cast(_targetType); - solAssert(targetType.isAddress(), "Function type can only be converted to address."); - FunctionType const& typeOnStack = dynamic_cast(_typeOnStack); - solAssert(typeOnStack.location() == FunctionType::Location::External, "Only external function type can be converted."); + if (targetTypeCategory == Type::Category::Integer) + { + IntegerType const& targetType = dynamic_cast(_targetType); + solAssert(targetType.isAddress(), "Function type can only be converted to address."); + FunctionType const& typeOnStack = dynamic_cast(_typeOnStack); + solAssert(typeOnStack.location() == FunctionType::Location::External, "Only external function type can be converted."); - // stack:
- m_context << Instruction::POP; - break; + // stack:
+ m_context << Instruction::POP; + break; + } } default: // All other types should not be convertible to non-equal types. From bab7f8f455dae78c4da1019b131abd01d28f63a6 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 1 Feb 2017 12:25:02 +0000 Subject: [PATCH 008/234] Add changelog for function types to address conversion --- Changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Changelog.md b/Changelog.md index be0e83295..c1098bdf2 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,8 @@ ### 0.4.10 (unreleased) +Features: + * Type system: Support explicit conversion of external function to address. + ### 0.4.9 (2017-01-31) Features: From ee147e14d392e62dae92d345735ec768bd486633 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 1 Feb 2017 20:47:56 +0000 Subject: [PATCH 009/234] Cover both failure cases --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 587f10751..f57680221 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -4746,7 +4746,19 @@ BOOST_AUTO_TEST_CASE(internal_function_type_to_address) } } )"; - CHECK_ERROR(text, TypeError, ""); + CHECK_ERROR(text, TypeError, "Explicit type conversion not allowed"); +} + +BOOST_AUTO_TEST_CASE(external_function_type_to_uint) +{ + char const* text = R"( + contract C { + function f() returns (uint) { + return uint(this.f); + } + } + )"; + CHECK_ERROR(text, TypeError, "Explicit type conversion not allowed"); } BOOST_AUTO_TEST_CASE(invalid_fixed_point_literal) From c01f5699e673f600fe87056b414996fef2224242 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 00:16:50 +0000 Subject: [PATCH 010/234] Add isNegative to RationalNumberType --- libsolidity/ast/Types.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 3917dca21..e280b32c2 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -411,6 +411,9 @@ public: /// @returns true if the value is not an integer. bool isFractional() const { return m_value.denominator() != 1; } + /// @returns true if the value is negative. + bool isNegative() const { return m_value < 0; } + private: rational m_value; }; From 697db80b48fbed596996a2dab20948f42fdb1dfb Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 00:24:45 +0000 Subject: [PATCH 011/234] Disallow arrays with negative length --- Changelog.md | 3 +++ libsolidity/analysis/ReferencesResolver.cpp | 2 ++ test/libsolidity/SolidityNameAndTypeResolution.cpp | 10 ++++++++++ 3 files changed, 15 insertions(+) diff --git a/Changelog.md b/Changelog.md index c1098bdf2..79d2fe44a 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,9 @@ Features: * Type system: Support explicit conversion of external function to address. +Bugfixes: + * Type system: Disallow arrays with negative length. + ### 0.4.9 (2017-01-31) Features: diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp index df579c3d9..d589f4a0a 100644 --- a/libsolidity/analysis/ReferencesResolver.cpp +++ b/libsolidity/analysis/ReferencesResolver.cpp @@ -130,6 +130,8 @@ void ReferencesResolver::endVisit(ArrayTypeName const& _typeName) auto const* lengthType = dynamic_cast(length->annotation().type.get()); if (!lengthType || lengthType->isFractional()) fatalTypeError(length->location(), "Invalid array length, expected integer literal."); + else if (lengthType->isNegative()) + fatalTypeError(length->location(), "Array with negative length specified."); else _typeName.annotation().type = make_shared(DataLocation::Storage, baseType, lengthType->literalValue(nullptr)); } diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index f57680221..0151d244a 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1919,6 +1919,16 @@ BOOST_AUTO_TEST_CASE(array_with_nonconstant_length) CHECK_ERROR(text, TypeError, ""); } +BOOST_AUTO_TEST_CASE(array_with_negative_length) +{ + char const* text = R"( + contract c { + function f(uint a) { uint8[-1] x; } + } + )"; + CHECK_ERROR(text, TypeError, "Array with negative length specified"); +} + BOOST_AUTO_TEST_CASE(array_copy_with_different_types1) { char const* text = R"( From 902f69640b1e6c3e8d1769fa94b34b78186cb52a Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 10:06:28 +0000 Subject: [PATCH 012/234] Replace cpp-ethereum with solidity in the license headers --- libdevcore/ABI.h | 8 ++++---- libdevcore/Assertions.h | 8 ++++---- libdevcore/Common.h | 8 ++++---- libdevcore/CommonData.cpp | 8 ++++---- libdevcore/CommonData.h | 8 ++++---- libdevcore/CommonIO.cpp | 8 ++++---- libdevcore/CommonIO.h | 8 ++++---- libdevcore/Exceptions.h | 8 ++++---- libdevcore/FixedHash.h | 8 ++++---- libdevcore/JSON.h | 8 ++++---- libdevcore/SHA3.cpp | 8 ++++---- libdevcore/SHA3.h | 8 ++++---- libdevcore/SwarmHash.cpp | 8 ++++---- libdevcore/SwarmHash.h | 8 ++++---- libdevcore/UTF8.cpp | 8 ++++---- libdevcore/UTF8.h | 8 ++++---- libdevcore/UndefMacros.h | 8 ++++---- liblll/CodeFragment.cpp | 8 ++++---- liblll/CodeFragment.h | 8 ++++---- liblll/Compiler.cpp | 8 ++++---- liblll/Compiler.h | 8 ++++---- liblll/CompilerState.cpp | 8 ++++---- liblll/CompilerState.h | 8 ++++---- liblll/Exceptions.h | 8 ++++---- liblll/Parser.cpp | 8 ++++---- liblll/Parser.h | 8 ++++---- lllc/main.cpp | 8 ++++---- test/libdevcore/Checksum.cpp | 8 ++++---- test/libdevcore/SwarmHash.cpp | 8 ++++---- 29 files changed, 116 insertions(+), 116 deletions(-) diff --git a/libdevcore/ABI.h b/libdevcore/ABI.h index 423cfda8b..8b9e5c980 100644 --- a/libdevcore/ABI.h +++ b/libdevcore/ABI.h @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file ABI.h * @author Gav Wood diff --git a/libdevcore/Assertions.h b/libdevcore/Assertions.h index 0fb5837c7..e54b9d556 100644 --- a/libdevcore/Assertions.h +++ b/libdevcore/Assertions.h @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** * @file Assertions.h diff --git a/libdevcore/Common.h b/libdevcore/Common.h index 225f38ac0..dc981ff68 100644 --- a/libdevcore/Common.h +++ b/libdevcore/Common.h @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file Common.h * @author Gav Wood diff --git a/libdevcore/CommonData.cpp b/libdevcore/CommonData.cpp index a53d9628e..14caf4947 100644 --- a/libdevcore/CommonData.cpp +++ b/libdevcore/CommonData.cpp @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file CommonData.cpp * @author Gav Wood diff --git a/libdevcore/CommonData.h b/libdevcore/CommonData.h index e0a6d2210..98ad548d7 100644 --- a/libdevcore/CommonData.h +++ b/libdevcore/CommonData.h @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file CommonData.h * @author Gav Wood diff --git a/libdevcore/CommonIO.cpp b/libdevcore/CommonIO.cpp index 60ac518d4..8dbcb00a1 100644 --- a/libdevcore/CommonIO.cpp +++ b/libdevcore/CommonIO.cpp @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file CommonIO.cpp * @author Gav Wood diff --git a/libdevcore/CommonIO.h b/libdevcore/CommonIO.h index 8238fe0ff..d84362cfc 100644 --- a/libdevcore/CommonIO.h +++ b/libdevcore/CommonIO.h @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file CommonIO.h * @author Gav Wood diff --git a/libdevcore/Exceptions.h b/libdevcore/Exceptions.h index 667ec31cb..4622774a4 100644 --- a/libdevcore/Exceptions.h +++ b/libdevcore/Exceptions.h @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file Exceptions.h * @author Gav Wood diff --git a/libdevcore/FixedHash.h b/libdevcore/FixedHash.h index a23aecc60..5b1c7acf5 100644 --- a/libdevcore/FixedHash.h +++ b/libdevcore/FixedHash.h @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file FixedHash.h * @author Gav Wood diff --git a/libdevcore/JSON.h b/libdevcore/JSON.h index 9f7d9a038..8499d6239 100644 --- a/libdevcore/JSON.h +++ b/libdevcore/JSON.h @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file JSON.h * @date 2016 diff --git a/libdevcore/SHA3.cpp b/libdevcore/SHA3.cpp index 3b12f39f3..4d82ec85b 100644 --- a/libdevcore/SHA3.cpp +++ b/libdevcore/SHA3.cpp @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file SHA3.cpp * @author Gav Wood diff --git a/libdevcore/SHA3.h b/libdevcore/SHA3.h index c481bfc92..ce0755218 100644 --- a/libdevcore/SHA3.h +++ b/libdevcore/SHA3.h @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file SHA3.h * @author Gav Wood diff --git a/libdevcore/SwarmHash.cpp b/libdevcore/SwarmHash.cpp index aa98eafd6..781886681 100644 --- a/libdevcore/SwarmHash.cpp +++ b/libdevcore/SwarmHash.cpp @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file SwarmHash.cpp */ diff --git a/libdevcore/SwarmHash.h b/libdevcore/SwarmHash.h index f474ce119..a5da96f53 100644 --- a/libdevcore/SwarmHash.h +++ b/libdevcore/SwarmHash.h @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file SwarmHash.h */ diff --git a/libdevcore/UTF8.cpp b/libdevcore/UTF8.cpp index 1c7ed17c7..9fbf4b45a 100644 --- a/libdevcore/UTF8.cpp +++ b/libdevcore/UTF8.cpp @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file UTF8.cpp * @author Alex Beregszaszi diff --git a/libdevcore/UTF8.h b/libdevcore/UTF8.h index 753914e3f..1f755e70e 100644 --- a/libdevcore/UTF8.h +++ b/libdevcore/UTF8.h @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file UTF8.h * @author Alex Beregszaszi diff --git a/libdevcore/UndefMacros.h b/libdevcore/UndefMacros.h index 91249523b..d2da3323d 100644 --- a/libdevcore/UndefMacros.h +++ b/libdevcore/UndefMacros.h @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file UndefMacros.h * @author Lefteris diff --git a/liblll/CodeFragment.cpp b/liblll/CodeFragment.cpp index af7d7f0a6..2b8822a6d 100644 --- a/liblll/CodeFragment.cpp +++ b/liblll/CodeFragment.cpp @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file CodeFragment.cpp * @author Gav Wood diff --git a/liblll/CodeFragment.h b/liblll/CodeFragment.h index 637d169fb..6622de3e7 100644 --- a/liblll/CodeFragment.h +++ b/liblll/CodeFragment.h @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file CodeFragment.h * @author Gav Wood diff --git a/liblll/Compiler.cpp b/liblll/Compiler.cpp index cd909f347..ea8b27af8 100644 --- a/liblll/Compiler.cpp +++ b/liblll/Compiler.cpp @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file Compiler.cpp * @author Gav Wood diff --git a/liblll/Compiler.h b/liblll/Compiler.h index 0fadd2785..04aa1e268 100644 --- a/liblll/Compiler.h +++ b/liblll/Compiler.h @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file Compiler.h * @author Gav Wood diff --git a/liblll/CompilerState.cpp b/liblll/CompilerState.cpp index 91c2452d8..88e43e188 100644 --- a/liblll/CompilerState.cpp +++ b/liblll/CompilerState.cpp @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file CompilerState.cpp * @author Gav Wood diff --git a/liblll/CompilerState.h b/liblll/CompilerState.h index bfe56f927..c29d3b7d3 100644 --- a/liblll/CompilerState.h +++ b/liblll/CompilerState.h @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file CompilerState.h * @author Gav Wood diff --git a/liblll/Exceptions.h b/liblll/Exceptions.h index aa4bf4e82..e8ca99db0 100644 --- a/liblll/Exceptions.h +++ b/liblll/Exceptions.h @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file Exceptions.h * @author Gav Wood diff --git a/liblll/Parser.cpp b/liblll/Parser.cpp index ad5e1885b..44d2a2ae6 100644 --- a/liblll/Parser.cpp +++ b/liblll/Parser.cpp @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file Parser.cpp * @author Gav Wood diff --git a/liblll/Parser.h b/liblll/Parser.h index e45428882..694d0cc6e 100644 --- a/liblll/Parser.h +++ b/liblll/Parser.h @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file Parser.h * @author Gav Wood diff --git a/lllc/main.cpp b/lllc/main.cpp index 9763e820e..adf181c7d 100644 --- a/lllc/main.cpp +++ b/lllc/main.cpp @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** @file main.cpp * @author Gav Wood diff --git a/test/libdevcore/Checksum.cpp b/test/libdevcore/Checksum.cpp index 322608884..17a17d228 100644 --- a/test/libdevcore/Checksum.cpp +++ b/test/libdevcore/Checksum.cpp @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** * Unit tests for the address checksum. diff --git a/test/libdevcore/SwarmHash.cpp b/test/libdevcore/SwarmHash.cpp index 7f3186ace..1ed1da181 100644 --- a/test/libdevcore/SwarmHash.cpp +++ b/test/libdevcore/SwarmHash.cpp @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of solidity. - cpp-ethereum is free software: you can redistribute it and/or modify + solidity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + solidity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with solidity. If not, see . */ /** * Unit tests for the swarm hash computation routine. From 821314aa270fe8b83a05d0b68fefe80fdeeef76c Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 10:19:22 +0000 Subject: [PATCH 013/234] Explain the difference between solc and solcjs --- docs/installing-solidity.rst | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/installing-solidity.rst b/docs/installing-solidity.rst index 345780d71..66e8038f1 100644 --- a/docs/installing-solidity.rst +++ b/docs/installing-solidity.rst @@ -25,24 +25,25 @@ without connection to the Internet, you can go to https://github.com/ethereum/browser-solidity/tree/gh-pages and download the .ZIP file as explained on that page. - npm / Node.js ============= This is probably the most portable and most convenient way to install Solidity locally. A platform-independent JavaScript library is provided by compiling the C++ source -into JavaScript using Emscripten for browser-solidity and there is also an npm -package available. +into JavaScript using Emscripten. It can be used in projects directly (such as Browser-Solidity). +Please refer to the `solc-js `_ repository for instructions. -To install it, simply use +It also contains a commandline tool called `solcjs`, which can be installed via npm: .. code:: bash - npm install solc + npm install -g solc -Details about the usage of the Node.js package can be found in the -`solc-js repository `_. +.. note:: + + The comandline options of `solcjs` are not compatible with `solc` and tools (such as `geth`) + expecting the behaviour of `solc` will not work with `solcjs`. Docker ====== From 7ec3dd9bbc9f212b6f631db0e42fde47de091c63 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 01:29:09 +0000 Subject: [PATCH 014/234] More verbose log of when using invalid instructions --- libevmasm/Instruction.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libevmasm/Instruction.h b/libevmasm/Instruction.h index a8a72234d..be71a4994 100644 --- a/libevmasm/Instruction.h +++ b/libevmasm/Instruction.h @@ -202,28 +202,28 @@ inline unsigned getSwapNumber(Instruction _inst) /// @returns the PUSH<_number> instruction inline Instruction pushInstruction(unsigned _number) { - assertThrow(1 <= _number && _number <= 32, InvalidOpcode, "Invalid PUSH instruction requested."); + assertThrow(1 <= _number && _number <= 32, InvalidOpcode, std::string("Invalid PUSH instruction requested (") + std::to_string(_number) + ")."); return Instruction(unsigned(Instruction::PUSH1) + _number - 1); } /// @returns the DUP<_number> instruction inline Instruction dupInstruction(unsigned _number) { - assertThrow(1 <= _number && _number <= 16, InvalidOpcode, "Invalid DUP instruction requested."); + assertThrow(1 <= _number && _number <= 16, InvalidOpcode, std::string("Invalid DUP instruction requested (") + std::to_string(_number) + ")."); return Instruction(unsigned(Instruction::DUP1) + _number - 1); } /// @returns the SWAP<_number> instruction inline Instruction swapInstruction(unsigned _number) { - assertThrow(1 <= _number && _number <= 16, InvalidOpcode, "Invalid SWAP instruction requested."); + assertThrow(1 <= _number && _number <= 16, InvalidOpcode, std::string("Invalid SWAP instruction requested (") + std::to_string(_number) + ")."); return Instruction(unsigned(Instruction::SWAP1) + _number - 1); } /// @returns the LOG<_number> instruction inline Instruction logInstruction(unsigned _number) { - assertThrow(_number <= 4, InvalidOpcode, "Invalid LOG instruction requested."); + assertThrow(_number <= 4, InvalidOpcode, std::string("Invalid LOG instruction requested (") + std::to_string(_number) + ")."); return Instruction(unsigned(Instruction::LOG0) + _number); } From ba0015cf256b3cf5f90a0daf225072286d8d3da4 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 01:29:24 +0000 Subject: [PATCH 015/234] Warn early when exhausting stack --- libsolidity/codegen/CompilerUtils.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 9f019d279..42323abd2 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -200,6 +200,7 @@ void CompilerUtils::encodeToMemory( // leave end_of_mem as dyn head pointer m_context << Instruction::DUP1 << u256(32) << Instruction::ADD; dynPointers++; + solAssert((argSize + dynPointers) < 16, "Stack too deep, try using less variables."); } else { From 51a150e82ae04c7470ad1aa8fdc07f45baf79b59 Mon Sep 17 00:00:00 2001 From: Will White Date: Thu, 2 Feb 2017 15:19:27 +0000 Subject: [PATCH 016/234] Other contracts can't write to a public variable The removed words implied that other contracts can write to a public variable. --- docs/introduction-to-smart-contracts.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/introduction-to-smart-contracts.rst b/docs/introduction-to-smart-contracts.rst index 4c134abcf..524cbcb0e 100644 --- a/docs/introduction-to-smart-contracts.rst +++ b/docs/introduction-to-smart-contracts.rst @@ -109,8 +109,7 @@ that does not allow any arithmetic operations. It is suitable for storing addresses of contracts or keypairs belonging to external persons. The keyword ``public`` automatically generates a function that allows you to access the current value of the state variable. -Without this keyword, other contracts have no way to access the variable -and only the code of this contract can write to it. +Without this keyword, other contracts have no way to access the variable. The function will look something like this:: function minter() returns (address) { return minter; } From ace583d0a1ec21cc184fb5734a9fd8c2147391e4 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 23:52:34 +0000 Subject: [PATCH 017/234] Rename accessor to getter --- docs/contracts.rst | 24 ++++++++++++------------ docs/control-structures.rst | 2 +- docs/frequently-asked-questions.rst | 2 +- docs/introduction-to-smart-contracts.rst | 2 +- docs/miscellaneous.rst | 4 ++-- docs/structure-of-a-contract.rst | 4 ++-- docs/types.rst | 10 +++++----- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/docs/contracts.rst b/docs/contracts.rst index edc42c3d7..1516ba0bb 100644 --- a/docs/contracts.rst +++ b/docs/contracts.rst @@ -145,11 +145,11 @@ This means that cyclic creation dependencies are impossible. .. index:: ! visibility, external, public, private, internal -.. _visibility-and-accessors: +.. _visibility-and-getters: -************************ -Visibility and Accessors -************************ +********************** +Visibility and Getters +********************** Since Solidity knows two kinds of function calls (internal ones that do not create an actual EVM call (also called @@ -173,7 +173,7 @@ and the default is ``internal``. ``public``: Public functions are part of the contract interface and can be either called internally or via - messages. For public state variables, an automatic accessor + messages. For public state variables, an automatic getter function (see below) is generated. ``internal``: @@ -243,12 +243,12 @@ In the following example, ``D``, can call ``c.getData()`` to retrieve the value } } -.. index:: ! accessor;function, ! function;accessor +.. index:: ! getter;function, ! function;getter -Accessor Functions -================== +Getter Functions +================ -The compiler automatically creates accessor functions for +The compiler automatically creates getter functions for all **public** state variables. For the contract given below, the compiler will generate a function called ``data`` that does not take any arguments and returns a ``uint``, the value of the state @@ -271,7 +271,7 @@ be done at declaration. } } -The accessor functions have external visibility. If the +The getter functions have external visibility. If the symbol is accessed internally (i.e. without ``this.``), it is evaluated as a state variable and if it is accessed externally (i.e. with ``this.``), it is evaluated as a function. @@ -462,7 +462,7 @@ Functions can be declared constant. These functions promise not to modify the st } .. note:: - Accessor methods are marked constant. + Getter methods are marked constant. .. warning:: The compiler does not enforce yet that a constant method is not modifying state. @@ -882,7 +882,7 @@ Inheriting Different Kinds of Members of the Same Name When the inheritance results in a contract with a function and a modifier of the same name, it is considered as an error. This error is produced also by an event and a modifier of the same name, and a function and an event of the same name. -As an exception, a state variable accessor can override a public function. +As an exception, a state variable getter can override a public function. .. index:: ! contract;abstract, ! abstract contract diff --git a/docs/control-structures.rst b/docs/control-structures.rst index 757988cca..1c7d71f26 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -393,7 +393,7 @@ Currently, Solidity automatically generates a runtime exception in the following #. If you convert a value too big or negative into an enum type. #. If you perform an external function call targeting a contract that contains no code. #. If your contract receives Ether via a public function without ``payable`` modifier (including the constructor and the fallback function). -#. If your contract receives Ether via a public accessor function. +#. If your contract receives Ether via a public getter function. #. If you call a zero-initialized variable of internal function type. Internally, Solidity performs an "invalid jump" when a user-provided exception is thrown. In contrast, it performs an invalid operation diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst index 43fba3322..d2fc5b1ce 100644 --- a/docs/frequently-asked-questions.rst +++ b/docs/frequently-asked-questions.rst @@ -641,7 +641,7 @@ Not yet, as this requires two levels of dynamic arrays (``string`` is a dynamic If you issue a call for an array, it is possible to retrieve the whole array? Or must you write a helper function for that? =========================================================================================================================== -The automatic accessor function for a public state variable of array type only returns +The automatic getter function for a public state variable of array type only returns individual elements. If you want to return the complete array, you have to manually write a function to do that. diff --git a/docs/introduction-to-smart-contracts.rst b/docs/introduction-to-smart-contracts.rst index 524cbcb0e..f02447cf4 100644 --- a/docs/introduction-to-smart-contracts.rst +++ b/docs/introduction-to-smart-contracts.rst @@ -131,7 +131,7 @@ too far, though, as it is neither possible to obtain a list of all keys of a mapping, nor a list of all values. So either keep in mind (or better, keep a list or use a more advanced data type) what you added to the mapping or use it in a context where this is not needed, -like this one. The accessor function created by the ``public`` keyword +like this one. The getter function created by the ``public`` keyword is a bit more complex in this case. It roughly looks like the following:: diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index 378c3c969..c5a0262ff 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -427,7 +427,7 @@ Tips and Tricks * Use ``delete`` on arrays to delete all its elements. * Use shorter types for struct elements and sort them such that short types are grouped together. This can lower the gas costs as multiple SSTORE operations might be combined into a single (SSTORE costs 5000 or 20000 gas, so this is what you want to optimise). Use the gas price estimator (with optimiser enabled) to check! -* Make your state variables public - the compiler will create :ref:`getters ` for you for free. +* Make your state variables public - the compiler will create :ref:`getters ` for you for free. * If you end up checking conditions on input or state a lot at the beginning of your functions, try using :ref:`modifiers`. * If your contract has a function called ``send`` but you want to use the built-in send-function, use ``address(contractVariable).send(amount)``. * Initialise storage structs with a single assignment: ``x = MyStruct({a: 1, b: 2});`` @@ -541,7 +541,7 @@ Function Visibility Specifiers return true; } -- ``public``: visible externally and internally (creates accessor function for storage/state variables) +- ``public``: visible externally and internally (creates getter function for storage/state variables) - ``private``: only visible in the current contract - ``external``: only visible externally (only for functions) - i.e. can only be message-called (via ``this.func``) - ``internal``: only visible internally diff --git a/docs/structure-of-a-contract.rst b/docs/structure-of-a-contract.rst index c7af0c8ce..24ef69a6e 100644 --- a/docs/structure-of-a-contract.rst +++ b/docs/structure-of-a-contract.rst @@ -28,7 +28,7 @@ State variables are values which are permanently stored in contract storage. } See the :ref:`types` section for valid state variable types and -:ref:`visibility-and-accessors` for possible choices for +:ref:`visibility-and-getters` for possible choices for visibility. .. _structure-functions: @@ -49,7 +49,7 @@ Functions are the executable units of code within a contract. } :ref:`function-calls` can happen internally or externally -and have different levels of visibility (:ref:`visibility-and-accessors`) +and have different levels of visibility (:ref:`visibility-and-getters`) towards other contracts. .. _structure-function-modifiers: diff --git a/docs/types.rst b/docs/types.rst index 3fb1db953..69c23e6e0 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -543,8 +543,8 @@ So ``bytes`` should always be preferred over ``byte[]`` because it is cheaper. that you are accessing the low-level bytes of the UTF-8 representation, and not the individual characters! -It is possible to mark arrays ``public`` and have Solidity create an accessor. -The numeric index will become a required parameter for the accessor. +It is possible to mark arrays ``public`` and have Solidity create a getter. +The numeric index will become a required parameter for the getter. .. index:: ! array;allocating, new @@ -792,11 +792,11 @@ Because of this, mappings do not have a length or a concept of a key or value be Mappings are only allowed for state variables (or as storage reference types in internal functions). -It is possible to mark mappings ``public`` and have Solidity create an accessor. -The ``_KeyType`` will become a required parameter for the accessor and it will +It is possible to mark mappings ``public`` and have Solidity create a getter. +The ``_KeyType`` will become a required parameter for the getter and it will return ``_ValueType``. -The ``_ValueType`` can be a mapping too. The accessor will have one parameter +The ``_ValueType`` can be a mapping too. The getter will have one parameter for each ``_KeyType``, recursively. :: From f50caa967c8cf0f2fa2688350f91dae3ef836c80 Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Thu, 2 Feb 2017 18:00:46 -0600 Subject: [PATCH 018/234] implement a build script Signed-off-by: RJ Catalano --- .travis.yml | 6 +----- docs/installing-solidity.rst | 10 ++++++++-- scripts/build.sh | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 7 deletions(-) create mode 100755 scripts/build.sh diff --git a/.travis.yml b/.travis.yml index 017f1a611..d4b37f200 100644 --- a/.travis.yml +++ b/.travis.yml @@ -148,11 +148,7 @@ install: - echo -n "$TRAVIS_COMMIT" > commit_hash.txt before_script: - test $TRAVIS_EMSCRIPTEN != On || ./scripts/build_emscripten.sh - - test $TRAVIS_RELEASE != On || (mkdir -p build - && cd build - && cmake .. -DCMAKE_BUILD_TYPE=$TRAVIS_BUILD_TYPE - && make -j2 - && cd .. + - test $TRAVIS_RELEASE != On || (./scripts/build.sh $TRAVIS_BUILD_TYPE && ./scripts/release.sh $ZIP_SUFFIX && ./scripts/create_source_tarball.sh ) script: diff --git a/docs/installing-solidity.rst b/docs/installing-solidity.rst index 66e8038f1..bedf62ea0 100644 --- a/docs/installing-solidity.rst +++ b/docs/installing-solidity.rst @@ -198,7 +198,13 @@ Building Solidity is quite similar on Linux, macOS and other Unices: cd build cmake .. && make -And even on Windows: +or even easier: + +.. code:: bash + + ./scripts/build.sh + +And even for Windows: .. code:: bash @@ -251,4 +257,4 @@ Example: 3. a breaking change is introduced - version is bumped to 0.5.0 4. the 0.5.0 release is made -This behaviour works well with the version pragma. +This behaviour works well with the version pragma. \ No newline at end of file diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 000000000..e056ae4a8 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +if [ -z "$1" ]; then + BUILD_TYPE=Release +else + BUILD_TYPE="$1" +fi + +cd $(dirname "$0") +mkdir -p build +cd build +cmake .. -DCMAKE_BUILD_TYPE="$BUILD_TYPE" +make -j2 + +if [ -z $CI ]; then + install solc/solc /usr/local/bin && install test/soltest /usr/local/bin +fi \ No newline at end of file From 60e884b0a39a5f116291ae03e98b228847831f2d Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Thu, 2 Feb 2017 18:38:38 -0600 Subject: [PATCH 019/234] clarified binaries installation Signed-off-by: RJ Catalano --- docs/installing-solidity.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/installing-solidity.rst b/docs/installing-solidity.rst index bedf62ea0..44a2d45fe 100644 --- a/docs/installing-solidity.rst +++ b/docs/installing-solidity.rst @@ -201,7 +201,8 @@ Building Solidity is quite similar on Linux, macOS and other Unices: or even easier: .. code:: bash - + + #note: this will install binaries solc and soltest at usr/local/bin ./scripts/build.sh And even for Windows: From 9f9807f95dcf3bed2055e4612bc2ef2bfa2c0c71 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 23:45:00 +0000 Subject: [PATCH 020/234] Remove obsolete esoteric features section --- docs/miscellaneous.rst | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index c5a0262ff..cc40d6a75 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -137,31 +137,6 @@ Different types have different rules for cleaning up invalid values: | | |will be thrown | +---------------+---------------+-------------------+ - -***************** -Esoteric Features -***************** - -There are some types in Solidity's type system that have no counterpart in the syntax. One of these types are the types of functions. But still, using ``var`` it is possible to have local variables of these types:: - - contract FunctionSelector { - function select(bool useB, uint x) returns (uint z) { - var f = a; - if (useB) f = b; - return f(x); - } - - function a(uint x) returns (uint z) { - return x * x; - } - - function b(uint x) returns (uint z) { - return 2 * x; - } - } - -Calling ``select(false, x)`` will compute ``x * x`` and ``select(true, x)`` will compute ``2 * x``. - .. index:: optimizer, common subexpression elimination, constant propagation ************************* From 46412473b6d198106a0b80dc79645eeb693f1492 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sun, 5 Feb 2017 19:19:29 +0000 Subject: [PATCH 021/234] Always escape filenames in solc --- Changelog.md | 1 + solc/CommandLineInterface.cpp | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Changelog.md b/Changelog.md index 79d2fe44a..038d944f6 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,7 @@ Features: * Type system: Support explicit conversion of external function to address. Bugfixes: + * Commandline interface: Always escape filenames (replace ``/``, ``:`` and ``.`` with ``_``). * Type system: Disallow arrays with negative length. ### 0.4.9 (2017-01-31) diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index dd80e1894..26355353a 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -200,7 +200,7 @@ void CommandLineInterface::handleBinary(string const& _contract) if (m_args.count(g_argCloneBinary)) { if (m_args.count(g_argOutputDir)) - createFile(_contract + ".clone_bin", m_compiler->cloneObject(_contract).toHex()); + createFile(m_compiler->filesystemFriendlyName(_contract) + ".clone_bin", m_compiler->cloneObject(_contract).toHex()); else { cout << "Clone Binary: " << endl; @@ -210,7 +210,7 @@ void CommandLineInterface::handleBinary(string const& _contract) if (m_args.count(g_argBinaryRuntime)) { if (m_args.count(g_argOutputDir)) - createFile(_contract + ".bin-runtime", m_compiler->runtimeObject(_contract).toHex()); + createFile(m_compiler->filesystemFriendlyName(_contract) + ".bin-runtime", m_compiler->runtimeObject(_contract).toHex()); else { cout << "Binary of the runtime part: " << endl; @@ -222,7 +222,7 @@ void CommandLineInterface::handleBinary(string const& _contract) void CommandLineInterface::handleOpcode(string const& _contract) { if (m_args.count(g_argOutputDir)) - createFile(_contract + ".opcode", solidity::disassemble(m_compiler->object(_contract).bytecode)); + createFile(m_compiler->filesystemFriendlyName(_contract) + ".opcode", solidity::disassemble(m_compiler->object(_contract).bytecode)); else { cout << "Opcodes: " << endl; @@ -249,7 +249,7 @@ void CommandLineInterface::handleSignatureHashes(string const& _contract) out += toHex(it.first.ref()) + ": " + it.second->externalSignature() + "\n"; if (m_args.count(g_argOutputDir)) - createFile(_contract + ".signatures", out); + createFile(m_compiler->filesystemFriendlyName(_contract) + ".signatures", out); else cout << "Function signatures: " << endl << out; } @@ -261,7 +261,7 @@ void CommandLineInterface::handleOnChainMetadata(string const& _contract) string data = m_compiler->onChainMetadata(_contract); if (m_args.count("output-dir")) - createFile(_contract + "_meta.json", data); + createFile(m_compiler->filesystemFriendlyName(_contract) + "_meta.json", data); else cout << "Metadata: " << endl << data << endl; } @@ -302,7 +302,7 @@ void CommandLineInterface::handleMeta(DocumentationType _type, string const& _co output = dev::jsonPrettyPrint(m_compiler->metadata(_contract, _type)); if (m_args.count(g_argOutputDir)) - createFile(_contract + suffix, output); + createFile(m_compiler->filesystemFriendlyName(_contract) + suffix, output); else { cout << title << endl; @@ -981,7 +981,7 @@ void CommandLineInterface::outputCompilationResults() { stringstream data; m_compiler->streamAssembly(data, contract, m_sourceCodes, m_args.count(g_argAsmJson)); - createFile(contract + (m_args.count(g_argAsmJson) ? "_evm.json" : ".evm"), data.str()); + createFile(m_compiler->filesystemFriendlyName(contract) + (m_args.count(g_argAsmJson) ? "_evm.json" : ".evm"), data.str()); } else { From a5d0fd9c8a21af4a524ae60470c9381e94af446a Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sun, 5 Feb 2017 19:39:30 +0000 Subject: [PATCH 022/234] Do not create directories . and .. --- Changelog.md | 1 + solc/CommandLineInterface.cpp | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 038d944f6..0c4e83294 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,7 @@ Features: Bugfixes: * Commandline interface: Always escape filenames (replace ``/``, ``:`` and ``.`` with ``_``). + * Commandline interface: Do not try creating paths ``.`` and ``..``. * Type system: Disallow arrays with negative length. ### 0.4.9 (2017-01-31) diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 26355353a..6759727fe 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -461,7 +461,9 @@ void CommandLineInterface::createFile(string const& _fileName, string const& _da namespace fs = boost::filesystem; // create directory if not existent fs::path p(m_args.at(g_argOutputDir).as()); - fs::create_directories(p); + // Do not try creating the directory if the first item is . or .. + if (p.filename() != "." && p.filename() != "..") + fs::create_directories(p); string pathName = (p / _fileName).string(); ofstream outFile(pathName); outFile << _data; From e5e0eae057816c6ed7f53a3972b7dff3032348ea Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 6 Feb 2017 16:00:29 +0000 Subject: [PATCH 023/234] Take documentation version numbers from CMake --- docs/conf.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 159cd3eab..ca8c0fecc 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -15,6 +15,7 @@ import sys import os +import re # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the @@ -56,9 +57,14 @@ copyright = '2016-2017, Ethereum' # built documents. # # The short X.Y version. -version = '0.4.10' +with open('../CMakeLists.txt', 'r') as f: + version = re.search('PROJECT_VERSION "([^"]+)"', f.read()).group(1) # The full version, including alpha/beta/rc tags. -release = '0.4.10-develop' +if os.path.isfile('../prerelease.txt') != True or os.path.getsize('../prerelease.txt') == 0: + release = version +else: + # This is a prerelease version + release = version + '-develop' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. From 53c71c8be3ee6caa2f93d0745f2131d1ff6e3ff4 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 6 Feb 2017 15:17:23 +0000 Subject: [PATCH 024/234] Require node.js >= 5 --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d4b37f200..c31d9b2b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ # You should have received a copy of the GNU General Public License # along with solidity. If not, see # -# (c) 2016 solidity contributors. +# (c) 2016-2017 solidity contributors. #------------------------------------------------------------------------------ language: cpp @@ -73,7 +73,7 @@ matrix: dist: trusty sudo: required compiler: gcc - node_js: stable + node_js: "5" services: - docker before_install: From 82a512fb2f81d776dead0c595677415b9fc4fa3f Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 6 Feb 2017 18:23:49 +0000 Subject: [PATCH 025/234] Add archlinux installation instructions --- docs/installing-solidity.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/installing-solidity.rst b/docs/installing-solidity.rst index 44a2d45fe..42905ede4 100644 --- a/docs/installing-solidity.rst +++ b/docs/installing-solidity.rst @@ -83,6 +83,12 @@ If you want to use the cutting edge developer version: sudo apt-get update sudo apt-get install solc +Arch Linux also has packages, albeit limited to the latest development version: + +.. code:: bash + + pacman -S solidity-git + Homebrew is missing pre-built bottles at the time of writing, following a Jenkins to TravisCI migration, but Homebrew should still work just fine as a means to build-from-source. From 693226b1abc8e0557943482b9ca23b61e859ceba Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 6 Feb 2017 18:35:18 +0000 Subject: [PATCH 026/234] Rename SUICIDE opcode to SELFDESTRUCT in libevmasm --- libevmasm/EVMSchedule.h | 2 +- libevmasm/GasMeter.h | 2 +- libevmasm/Instruction.cpp | 6 +++--- libevmasm/Instruction.h | 2 +- libevmasm/PeepholeOptimiser.cpp | 2 +- libevmasm/SemanticInformation.cpp | 2 +- libsolidity/codegen/ExpressionCompiler.cpp | 2 +- libsolidity/inlineasm/AsmParser.cpp | 4 ++-- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libevmasm/EVMSchedule.h b/libevmasm/EVMSchedule.h index f882f0068..ce9003bdd 100644 --- a/libevmasm/EVMSchedule.h +++ b/libevmasm/EVMSchedule.h @@ -47,7 +47,7 @@ struct EVMSchedule unsigned callStipend = 2300; unsigned callValueTransferGas = 9000; unsigned callNewAccountGas = 25000; - unsigned suicideRefundGas = 24000; + unsigned selfdestructRefundGas = 24000; unsigned memoryGas = 3; unsigned quadCoeffDiv = 512; unsigned createDataGas = 200; diff --git a/libevmasm/GasMeter.h b/libevmasm/GasMeter.h index 0bc10f1f2..8ade838a2 100644 --- a/libevmasm/GasMeter.h +++ b/libevmasm/GasMeter.h @@ -61,7 +61,7 @@ namespace GasCosts static unsigned const callStipend = 2300; static unsigned const callValueTransferGas = 9000; static unsigned const callNewAccountGas = 25000; - static unsigned const suicideRefundGas = 24000; + static unsigned const selfdestructRefundGas = 24000; static unsigned const memoryGas = 3; static unsigned const quadCoeffDiv = 512; static unsigned const createDataGas = 200; diff --git a/libevmasm/Instruction.cpp b/libevmasm/Instruction.cpp index b0f063dae..f9ee9be1f 100644 --- a/libevmasm/Instruction.cpp +++ b/libevmasm/Instruction.cpp @@ -160,7 +160,7 @@ const std::map dev::solidity::c_instructions = { "RETURN", Instruction::RETURN }, { "DELEGATECALL", Instruction::DELEGATECALL }, { "INVALID", Instruction::INVALID }, - { "SUICIDE", Instruction::SUICIDE } + { "SELFDESTRUCT", Instruction::SELFDESTRUCT } }; static const std::map c_instructionInfo = @@ -293,9 +293,9 @@ static const std::map c_instructionInfo = { Instruction::CALL, { "CALL", 0, 7, 1, true, Tier::Special } }, { Instruction::CALLCODE, { "CALLCODE", 0, 7, 1, true, Tier::Special } }, { Instruction::RETURN, { "RETURN", 0, 2, 0, true, Tier::Zero } }, - { Instruction::DELEGATECALL,{ "DELEGATECALL", 0, 6, 1, true, Tier::Special } }, + { Instruction::DELEGATECALL, { "DELEGATECALL", 0, 6, 1, true, Tier::Special } }, { Instruction::INVALID, { "INVALID", 0, 0, 0, true, Tier::Zero } }, - { Instruction::SUICIDE, { "SUICIDE", 0, 1, 0, true, Tier::Zero } } + { Instruction::SELFDESTRUCT, { "SELFDESTRUCT", 0, 1, 0, true, Tier::Zero } } }; void dev::solidity::eachInstruction( diff --git a/libevmasm/Instruction.h b/libevmasm/Instruction.h index be71a4994..7f56ad3a9 100644 --- a/libevmasm/Instruction.h +++ b/libevmasm/Instruction.h @@ -178,7 +178,7 @@ enum class Instruction: uint8_t DELEGATECALL, ///< like CALLCODE but keeps caller's value and sender INVALID = 0xfe, ///< invalid instruction for expressing runtime errors (e.g., division-by-zero) - SUICIDE = 0xff ///< halt execution and register account for later deletion + SELFDESTRUCT = 0xff ///< halt execution and register account for later deletion }; /// @returns the number of PUSH Instruction _inst diff --git a/libevmasm/PeepholeOptimiser.cpp b/libevmasm/PeepholeOptimiser.cpp index 528ce1c47..9a8341ab9 100644 --- a/libevmasm/PeepholeOptimiser.cpp +++ b/libevmasm/PeepholeOptimiser.cpp @@ -200,7 +200,7 @@ struct UnreachableCode it[0] != Instruction::RETURN && it[0] != Instruction::STOP && it[0] != Instruction::INVALID && - it[0] != Instruction::SUICIDE + it[0] != Instruction::SELFDESTRUCT ) return false; diff --git a/libevmasm/SemanticInformation.cpp b/libevmasm/SemanticInformation.cpp index d3ce4735c..3a0843b8f 100644 --- a/libevmasm/SemanticInformation.cpp +++ b/libevmasm/SemanticInformation.cpp @@ -116,7 +116,7 @@ bool SemanticInformation::altersControlFlow(AssemblyItem const& _item) case Instruction::JUMP: case Instruction::JUMPI: case Instruction::RETURN: - case Instruction::SUICIDE: + case Instruction::SELFDESTRUCT: case Instruction::STOP: case Instruction::INVALID: return true; diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index b66a3e129..d74d9dd3d 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -648,7 +648,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) case Location::Selfdestruct: arguments.front()->accept(*this); utils().convertType(*arguments.front()->annotation().type, *function.parameterTypes().front(), true); - m_context << Instruction::SUICIDE; + m_context << Instruction::SELFDESTRUCT; break; case Location::SHA3: { diff --git a/libsolidity/inlineasm/AsmParser.cpp b/libsolidity/inlineasm/AsmParser.cpp index fcc92dbbf..46a2730d9 100644 --- a/libsolidity/inlineasm/AsmParser.cpp +++ b/libsolidity/inlineasm/AsmParser.cpp @@ -152,8 +152,8 @@ std::map const& Parser::instructions() s_instructions[name] = instruction.second; } - // add alias for selfdestruct - s_instructions["selfdestruct"] = solidity::Instruction::SUICIDE; + // add alias for suicide + s_instructions["suicide"] = solidity::Instruction::SELFDESTRUCT; } return s_instructions; } From 9c3b28e21e78519c280c076b0756413422ad5eeb Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 7 Feb 2017 17:40:26 +0000 Subject: [PATCH 027/234] Fix tests on mac (wc produces whitespace) --- scripts/tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests.sh b/scripts/tests.sh index f21429464..ba932da59 100755 --- a/scripts/tests.sh +++ b/scripts/tests.sh @@ -35,7 +35,7 @@ echo "Running commandline tests..." echo "Checking that StandardToken.sol, owned.sol and mortal.sol produce bytecode..." output=$("$REPO_ROOT"/build/solc/solc --bin "$REPO_ROOT"/std/*.sol 2>/dev/null | grep "ffff" | wc -l) -test "$output" = "3" +test "${output//[[:blank:]]/}" = "3" # This conditional is only needed because we don't have a working Homebrew # install for `eth` at the time of writing, so we unzip the ZIP file locally From 1fc42d733df0d85eaf61495a53906ca65a9544be Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Fri, 3 Feb 2017 03:37:24 -0300 Subject: [PATCH 028/234] grammar.txt: Add rule for tuple destructuring --- docs/grammar.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/grammar.txt b/docs/grammar.txt index a9f328c06..dc1885729 100644 --- a/docs/grammar.txt +++ b/docs/grammar.txt @@ -68,7 +68,8 @@ Continue = 'continue' Break = 'break' Return = 'return' Expression? Throw = 'throw' -VariableDefinition = VariableDeclaration ( '=' Expression )? +VariableDefinition = ('var' IdentifierList | VariableDeclaration) ( '=' Expression )? +IdentifierList = '(' ( Identifier? ',' )* Identifier? ')' // Precedence by order (see github.com/ethereum/solidity/pull/732) Expression = From 82c2bf8ed263133b4228a9b1ee5e011251004f92 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 8 Feb 2017 20:47:24 +0000 Subject: [PATCH 029/234] Ensure that all commands succed and move back to root --- scripts/build.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index e056ae4a8..3785e1c13 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,17 +1,23 @@ #!/usr/bin/env bash -if [ -z "$1" ]; then +if [ -z "$1" ]; then BUILD_TYPE=Release -else +else BUILD_TYPE="$1" fi -cd $(dirname "$0") -mkdir -p build -cd build -cmake .. -DCMAKE_BUILD_TYPE="$BUILD_TYPE" +cd $(dirname "$0")/.. && +mkdir -p build && +cd build && +cmake .. -DCMAKE_BUILD_TYPE="$BUILD_TYPE" && make -j2 +if [ $? -ne 0 ]; then + echo "Failed to build" + exit 1 +fi + if [ -z $CI ]; then + echo "Installing solc and soltest" install solc/solc /usr/local/bin && install test/soltest /usr/local/bin fi \ No newline at end of file From 43bae9dd0bd924ad4a7277ea3c0a8f69d85f4870 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 7 Feb 2017 12:32:23 +0000 Subject: [PATCH 030/234] Ensure that a valid RPC response is received through IPC --- test/RPCSession.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index 44d21d69a..f67696d96 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -302,7 +302,7 @@ Json::Value RPCSession::rpcCall(string const& _methodName, vector const& //cout << "Reply: " << reply << endl; Json::Value result; - Json::Reader().parse(reply, result, false); + BOOST_REQUIRE(Json::Reader().parse(reply, result, false)); if (result.isMember("error")) { From 3be6d105252d2153a6c05a4e788f615ed0921d6b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 7 Feb 2017 12:32:58 +0000 Subject: [PATCH 031/234] Avoid crash if fdopen failed in IPC --- test/RPCSession.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index f67696d96..43f10824c 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -75,6 +75,8 @@ IPCSocket::IPCSocket(string const& _path): m_path(_path) BOOST_FAIL("Error connecting to IPC socket: " << _path); m_fp = fdopen(m_socket, "r"); + if (!m_fp) + BOOST_FAIL("Error opening IPC socket: " << _path); #endif } From f9357dbb22de8690940d605fc72ef6df4deb7f6b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 7 Feb 2017 12:35:27 +0000 Subject: [PATCH 032/234] Check the return value of RPC calls --- test/RPCSession.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index 43f10824c..ffdb48b1e 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -111,7 +111,9 @@ string IPCSocket::sendRequest(string const& _req) if (!fSuccess) BOOST_FAIL("ReadFile from pipe failed"); - cerr << "."; //Output for log activity + // This is needed for Appveyor, otherwise it may terminate + // the session due to the inactivity. + cerr << "."; return returnStr; #else send(m_socket, _req.c_str(), _req.length(), 0); @@ -189,7 +191,7 @@ string RPCSession::eth_getStorageRoot(string const& _address, string const& _blo void RPCSession::personal_unlockAccount(string const& _address, string const& _password, int _duration) { - rpcCall("personal_unlockAccount", { quote(_address), quote(_password), to_string(_duration) }); + BOOST_CHECK(rpcCall("personal_unlockAccount", { quote(_address), quote(_password), to_string(_duration) }) == true); } string RPCSession::personal_newAccount(string const& _password) @@ -233,18 +235,18 @@ void RPCSession::test_setChainParams(vector const& _accounts) void RPCSession::test_setChainParams(string const& _config) { - rpcCall("test_setChainParams", { _config }); + BOOST_CHECK(rpcCall("test_setChainParams", { _config }) == true); } void RPCSession::test_rewindToBlock(size_t _blockNr) { - rpcCall("test_rewindToBlock", { to_string(_blockNr) }); + BOOST_CHECK(rpcCall("test_rewindToBlock", { to_string(_blockNr) }) == true); } void RPCSession::test_mineBlocks(int _number) { u256 startBlock = fromBigEndian(fromHex(rpcCall("eth_blockNumber").asString())); - rpcCall("test_mineBlocks", { to_string(_number) }, true); + BOOST_CHECK(rpcCall("test_mineBlocks", { to_string(_number) }, true) == true); bool mined = false; @@ -283,7 +285,7 @@ void RPCSession::test_mineBlocks(int _number) void RPCSession::test_modifyTimestamp(size_t _timestamp) { - rpcCall("test_modifyTimestamp", { to_string(_timestamp) }); + BOOST_CHECK(rpcCall("test_modifyTimestamp", { to_string(_timestamp) }) == true); } Json::Value RPCSession::rpcCall(string const& _methodName, vector const& _args, bool _canFail) From af6ab7fa916ac0f56c2caeae03be47bbefd8a50f Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 8 Feb 2017 12:31:26 +0000 Subject: [PATCH 033/234] Use BOOST_REQUIRE() and stop at the first failure --- test/RPCSession.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index ffdb48b1e..5cd1bc7ed 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -191,7 +191,7 @@ string RPCSession::eth_getStorageRoot(string const& _address, string const& _blo void RPCSession::personal_unlockAccount(string const& _address, string const& _password, int _duration) { - BOOST_CHECK(rpcCall("personal_unlockAccount", { quote(_address), quote(_password), to_string(_duration) }) == true); + BOOST_REQUIRE(rpcCall("personal_unlockAccount", { quote(_address), quote(_password), to_string(_duration) }) == true); } string RPCSession::personal_newAccount(string const& _password) @@ -235,18 +235,18 @@ void RPCSession::test_setChainParams(vector const& _accounts) void RPCSession::test_setChainParams(string const& _config) { - BOOST_CHECK(rpcCall("test_setChainParams", { _config }) == true); + BOOST_REQUIRE(rpcCall("test_setChainParams", { _config }) == true); } void RPCSession::test_rewindToBlock(size_t _blockNr) { - BOOST_CHECK(rpcCall("test_rewindToBlock", { to_string(_blockNr) }) == true); + BOOST_REQUIRE(rpcCall("test_rewindToBlock", { to_string(_blockNr) }) == true); } void RPCSession::test_mineBlocks(int _number) { u256 startBlock = fromBigEndian(fromHex(rpcCall("eth_blockNumber").asString())); - BOOST_CHECK(rpcCall("test_mineBlocks", { to_string(_number) }, true) == true); + BOOST_REQUIRE(rpcCall("test_mineBlocks", { to_string(_number) }, true) == true); bool mined = false; @@ -285,7 +285,7 @@ void RPCSession::test_mineBlocks(int _number) void RPCSession::test_modifyTimestamp(size_t _timestamp) { - BOOST_CHECK(rpcCall("test_modifyTimestamp", { to_string(_timestamp) }) == true); + BOOST_REQUIRE(rpcCall("test_modifyTimestamp", { to_string(_timestamp) }) == true); } Json::Value RPCSession::rpcCall(string const& _methodName, vector const& _args, bool _canFail) From fba3b849293c7c88f0d11316b97edeb55c44f173 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 8 Feb 2017 21:19:05 +0000 Subject: [PATCH 034/234] Include --show-progress in soltest --- appveyor.yml | 2 +- scripts/tests.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 85fb36f2b..86a689a70 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -62,7 +62,7 @@ test_script: - ps: Start-Sleep -s 100 - cd %APPVEYOR_BUILD_FOLDER%\build\test\%CONFIGURATION% - copy "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist\x86\Microsoft.VC140.CRT\msvc*.dll" . - - soltest.exe -- --ipcpath \\.\pipe\geth.ipc + - soltest.exe --show-progress -- --ipcpath \\.\pipe\geth.ipc artifacts: - path: solidity-windows.zip diff --git a/scripts/tests.sh b/scripts/tests.sh index ba932da59..8edfda0bc 100755 --- a/scripts/tests.sh +++ b/scripts/tests.sh @@ -62,9 +62,9 @@ echo "--> IPC available." # And then run the Solidity unit-tests (once without optimization, once with), # pointing to that IPC endpoint. echo "--> Running tests without optimizer..." - "$REPO_ROOT"/build/test/soltest -- --ipcpath /tmp/test/geth.ipc && \ + "$REPO_ROOT"/build/test/soltest --show-progress -- --ipcpath /tmp/test/geth.ipc && \ echo "--> Running tests WITH optimizer..." && \ - "$REPO_ROOT"/build/test/soltest -- --optimize --ipcpath /tmp/test/geth.ipc + "$REPO_ROOT"/build/test/soltest --show-progress -- --optimize --ipcpath /tmp/test/geth.ipc ERROR_CODE=$? pkill eth || true sleep 4 From 92fb07c78319c256a01c6146d83a7c9c7419a240 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 8 Feb 2017 21:19:27 +0000 Subject: [PATCH 035/234] Do not log dots in soltest on windows --- test/RPCSession.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index 5cd1bc7ed..968d77b1d 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -111,9 +111,6 @@ string IPCSocket::sendRequest(string const& _req) if (!fSuccess) BOOST_FAIL("ReadFile from pipe failed"); - // This is needed for Appveyor, otherwise it may terminate - // the session due to the inactivity. - cerr << "."; return returnStr; #else send(m_socket, _req.c_str(), _req.length(), 0); From 4fccb5fdaca054905bfab7cb01e7eba6fb47c114 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 10 Jun 2016 17:25:51 +0200 Subject: [PATCH 036/234] Document input description and metadata output. --- docs/index.rst | 1 + docs/miscellaneous.rst | 39 ---------- docs/using-the-compiler.rst | 141 ++++++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+), 39 deletions(-) create mode 100644 docs/using-the-compiler.rst diff --git a/docs/index.rst b/docs/index.rst index cb79687b9..904c3a544 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -130,6 +130,7 @@ Contents solidity-by-example.rst solidity-in-depth.rst security-considerations.rst + using-the-compiler.rst style-guide.rst common-patterns.rst contributing.rst diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index cc40d6a75..476500676 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -221,45 +221,6 @@ This means the following source mappings represent the same information: ``1:2:1;:9;2::2;;`` - -.. index:: ! commandline compiler, compiler;commandline, ! solc, ! linker - -.. _commandline-compiler: - -****************************** -Using the Commandline Compiler -****************************** - -One of the build targets of the Solidity repository is ``solc``, the solidity commandline compiler. -Using ``solc --help`` provides you with an explanation of all options. The compiler can produce various outputs, ranging from simple binaries and assembly over an abstract syntax tree (parse tree) to estimations of gas usage. -If you only want to compile a single file, you run it as ``solc --bin sourceFile.sol`` and it will print the binary. Before you deploy your contract, activate the optimizer while compiling using ``solc --optimize --bin sourceFile.sol``. If you want to get some of the more advanced output variants of ``solc``, it is probably better to tell it to output everything to separate files using ``solc -o outputDirectory --bin --ast --asm sourceFile.sol``. - -The commandline compiler will automatically read imported files from the filesystem, but -it is also possible to provide path redirects using ``context:prefix=path`` in the following way: - -:: - - solc github.com/ethereum/dapp-bin/=/usr/local/lib/dapp-bin/ =/usr/local/lib/fallback file.sol - -This essentially instructs the compiler to search for anything starting with -``github.com/ethereum/dapp-bin/`` under ``/usr/local/lib/dapp-bin`` and if it does not -find the file there, it will look at ``/usr/local/lib/fallback`` (the empty prefix -always matches). ``solc`` will not read files from the filesystem that lie outside of -the remapping targets and outside of the directories where explicitly specified source -files reside, so things like ``import "/etc/passwd";`` only work if you add ``=/`` as a remapping. - -You can restrict remappings to only certain source files by prefixing a context. - -The section on :ref:`import` provides more details on remappings. - -If there are multiple matches due to remappings, the one with the longest common prefix is selected. - -If your contracts use :ref:`libraries `, you will notice that the bytecode contains substrings of the form ``__LibraryName______``. You can use ``solc`` as a linker meaning that it will insert the library addresses for you at those points: - -Either add ``--libraries "Math:0x12345678901234567890 Heap:0xabcdef0123456"`` to your command to provide an address for each library or store the string in a file (one library per line) and run ``solc`` using ``--libraries fileName``. - -If ``solc`` is called with the option ``--link``, all input files are interpreted to be unlinked binaries (hex-encoded) in the ``__LibraryName____``-format given above and are linked in-place (if the input is read from stdin, it is written to stdout). All options except ``--libraries`` are ignored (including ``-o``) in this case. - ***************** Contract Metadata ***************** diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst new file mode 100644 index 000000000..47d7c7175 --- /dev/null +++ b/docs/using-the-compiler.rst @@ -0,0 +1,141 @@ +.. index:: ! commandline compiler, compiler;commandline, ! solc, ! linker + +.. _commandline-compiler: + +****************************** +Using the Commandline Compiler +****************************** + +One of the build targets of the Solidity repository is ``solc``, the solidity commandline compiler. +Using ``solc --help`` provides you with an explanation of all options. The compiler can produce various outputs, ranging from simple binaries and assembly over an abstract syntax tree (parse tree) to estimations of gas usage. +If you only want to compile a single file, you run it as ``solc --bin sourceFile.sol`` and it will print the binary. Before you deploy your contract, activate the optimizer while compiling using ``solc --optimize --bin sourceFile.sol``. If you want to get some of the more advanced output variants of ``solc``, it is probably better to tell it to output everything to separate files using ``solc -o outputDirectory --bin --ast --asm sourceFile.sol``. + +The commandline compiler will automatically read imported files from the filesystem, but +it is also possible to provide path redirects using ``prefix=path`` in the following way: + +:: + + solc github.com/ethereum/dapp-bin/=/usr/local/lib/dapp-bin/ =/usr/local/lib/fallback file.sol + +This essentially instructs the compiler to search for anything starting with +``github.com/ethereum/dapp-bin/`` under ``/usr/local/lib/dapp-bin`` and if it does not +find the file there, it will look at ``/usr/local/lib/fallback`` (the empty prefix +always matches). ``solc`` will not read files from the filesystem that lie outside of +the remapping targets and outside of the directories where explicitly specified source +files reside, so things like ``import "/etc/passwd";`` only work if you add ``=/`` as a remapping. + +If there are multiple matches due to remappings, the one with the longest common prefix is selected. + +If your contracts use :ref:`libraries `, you will notice that the bytecode contains substrings of the form ``__LibraryName______``. You can use ``solc`` as a linker meaning that it will insert the library addresses for you at those points: + +Either add ``--libraries "Math:0x12345678901234567890 Heap:0xabcdef0123456"`` to your command to provide an address for each library or store the string in a file (one library per line) and run ``solc`` using ``--libraries fileName``. + +If ``solc`` is called with the option ``--link``, all input files are interpreted to be unlinked binaries (hex-encoded) in the ``__LibraryName____``-format given above and are linked in-place (if the input is read from stdin, it is written to stdout). All options except ``--libraries`` are ignored (including ``-o``) in this case. + + +************************************************** +Standardized Input Description and Metadata Output +************************************************** + +In order to ease source code verification of complex contracts that are spread across several files, +there is a standardized for describing the relations between those files. +Furthermore, the compiler can generate a json file while compiling that includes +the source, natspec comments and other metadata whose hash is included in the +actual bytecode. + +There is some overlap between the input description and the metadata output +and due to the fact that some fields are optional, the metadata can be used as +input to the compiler. In order to verify the metadata, you actually take it, +re-run the compiler on the metadata and check that it again produces the same +metadata. + +If the compiler is invoked in a different way, not using the input +description (for example by using a file content retrieval callback), +the compiler can still generate the metadata alongside the bytecode of each +contract. + +The metadata standard is versioned. Future versions are only required to provide the "version" field, +the two keys inside the "compiler" field. The field compiler.keccak should be the keccak hash +of a binary of the compiler with the given version. + +The example below is presented in a human-readable way. Properly formatted metadata +should use quotes correctly, reduce whitespace to a minimum and sort the keys of all objects +to arrive at a unique formatting. + +Comments are of course not permitted and used here only for explanatory purposes. + +Input Description +----------------- + +The input description could change with each compiler version, but it +should be backwards compatible if possible. + + { + sources: + { + "abc": "contract b{}", + "def": {keccak: "0x123..."}, // source has to be retrieved by its hash + "dir/file.sol": "contract a {}" + }, + settings: + { + remappings: [":g/dir"], + optimizer: {enabled: true, runs: 500}, + compilationTarget: "myFile.sol:MyContract", // Can also be an array + // To be backwards compatible, use the full name of the contract in the output + // only if there are name clashes. + // If the full name was given as "compilationTargets", use the full name. + libraries: { + "def:MyLib": "0x123123..." + }, + // The following can be used to restrict the fields the compiler will output. + outputSelection: { + // to be defined + } + } + } + +Metadata Output +--------------- + +Note that the actual bytecode is not part of the metadata because the hash +of the metadata structure will be included in the bytecode itself. + +This requires the compiler to be able to compute the hash of its own binary, +which requires it to be statically linked. The hash of the binary is not +too important. It is much more important to have the commit hash because +that can be used to query a location of the binary (and whether the version is +"official") at a registry contract. + + { + version: "1", + compiler: { + version: "soljson-2313-2016-12-12", + keccak: "0x123..." + }, + sources: + { + "abc": "contract b{}", + "def": {keccak: "0x123..."}, // source has to be retrieved by its hash + "dir/file.sol": "contract a {}" + }, + settings: + { + remappings: [":g/dir"], + optimizer: {enabled: true, runs: 500}, + compilationTarget: "myFile.sol:MyContract", + // To be backwards compatible, use the full name of the contract in the output + // only if there are name clashes. + // If the full name was given as "compilationTargets", use the full name. + libraries: { + "def:MyLib": "0x123123..." + } + }, + output: + { + abi: [ /* abi definition */ ], + userDocumentation: [ /* user documentation comments */ ], + developerDocumentation: [ /* developer documentation comments */ ], + natspec: [ /* natspec comments */ ] + } + } From 57662e1bf3cba937289c50b3b711918a456101a6 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 10 Jun 2016 22:03:22 +0200 Subject: [PATCH 037/234] Add language and some minor corrections and clarifications. --- docs/using-the-compiler.rst | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index 47d7c7175..8ceb52a74 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -38,10 +38,11 @@ Standardized Input Description and Metadata Output ************************************************** In order to ease source code verification of complex contracts that are spread across several files, -there is a standardized for describing the relations between those files. +there is a standardized way for describing the relations between those files. Furthermore, the compiler can generate a json file while compiling that includes the source, natspec comments and other metadata whose hash is included in the -actual bytecode. +actual bytecode. Specifically, the creation data for a contract has to begin with +`push32 pop`. There is some overlap between the input description and the metadata output and due to the fact that some fields are optional, the metadata can be used as @@ -55,8 +56,8 @@ the compiler can still generate the metadata alongside the bytecode of each contract. The metadata standard is versioned. Future versions are only required to provide the "version" field, -the two keys inside the "compiler" field. The field compiler.keccak should be the keccak hash -of a binary of the compiler with the given version. +the "language" field and the two keys inside the "compiler" field. +The field compiler.keccak should be the keccak hash of a binary of the compiler with the given version. The example below is presented in a human-readable way. Properly formatted metadata should use quotes correctly, reduce whitespace to a minimum and sort the keys of all objects @@ -67,7 +68,7 @@ Comments are of course not permitted and used here only for explanatory purposes Input Description ----------------- -The input description could change with each compiler version, but it +The input description is language-specific and could change with each compiler version, but it should be backwards compatible if possible. { @@ -105,11 +106,13 @@ This requires the compiler to be able to compute the hash of its own binary, which requires it to be statically linked. The hash of the binary is not too important. It is much more important to have the commit hash because that can be used to query a location of the binary (and whether the version is -"official") at a registry contract. +"official") at a registry contract. { version: "1", + language: "Solidity", compiler: { + commit: "55db20e32c97098d13230ab7500758e8e3b31d64", version: "soljson-2313-2016-12-12", keccak: "0x123..." }, From 77b934c86118fe9148265dbb6b4db9ed1335ac27 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 16 Nov 2016 13:05:24 +0000 Subject: [PATCH 038/234] Update with https://pad.riseup.net/p/7x3G896a3NLA --- docs/using-the-compiler.rst | 148 +++++++++++++++++++++++++++++------- 1 file changed, 121 insertions(+), 27 deletions(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index 8ceb52a74..5b8a4b5c2 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -40,21 +40,10 @@ Standardized Input Description and Metadata Output In order to ease source code verification of complex contracts that are spread across several files, there is a standardized way for describing the relations between those files. Furthermore, the compiler can generate a json file while compiling that includes -the source, natspec comments and other metadata whose hash is included in the +the (hash of the) source, natspec comments and other metadata whose hash is included in the actual bytecode. Specifically, the creation data for a contract has to begin with `push32 pop`. -There is some overlap between the input description and the metadata output -and due to the fact that some fields are optional, the metadata can be used as -input to the compiler. In order to verify the metadata, you actually take it, -re-run the compiler on the metadata and check that it again produces the same -metadata. - -If the compiler is invoked in a different way, not using the input -description (for example by using a file content retrieval callback), -the compiler can still generate the metadata alongside the bytecode of each -contract. - The metadata standard is versioned. Future versions are only required to provide the "version" field, the "language" field and the two keys inside the "compiler" field. The field compiler.keccak should be the keccak hash of a binary of the compiler with the given version. @@ -68,34 +57,128 @@ Comments are of course not permitted and used here only for explanatory purposes Input Description ----------------- +QUESTION: How to specific file-reading callback? - probably not as part of json input + The input description is language-specific and could change with each compiler version, but it should be backwards compatible if possible. { sources: { - "abc": "contract b{}", + // the keys here are the "global" names of the source files, imports can use other files via remappings (see below) + "abc": "contract b{}", // specify source directly + // (axic) I think 'keccak' on its on is not enough. I would go perhaps with swarm: "0x12.." and ipfs: "Qma..." for simplicity + // (chriseth) Where the content is stored is a second component, but yes, we could give an indication there. "def": {keccak: "0x123..."}, // source has to be retrieved by its hash + "ghi": {file: "/tmp/path/to/file.sol"}, // file on filesystem + // (axic) I'm inclined to think the source _must_ be provided in the JSON, + "dir/file.sol": "contract a {}" }, settings: { - remappings: [":g/dir"], + remappings: [":g/dir"], // just as it used to be + // (axic) what is remapping doing exactly? optimizer: {enabled: true, runs: 500}, - compilationTarget: "myFile.sol:MyContract", // Can also be an array - // To be backwards compatible, use the full name of the contract in the output - // only if there are name clashes. - // If the full name was given as "compilationTargets", use the full name. + // if given, only compiles this contract, can also be an array. If only a contract name is given, tries to find it if unique. + compilationTarget: "myFile.sol:MyContract", + // addresses of the libraries. If not all libraries are given here, it can result in unlinked objects whose output data is different libraries: { "def:MyLib": "0x123123..." }, // The following can be used to restrict the fields the compiler will output. + // (axic) + outputSelection: [ + "abi", "evm.assembly", "evm.bytecode", ..., "why3", "ewasm.wasm" + ] outputSelection: { + abi,asm,ast,bin,bin-runtime,clone-bin,devdoc,interface,opcodes,srcmap,srcmap-runtime,userdoc + + --ast AST of all source files. + --ast-json AST of all source files in JSON format. + --asm EVM assembly of the contracts. + --asm-json EVM assembly of the contracts in JSON format. + --opcodes Opcodes of the contracts. + --bin Binary of the contracts in hex. + --bin-runtime Binary of the runtime part of the contracts in hex. + --clone-bin Binary of the clone contracts in hex. + --abi ABI specification of the contracts. + --interface Solidity interface of the contracts. + --hashes Function signature hashes of the contracts. + --userdoc Natspec user documentation of all contracts. + --devdoc Natspec developer documentation of all contracts. + --formal Translated source suitable for formal analysis. + // to be defined } } } + +Regular Output +-------------- + + + { + errors: ["error1", "error2"], // we might structure them + errors: [ + { + // (axic) + file: "sourceFile.sol", // optional? + contract: "contractName", // optional + line: 100, // optional - currently, we always have a byte range in the source file + // Errors/warnings originate in several components, most of them are not + // backend-specific. Currently, why3 errors are part of the why3 output. + // I think it is better to put code-generator-specific errors into the code-generator output + // area, and warnings and errors that are code-generator-agnostic into this general area, + // so that it is easier to determine whether some source code is invalid or only + // triggers errors/warnings in some backend that might only implement some part of solidity. + type: "evm" or "why3" or "ewasm" // maybe a better field name would be needed + severity: "warning" or "error" // mandatory + message: "Invalid keyword" // mandatory + } + ] + contracts: { + "sourceFile.sol:ContractName": { + abi: + evm: { + assembly: + bytecode: + runtimeBytecode: + opcodes: + annotatedOpcodes: // (axic) see https://github.com/ethereum/solidity/issues/1178 + gasEstimates: + sourceMap: + runtimeSourceMap: + // If given, this is an unlinked object (cannot be filtered out explicitly, might be + // filtered if both bytecode, runtimeBytecode, opcodes and others are filtered out) + linkReferences: { + "sourceFile.sol:Library1": [1, 200, 80] // byte offsets into bytecode. Linking replaces the 20 bytes there. + } + // the same for runtimeBytecode - I'm not sure it is a good idea to allow to link libraries differently for the runtime bytecode. + // furthermore, runtime bytecode is always a substring of the bytecode anyway. + runtimeLinkReferences: { + } + }, + functionHashes: + metadata: // see below + ewasm: { + wast: // S-expression format + wasm: // + } + } + }, + formal: { + "why3": "..." + }, + sourceList: ["source1.sol", "source2.sol"], // this is important for source references both in the ast as well as in the srcmap in the contract + sources: { + "source1.sol": { + "AST": { ... } + } + } + } + Metadata Output --------------- @@ -118,18 +201,15 @@ that can be used to query a location of the binary (and whether the version is }, sources: { - "abc": "contract b{}", - "def": {keccak: "0x123..."}, // source has to be retrieved by its hash - "dir/file.sol": "contract a {}" + "abc": {keccak: "0x456..."}, // here, sources are always given by hash + "def": {keccak: "0x123..."}, + "dir/file.sol": {keccax: "0xabc..."} }, settings: { remappings: [":g/dir"], optimizer: {enabled: true, runs: 500}, compilationTarget: "myFile.sol:MyContract", - // To be backwards compatible, use the full name of the contract in the output - // only if there are name clashes. - // If the full name was given as "compilationTargets", use the full name. libraries: { "def:MyLib": "0x123123..." } @@ -137,8 +217,22 @@ that can be used to query a location of the binary (and whether the version is output: { abi: [ /* abi definition */ ], - userDocumentation: [ /* user documentation comments */ ], - developerDocumentation: [ /* developer documentation comments */ ], - natspec: [ /* natspec comments */ ] + natspec: [ /* user documentation comments */ ] } } + +This is used in the following way: A component that wants to interact +with a contract (e.g. mist) retrieves the creation transaction of the contract +and from that the first 33 bytes. If the first byte decodes into a PUSH32 +instruction, the other 32 bytes are interpreted as the keccak-hash of +a file which is retrieved via a content-addressable storage like swarm. +That file is JSON-decoded into a structure like above. Sources are +retrieved in the same way and combined with the structure into a proper +compiler input description, which selects only the bytecode as output. + +The compiler of the correct version (which is checked to be part of the "official" compilers) +is invoked on that input. The resulting +bytecode is compared (excess bytecode in the creation transaction +is constructor input data) which automatically verifies the metadata since +its hash is part of the bytecode. The constructor input data is decoded +according to the interface and presented to the user. From 0b3f1a5378daa4075820a6be94afb2d9106c3ebd Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 16 Nov 2016 13:20:10 +0000 Subject: [PATCH 039/234] Describe the ABI output field --- docs/using-the-compiler.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index 5b8a4b5c2..72166f181 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -140,7 +140,9 @@ Regular Output ] contracts: { "sourceFile.sol:ContractName": { - abi: + // The Ethereum Contract ABI. If empty, it is represented as an empty array. + // See https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI + abi: [], evm: { assembly: bytecode: From 04089edc4e651493f7596bf2372c7c0487fc2dad Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 16 Nov 2016 13:20:34 +0000 Subject: [PATCH 040/234] Add missing fields --- docs/using-the-compiler.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index 72166f181..a49bfb8e5 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -167,7 +167,10 @@ Regular Output ewasm: { wast: // S-expression format wasm: // - } + }, + userdoc: // Obsolete + devdoc: // Obsolete + natspec: // Combined dev+userdoc } }, formal: { From 073871c248b097b654fb354fd756559009d7c3e9 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 16 Nov 2016 13:25:40 +0000 Subject: [PATCH 041/234] Update the metadata JSON spec --- docs/using-the-compiler.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index a49bfb8e5..4fc5c71d1 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -204,12 +204,15 @@ that can be used to query a location of the binary (and whether the version is version: "soljson-2313-2016-12-12", keccak: "0x123..." }, + // This is a subset of the regular compiler input sources: { "abc": {keccak: "0x456..."}, // here, sources are always given by hash "def": {keccak: "0x123..."}, - "dir/file.sol": {keccax: "0xabc..."} + "dir/file.sol": {keccax: "0xabc..."}, + "xkcd": {swarm: "0x456..."} }, + // This is a subset of the regular compiler input settings: { remappings: [":g/dir"], @@ -219,9 +222,12 @@ that can be used to query a location of the binary (and whether the version is "def:MyLib": "0x123123..." } }, + // This is a subset of the regular compiler output output: { abi: [ /* abi definition */ ], + userdoc: [], + devdoc: [], natspec: [ /* user documentation comments */ ] } } From 559c4c7a451bbe0518441bd0442b8325f40b279a Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 17 Nov 2016 10:31:46 +0000 Subject: [PATCH 042/234] Update the metadata JSON spec --- docs/using-the-compiler.rst | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index 4fc5c71d1..de9e104ac 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -197,29 +197,43 @@ that can be used to query a location of the binary (and whether the version is "official") at a registry contract. { + // The version of the metadata format (required field) version: "1", + // Required field language: "Solidity", + // Required field, the contents are specific to the language compiler: { - commit: "55db20e32c97098d13230ab7500758e8e3b31d64", - version: "soljson-2313-2016-12-12", - keccak: "0x123..." + name: "solc", + version: "0.4.5-nightly.2016.11.15+commit.c1b1efaf.Emscripten.clang", + // Optional hash of the compiler binary which produced this output + keccak256: "0x123..." }, // This is a subset of the regular compiler input sources: { - "abc": {keccak: "0x456..."}, // here, sources are always given by hash - "def": {keccak: "0x123..."}, - "dir/file.sol": {keccax: "0xabc..."}, - "xkcd": {swarm: "0x456..."} + "myFile.sol": { + "keccak256": "0x123...", + "url": "bzzr://0x56..." + }, + "Token": { + "keccak256": "0x456...", + "url": "https://raw.githubusercontent.com/ethereum/solidity/develop/std/Token.sol" + }, + "mortal": { + "content": "contract mortal is owned { function kill() { if (msg.sender == owner) selfdestruct(owner); } }" + } }, // This is a subset of the regular compiler input + // Its content is specific to the compiler (determined by the language and compiler fields) settings: { remappings: [":g/dir"], optimizer: {enabled: true, runs: 500}, - compilationTarget: "myFile.sol:MyContract", + compilationTarget: { + "myFile.sol": MyContract" + }, libraries: { - "def:MyLib": "0x123123..." + "MyLib": "0x123123..." } }, // This is a subset of the regular compiler output @@ -228,7 +242,6 @@ that can be used to query a location of the binary (and whether the version is abi: [ /* abi definition */ ], userdoc: [], devdoc: [], - natspec: [ /* user documentation comments */ ] } } From d9f14e77371b09b419e6561cf847cd4d0e72bde0 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 2 Dec 2016 10:36:11 +0000 Subject: [PATCH 043/234] The metadata section has been moved, make only a reference to it --- docs/using-the-compiler.rst | 100 ++---------------------------------- 1 file changed, 5 insertions(+), 95 deletions(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index de9e104ac..0fec6c8c2 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -33,24 +33,11 @@ Either add ``--libraries "Math:0x12345678901234567890 Heap:0xabcdef0123456"`` to If ``solc`` is called with the option ``--link``, all input files are interpreted to be unlinked binaries (hex-encoded) in the ``__LibraryName____``-format given above and are linked in-place (if the input is read from stdin, it is written to stdout). All options except ``--libraries`` are ignored (including ``-o``) in this case. -************************************************** -Standardized Input Description and Metadata Output -************************************************** +***************************************** +Standardized Input and Output Description +***************************************** -In order to ease source code verification of complex contracts that are spread across several files, -there is a standardized way for describing the relations between those files. -Furthermore, the compiler can generate a json file while compiling that includes -the (hash of the) source, natspec comments and other metadata whose hash is included in the -actual bytecode. Specifically, the creation data for a contract has to begin with -`push32 pop`. - -The metadata standard is versioned. Future versions are only required to provide the "version" field, -the "language" field and the two keys inside the "compiler" field. -The field compiler.keccak should be the keccak hash of a binary of the compiler with the given version. - -The example below is presented in a human-readable way. Properly formatted metadata -should use quotes correctly, reduce whitespace to a minimum and sort the keys of all objects -to arrive at a unique formatting. +The compiler API expects a JSON formatted input and outputs the compilations result in a JSON formatted output. Comments are of course not permitted and used here only for explanatory purposes. @@ -163,7 +150,7 @@ Regular Output } }, functionHashes: - metadata: // see below + metadata: // see the Metadata Output documentation ewasm: { wast: // S-expression format wasm: // @@ -183,80 +170,3 @@ Regular Output } } } - -Metadata Output ---------------- - -Note that the actual bytecode is not part of the metadata because the hash -of the metadata structure will be included in the bytecode itself. - -This requires the compiler to be able to compute the hash of its own binary, -which requires it to be statically linked. The hash of the binary is not -too important. It is much more important to have the commit hash because -that can be used to query a location of the binary (and whether the version is -"official") at a registry contract. - - { - // The version of the metadata format (required field) - version: "1", - // Required field - language: "Solidity", - // Required field, the contents are specific to the language - compiler: { - name: "solc", - version: "0.4.5-nightly.2016.11.15+commit.c1b1efaf.Emscripten.clang", - // Optional hash of the compiler binary which produced this output - keccak256: "0x123..." - }, - // This is a subset of the regular compiler input - sources: - { - "myFile.sol": { - "keccak256": "0x123...", - "url": "bzzr://0x56..." - }, - "Token": { - "keccak256": "0x456...", - "url": "https://raw.githubusercontent.com/ethereum/solidity/develop/std/Token.sol" - }, - "mortal": { - "content": "contract mortal is owned { function kill() { if (msg.sender == owner) selfdestruct(owner); } }" - } - }, - // This is a subset of the regular compiler input - // Its content is specific to the compiler (determined by the language and compiler fields) - settings: - { - remappings: [":g/dir"], - optimizer: {enabled: true, runs: 500}, - compilationTarget: { - "myFile.sol": MyContract" - }, - libraries: { - "MyLib": "0x123123..." - } - }, - // This is a subset of the regular compiler output - output: - { - abi: [ /* abi definition */ ], - userdoc: [], - devdoc: [], - } - } - -This is used in the following way: A component that wants to interact -with a contract (e.g. mist) retrieves the creation transaction of the contract -and from that the first 33 bytes. If the first byte decodes into a PUSH32 -instruction, the other 32 bytes are interpreted as the keccak-hash of -a file which is retrieved via a content-addressable storage like swarm. -That file is JSON-decoded into a structure like above. Sources are -retrieved in the same way and combined with the structure into a proper -compiler input description, which selects only the bytecode as output. - -The compiler of the correct version (which is checked to be part of the "official" compilers) -is invoked on that input. The resulting -bytecode is compared (excess bytecode in the creation transaction -is constructor input data) which automatically verifies the metadata since -its hash is part of the bytecode. The constructor input data is decoded -according to the interface and presented to the user. From 720cf20855b7695f3c2059c2e1c52e2cb2501995 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 2 Dec 2016 13:46:56 +0000 Subject: [PATCH 044/234] Place into a code block --- docs/using-the-compiler.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index 0fec6c8c2..dcd5e5892 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -49,6 +49,8 @@ QUESTION: How to specific file-reading callback? - probably not as part of json The input description is language-specific and could change with each compiler version, but it should be backwards compatible if possible. +.. code-block:: none + { sources: { @@ -105,6 +107,7 @@ should be backwards compatible if possible. Regular Output -------------- +.. code-block:: none { errors: ["error1", "error2"], // we might structure them From 6e2cc081ecec5c5c20945b70159d36b9e8286d0a Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 13:54:21 +0000 Subject: [PATCH 045/234] Update sources definition based on the metadata --- docs/using-the-compiler.rst | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index dcd5e5892..57135df88 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -52,17 +52,33 @@ should be backwards compatible if possible. .. code-block:: none { + // Required sources: { - // the keys here are the "global" names of the source files, imports can use other files via remappings (see below) - "abc": "contract b{}", // specify source directly - // (axic) I think 'keccak' on its on is not enough. I would go perhaps with swarm: "0x12.." and ipfs: "Qma..." for simplicity - // (chriseth) Where the content is stored is a second component, but yes, we could give an indication there. - "def": {keccak: "0x123..."}, // source has to be retrieved by its hash - "ghi": {file: "/tmp/path/to/file.sol"}, // file on filesystem - // (axic) I'm inclined to think the source _must_ be provided in the JSON, - - "dir/file.sol": "contract a {}" + // The keys here are the "global" names of the source files, + // imports can use other files via remappings (see below). + "myFile.sol": + { + // Optional: keccak256 hash of the source file + "keccak256": "0x123...", + // Required (unless "content" is used, see below): URL(s) to the source file. + // URL(s) should be imported in this order and the result checked against the + // keccak256 hash (if available). If the hash doesn't match or none of the + // URL(s) result in success, an error should be raised. + "urls": + [ + "bzzr://56ab...", + "ipfs://Qma...", + "file:///tmp/path/to/file.sol" + ] + }, + "mortal": + { + // Optional: keccak256 hash of the source file + "keccak256": "0x234...", + // Required (unless "urls" is used): literal contents of the source file + "content": "contract mortal is owned { function kill() { if (msg.sender == owner) selfdestruct(owner); } }" + } }, settings: { From 82c0e4de1df0d4b17e01e7fd35ebc312156b85fd Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 13:58:30 +0000 Subject: [PATCH 046/234] Update settings section --- docs/using-the-compiler.rst | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index 57135df88..2238a773b 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -80,17 +80,29 @@ should be backwards compatible if possible. "content": "contract mortal is owned { function kill() { if (msg.sender == owner) selfdestruct(owner); } }" } }, + // Optional settings: { - remappings: [":g/dir"], // just as it used to be - // (axic) what is remapping doing exactly? - optimizer: {enabled: true, runs: 500}, - // if given, only compiles this contract, can also be an array. If only a contract name is given, tries to find it if unique. - compilationTarget: "myFile.sol:MyContract", - // addresses of the libraries. If not all libraries are given here, it can result in unlinked objects whose output data is different - libraries: { - "def:MyLib": "0x123123..." + // Optional: Sorted list of remappings + remappings: [ ":g/dir" ], + // Optional: Optimizer settings (enabled defaults to false) + optimizer: { + enabled: true, + runs: 500 }, + // If given, only compiles the specified contracts. + compilationTarget: { + "myFile.sol": "MyContract" + }, + // Addresses of the libraries. If not all libraries are given here, it can result in unlinked objects whose output data is different. + libraries: { + // The top level key is the the name of the source file where the library is used. + // If remappings are used, this source file should match the global path after remappings were applied. + // If this key is an empty string, that refers to a global level. + "myFile.sol": { + "MyLib": "0x123123..." + } + } // The following can be used to restrict the fields the compiler will output. // (axic) outputSelection: [ @@ -144,6 +156,7 @@ Regular Output message: "Invalid keyword" // mandatory } ] + // This contains all the compiled outputs. It can be limited/filtered by the compilationTarget setting. contracts: { "sourceFile.sol:ContractName": { // The Ethereum Contract ABI. If empty, it is represented as an empty array. From 4b5639bf63f2c86604cb55387324e00759a0b1f2 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 14:57:07 +0000 Subject: [PATCH 047/234] Update output selection --- docs/using-the-compiler.rst | 67 ++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index 2238a773b..ebb03832a 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -90,10 +90,6 @@ should be backwards compatible if possible. enabled: true, runs: 500 }, - // If given, only compiles the specified contracts. - compilationTarget: { - "myFile.sol": "MyContract" - }, // Addresses of the libraries. If not all libraries are given here, it can result in unlinked objects whose output data is different. libraries: { // The top level key is the the name of the source file where the library is used. @@ -103,30 +99,47 @@ should be backwards compatible if possible. "MyLib": "0x123123..." } } - // The following can be used to restrict the fields the compiler will output. - // (axic) - outputSelection: [ - "abi", "evm.assembly", "evm.bytecode", ..., "why3", "ewasm.wasm" - ] + // The following can be used to select desired outputs. + // If this field is omitted, then the compiler loads and does type checking, but will not generate any outputs apart from errors. + // The first level key is the file name and the second is the contract name, where empty contract name refers to the file itself, + // while the star refers to all of the contracts. + // + // The available output types are as follows: + // abi - ABI + // ast - AST of all source files + // why3 - Why3 translated output + // devdoc - Developer documentation (natspec) + // userdoc - User documentation (natspec) + // metadata - Metadata + // evm.ir - New assembly format before desugaring (not supported atm) + // evm.assembly - New assembly format after desugaring (not supported atm) + // evm.asm - Current assembly format (--asm) + // evm.asmJSON - Current assembly format in JSON (--asm-json) + // evm.opcodes - Opcodes list + // evm.methodIdentifiers - The list of function hashes + // evm.gasEstimates - Function gas estimates + // evm.bytecode - Bytecode (--bin) + // evm.deployedBytecode - Deployed bytecode (--bin-runtime) + // evm.sourceMap - Source mapping (useful for debugging) + // ewasm.wast - eWASM S-expressions format (not supported atm) + // ewasm.wasm - eWASM binary format (not supported atm) outputSelection: { - abi,asm,ast,bin,bin-runtime,clone-bin,devdoc,interface,opcodes,srcmap,srcmap-runtime,userdoc - - --ast AST of all source files. - --ast-json AST of all source files in JSON format. - --asm EVM assembly of the contracts. - --asm-json EVM assembly of the contracts in JSON format. - --opcodes Opcodes of the contracts. - --bin Binary of the contracts in hex. - --bin-runtime Binary of the runtime part of the contracts in hex. - --clone-bin Binary of the clone contracts in hex. - --abi ABI specification of the contracts. - --interface Solidity interface of the contracts. - --hashes Function signature hashes of the contracts. - --userdoc Natspec user documentation of all contracts. - --devdoc Natspec developer documentation of all contracts. - --formal Translated source suitable for formal analysis. - - // to be defined + // Enable the metadata and bytecode outputs of every single contract. + "*": { + "*": [ "metadata", "evm.bytecode" ] + }, + // Enable the abi and opcodes output of MyContract defined in file def. + "def": { + "MyContract": [ "abi", "evm.opcodes" ] + }, + // Enable the source map output of every single contract. + "*": { + "*": [ "evm.sourceMap" ] + }, + // Enable the AST and Why3 output of every single file. + "*": { + "": [ "ast", "why3" ] + } } } } From cbb668672fe14f30ae51a022e48f27ddcbe9b324 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 15:00:01 +0000 Subject: [PATCH 048/234] Add metadata.useLiteralContent option --- docs/using-the-compiler.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index ebb03832a..2518310b6 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -90,6 +90,11 @@ should be backwards compatible if possible. enabled: true, runs: 500 }, + // Metadata settings (optional) + metadata: { + // Use only literal content and not URLs (false by default) + useLiteralContent: true + }, // Addresses of the libraries. If not all libraries are given here, it can result in unlinked objects whose output data is different. libraries: { // The top level key is the the name of the source file where the library is used. From d46ec20f88feac1326381e5ac67a02086c5f4516 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 20:52:59 +0000 Subject: [PATCH 049/234] Change layout and include API, Input, Output sections --- docs/using-the-compiler.rst | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index 2518310b6..b89af912d 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -1,8 +1,11 @@ +****************** +Using the compiler +****************** + .. index:: ! commandline compiler, compiler;commandline, ! solc, ! linker .. _commandline-compiler: -****************************** Using the Commandline Compiler ****************************** @@ -32,23 +35,26 @@ Either add ``--libraries "Math:0x12345678901234567890 Heap:0xabcdef0123456"`` to If ``solc`` is called with the option ``--link``, all input files are interpreted to be unlinked binaries (hex-encoded) in the ``__LibraryName____``-format given above and are linked in-place (if the input is read from stdin, it is written to stdout). All options except ``--libraries`` are ignored (including ``-o``) in this case. +.. _compiler-api: -***************************************** -Standardized Input and Output Description -***************************************** +Using the Compiler API +********************** The compiler API expects a JSON formatted input and outputs the compilations result in a JSON formatted output. +TBD + +Compiler Input and Output JSON Description +****************************************** + +These JSON formats are used by the compiler API as well as are available through ``solc``. These are subject to change, +some fields are optional (as noted), but it is aimed at to only make backwards compatible changes. + Comments are of course not permitted and used here only for explanatory purposes. Input Description ----------------- -QUESTION: How to specific file-reading callback? - probably not as part of json input - -The input description is language-specific and could change with each compiler version, but it -should be backwards compatible if possible. - .. code-block:: none { @@ -150,8 +156,8 @@ should be backwards compatible if possible. } -Regular Output --------------- +Output Description +------------------ .. code-block:: none From 21a022848540dc488b312f94b62d62fce66aafc7 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 21:10:19 +0000 Subject: [PATCH 050/234] Include pseudo-code of compiler API --- docs/using-the-compiler.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index b89af912d..703a1c577 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -42,7 +42,18 @@ Using the Compiler API The compiler API expects a JSON formatted input and outputs the compilations result in a JSON formatted output. -TBD +See the following pseudo-code: + +.. code-block:: none + + // defined by the consumer of the API + importCallback(url:string) -> content:string + + // invoking the compiler + solc.compile(inputJSON:string, importCallback:function) -> outputJSON:string + +The compiler will ask the ``importCallback`` for each URL defined for a source file and will stop when it succeeds. +If all URLs failed, the compilation results in a failure. Compiler Input and Output JSON Description ****************************************** @@ -66,6 +77,7 @@ Input Description "myFile.sol": { // Optional: keccak256 hash of the source file + // It is used to verify the retrieved content if imported via URLs. "keccak256": "0x123...", // Required (unless "content" is used, see below): URL(s) to the source file. // URL(s) should be imported in this order and the result checked against the From 627a2cec4d058edc6d2e07a37cf0b464ee868b6b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 21:18:09 +0000 Subject: [PATCH 051/234] Update errors output --- docs/using-the-compiler.rst | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index 703a1c577..2e0cba1f9 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -174,24 +174,27 @@ Output Description .. code-block:: none { - errors: ["error1", "error2"], // we might structure them + // Optional: not present if no errors/warnings were encountered errors: [ - { - // (axic) - file: "sourceFile.sol", // optional? - contract: "contractName", // optional - line: 100, // optional - currently, we always have a byte range in the source file - // Errors/warnings originate in several components, most of them are not - // backend-specific. Currently, why3 errors are part of the why3 output. - // I think it is better to put code-generator-specific errors into the code-generator output - // area, and warnings and errors that are code-generator-agnostic into this general area, - // so that it is easier to determine whether some source code is invalid or only - // triggers errors/warnings in some backend that might only implement some part of solidity. - type: "evm" or "why3" or "ewasm" // maybe a better field name would be needed - severity: "warning" or "error" // mandatory - message: "Invalid keyword" // mandatory - } - ] + { + // Optional + file: "sourceFile.sol", + // Optional + contract: "contractName", + // Optional + line: 100, + // Optional + column: 0, + // Mandatory: Error type, such as "TypeError", "InternalCompilerError", "Exception", etc + type: "TypeError", + // Mandatory: Component where the error originated, such as "general", "why3", "ewasm", etc. + component: "general", + // Mandatory ("error" or "warning") + severity: "error", + // Mandatory + message: "Invalid keyword" + } + ], // This contains all the compiled outputs. It can be limited/filtered by the compilationTarget setting. contracts: { "sourceFile.sol:ContractName": { From 4b19f560b8ac5fd20d46db93a3aa2d1c41adb0db Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 21:27:12 +0000 Subject: [PATCH 052/234] Make contracts output two-level --- docs/using-the-compiler.rst | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index 2e0cba1f9..3282b85a0 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -195,13 +195,14 @@ Output Description message: "Invalid keyword" } ], - // This contains all the compiled outputs. It can be limited/filtered by the compilationTarget setting. + // This contains the contract-level outputs. It can be limited/filtered by the outputSelection settings. contracts: { - "sourceFile.sol:ContractName": { - // The Ethereum Contract ABI. If empty, it is represented as an empty array. - // See https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI - abi: [], - evm: { + "sourceFile.sol": { + "ContractName": { + // The Ethereum Contract ABI. If empty, it is represented as an empty array. + // See https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI + abi: [], + evm: { assembly: bytecode: runtimeBytecode: @@ -219,16 +220,17 @@ Output Description // furthermore, runtime bytecode is always a substring of the bytecode anyway. runtimeLinkReferences: { } - }, - functionHashes: - metadata: // see the Metadata Output documentation - ewasm: { + }, + functionHashes: + metadata: // see the Metadata Output documentation + ewasm: { wast: // S-expression format wasm: // - }, - userdoc: // Obsolete - devdoc: // Obsolete - natspec: // Combined dev+userdoc + }, + userdoc: // Obsolete + devdoc: // Obsolete + natspec: // Combined dev+userdoc + } } }, formal: { From c217bc2dcaf9deec38a54cc094b09288e95ba58f Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 21:33:46 +0000 Subject: [PATCH 053/234] Updated EVM output --- docs/using-the-compiler.rst | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index 3282b85a0..2d78d58a0 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -204,22 +204,25 @@ Output Description abi: [], evm: { assembly: - bytecode: - runtimeBytecode: + // Bytecode and related details. + bytecode: { + // The bytecode as a hex string. + object: "00fe", + // The source mapping as a string. See the source mapping definition. + sourceMap: "", + // If given, this is an unlinked object. + linkReferences: { + "libraryFile.sol": { + // Byte offsets into the bytecode. Linking replaces the 20 bytes located there. + "Library1": [1, 200, 80] + } + } + } + // The same layout as above. + deployedBytecode: { }, opcodes: annotatedOpcodes: // (axic) see https://github.com/ethereum/solidity/issues/1178 gasEstimates: - sourceMap: - runtimeSourceMap: - // If given, this is an unlinked object (cannot be filtered out explicitly, might be - // filtered if both bytecode, runtimeBytecode, opcodes and others are filtered out) - linkReferences: { - "sourceFile.sol:Library1": [1, 200, 80] // byte offsets into bytecode. Linking replaces the 20 bytes there. - } - // the same for runtimeBytecode - I'm not sure it is a good idea to allow to link libraries differently for the runtime bytecode. - // furthermore, runtime bytecode is always a substring of the bytecode anyway. - runtimeLinkReferences: { - } }, functionHashes: metadata: // see the Metadata Output documentation From a3340e210e94c3e31cf26b65cc49e03f8ef444de Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 21:35:07 +0000 Subject: [PATCH 054/234] Error list should have sourceLocation --- docs/using-the-compiler.rst | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index 2d78d58a0..67b3f32ca 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -179,12 +179,10 @@ Output Description { // Optional file: "sourceFile.sol", - // Optional - contract: "contractName", - // Optional - line: 100, - // Optional - column: 0, + // Optional: Location within the source file. + sourceLocation: [ + { start: 0, end: 100 }, + ], // Mandatory: Error type, such as "TypeError", "InternalCompilerError", "Exception", etc type: "TypeError", // Mandatory: Component where the error originated, such as "general", "why3", "ewasm", etc. From 9fc017d10b3da56f4e94b73bf9f9f6ec7d5345cf Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 21:35:57 +0000 Subject: [PATCH 055/234] Support linkReferences with length specified --- docs/using-the-compiler.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index 67b3f32ca..ed7f08565 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -212,7 +212,10 @@ Output Description linkReferences: { "libraryFile.sol": { // Byte offsets into the bytecode. Linking replaces the 20 bytes located there. - "Library1": [1, 200, 80] + "Library1": [ + { start: 0, length: 20 }, + { start: 200, length: 20 } + ] } } } From 9fa54db7bd0003da3ef4f7daa6df860e71f7af75 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 21:52:35 +0000 Subject: [PATCH 056/234] Explain every contract output field --- docs/using-the-compiler.rst | 49 ++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index ed7f08565..6a50ca685 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -201,7 +201,14 @@ Output Description // See https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI abi: [], evm: { - assembly: + // Intermediate representation (string) + ir: "", + // Assembly (string) + assembly: "", + // Old-style assembly (string) + asm: "", + // Old-style assembly (JSON object) + asmJSON: [], // Bytecode and related details. bytecode: { // The bytecode as a hex string. @@ -221,19 +228,39 @@ Output Description } // The same layout as above. deployedBytecode: { }, - opcodes: - annotatedOpcodes: // (axic) see https://github.com/ethereum/solidity/issues/1178 - gasEstimates: + // Opcodes list (string) + opcodes: "", + // The list of function hashes + methodIdentifiers: { + "5c19a95c": "delegate(address)", + }, + // Function gas estimates + gasEstimates: { + creation: { + dataCost: 420000, + // -1 means infinite (aka. unknown) + executionCost: -1 + }, + external: { + "delegate(address)": 25000 + }, + internal: { + "heavyLifting()": -1 + } + } }, - functionHashes: - metadata: // see the Metadata Output documentation + // See the Metadata Output documentation + metadata: {}, ewasm: { - wast: // S-expression format - wasm: // + // S-expressions format + wast: "", + // Binary format (hex string) + wasm: "" }, - userdoc: // Obsolete - devdoc: // Obsolete - natspec: // Combined dev+userdoc + // User documentation (natspec) + userdoc: {}, + // Developer documentation (natspec) + devdoc: {} } } }, From 96677cd1788ab7eb8c493f4de7030200b0c39108 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 2 Feb 2017 22:06:10 +0000 Subject: [PATCH 057/234] Update the AST output --- docs/using-the-compiler.rst | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index 6a50ca685..f2d6b858a 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -193,6 +193,15 @@ Output Description message: "Invalid keyword" } ], + // This contains the file-level outputs. In can be limited/filtered by the outputSelection settings. + sources: { + "sourceFile.sol": { + // Identifier (used in source maps) + id: 1, + // The AST object + ast: {} + } + }, // This contains the contract-level outputs. It can be limited/filtered by the outputSelection settings. contracts: { "sourceFile.sol": { @@ -264,13 +273,6 @@ Output Description } } }, - formal: { - "why3": "..." - }, - sourceList: ["source1.sol", "source2.sol"], // this is important for source references both in the ast as well as in the srcmap in the contract - sources: { - "source1.sol": { - "AST": { ... } - } - } + // Why3 output (string) + why3: "" } From 10d3a591d42952980203c6f9395f81065f06575b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 6 Feb 2017 16:55:56 +0000 Subject: [PATCH 058/234] Move file into sourceLocation --- docs/using-the-compiler.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index f2d6b858a..ab8f3d826 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -177,11 +177,11 @@ Output Description // Optional: not present if no errors/warnings were encountered errors: [ { - // Optional - file: "sourceFile.sol", // Optional: Location within the source file. - sourceLocation: [ - { start: 0, end: 100 }, + sourceLocation: { + file: "sourceFile.sol", + start: 0, + end: 100 ], // Mandatory: Error type, such as "TypeError", "InternalCompilerError", "Exception", etc type: "TypeError", From 749db7608b269b4b2dde7649d63f32c87184f2b7 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 8 Feb 2017 19:00:07 +0000 Subject: [PATCH 059/234] Include language field in the JSON --- docs/using-the-compiler.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index ab8f3d826..9ea1a6abc 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -69,6 +69,8 @@ Input Description .. code-block:: none { + // Required: Source code language, such as "Solidity", "serpent", "lll", "assembly", etc. + language: "Solidity", // Required sources: { @@ -205,6 +207,7 @@ Output Description // This contains the contract-level outputs. It can be limited/filtered by the outputSelection settings. contracts: { "sourceFile.sol": { + // If the language used has no contract names, this field should equal to an empty string. "ContractName": { // The Ethereum Contract ABI. If empty, it is represented as an empty array. // See https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI From cd81e58e3be5dd52a138f3ccac4ab2a305979acc Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 8 Feb 2017 19:16:23 +0000 Subject: [PATCH 060/234] Drop the legacy assembly output --- docs/using-the-compiler.rst | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index 9ea1a6abc..f197c663b 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -136,15 +136,14 @@ Input Description // devdoc - Developer documentation (natspec) // userdoc - User documentation (natspec) // metadata - Metadata - // evm.ir - New assembly format before desugaring (not supported atm) - // evm.assembly - New assembly format after desugaring (not supported atm) - // evm.asm - Current assembly format (--asm) - // evm.asmJSON - Current assembly format in JSON (--asm-json) + // evm.ir - New assembly format before desugaring + // evm.assembly - New assembly format after desugaring + // evm.legacyAssemblyJSON - Old-style assembly format in JSON // evm.opcodes - Opcodes list // evm.methodIdentifiers - The list of function hashes // evm.gasEstimates - Function gas estimates - // evm.bytecode - Bytecode (--bin) - // evm.deployedBytecode - Deployed bytecode (--bin-runtime) + // evm.bytecode - Bytecode + // evm.deployedBytecode - Deployed bytecode // evm.sourceMap - Source mapping (useful for debugging) // ewasm.wast - eWASM S-expressions format (not supported atm) // ewasm.wasm - eWASM binary format (not supported atm) @@ -218,9 +217,7 @@ Output Description // Assembly (string) assembly: "", // Old-style assembly (string) - asm: "", - // Old-style assembly (JSON object) - asmJSON: [], + legacyAssemblyJSON: [], // Bytecode and related details. bytecode: { // The bytecode as a hex string. From dc431fe1f6e0ff0ddcf1561b7ef136cc654cf976 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 8 Feb 2017 19:22:40 +0000 Subject: [PATCH 061/234] Simplify the compiler API section (and remove pseudo code) --- docs/using-the-compiler.rst | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index f197c663b..08f181329 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -37,30 +37,18 @@ If ``solc`` is called with the option ``--link``, all input files are interprete .. _compiler-api: -Using the Compiler API -********************** - -The compiler API expects a JSON formatted input and outputs the compilations result in a JSON formatted output. - -See the following pseudo-code: - -.. code-block:: none - - // defined by the consumer of the API - importCallback(url:string) -> content:string - - // invoking the compiler - solc.compile(inputJSON:string, importCallback:function) -> outputJSON:string - -The compiler will ask the ``importCallback`` for each URL defined for a source file and will stop when it succeeds. -If all URLs failed, the compilation results in a failure. - Compiler Input and Output JSON Description ****************************************** +.. warning:: + + This JSON interface is not yet supported by the Solidity compiler, but will be released in a future version. + These JSON formats are used by the compiler API as well as are available through ``solc``. These are subject to change, some fields are optional (as noted), but it is aimed at to only make backwards compatible changes. +The compiler API expects a JSON formatted input and outputs the compilation result in a JSON formatted output. + Comments are of course not permitted and used here only for explanatory purposes. Input Description From 753e104cbcb0627300d1891f87fcd00b83950f46 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 9 Feb 2017 10:21:08 +0100 Subject: [PATCH 062/234] Use nodejs 6 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c31d9b2b2..b642d947f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -73,7 +73,7 @@ matrix: dist: trusty sudo: required compiler: gcc - node_js: "5" + node_js: "6" services: - docker before_install: From b508aac64a1c189367a34e79906a7b2553d0ad15 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 7 Feb 2017 13:34:00 +0000 Subject: [PATCH 063/234] Use only send/recv in IPC --- test/RPCSession.cpp | 9 +++------ test/RPCSession.h | 3 +-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index 968d77b1d..791d2cfe9 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -73,10 +73,6 @@ IPCSocket::IPCSocket(string const& _path): m_path(_path) if (connect(m_socket, reinterpret_cast(&saun), sizeof(struct sockaddr_un)) < 0) BOOST_FAIL("Error connecting to IPC socket: " << _path); - - m_fp = fdopen(m_socket, "r"); - if (!m_fp) - BOOST_FAIL("Error opening IPC socket: " << _path); #endif } @@ -113,11 +109,12 @@ string IPCSocket::sendRequest(string const& _req) return returnStr; #else - send(m_socket, _req.c_str(), _req.length(), 0); + if (send(m_socket, _req.c_str(), _req.length(), 0) != (ssize_t)_req.length()) + BOOST_FAIL("Writing on IPC failed"); char c; string response; - while ((c = fgetc(m_fp)) != EOF) + while (recv(m_socket, &c, 1, 0) == 1) { if (c != '\n') response += c; diff --git a/test/RPCSession.h b/test/RPCSession.h index fc166b99b..5369e1e2e 100644 --- a/test/RPCSession.h +++ b/test/RPCSession.h @@ -55,12 +55,11 @@ class IPCSocket: public boost::noncopyable public: IPCSocket(std::string const& _path); std::string sendRequest(std::string const& _req); - ~IPCSocket() { close(m_socket); fclose(m_fp); } + ~IPCSocket() { close(m_socket); } std::string const& path() const { return m_path; } private: - FILE *m_fp; std::string m_path; int m_socket; }; From 9cffa9a92edf564d85dfbaeee6cbabac3cd42c98 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 9 Feb 2017 14:56:18 +0000 Subject: [PATCH 064/234] Do not use -Og for debug mode (won't work on Mac/clang) --- cmake/EthCompilerSettings.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/EthCompilerSettings.cmake b/cmake/EthCompilerSettings.cmake index c734423b7..97db9168c 100644 --- a/cmake/EthCompilerSettings.cmake +++ b/cmake/EthCompilerSettings.cmake @@ -71,7 +71,7 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA add_compile_options(-fPIC) # Configuration-specific compiler settings. - set(CMAKE_CXX_FLAGS_DEBUG "-Og -g -DETH_DEBUG") + set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DETH_DEBUG") set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") From 5396c7692b87587dc35c07b2c6239782efd20739 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 7 Feb 2017 14:10:43 +0000 Subject: [PATCH 065/234] Do not expect a new line, rather buffer up the response in IPC --- test/RPCSession.cpp | 32 ++++++++++++++------------------ test/RPCSession.h | 5 +++-- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index 791d2cfe9..8d18d118d 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -18,6 +18,7 @@ */ /** @file RPCSession.cpp * @author Dimtiry Khokhlov + * @author Alex Beregszaszi * @date 2016 */ @@ -91,18 +92,17 @@ string IPCSocket::sendRequest(string const& _req) if (!fSuccess) BOOST_FAIL("WriteFile to pipe failed"); - DWORD cbRead; - TCHAR chBuf[c_buffsize]; + DWORD cbRead; // Read from the pipe. fSuccess = ReadFile( - m_socket, // pipe handle - chBuf, // buffer to receive reply - c_buffsize,// size of buffer - &cbRead, // number of bytes read - NULL); // not overlapped + m_socket, // pipe handle + m_readBuf, // buffer to receive reply + sizeof(m_readBuf), // size of buffer + &cbRead, // number of bytes read + NULL); // not overlapped - returnStr += chBuf; + returnStr += m_readBuf; if (!fSuccess) BOOST_FAIL("ReadFile from pipe failed"); @@ -112,16 +112,12 @@ string IPCSocket::sendRequest(string const& _req) if (send(m_socket, _req.c_str(), _req.length(), 0) != (ssize_t)_req.length()) BOOST_FAIL("Writing on IPC failed"); - char c; - string response; - while (recv(m_socket, &c, 1, 0) == 1) - { - if (c != '\n') - response += c; - else - break; - } - return response; + ssize_t ret = recv(m_socket, m_readBuf, sizeof(m_readBuf), 0); + + if (ret < 0) + BOOST_FAIL("Reading on IPC failed"); + + return string(m_readBuf, m_readBuf + ret); #endif } diff --git a/test/RPCSession.h b/test/RPCSession.h index 5369e1e2e..f1aee6a81 100644 --- a/test/RPCSession.h +++ b/test/RPCSession.h @@ -35,7 +35,6 @@ #include #if defined(_WIN32) -const int c_buffsize = 5120000; //because windows pipe is broken and wont work as in examples. use larger buffer limit to receive whole package in one call class IPCSocket : public boost::noncopyable { public: @@ -47,7 +46,8 @@ public: private: std::string m_path; - HANDLE m_socket; + HANDLE m_socket; + TCHAR m_readBuf[512000]; }; #else class IPCSocket: public boost::noncopyable @@ -62,6 +62,7 @@ public: private: std::string m_path; int m_socket; + char m_readBuf[512000]; }; #endif From f9a818eaf8713f14f80576ea706d484d2bc92c7b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 9 Feb 2017 12:24:23 +0000 Subject: [PATCH 066/234] Detect closed sockets in IPC --- test/RPCSession.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index 8d18d118d..9d046c4fb 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -114,7 +114,8 @@ string IPCSocket::sendRequest(string const& _req) ssize_t ret = recv(m_socket, m_readBuf, sizeof(m_readBuf), 0); - if (ret < 0) + // Also consider closed socket an error. + if (ret <= 0) BOOST_FAIL("Reading on IPC failed"); return string(m_readBuf, m_readBuf + ret); From f2cafd497459d7ed0ea7f6efdeeb77a51cacecc7 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 9 Feb 2017 13:06:48 +0000 Subject: [PATCH 067/234] Simplify the Windows IPC code --- test/RPCSession.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index 9d046c4fb..caaf9a8cb 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -80,7 +80,7 @@ IPCSocket::IPCSocket(string const& _path): m_path(_path) string IPCSocket::sendRequest(string const& _req) { #if defined(_WIN32) - string returnStr; + // Write to the pipe. DWORD cbWritten; BOOL fSuccess = WriteFile( m_socket, // pipe handle @@ -92,9 +92,8 @@ string IPCSocket::sendRequest(string const& _req) if (!fSuccess) BOOST_FAIL("WriteFile to pipe failed"); - DWORD cbRead; - // Read from the pipe. + DWORD cbRead; fSuccess = ReadFile( m_socket, // pipe handle m_readBuf, // buffer to receive reply @@ -102,12 +101,10 @@ string IPCSocket::sendRequest(string const& _req) &cbRead, // number of bytes read NULL); // not overlapped - returnStr += m_readBuf; - if (!fSuccess) BOOST_FAIL("ReadFile from pipe failed"); - return returnStr; + return string(m_readBuf, m_readBuf + cbRead); #else if (send(m_socket, _req.c_str(), _req.length(), 0) != (ssize_t)_req.length()) BOOST_FAIL("Writing on IPC failed"); From 95f8c5bcdb69ab4cba835f8bc06ab89da4768db8 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 9 Feb 2017 13:08:52 +0000 Subject: [PATCH 068/234] Ensure that the whole message was written on Windows IPC --- test/RPCSession.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index caaf9a8cb..b3451528f 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -89,7 +89,7 @@ string IPCSocket::sendRequest(string const& _req) &cbWritten, // bytes written NULL); // not overlapped - if (!fSuccess) + if (!fSuccess || (_req.size() != cbWritten)) BOOST_FAIL("WriteFile to pipe failed"); // Read from the pipe. From 503cf4eaebabf03b8d541bd8f9c9c833daceec63 Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Thu, 2 Feb 2017 18:52:41 -0600 Subject: [PATCH 069/234] reorganize travis Signed-off-by: RJ Catalano --- .travis.yml | 85 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 35 deletions(-) diff --git a/.travis.yml b/.travis.yml index b642d947f..eafba71f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,6 +33,18 @@ branches: - develop - release - /^v[0-9]/ + +env: + global: + - ENCRYPTION_LABEL="6d4541b72666" + - SOLC_BUILD_TYPE=RelWithDebInfo + - SOLC_DOCS=Off + - SOLC_EMSCRIPTEN=Off + - SOLC_INSTALL_DEPS_TRAVIS=On + - SOLC_RELEASE=On + - SOLC_TESTS=On + - SOLC_DOCKER=Off + matrix: include: # Ubuntu 14.04 LTS "Trusty Tahr" @@ -61,10 +73,23 @@ matrix: dist: trusty sudo: required compiler: gcc + before_install: + - sudo apt-get -y install python-sphinx env: - - TRAVIS_DOCS=On - - TRAVIS_RELEASE=Off - - TRAVIS_TESTS=Off + - SOLC_DOCS=On + - SOLC_RELEASE=Off + - SOLC_TESTS=Off + # Docker target, which generates a statically linked alpine image + - os: linux + dist: trusty + sudo: required + services: + - docker + env: + - SOLC_DOCKER=On + - SOLC_INSTALL_DEPS_TRAVIS=Off + - SOLC_RELEASE=Off + - SOLC_TESTS=Off # Emscripten target, which compiles 'solc' to javascript and uploads the resulting .js # files to https://github.com/ethereum/solc-bin. These binaries are used in Browser-Solidity @@ -79,10 +104,10 @@ matrix: before_install: - docker pull trzeci/emscripten:sdk-tag-1.35.4-64bit env: - - TRAVIS_EMSCRIPTEN=On - - TRAVIS_INSTALL_DEPS=Off - - TRAVIS_RELEASE=Off - - TRAVIS_TESTS=Off + - SOLC_EMSCRIPTEN=On + - SOLC_INSTALL_DEPS_TRAVIS=Off + - SOLC_RELEASE=Off + - SOLC_TESTS=Off # OS X Mavericks (10.9) # https://en.wikipedia.org/wiki/OS_X_Mavericks @@ -143,37 +168,18 @@ cache: - $HOME/.local install: - - test $TRAVIS_INSTALL_DEPS != On || ./scripts/install_deps.sh + - test $SOLC_INSTALL_DEPS_TRAVIS != On || ./scripts/install_deps.sh - test "$TRAVIS_OS_NAME" != "linux" || ./scripts/install_cmake.sh - echo -n "$TRAVIS_COMMIT" > commit_hash.txt + - test $SOLC_DOCKER != On || docker build -t ethereum/solc:build -f ./scripts/Dockerfile . before_script: - - test $TRAVIS_EMSCRIPTEN != On || ./scripts/build_emscripten.sh - - test $TRAVIS_RELEASE != On || (./scripts/build.sh $TRAVIS_BUILD_TYPE + - test $SOLC_EMSCRIPTEN != On || ./scripts/build_emscripten.sh + - test $SOLC_RELEASE != On || (./scripts/build.sh $SOLC_BUILD_TYPE && ./scripts/release.sh $ZIP_SUFFIX && ./scripts/create_source_tarball.sh ) script: - - test $TRAVIS_DOCS != On || ./scripts/docs.sh - - # There are a variety of reliability issues with the Solidity unit-tests at the time of - # writing (especially on macOS), so within TravisCI we will try to run the unit-tests - # up to 3 times before giving up and declaring the tests as broken. - # - # We should aim to remove this "retry logic" as soon as we can, because it is a - # band-aid for issues which need solving at their root. Some of those issues will be - # in Solidity's RPC setup and some will be in 'eth'. It seems unlikely that Solidity - # itself is broken from the failure messages which we are seeing. - # - # More details on known issues at https://github.com/ethereum/solidity/issues/769 - - test $TRAVIS_TESTS != On || (cd $TRAVIS_BUILD_DIR && (./scripts/tests.sh || ./scripts/tests.sh || ./scripts/tests.sh) ) -env: - global: - - ENCRYPTION_LABEL="6d4541b72666" - - TRAVIS_BUILD_TYPE=RelWithDebInfo - - TRAVIS_DOCS=Off - - TRAVIS_EMSCRIPTEN=Off - - TRAVIS_INSTALL_DEPS=On - - TRAVIS_RELEASE=On - - TRAVIS_TESTS=On + - test $SOLC_DOCS != On || ./scripts/docs.sh + - test $SOLC_TESTS != On || (cd $TRAVIS_BUILD_DIR && ./scripts/tests.sh ) deploy: # This is the deploy target for the Emscripten build. @@ -182,14 +188,23 @@ deploy: # Both the build and deploy steps for Emscripten are only run within the Ubuntu # configurations (not for macOS). That is controlled by conditionals within the bash # scripts because TravisCI doesn't provide much in the way of conditional logic. + # This is also the deploy target for the dockerfile. If we are pushing into a develop branch, it will be tagged + # as a nightly and appended the commit of the branch it was pushed in. If we are pushing to master it will + # be tagged as "stable" and given the version tag as well. - provider: script - script: test $TRAVIS_EMSCRIPTEN != On || scripts/release_emscripten.sh + script: test $SOLC_EMSCRIPTEN == On || scripts/release_emscripten.sh + skip_cleanup: true + on: + branch: + - develop + - release + - provider: script + script: test $SOLC_DOCKER != On || ./scripts/docker_deploy.sh skip_cleanup: true on: branch: - develop - release - # This is the deploy target for the native build (Linux and macOS) # which generates ZIPs per commit and the source tarball. # @@ -207,4 +222,4 @@ deploy: on: all_branches: true tags: true - condition: $TRAVIS_RELEASE == On + condition: $SOLC_RELEASE == On \ No newline at end of file From 00feec567afbedc0b09805d7226c94c1d96c0c2a Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Thu, 2 Feb 2017 18:52:59 -0600 Subject: [PATCH 070/234] reorganize deps installation Signed-off-by: RJ Catalano --- scripts/install_deps.sh | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/scripts/install_deps.sh b/scripts/install_deps.sh index f21c48d03..869bce35a 100755 --- a/scripts/install_deps.sh +++ b/scripts/install_deps.sh @@ -57,7 +57,7 @@ detect_linux_distro() { # extract 'foo' from NAME=foo, only on the line with NAME=foo DISTRO=$(sed -n -e 's/^NAME="\(.*\)\"/\1/p' /etc/os-release) elif [ -f /etc/centos-release ]; then - DISTRO=CentOS + DISTRO=CentOS else DISTRO='' fi @@ -93,19 +93,17 @@ case $(uname -s) in # Check for Homebrew install and abort if it is not installed. brew -v > /dev/null 2>&1 || { echo >&2 "ERROR - solidity requires a Homebrew install. See http://brew.sh."; exit 1; } - brew update - brew upgrade - brew install boost brew install cmake - - # We should really 'brew install' our eth client here, but at the time of writing - # the bottle is known broken, so we will just cheat and use a hardcoded ZIP for - # the time being, which is good enough. The cause of the breaks will go away - # when we commit the repository reorg changes anyway. - curl -L -O https://github.com/bobsummerwill/cpp-ethereum/releases/download/v1.3.0/cpp-ethereum-osx-mavericks-v1.3.0.zip - unzip cpp-ethereum-osx-mavericks-v1.3.0.zip + if ["$CI" = true]; then + brew upgrade cmake + brew tap ethereum/ethereum + brew install cpp-ethereum + brew linkapps cpp-ethereum + else + brew upgrade + fi ;; @@ -207,7 +205,6 @@ case $(uname -s) in # Install "normal packages" sudo apt-get -y update sudo apt-get -y install \ - python-sphinx \ build-essential \ cmake \ g++ \ @@ -311,17 +308,17 @@ case $(uname -s) in sudo apt-get -y update sudo apt-get -y install \ - python-sphinx \ build-essential \ cmake \ git \ libboost-all-dev - - # Install 'eth', for use in the Solidity Tests-over-IPC. - sudo add-apt-repository -y ppa:ethereum/ethereum - sudo add-apt-repository -y ppa:ethereum/ethereum-dev - sudo apt-get -y update - sudo apt-get -y install eth + if [ "$CI" = true ]; then + # Install 'eth', for use in the Solidity Tests-over-IPC. + sudo add-apt-repository -y ppa:ethereum/ethereum + sudo add-apt-repository -y ppa:ethereum/ethereum-dev + sudo apt-get -y update + sudo apt-get -y install eth + fi ;; @@ -397,4 +394,4 @@ case $(uname -s) in echo "If you would like to get your operating system working, that would be fantastic." echo "Drop us a message at https://gitter.im/ethereum/solidity." ;; -esac +esac \ No newline at end of file From d76d9d41690b69622b703b7a3f567e830d095f9e Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Thu, 2 Feb 2017 18:53:30 -0600 Subject: [PATCH 071/234] create automated docker deployment Signed-off-by: RJ Catalano --- scripts/Dockerfile | 22 +++++++++++++--------- scripts/docker_deploy.sh | 17 +++++++++++++++++ 2 files changed, 30 insertions(+), 9 deletions(-) create mode 100755 scripts/docker_deploy.sh diff --git a/scripts/Dockerfile b/scripts/Dockerfile index e34436ed2..8be19783e 100644 --- a/scripts/Dockerfile +++ b/scripts/Dockerfile @@ -1,12 +1,16 @@ FROM alpine MAINTAINER chriseth +#Official solidity docker image -RUN \ - apk --no-cache --update add build-base cmake boost-dev git && \ - sed -i -E -e 's/include /include /' /usr/include/boost/asio/detail/socket_types.hpp && \ - git clone --depth 1 --recursive -b develop https://github.com/ethereum/solidity && \ - cd /solidity && cmake -DCMAKE_BUILD_TYPE=Release -DTESTS=0 -DSTATIC_LINKING=1 && \ - cd /solidity && make solc && install -s solc/solc /usr/bin && \ - cd / && rm -rf solidity && \ - apk del sed build-base git make cmake gcc g++ musl-dev curl-dev boost-dev && \ - rm -rf /var/cache/apk/* +#Establish working directory as solidity +WORKDIR /solidity +#Copy working directory on travis to the image +COPY / $WORKDIR + +#Install dependencies, eliminate annoying warnings, and build release, delete all remaining points and statically link. +RUN ./scripts/install_deps.sh && sed -i -E -e 's/include /include /' /usr/include/boost/asio/detail/socket_types.hpp &&\ +cmake -DCMAKE_BUILD_TYPE=Release -DTESTS=0 -DSTATIC_LINKING=1 &&\ +make solc && install -s solc/solc /usr/bin &&\ +cd / && rm -rf solidity &&\ +apk del sed build-base git make cmake gcc g++ musl-dev curl-dev boost-dev &&\ +rm -rf /var/cache/apk/* \ No newline at end of file diff --git a/scripts/docker_deploy.sh b/scripts/docker_deploy.sh new file mode 100755 index 000000000..f4c61601b --- /dev/null +++ b/scripts/docker_deploy.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env sh + +docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"; +version=version=$(grep -oP "PROJECT_VERSION \"?\K[0-9.]+(?=\")"? $(dirname "$0")/CMakeLists.txt) +if [ "$TRAVIS_BRANCH" == "develop" ]; then + docker tag ethereum/solc:build ethereum/solc:nightly; + docker tag ethereum/solc:build ethereum/solc:nightly-"$version"-"$TRAVIS_COMMIT" + docker push ethereum/solc:nightly-"$version"-"$TRAVIS_COMMIT"; + docker push ethereum/solc:nightly; +elif [ "$TRAVIS_BRANCH" == "release"]; then + docker tag ethereum/solc:build ethereum/solc:stable; + docker tag ethereum/solc:build ethereum/solc:"$version"; + docker tag ethereum/solc:build ethereum/solc: + docker push ethereum/solc; + docker push ethereum/solc:"$version"; + docker push ethereum/solc:stable; +fi \ No newline at end of file From d9e7af939ca202975a6dff7537d73614d75f1470 Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Thu, 2 Feb 2017 18:53:42 -0600 Subject: [PATCH 072/234] defeat race condition Signed-off-by: RJ Catalano --- scripts/tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/tests.sh b/scripts/tests.sh index 8edfda0bc..88815f5f6 100755 --- a/scripts/tests.sh +++ b/scripts/tests.sh @@ -58,7 +58,7 @@ $ETH_PATH --test -d /tmp/test & # is available and is ready for the unit-tests to start talking to it. while [ ! -S /tmp/test/geth.ipc ]; do sleep 2; done echo "--> IPC available." - +sleep 2 # And then run the Solidity unit-tests (once without optimization, once with), # pointing to that IPC endpoint. echo "--> Running tests without optimizer..." @@ -69,4 +69,4 @@ ERROR_CODE=$? pkill eth || true sleep 4 pgrep eth && pkill -9 eth || true -exit $ERROR_CODE +exit $ERROR_CODE \ No newline at end of file From 7ffc6863fb33775fb95b6ca2994dd769d3db33c3 Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Thu, 2 Feb 2017 20:57:07 -0600 Subject: [PATCH 073/234] edit the documentation for the travis file Signed-off-by: RJ Catalano --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index eafba71f6..df8b4ebba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -188,9 +188,7 @@ deploy: # Both the build and deploy steps for Emscripten are only run within the Ubuntu # configurations (not for macOS). That is controlled by conditionals within the bash # scripts because TravisCI doesn't provide much in the way of conditional logic. - # This is also the deploy target for the dockerfile. If we are pushing into a develop branch, it will be tagged - # as a nightly and appended the commit of the branch it was pushed in. If we are pushing to master it will - # be tagged as "stable" and given the version tag as well. + - provider: script script: test $SOLC_EMSCRIPTEN == On || scripts/release_emscripten.sh skip_cleanup: true @@ -198,6 +196,9 @@ deploy: branch: - develop - release + # This is the deploy target for the dockerfile. If we are pushing into a develop branch, it will be tagged + # as a nightly and appended the commit of the branch it was pushed in. If we are pushing to master it will + # be tagged as "stable" and given the version tag as well. - provider: script script: test $SOLC_DOCKER != On || ./scripts/docker_deploy.sh skip_cleanup: true From e884f7a4790c498e4b406e42aec5a7f7b4102368 Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Tue, 7 Feb 2017 16:20:48 -0600 Subject: [PATCH 074/234] minor fixups Signed-off-by: RJ Catalano --- scripts/docker_deploy.sh | 2 +- scripts/install_deps.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/docker_deploy.sh b/scripts/docker_deploy.sh index f4c61601b..870cca442 100755 --- a/scripts/docker_deploy.sh +++ b/scripts/docker_deploy.sh @@ -1,7 +1,7 @@ #!/usr/bin/env sh docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"; -version=version=$(grep -oP "PROJECT_VERSION \"?\K[0-9.]+(?=\")"? $(dirname "$0")/CMakeLists.txt) +version=$(grep -oP "PROJECT_VERSION \"?\K[0-9.]+(?=\")"? $(dirname "$0")/CMakeLists.txt) if [ "$TRAVIS_BRANCH" == "develop" ]; then docker tag ethereum/solc:build ethereum/solc:nightly; docker tag ethereum/solc:build ethereum/solc:nightly-"$version"-"$TRAVIS_COMMIT" diff --git a/scripts/install_deps.sh b/scripts/install_deps.sh index 869bce35a..7cfc92f2f 100755 --- a/scripts/install_deps.sh +++ b/scripts/install_deps.sh @@ -57,7 +57,7 @@ detect_linux_distro() { # extract 'foo' from NAME=foo, only on the line with NAME=foo DISTRO=$(sed -n -e 's/^NAME="\(.*\)\"/\1/p' /etc/os-release) elif [ -f /etc/centos-release ]; then - DISTRO=CentOS + DISTRO=CentOS else DISTRO='' fi From e9ae50dc5994a02119655eff4ed488fb3918d41f Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Thu, 9 Feb 2017 11:36:08 -0600 Subject: [PATCH 075/234] clarify branches for docker to push on and clarify where to find cmakelists.txt Signed-off-by: RJ Catalano --- scripts/docker_deploy.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/docker_deploy.sh b/scripts/docker_deploy.sh index 870cca442..dcd03f9ef 100755 --- a/scripts/docker_deploy.sh +++ b/scripts/docker_deploy.sh @@ -1,7 +1,7 @@ #!/usr/bin/env sh docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"; -version=$(grep -oP "PROJECT_VERSION \"?\K[0-9.]+(?=\")"? $(dirname "$0")/CMakeLists.txt) +version=$(grep -oP "PROJECT_VERSION \"?\K[0-9.]+(?=\")"? $(dirname "$0")/../CMakeLists.txt) if [ "$TRAVIS_BRANCH" == "develop" ]; then docker tag ethereum/solc:build ethereum/solc:nightly; docker tag ethereum/solc:build ethereum/solc:nightly-"$version"-"$TRAVIS_COMMIT" @@ -9,9 +9,8 @@ if [ "$TRAVIS_BRANCH" == "develop" ]; then docker push ethereum/solc:nightly; elif [ "$TRAVIS_BRANCH" == "release"]; then docker tag ethereum/solc:build ethereum/solc:stable; - docker tag ethereum/solc:build ethereum/solc:"$version"; - docker tag ethereum/solc:build ethereum/solc: - docker push ethereum/solc; - docker push ethereum/solc:"$version"; docker push ethereum/solc:stable; +elif [ "$TRAVIS_BRANCH" == v"$version"]; then + docker tag ethereum/solc:build ethereum/solc:"$version"; + docker push ethereum/solc:"$version"; fi \ No newline at end of file From 4f6ebae36c03bea6882c77a1c7841095e7c99049 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 10 Feb 2017 14:07:46 +0100 Subject: [PATCH 076/234] Check for tag in travis. --- scripts/docker_deploy.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/docker_deploy.sh b/scripts/docker_deploy.sh index dcd03f9ef..c9682c166 100755 --- a/scripts/docker_deploy.sh +++ b/scripts/docker_deploy.sh @@ -10,7 +10,7 @@ if [ "$TRAVIS_BRANCH" == "develop" ]; then elif [ "$TRAVIS_BRANCH" == "release"]; then docker tag ethereum/solc:build ethereum/solc:stable; docker push ethereum/solc:stable; -elif [ "$TRAVIS_BRANCH" == v"$version"]; then +elif [ "$TRAVIS_TAG" == v"$version"]; then docker tag ethereum/solc:build ethereum/solc:"$version"; docker push ethereum/solc:"$version"; -fi \ No newline at end of file +fi From 3128ec2ca5d30aaca78aae457642214f3f52e31f Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 7 Feb 2017 16:20:05 +0000 Subject: [PATCH 077/234] Add blockNumber and blockTimestamp to ExecutionFramework --- test/ExecutionFramework.cpp | 8 ++++++++ test/ExecutionFramework.h | 2 ++ test/RPCSession.cpp | 1 + test/RPCSession.h | 1 + 4 files changed, 12 insertions(+) diff --git a/test/ExecutionFramework.cpp b/test/ExecutionFramework.cpp index ddcd9cb68..701396428 100644 --- a/test/ExecutionFramework.cpp +++ b/test/ExecutionFramework.cpp @@ -82,6 +82,8 @@ void ExecutionFramework::sendMessage(bytes const& _data, bool _isCreation, u256 m_rpc.test_mineBlocks(1); RPCSession::TransactionReceipt receipt(m_rpc.eth_getTransactionReceipt(txHash)); + m_blockNumber = u256(receipt.blockNumber); + if (_isCreation) { m_contractAddress = Address(receipt.contractAddress); @@ -129,6 +131,12 @@ size_t ExecutionFramework::currentTimestamp() return size_t(u256(latestBlock.get("timestamp", "invalid").asString())); } +size_t ExecutionFramework::blockTimestamp(u256 _number) +{ + auto latestBlock = m_rpc.rpcCall("eth_getBlockByNumber", {toString(_number), "false"}); + return size_t(u256(latestBlock.get("timestamp", "invalid").asString())); +} + Address ExecutionFramework::account(size_t _i) { return Address(m_rpc.accountCreateIfNotExists(_i)); diff --git a/test/ExecutionFramework.h b/test/ExecutionFramework.h index 733fd56dc..76d0fd8cf 100644 --- a/test/ExecutionFramework.h +++ b/test/ExecutionFramework.h @@ -262,6 +262,7 @@ protected: void sendMessage(bytes const& _data, bool _isCreation, u256 const& _value = 0); void sendEther(Address const& _to, u256 const& _value); size_t currentTimestamp(); + size_t blockTimestamp(u256 number); /// @returns the (potentially newly created) _ith address. Address account(size_t _i); @@ -284,6 +285,7 @@ protected: bool m_showMessages = false; Address m_sender; Address m_contractAddress; + u256 m_blockNumber; u256 const m_gasPrice = 100 * szabo; u256 const m_gas = 100000000; bytes m_output; diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index b3451528f..a58355d0b 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -138,6 +138,7 @@ RPCSession::TransactionReceipt RPCSession::eth_getTransactionReceipt(string cons BOOST_REQUIRE(!result.isNull()); receipt.gasUsed = result["gasUsed"].asString(); receipt.contractAddress = result["contractAddress"].asString(); + receipt.blockNumber = result["blockNumber"].asString(); for (auto const& log: result["logs"]) { LogEntry entry; diff --git a/test/RPCSession.h b/test/RPCSession.h index f1aee6a81..b2e8a3092 100644 --- a/test/RPCSession.h +++ b/test/RPCSession.h @@ -92,6 +92,7 @@ public: std::string gasUsed; std::string contractAddress; std::vector logEntries; + std::string blockNumber; }; static RPCSession& instance(std::string const& _path); From 4cf44f1b41fe021653a6f45c72c19253dd352459 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 7 Feb 2017 16:20:25 +0000 Subject: [PATCH 078/234] Do not use modifyTimestamp where not needed --- test/libsolidity/SolidityEndToEndTest.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 4924b55d0..3c2e939cf 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1482,9 +1482,12 @@ BOOST_AUTO_TEST_CASE(now) } } )"; - m_rpc.test_modifyTimestamp(0x776347e2); compileAndRun(sourceCode); - BOOST_CHECK(callContractFunction("someInfo()") == encodeArgs(true, 0x776347e3)); + u256 startBlock = m_blockNumber; + auto ret = callContractFunction("someInfo()"); + u256 endBlock = m_blockNumber; + BOOST_CHECK(startBlock != endBlock); + BOOST_CHECK(ret == encodeArgs(true, blockTimestamp(endBlock))); } BOOST_AUTO_TEST_CASE(type_conversions_cleanup) From 702ee20a0179afe607383554ee89b0f863e14f63 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 9 Feb 2017 18:41:51 +0000 Subject: [PATCH 079/234] Create getBlockByNumber RPC method --- test/ExecutionFramework.cpp | 4 ++-- test/RPCSession.cpp | 10 ++++++++-- test/RPCSession.h | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/test/ExecutionFramework.cpp b/test/ExecutionFramework.cpp index 701396428..f4e5fcef5 100644 --- a/test/ExecutionFramework.cpp +++ b/test/ExecutionFramework.cpp @@ -127,13 +127,13 @@ void ExecutionFramework::sendEther(Address const& _to, u256 const& _value) size_t ExecutionFramework::currentTimestamp() { - auto latestBlock = m_rpc.rpcCall("eth_getBlockByNumber", {"\"latest\"", "false"}); + auto latestBlock = m_rpc.eth_getBlockByNumber("latest", false); return size_t(u256(latestBlock.get("timestamp", "invalid").asString())); } size_t ExecutionFramework::blockTimestamp(u256 _number) { - auto latestBlock = m_rpc.rpcCall("eth_getBlockByNumber", {toString(_number), "false"}); + auto latestBlock = m_rpc.eth_getBlockByNumber(toString(_number), false); return size_t(u256(latestBlock.get("timestamp", "invalid").asString())); } diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index a58355d0b..c27e73d42 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -131,6 +131,12 @@ string RPCSession::eth_getCode(string const& _address, string const& _blockNumbe return rpcCall("eth_getCode", { quote(_address), quote(_blockNumber) }).asString(); } +Json::Value RPCSession::eth_getBlockByNumber(string const& _blockNumber, bool _fullObjects) +{ + // NOTE: to_string() converts bool to 0 or 1 + return rpcCall("eth_getBlockByNumber", { quote(_blockNumber), _fullObjects ? "true" : "false" }); +} + RPCSession::TransactionReceipt RPCSession::eth_getTransactionReceipt(string const& _transactionHash) { TransactionReceipt receipt; @@ -290,9 +296,9 @@ Json::Value RPCSession::rpcCall(string const& _methodName, vector const& request += "],\"id\":" + to_string(m_rpcSequence) + "}"; ++m_rpcSequence; - //cout << "Request: " << request << endl; + // cout << "Request: " << request << endl; string reply = m_ipcSocket.sendRequest(request); - //cout << "Reply: " << reply << endl; + // cout << "Reply: " << reply << endl; Json::Value result; BOOST_REQUIRE(Json::Reader().parse(reply, result, false)); diff --git a/test/RPCSession.h b/test/RPCSession.h index b2e8a3092..105ba3788 100644 --- a/test/RPCSession.h +++ b/test/RPCSession.h @@ -98,6 +98,7 @@ public: static RPCSession& instance(std::string const& _path); std::string eth_getCode(std::string const& _address, std::string const& _blockNumber); + Json::Value eth_getBlockByNumber(std::string const& _blockNumber, bool _fullObjects); std::string eth_call(TransactionData const& _td, std::string const& _blockNumber); TransactionReceipt eth_getTransactionReceipt(std::string const& _transactionHash); std::string eth_sendTransaction(TransactionData const& _transactionData); From a82acba49ae68a960f33a2938f3d3560bf65441c Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 10 Feb 2017 13:26:11 +0000 Subject: [PATCH 080/234] Compare start/end timestamp --- test/libsolidity/SolidityEndToEndTest.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 3c2e939cf..53b61450d 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1484,10 +1484,13 @@ BOOST_AUTO_TEST_CASE(now) )"; compileAndRun(sourceCode); u256 startBlock = m_blockNumber; + size_t startTime = blockTimestamp(startBlock); auto ret = callContractFunction("someInfo()"); u256 endBlock = m_blockNumber; + size_t endTime = blockTimestamp(endBlock); BOOST_CHECK(startBlock != endBlock); - BOOST_CHECK(ret == encodeArgs(true, blockTimestamp(endBlock))); + BOOST_CHECK(startTime != endTime); + BOOST_CHECK(ret == encodeArgs(true, endTime)); } BOOST_AUTO_TEST_CASE(type_conversions_cleanup) From f8461e9e31b96e6656b8dcabd73de2e5176e6fe3 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 9 Feb 2017 01:37:53 +0000 Subject: [PATCH 081/234] Implement assert as a global function --- Changelog.md | 1 + libsolidity/analysis/GlobalContext.cpp | 4 +++- libsolidity/ast/Types.h | 7 ++++--- libsolidity/codegen/ExpressionCompiler.cpp | 8 ++++++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Changelog.md b/Changelog.md index 0c4e83294..e8656ac87 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,7 @@ ### 0.4.10 (unreleased) Features: + * Add ``assert(condition)`` to abort execution. * Type system: Support explicit conversion of external function to address. Bugfixes: diff --git a/libsolidity/analysis/GlobalContext.cpp b/libsolidity/analysis/GlobalContext.cpp index e46868be2..cc418c5e0 100644 --- a/libsolidity/analysis/GlobalContext.cpp +++ b/libsolidity/analysis/GlobalContext.cpp @@ -65,7 +65,9 @@ m_magicVariables(vector>{make_shared< make_shared("ecrecover", make_shared(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Location::ECRecover)), make_shared("ripemd160", - make_shared(strings(), strings{"bytes20"}, FunctionType::Location::RIPEMD160, true))}) + make_shared(strings(), strings{"bytes20"}, FunctionType::Location::RIPEMD160, true)), + make_shared("assert", + make_shared(strings{"bool"}, strings{}, FunctionType::Location::Assert))}) { } diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index e280b32c2..83d840e06 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -819,8 +819,8 @@ public: { Internal, ///< stack-call using plain JUMP External, ///< external call using CALL - CallCode, ///< extercnal call using CALLCODE, i.e. not exchanging the storage - DelegateCall, ///< extercnal call using DELEGATECALL, i.e. not exchanging the storage + CallCode, ///< external call using CALLCODE, i.e. not exchanging the storage + DelegateCall, ///< external call using DELEGATECALL, i.e. not exchanging the storage Bare, ///< CALL without function hash BareCallCode, ///< CALLCODE without function hash BareDelegateCall, ///< DELEGATECALL without function hash @@ -844,7 +844,8 @@ public: MulMod, ///< MULMOD ArrayPush, ///< .push() to a dynamically sized array in storage ByteArrayPush, ///< .push() to a dynamically sized byte array in storage - ObjectCreation ///< array creation using new + ObjectCreation, ///< array creation using new + Assert ///< assert() }; virtual Category category() const override { return Category::Function; } diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index d74d9dd3d..a99e3d406 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -863,6 +863,14 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) m_context << Instruction::POP; break; } + case Location::Assert: + { + arguments.front()->accept(*this); + utils().convertType(*arguments.front()->annotation().type, *function.parameterTypes().front(), true); + m_context << Instruction::ISZERO; + m_context.appendConditionalJumpTo(m_context.errorTag()); + break; + } default: BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Invalid function type.")); } From 8429c03f2ab81ad5fe077df6f69f6dbe88609779 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 9 Feb 2017 15:27:23 +0000 Subject: [PATCH 082/234] Add tests for assert() --- test/libsolidity/SolidityEndToEndTest.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 4924b55d0..e49db34e9 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -9077,6 +9077,25 @@ BOOST_AUTO_TEST_CASE(invalid_instruction) BOOST_CHECK(callContractFunction("f()") == encodeArgs()); } +BOOST_AUTO_TEST_CASE(assert) +{ + char const* sourceCode = R"( + contract C { + function f() { + assert(false); + } + function g(bool val) returns (bool) { + assert(val == true); + return true; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("f()") == encodeArgs()); + BOOST_CHECK(callContractFunction("g(bool)", false) == encodeArgs()); + BOOST_CHECK(callContractFunction("g(bool)", true) == encodeArgs(true)); +} + BOOST_AUTO_TEST_SUITE_END() } From 7f726de1cb861f4c7cb4e89e4ec56cd5712d0855 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 9 Feb 2017 15:31:03 +0000 Subject: [PATCH 083/234] Document assert() --- docs/miscellaneous.rst | 3 ++- docs/units-and-global-variables.rst | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index 476500676..27289daf1 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -435,7 +435,7 @@ The following is the order of precedence for operators, listed in order of evalu | *16* | Comma operator | ``,`` | +------------+-------------------------------------+--------------------------------------------+ -.. index:: block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin, keccak256, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send +.. index:: block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin, assert, keccak256, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send Global Variables ================ @@ -460,6 +460,7 @@ Global Variables - ``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 - ``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`` - ``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(bool condition)``: throws if the condition is not met - ``this`` (current contract's type): the current contract, explicitly convertible to ``address`` - ``super``: the contract one level higher in the inheritance hierarchy - ``selfdestruct(address recipient)``: destroy the current contract, sending its funds to the given address diff --git a/docs/units-and-global-variables.rst b/docs/units-and-global-variables.rst index dd3d4be8d..a6f6613f1 100644 --- a/docs/units-and-global-variables.rst +++ b/docs/units-and-global-variables.rst @@ -79,11 +79,13 @@ Block and Transaction Properties You can only access the hashes of the most recent 256 blocks, all other values will be zero. -.. index:: keccak256, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send +.. index:: assert, keccak256, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send Mathematical and Cryptographic Functions ---------------------------------------- +``assert(bool condition)``: + throws if the condition is not met. ``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``. ``mulmod(uint x, uint y, uint k) returns (uint)``: From 39cd2214f2161d2e09ab0de21a64f6dcdb851b13 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 10 Feb 2017 13:31:40 +0000 Subject: [PATCH 084/234] Document user provided exceptions --- docs/control-structures.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/control-structures.rst b/docs/control-structures.rst index 1c7d71f26..ff0a48ec1 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -396,6 +396,10 @@ Currently, Solidity automatically generates a runtime exception in the following #. If your contract receives Ether via a public getter function. #. If you call a zero-initialized variable of internal function type. +While a user-provided exception is generated in the following situations: +#. Calling ``throw``. +#. The condition of ``assert(condition)`` is not met. + Internally, Solidity performs an "invalid jump" when a user-provided exception is thrown. In contrast, it performs an invalid operation (instruction ``0xfe``) if a runtime exception is encountered. In both cases, this causes the EVM to revert all changes made to the state. The reason for this is that there is no safe way to continue execution, because an expected effect From 8a3d4a0500e98dbca83c0217d141fcb4860986e3 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 10 Feb 2017 13:32:36 +0000 Subject: [PATCH 085/234] Cleanup is not needed for assert() --- libsolidity/codegen/ExpressionCompiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index a99e3d406..f69d61db9 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -866,7 +866,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) case Location::Assert: { arguments.front()->accept(*this); - utils().convertType(*arguments.front()->annotation().type, *function.parameterTypes().front(), true); + utils().convertType(*arguments.front()->annotation().type, *function.parameterTypes().front(), false); m_context << Instruction::ISZERO; m_context.appendConditionalJumpTo(m_context.errorTag()); break; From fd7ffedead51f77135250dca29326c890f3632a2 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 10 Feb 2017 21:41:40 +0000 Subject: [PATCH 086/234] Use different wording for assert --- Changelog.md | 2 +- docs/miscellaneous.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index e8656ac87..d383ba421 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,7 +1,7 @@ ### 0.4.10 (unreleased) Features: - * Add ``assert(condition)`` to abort execution. + * Add ``assert(condition)``, which throws if condition is false. * Type system: Support explicit conversion of external function to address. Bugfixes: diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index 27289daf1..a64ceeb2b 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -460,7 +460,7 @@ Global Variables - ``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 - ``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`` - ``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(bool condition)``: throws if the condition is not met +- ``assert(bool condition)``: throws if the condition is false - ``this`` (current contract's type): the current contract, explicitly convertible to ``address`` - ``super``: the contract one level higher in the inheritance hierarchy - ``selfdestruct(address recipient)``: destroy the current contract, sending its funds to the given address From 148f9233516ff5ad94d81aba9bc9c0440d3afc7b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 6 Feb 2017 20:21:27 +0000 Subject: [PATCH 087/234] Add REVERT to libevmasm --- libevmasm/GasMeter.cpp | 1 + libevmasm/Instruction.cpp | 2 ++ libevmasm/Instruction.h | 1 + libevmasm/PeepholeOptimiser.cpp | 3 ++- libevmasm/SemanticInformation.cpp | 1 + 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libevmasm/GasMeter.cpp b/libevmasm/GasMeter.cpp index 462c09dd0..a0adc35d5 100644 --- a/libevmasm/GasMeter.cpp +++ b/libevmasm/GasMeter.cpp @@ -80,6 +80,7 @@ GasMeter::GasConsumption GasMeter::estimateMax(AssemblyItem const& _item, bool _ gas += GasCosts::sloadGas; break; case Instruction::RETURN: + case Instruction::REVERT: gas += memoryGas(0, -1); break; case Instruction::MLOAD: diff --git a/libevmasm/Instruction.cpp b/libevmasm/Instruction.cpp index f9ee9be1f..de6630f30 100644 --- a/libevmasm/Instruction.cpp +++ b/libevmasm/Instruction.cpp @@ -159,6 +159,7 @@ const std::map dev::solidity::c_instructions = { "CALLCODE", Instruction::CALLCODE }, { "RETURN", Instruction::RETURN }, { "DELEGATECALL", Instruction::DELEGATECALL }, + { "REVERT", Instruction::REVERT }, { "INVALID", Instruction::INVALID }, { "SELFDESTRUCT", Instruction::SELFDESTRUCT } }; @@ -294,6 +295,7 @@ static const std::map c_instructionInfo = { Instruction::CALLCODE, { "CALLCODE", 0, 7, 1, true, Tier::Special } }, { Instruction::RETURN, { "RETURN", 0, 2, 0, true, Tier::Zero } }, { Instruction::DELEGATECALL, { "DELEGATECALL", 0, 6, 1, true, Tier::Special } }, + { Instruction::REVERT, { "REVERT", 0, 2, 0, true, Tier::Zero } }, { Instruction::INVALID, { "INVALID", 0, 0, 0, true, Tier::Zero } }, { Instruction::SELFDESTRUCT, { "SELFDESTRUCT", 0, 1, 0, true, Tier::Zero } } }; diff --git a/libevmasm/Instruction.h b/libevmasm/Instruction.h index 7f56ad3a9..d79ec969e 100644 --- a/libevmasm/Instruction.h +++ b/libevmasm/Instruction.h @@ -177,6 +177,7 @@ enum class Instruction: uint8_t RETURN, ///< halt execution returning output data DELEGATECALL, ///< like CALLCODE but keeps caller's value and sender + REVERT = 0xfd, ///< halt execution, revert state and return output data INVALID = 0xfe, ///< invalid instruction for expressing runtime errors (e.g., division-by-zero) SELFDESTRUCT = 0xff ///< halt execution and register account for later deletion }; diff --git a/libevmasm/PeepholeOptimiser.cpp b/libevmasm/PeepholeOptimiser.cpp index 9a8341ab9..6c92d76bc 100644 --- a/libevmasm/PeepholeOptimiser.cpp +++ b/libevmasm/PeepholeOptimiser.cpp @@ -200,7 +200,8 @@ struct UnreachableCode it[0] != Instruction::RETURN && it[0] != Instruction::STOP && it[0] != Instruction::INVALID && - it[0] != Instruction::SELFDESTRUCT + it[0] != Instruction::SELFDESTRUCT && + it[0] != Instruction::REVERT ) return false; diff --git a/libevmasm/SemanticInformation.cpp b/libevmasm/SemanticInformation.cpp index 3a0843b8f..61586e7b7 100644 --- a/libevmasm/SemanticInformation.cpp +++ b/libevmasm/SemanticInformation.cpp @@ -119,6 +119,7 @@ bool SemanticInformation::altersControlFlow(AssemblyItem const& _item) case Instruction::SELFDESTRUCT: case Instruction::STOP: case Instruction::INVALID: + case Instruction::REVERT: return true; default: return false; From f3158f92d6070b6088c6a1b32f2934b9cd7dde1b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 6 Feb 2017 22:11:19 +0000 Subject: [PATCH 088/234] Support revert() --- libsolidity/analysis/GlobalContext.cpp | 4 +++- libsolidity/ast/Types.cpp | 1 + libsolidity/ast/Types.h | 1 + libsolidity/codegen/ExpressionCompiler.cpp | 5 +++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libsolidity/analysis/GlobalContext.cpp b/libsolidity/analysis/GlobalContext.cpp index cc418c5e0..4f100cd0e 100644 --- a/libsolidity/analysis/GlobalContext.cpp +++ b/libsolidity/analysis/GlobalContext.cpp @@ -67,7 +67,9 @@ m_magicVariables(vector>{make_shared< make_shared("ripemd160", make_shared(strings(), strings{"bytes20"}, FunctionType::Location::RIPEMD160, true)), make_shared("assert", - make_shared(strings{"bool"}, strings{}, FunctionType::Location::Assert))}) + make_shared(strings{"bool"}, strings{}, FunctionType::Location::Assert)), + make_shared("revert", + make_shared(strings(), strings(), FunctionType::Location::Revert))}) { } diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 4a64b4c81..5b7b4a2cd 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -2095,6 +2095,7 @@ string FunctionType::identifier() const case Location::Send: id += "send"; break; case Location::SHA3: id += "sha3"; break; case Location::Selfdestruct: id += "selfdestruct"; break; + case Location::Revert: id += "revert"; break; case Location::ECRecover: id += "ecrecover"; break; case Location::SHA256: id += "sha256"; break; case Location::RIPEMD160: id += "ripemd160"; break; diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 83d840e06..3546e5220 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -828,6 +828,7 @@ public: Send, ///< CALL, but without data and gas SHA3, ///< SHA3 Selfdestruct, ///< SELFDESTRUCT + Revert, ///< REVERT ECRecover, ///< CALL to special contract for ecrecover SHA256, ///< CALL to special contract for sha256 RIPEMD160, ///< CALL to special contract for ripemd160 diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index f69d61db9..316ae888d 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -650,6 +650,11 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) utils().convertType(*arguments.front()->annotation().type, *function.parameterTypes().front(), true); m_context << Instruction::SELFDESTRUCT; break; + case Location::Revert: + // memory offset returned - zero length + m_context << u256(0) << u256(0); + m_context << Instruction::REVERT; + break; case Location::SHA3: { TypePointers argumentTypes; From 1fcad8b4ab48f63504c69c24372fb34f34a79436 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 6 Feb 2017 22:47:05 +0000 Subject: [PATCH 089/234] Document revert() --- Changelog.md | 2 ++ docs/assembly.rst | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Changelog.md b/Changelog.md index d383ba421..bd514cfe6 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,8 @@ Features: * Add ``assert(condition)``, which throws if condition is false. + * Code generator: Support ``revert()`` to abort with rolling back, but not consuming all gas. + * Inline assembly: Support ``revert`` (EIP140) as an opcode. * Type system: Support explicit conversion of external function to address. Bugfixes: diff --git a/docs/assembly.rst b/docs/assembly.rst index 79137b7e9..23ccfcbe2 100644 --- a/docs/assembly.rst +++ b/docs/assembly.rst @@ -248,6 +248,8 @@ In the grammar, opcodes are represented as pre-defined identifiers. +-------------------------+------+-----------------------------------------------------------------+ | return(p, s) | `-` | end execution, return data mem[p..(p+s)) | +-------------------------+------+-----------------------------------------------------------------+ +| revert(p, s) | `-` | end execution, revert state changes, return data mem[p..(p+s)) | ++-------------------------+------+-----------------------------------------------------------------+ | selfdestruct(a) | `-` | end execution, destroy current contract and send funds to a | +-------------------------+------+-----------------------------------------------------------------+ | invalid | `-` | end execution with invalid instruction | From 586d156f33c78469f3272b4e8b8eae4f6229d04e Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 8 Feb 2017 23:16:47 +0000 Subject: [PATCH 090/234] Use the REVERT opcode for throw; --- libsolidity/codegen/ContractCompiler.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index 9d6129a36..6524bd039 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -762,7 +762,9 @@ bool ContractCompiler::visit(Return const& _return) bool ContractCompiler::visit(Throw const& _throw) { CompilerContext::LocationSetter locationSetter(m_context, _throw); - m_context.appendJumpTo(m_context.errorTag()); + // Do not send back an error detail. + m_context << u256(0) << u256(0); + m_context << Instruction::REVERT; return false; } From 28a7b1e019dc6f694d0615d7ef1220f19c10e861 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 9 Feb 2017 16:32:48 +0000 Subject: [PATCH 091/234] Document revert() --- docs/control-structures.rst | 2 +- docs/miscellaneous.rst | 3 ++- docs/units-and-global-variables.rst | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/control-structures.rst b/docs/control-structures.rst index ff0a48ec1..df8ac729c 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -400,7 +400,7 @@ While a user-provided exception is generated in the following situations: #. Calling ``throw``. #. The condition of ``assert(condition)`` is not met. -Internally, Solidity performs an "invalid jump" when a user-provided exception is thrown. In contrast, it performs an invalid operation +Internally, Solidity performs a revert operation (instruction ``0xfd``) when a user-provided exception is thrown. In contrast, it performs an invalid operation (instruction ``0xfe``) if a runtime exception is encountered. In both cases, this causes the EVM to revert all changes made to the state. The reason for this is that there is no safe way to continue execution, because an expected effect did not occur. Because we want to retain the atomicity of transactions, the safest thing to do is to revert all changes and make the whole transaction diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index a64ceeb2b..3c57507ef 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -435,7 +435,7 @@ The following is the order of precedence for operators, listed in order of evalu | *16* | Comma operator | ``,`` | +------------+-------------------------------------+--------------------------------------------+ -.. index:: block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin, assert, keccak256, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send +.. index:: block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin, assert, revert, keccak256, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send Global Variables ================ @@ -453,6 +453,7 @@ Global Variables - ``now`` (``uint``): current block timestamp (alias for ``block.timestamp``) - ``tx.gasprice`` (``uint``): gas price of the transaction - ``tx.origin`` (``address``): sender of the transaction (full call chain) +- ``revert()``: abort execution and revert state changes - ``keccak256(...) returns (bytes32)``: compute the Ethereum-SHA-3 (Keccak-256) hash of the (tightly packed) arguments - ``sha3(...) returns (bytes32)``: an alias to `keccak256()` - ``sha256(...) returns (bytes32)``: compute the SHA-256 hash of the (tightly packed) arguments diff --git a/docs/units-and-global-variables.rst b/docs/units-and-global-variables.rst index a6f6613f1..72741b672 100644 --- a/docs/units-and-global-variables.rst +++ b/docs/units-and-global-variables.rst @@ -79,7 +79,7 @@ Block and Transaction Properties You can only access the hashes of the most recent 256 blocks, all other values will be zero. -.. index:: assert, keccak256, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send +.. index:: assert, revert, keccak256, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send Mathematical and Cryptographic Functions ---------------------------------------- @@ -100,6 +100,8 @@ Mathematical and Cryptographic Functions compute RIPEMD-160 hash of the (tightly packed) arguments ``ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address)``: recover the address associated with the public key from elliptic curve signature or return zero on error +``revert()``: + abort execution and revert state changes In the above, "tightly packed" means that the arguments are concatenated without padding. This means that the following are all identical:: From f26fe5bc1c835302af27981e96d0ebbf31c80389 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 9 Feb 2017 16:34:48 +0000 Subject: [PATCH 092/234] Add tests for revert() --- test/libsolidity/InlineAssembly.cpp | 5 +++++ test/libsolidity/SolidityEndToEndTest.cpp | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index cf0343a92..37d17495a 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -205,6 +205,11 @@ BOOST_AUTO_TEST_CASE(inline_assembly_shadowed_instruction_functional_assignment) BOOST_CHECK(!successAssemble("{ gas := 2 }")); } +BOOST_AUTO_TEST_CASE(revert) +{ + BOOST_CHECK(successAssemble("{ revert(0, 0) }")); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index e49db34e9..8c0e29fd2 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -9096,6 +9096,25 @@ BOOST_AUTO_TEST_CASE(assert) BOOST_CHECK(callContractFunction("g(bool)", true) == encodeArgs(true)); } +BOOST_AUTO_TEST_CASE(revert) +{ + char const* sourceCode = R"( + contract C { + function f() { + revert(); + } + function g() { + assembly { + revert(0, 0) + } + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("f()") == encodeArgs()); + BOOST_CHECK(callContractFunction("g()") == encodeArgs()); +} + BOOST_AUTO_TEST_SUITE_END() } From 30cfad35484e9b903bf90bb723382aebc832d560 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 10 Feb 2017 13:37:06 +0000 Subject: [PATCH 093/234] Check for state changes in revert() tests --- test/libsolidity/SolidityEndToEndTest.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 8c0e29fd2..92c1a9a1f 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -9100,10 +9100,13 @@ BOOST_AUTO_TEST_CASE(revert) { char const* sourceCode = R"( contract C { + uint public a = 42; function f() { + a = 1; revert(); } function g() { + a = 1; assembly { revert(0, 0) } @@ -9112,7 +9115,9 @@ BOOST_AUTO_TEST_CASE(revert) )"; compileAndRun(sourceCode, 0, "C"); BOOST_CHECK(callContractFunction("f()") == encodeArgs()); + BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(42))); BOOST_CHECK(callContractFunction("g()") == encodeArgs()); + BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(42))); } BOOST_AUTO_TEST_SUITE_END() From c8ec79548b8f8825735ee96f1768e7fc5313d19e Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 10 Feb 2017 22:53:32 +0000 Subject: [PATCH 094/234] Use the revert opcode in assert() --- libsolidity/codegen/ExpressionCompiler.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 316ae888d..2ed19a833 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -872,8 +872,14 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) { arguments.front()->accept(*this); utils().convertType(*arguments.front()->annotation().type, *function.parameterTypes().front(), false); - m_context << Instruction::ISZERO; - m_context.appendConditionalJumpTo(m_context.errorTag()); + // jump if condition was met + m_context << Instruction::ISZERO << Instruction::ISZERO; + auto success = m_context.appendConditionalJump(); + // condition was not met, abort + m_context << u256(0) << u256(0); + m_context << Instruction::REVERT; + // the success branch + m_context << success; break; } default: From a2bcb0008b2278ef469111081708a2274413c5ee Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sat, 11 Feb 2017 18:03:47 +0000 Subject: [PATCH 095/234] Run every travis script in a subshell --- .travis.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index df8b4ebba..cfbadb85d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -168,18 +168,18 @@ cache: - $HOME/.local install: - - test $SOLC_INSTALL_DEPS_TRAVIS != On || ./scripts/install_deps.sh - - test "$TRAVIS_OS_NAME" != "linux" || ./scripts/install_cmake.sh + - test $SOLC_INSTALL_DEPS_TRAVIS != On || (scripts/install_deps.sh) + - test "$TRAVIS_OS_NAME" != "linux" || (scripts/install_cmake.sh) - echo -n "$TRAVIS_COMMIT" > commit_hash.txt - - test $SOLC_DOCKER != On || docker build -t ethereum/solc:build -f ./scripts/Dockerfile . + - test $SOLC_DOCKER != On || (docker build -t ethereum/solc:build -f scripts/Dockerfile .) before_script: - - test $SOLC_EMSCRIPTEN != On || ./scripts/build_emscripten.sh - - test $SOLC_RELEASE != On || (./scripts/build.sh $SOLC_BUILD_TYPE - && ./scripts/release.sh $ZIP_SUFFIX - && ./scripts/create_source_tarball.sh ) + - test $SOLC_EMSCRIPTEN != On || (scripts/build_emscripten.sh) + - test $SOLC_RELEASE != On || (scripts/build.sh $SOLC_BUILD_TYPE + && scripts/release.sh $ZIP_SUFFIX + && scripts/create_source_tarball.sh) script: - - test $SOLC_DOCS != On || ./scripts/docs.sh - - test $SOLC_TESTS != On || (cd $TRAVIS_BUILD_DIR && ./scripts/tests.sh ) + - test $SOLC_DOCS != On || (scripts/docs.sh) + - test $SOLC_TESTS != On || (cd $TRAVIS_BUILD_DIR && scripts/tests.sh) deploy: # This is the deploy target for the Emscripten build. @@ -190,7 +190,7 @@ deploy: # scripts because TravisCI doesn't provide much in the way of conditional logic. - provider: script - script: test $SOLC_EMSCRIPTEN == On || scripts/release_emscripten.sh + script: test $SOLC_EMSCRIPTEN == On || (scripts/release_emscripten.sh) skip_cleanup: true on: branch: @@ -200,7 +200,7 @@ deploy: # as a nightly and appended the commit of the branch it was pushed in. If we are pushing to master it will # be tagged as "stable" and given the version tag as well. - provider: script - script: test $SOLC_DOCKER != On || ./scripts/docker_deploy.sh + script: test $SOLC_DOCKER != On || (scripts/docker_deploy.sh) skip_cleanup: true on: branch: @@ -223,4 +223,4 @@ deploy: on: all_branches: true tags: true - condition: $SOLC_RELEASE == On \ No newline at end of file + condition: $SOLC_RELEASE == On From 108b79d3bfba648e6e16d8d74c8073eb465f4d6f Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sat, 11 Feb 2017 18:07:41 +0000 Subject: [PATCH 096/234] Fix macOS builds --- .travis.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index cfbadb85d..0a0aa139a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,7 @@ #------------------------------------------------------------------------------ language: cpp + branches: # We need to whitelist the branches which we want to have "push" automation, # this includes tags (which are treated as branches by travis). @@ -79,6 +80,7 @@ matrix: - SOLC_DOCS=On - SOLC_RELEASE=Off - SOLC_TESTS=Off + # Docker target, which generates a statically linked alpine image - os: linux dist: trusty @@ -126,7 +128,7 @@ matrix: # env: # # Workaround for "macOS - Yosemite, El Capitan and Sierra hanging?" # # https://github.com/ethereum/solidity/issues/894 -# - TRAVIS_TESTS=Off +# - SOLC_TESTS=Off # - ZIP_SUFFIX=osx-yosemite # OS X El Capitan (10.11) @@ -137,10 +139,10 @@ matrix: # env: # # The use of Debug config here ONLY for El Capitan is a workaround for "The Heisenbug" # # See https://github.com/ethereum/webthree-umbrella/issues/565 -# - TRAVIS_BUILD_TYPE=Debug +# - SOLC_BUILD_TYPE=Debug # # Workaround for "macOS - Yosemite, El Capitan and Sierra hanging?" # # https://github.com/ethereum/solidity/issues/894 -# - TRAVIS_TESTS=Off +# - SOLC_TESTS=Off # - ZIP_SUFFIX=osx-elcapitan # macOS Sierra (10.12) @@ -151,10 +153,10 @@ matrix: # env: # # Look like "The Heisenbug" is occurring here too, so we'll do the same workaround. # # See https://travis-ci.org/ethereum/solidity/jobs/150240930 -# - TRAVIS_BUILD_TYPE=Debug +# - SOLC_BUILD_TYPE=Debug # # Workaround for "macOS - Yosemite, El Capitan and Sierra hanging?" # # https://github.com/ethereum/solidity/issues/894 -# - TRAVIS_TESTS=Off +# - SOLC_TESTS=Off # - ZIP_SUFFIX=macos-sierra git: @@ -172,11 +174,13 @@ install: - test "$TRAVIS_OS_NAME" != "linux" || (scripts/install_cmake.sh) - echo -n "$TRAVIS_COMMIT" > commit_hash.txt - test $SOLC_DOCKER != On || (docker build -t ethereum/solc:build -f scripts/Dockerfile .) + before_script: - test $SOLC_EMSCRIPTEN != On || (scripts/build_emscripten.sh) - test $SOLC_RELEASE != On || (scripts/build.sh $SOLC_BUILD_TYPE && scripts/release.sh $ZIP_SUFFIX && scripts/create_source_tarball.sh) + script: - test $SOLC_DOCS != On || (scripts/docs.sh) - test $SOLC_TESTS != On || (cd $TRAVIS_BUILD_DIR && scripts/tests.sh) From 31baabaf61c3d9e306ae6f79ebc1eb89bcee6d18 Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Sat, 11 Feb 2017 14:06:30 -0600 Subject: [PATCH 097/234] should fix all the emscripten errors and problems associated with it Signed-off-by: RJ Catalano --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0a0aa139a..77fb06cd7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -194,7 +194,7 @@ deploy: # scripts because TravisCI doesn't provide much in the way of conditional logic. - provider: script - script: test $SOLC_EMSCRIPTEN == On || (scripts/release_emscripten.sh) + script: test $SOLC_EMSCRIPTEN != On || (scripts/release_emscripten.sh) skip_cleanup: true on: branch: From 11c4a7b6426a0bd29b7b17ab21e7415b651a98ee Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 13 Feb 2017 11:22:07 +0100 Subject: [PATCH 098/234] Fail if docker deploy failed. --- scripts/docker_deploy.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/docker_deploy.sh b/scripts/docker_deploy.sh index c9682c166..fe157044e 100755 --- a/scripts/docker_deploy.sh +++ b/scripts/docker_deploy.sh @@ -1,5 +1,7 @@ #!/usr/bin/env sh +set -e + docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"; version=$(grep -oP "PROJECT_VERSION \"?\K[0-9.]+(?=\")"? $(dirname "$0")/../CMakeLists.txt) if [ "$TRAVIS_BRANCH" == "develop" ]; then From bc3e3fd7090def8f4da81c44b31a86c1fda19414 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 13 Feb 2017 12:28:39 +0100 Subject: [PATCH 099/234] Fix test expressions. --- scripts/docker_deploy.sh | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/scripts/docker_deploy.sh b/scripts/docker_deploy.sh index fe157044e..d2810a3e5 100755 --- a/scripts/docker_deploy.sh +++ b/scripts/docker_deploy.sh @@ -4,15 +4,20 @@ set -e docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"; version=$(grep -oP "PROJECT_VERSION \"?\K[0-9.]+(?=\")"? $(dirname "$0")/../CMakeLists.txt) -if [ "$TRAVIS_BRANCH" == "develop" ]; then - docker tag ethereum/solc:build ethereum/solc:nightly; - docker tag ethereum/solc:build ethereum/solc:nightly-"$version"-"$TRAVIS_COMMIT" - docker push ethereum/solc:nightly-"$version"-"$TRAVIS_COMMIT"; - docker push ethereum/solc:nightly; -elif [ "$TRAVIS_BRANCH" == "release"]; then - docker tag ethereum/solc:build ethereum/solc:stable; - docker push ethereum/solc:stable; -elif [ "$TRAVIS_TAG" == v"$version"]; then - docker tag ethereum/solc:build ethereum/solc:"$version"; - docker push ethereum/solc:"$version"; +if [ "$TRAVIS_BRANCH" = "develop" ] +then + docker tag ethereum/solc:build ethereum/solc:nightly; + docker tag ethereum/solc:build ethereum/solc:nightly-"$version"-"$TRAVIS_COMMIT" + docker push ethereum/solc:nightly-"$version"-"$TRAVIS_COMMIT"; + docker push ethereum/solc:nightly; +elif [ "$TRAVIS_BRANCH" = "release" ] +then + docker tag ethereum/solc:build ethereum/solc:stable; + docker push ethereum/solc:stable; +elif [ "$TRAVIS_TAG" = v"$version" ] +then + docker tag ethereum/solc:build ethereum/solc:"$version"; + docker push ethereum/solc:"$version"; +else + echo "Not publishing docker image from branch $TRAVIS_BRANCH or tag $TRAVIS_TAG" fi From 9ee0d6fb900c037b6143c3b48e688008b558ba12 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 13 Feb 2017 14:28:07 +0100 Subject: [PATCH 100/234] Try different nodejs version request formatting. --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 77fb06cd7..26e6b214a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -100,7 +100,8 @@ matrix: dist: trusty sudo: required compiler: gcc - node_js: "6" + node_js: + - "6" services: - docker before_install: From 1d4ef87bb11e447334d2dea99b5a70c7201d6b97 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 13 Feb 2017 13:59:29 +0000 Subject: [PATCH 101/234] Use maxMiningTime in mining as opposed to poll counter --- test/RPCSession.cpp | 12 ++++++++---- test/RPCSession.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index c27e73d42..613d042af 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -248,22 +248,26 @@ void RPCSession::test_mineBlocks(int _number) // We auto-calibrate the time it takes to mine the transaction. // It would be better to go without polling, but that would probably need a change to the test client + unsigned startTime = boost::posix_time::microsec_clock::local_time(); unsigned sleepTime = m_sleepTime; - size_t polls = 0; - for (; polls < 14 && !mined; ++polls) + size_t tries = 0; + for (; !mined; ++tries) { std::this_thread::sleep_for(chrono::milliseconds(sleepTime)); + boost::posix_time::time_duration timeSpent = boost::posix_time::microsec_clock::local_time() - startTime; + if (timeSpent > m_maxMiningTime) + break; if (fromBigEndian(fromHex(rpcCall("eth_blockNumber").asString())) >= startBlock + _number) mined = true; else sleepTime *= 2; } - if (polls > 1) + if (tries > 1) { m_successfulMineRuns = 0; m_sleepTime += 2; } - else if (polls == 1) + else if (tries == 1) { m_successfulMineRuns++; if (m_successfulMineRuns > 5) diff --git a/test/RPCSession.h b/test/RPCSession.h index 105ba3788..a0b1e9ef4 100644 --- a/test/RPCSession.h +++ b/test/RPCSession.h @@ -126,6 +126,7 @@ private: IPCSocket m_ipcSocket; size_t m_rpcSequence = 1; + unsigned m_maxMiningTime = 15000; // 15 seconds unsigned m_sleepTime = 10; unsigned m_successfulMineRuns = 0; From e9dd9d2c7220594e2731b081990396429c5288d7 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 13 Feb 2017 14:10:02 +0000 Subject: [PATCH 102/234] Simplify mining loop --- test/RPCSession.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index 613d042af..bf639e195 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -243,22 +243,20 @@ void RPCSession::test_mineBlocks(int _number) u256 startBlock = fromBigEndian(fromHex(rpcCall("eth_blockNumber").asString())); BOOST_REQUIRE(rpcCall("test_mineBlocks", { to_string(_number) }, true) == true); - bool mined = false; - // We auto-calibrate the time it takes to mine the transaction. // It would be better to go without polling, but that would probably need a change to the test client unsigned startTime = boost::posix_time::microsec_clock::local_time(); unsigned sleepTime = m_sleepTime; size_t tries = 0; - for (; !mined; ++tries) + for (; ; ++tries) { std::this_thread::sleep_for(chrono::milliseconds(sleepTime)); boost::posix_time::time_duration timeSpent = boost::posix_time::microsec_clock::local_time() - startTime; if (timeSpent > m_maxMiningTime) - break; + BOOST_FAIL("Error in test_mineBlocks: block mining timeout!"); if (fromBigEndian(fromHex(rpcCall("eth_blockNumber").asString())) >= startBlock + _number) - mined = true; + break; else sleepTime *= 2; } @@ -277,9 +275,6 @@ void RPCSession::test_mineBlocks(int _number) m_sleepTime--; } } - - if (!mined) - BOOST_FAIL("Error in test_mineBlocks: block mining timeout!"); } void RPCSession::test_modifyTimestamp(size_t _timestamp) From 0fe788aad6d55c440e04f6f64f1927613bd6b16b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 13 Feb 2017 15:01:15 +0000 Subject: [PATCH 103/234] Use std::chrono and not boost::posix_Time --- test/RPCSession.cpp | 5 +++-- test/RPCSession.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index bf639e195..ff00d7833 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -246,13 +246,14 @@ void RPCSession::test_mineBlocks(int _number) // We auto-calibrate the time it takes to mine the transaction. // It would be better to go without polling, but that would probably need a change to the test client - unsigned startTime = boost::posix_time::microsec_clock::local_time(); + auto startTime = std::chrono::steady_clock::now(); unsigned sleepTime = m_sleepTime; size_t tries = 0; for (; ; ++tries) { std::this_thread::sleep_for(chrono::milliseconds(sleepTime)); - boost::posix_time::time_duration timeSpent = boost::posix_time::microsec_clock::local_time() - startTime; + auto endTime = std::chrono::steady_clock::now(); + unsigned timeSpent = std::chrono::duration_cast(endTime - startTime).count(); if (timeSpent > m_maxMiningTime) BOOST_FAIL("Error in test_mineBlocks: block mining timeout!"); if (fromBigEndian(fromHex(rpcCall("eth_blockNumber").asString())) >= startBlock + _number) diff --git a/test/RPCSession.h b/test/RPCSession.h index a0b1e9ef4..414db3232 100644 --- a/test/RPCSession.h +++ b/test/RPCSession.h @@ -127,7 +127,7 @@ private: IPCSocket m_ipcSocket; size_t m_rpcSequence = 1; unsigned m_maxMiningTime = 15000; // 15 seconds - unsigned m_sleepTime = 10; + unsigned m_sleepTime = 10; // 10 milliseconds unsigned m_successfulMineRuns = 0; std::vector m_accounts; From 2ba09206dec5956ef436455c391499dc1c22e841 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 13 Feb 2017 17:41:12 +0100 Subject: [PATCH 104/234] Install nvm --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 26e6b214a..b5329243a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -105,6 +105,8 @@ matrix: services: - docker before_install: + - nvm install + - nvm use - docker pull trzeci/emscripten:sdk-tag-1.35.4-64bit env: - SOLC_EMSCRIPTEN=On From 99b00c75cc4f241aea6e4b6587b68baaba4ee4a5 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 13 Feb 2017 18:02:10 +0100 Subject: [PATCH 105/234] Use version 6 --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b5329243a..b722dacd4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -105,8 +105,8 @@ matrix: services: - docker before_install: - - nvm install - - nvm use + - nvm install 6 + - nvm use 6 - docker pull trzeci/emscripten:sdk-tag-1.35.4-64bit env: - SOLC_EMSCRIPTEN=On From 75d59b1adbbf20bf89a06955157b9a89bb2c67ae Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Sat, 11 Feb 2017 18:21:57 -0500 Subject: [PATCH 106/234] Update the sphinx highlighting rules --- docs/utils/SolidityLexer.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/docs/utils/SolidityLexer.py b/docs/utils/SolidityLexer.py index a7da59aaf..f5220c8bf 100644 --- a/docs/utils/SolidityLexer.py +++ b/docs/utils/SolidityLexer.py @@ -54,11 +54,10 @@ class SolidityLexer(RegexLexer): r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?', Operator, 'slashstartsregex'), (r'[{(\[;,]', Punctuation, 'slashstartsregex'), (r'[})\].]', Punctuation), - (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|' - r'throw|try|catch|finally|new|delete|typeof|instanceof|void|' - r'this|import|mapping|returns|private|public|external|internal|' - r'constant|memory|storage|payable)\b', Keyword, 'slashstartsregex'), - (r'(var|let|with|function|event|modifier|struct|enum|contract|library)\b', Keyword.Declaration, 'slashstartsregex'), + (r'(anonymous|as|assembly|break|constant|continue|do|else|external|hex|if|' + r'indexed|internal|import|is|mapping|memory|new|payable|public|pragma|' + r'private|return|returns|storage|super|this|throw|using|while)\b', Keyword, 'slashstartsregex'), + (r'(var|function|event|modifier|struct|enum|contract|library)\b', Keyword.Declaration, 'slashstartsregex'), (r'(bytes|string|address|uint|int|bool|byte|' + '|'.join( ['uint%d' % (i + 8) for i in range(0, 256, 8)] + @@ -68,16 +67,11 @@ class SolidityLexer(RegexLexer): ['fixed%dx%d' % ((i), (j + 8)) for i in range(0, 256, 8) for j in range(0, 256 - i, 8)] ) + r')\b', Keyword.Type, 'slashstartsregex'), (r'(wei|szabo|finney|ether|seconds|minutes|hours|days|weeks|years)\b', Keyword.Type, 'slashstartsregex'), - (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' - r'extends|final|float|goto|implements|int|interface|long|native|' - r'package|private|protected|public|short|static|super|synchronized|throws|' - r'transient|volatile)\b', Keyword.Reserved), - (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), - (r'(Array|Boolean|Date|Error|Function|Math|netscape|' - r'Number|Object|Packages|RegExp|String|sun|decodeURI|' - r'decodeURIComponent|encodeURI|encodeURIComponent|' - r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' - r'window)\b', Name.Builtin), + (r'(abstract|after|case|catch|default|final|in|inline|interface|let|match|' + r'null|of|pure|relocatable|static|switch|try|type|typeof|view)\b', Keyword.Reserved), + (r'(true|false)\b', Keyword.Constant), + (r'(block|msg|tx|now|suicide|selfdestruct|addmod|mulmod|sha3|keccak256|log[0-4]|' + r'sha256|ecrecover|ripemd160|assert|revert)', Name.Builtin), (r'[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other), (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), (r'0x[0-9a-fA-F]+', Number.Hex), From fc8e50f688bad9c13259fc926142b838d7aba5d3 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 27 Jan 2017 18:27:59 +0100 Subject: [PATCH 107/234] Refactor NameAndTypeResolver and SyntaxChecker to allow other entry points. --- libsolidity/analysis/NameAndTypeResolver.cpp | 106 +++++++++--------- libsolidity/analysis/NameAndTypeResolver.h | 9 +- libsolidity/analysis/ReferencesResolver.cpp | 27 ++++- libsolidity/analysis/ReferencesResolver.h | 9 +- libsolidity/analysis/SyntaxChecker.cpp | 4 +- libsolidity/analysis/SyntaxChecker.h | 2 +- .../SolidityNameAndTypeResolution.cpp | 2 +- 7 files changed, 92 insertions(+), 67 deletions(-) diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp index b0a82715d..2791fed7e 100644 --- a/libsolidity/analysis/NameAndTypeResolver.cpp +++ b/libsolidity/analysis/NameAndTypeResolver.cpp @@ -132,68 +132,64 @@ bool NameAndTypeResolver::performImports(SourceUnit& _sourceUnit, map const& baseContract: _contract.baseContracts()) - if (!resolver.resolve(*baseContract)) - success = false; - - m_currentScope = m_scopes[&_contract].get(); - - if (success) + if (ContractDefinition* contract = dynamic_cast(&_node)) { - linearizeBaseContracts(_contract); - vector properBases( - ++_contract.annotation().linearizedBaseContracts.begin(), - _contract.annotation().linearizedBaseContracts.end() - ); + m_currentScope = m_scopes[contract->scope()].get(); + solAssert(!!m_currentScope, ""); - for (ContractDefinition const* base: properBases) - importInheritedScope(*base); + for (ASTPointer const& baseContract: contract->baseContracts()) + if (!resolveNamesAndTypes(*baseContract, false)) + success = false; + + m_currentScope = m_scopes[contract].get(); + + if (success) + { + linearizeBaseContracts(*contract); + vector properBases( + ++contract->annotation().linearizedBaseContracts.begin(), + contract->annotation().linearizedBaseContracts.end() + ); + + for (ContractDefinition const* base: properBases) + importInheritedScope(*base); + } + + // these can contain code, only resolve parameters for now + for (ASTPointer const& node: contract->subNodes()) + { + m_currentScope = m_scopes[contract].get(); + if (!resolveNamesAndTypes(*node, false)) + success = false; + } + + if (!success) + return false; + + if (!_resolveInsideCode) + return success; + + m_currentScope = m_scopes[contract].get(); + + // now resolve references inside the code + for (ASTPointer const& node: contract->subNodes()) + { + m_currentScope = m_scopes[contract].get(); + if (!resolveNamesAndTypes(*node, true)) + success = false; + } } - - // these can contain code, only resolve parameters for now - for (ASTPointer const& node: _contract.subNodes()) + else { - m_currentScope = m_scopes[m_scopes.count(node.get()) ? node.get() : &_contract].get(); - if (!resolver.resolve(*node)) - success = false; + if (m_scopes.count(&_node)) + m_currentScope = m_scopes[&_node].get(); + return ReferencesResolver(m_errors, *this, _resolveInsideCode).resolve(_node); } - - if (!success) - return false; - - m_currentScope = m_scopes[&_contract].get(); - - // now resolve references inside the code - for (ModifierDefinition const* modifier: _contract.functionModifiers()) - { - m_currentScope = m_scopes[modifier].get(); - ReferencesResolver resolver(m_errors, *this, nullptr, true); - if (!resolver.resolve(*modifier)) - success = false; - } - - for (FunctionDefinition const* function: _contract.definedFunctions()) - { - m_currentScope = m_scopes[function].get(); - if (!ReferencesResolver( - m_errors, - *this, - function->returnParameterList().get(), - true - ).resolve(*function)) - success = false; - } - if (!success) - return false; } catch (FatalError const&) { @@ -201,7 +197,7 @@ bool NameAndTypeResolver::resolveNamesAndTypes(ContractDefinition& _contract) throw; // Something is weird here, rather throw again. return false; } - return true; + return success; } bool NameAndTypeResolver::updateDeclaration(Declaration const& _declaration) diff --git a/libsolidity/analysis/NameAndTypeResolver.h b/libsolidity/analysis/NameAndTypeResolver.h index 68c3ffa1d..fb018d749 100644 --- a/libsolidity/analysis/NameAndTypeResolver.h +++ b/libsolidity/analysis/NameAndTypeResolver.h @@ -48,9 +48,12 @@ public: bool registerDeclarations(SourceUnit& _sourceUnit); /// Applies the effect of import directives. bool performImports(SourceUnit& _sourceUnit, std::map const& _sourceUnits); - /// Resolves all names and types referenced from the given contract. + /// Resolves all names and types referenced from the given AST Node. + /// This is usually only called at the contract level, but with a bit of care, it can also + /// be called at deeper levels. + /// @param _avoidCode if false, does not descend into nodes that contain code. /// @returns false in case of error. - bool resolveNamesAndTypes(ContractDefinition& _contract); + bool resolveNamesAndTypes(ASTNode& _node, bool _resolveInsideCode = true); /// Updates the given global declaration (used for "this"). Not to be used with declarations /// that create their own scope. /// @returns false in case of error. @@ -77,8 +80,6 @@ public: ); private: - void reset(); - /// Imports all members declared directly in the given contract (i.e. does not import inherited members) /// into the current scope if they are not present already. void importInheritedScope(ContractDefinition const& _base); diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp index d589f4a0a..c06181d89 100644 --- a/libsolidity/analysis/ReferencesResolver.cpp +++ b/libsolidity/analysis/ReferencesResolver.cpp @@ -65,6 +65,30 @@ bool ReferencesResolver::visit(ElementaryTypeName const& _typeName) return true; } +bool ReferencesResolver::visit(FunctionDefinition const& _functionDefinition) +{ + m_returnParameters.push_back(_functionDefinition.returnParameterList().get()); + return true; +} + +void ReferencesResolver::endVisit(FunctionDefinition const&) +{ + solAssert(!m_returnParameters.empty(), ""); + m_returnParameters.pop_back(); +} + +bool ReferencesResolver::visit(ModifierDefinition const&) +{ + m_returnParameters.push_back(nullptr); + return true; +} + +void ReferencesResolver::endVisit(ModifierDefinition const&) +{ + solAssert(!m_returnParameters.empty(), ""); + m_returnParameters.pop_back(); +} + void ReferencesResolver::endVisit(UserDefinedTypeName const& _typeName) { Declaration const* declaration = m_resolver.pathFromCurrentScope(_typeName.namePath()); @@ -161,7 +185,8 @@ bool ReferencesResolver::visit(InlineAssembly const& _inlineAssembly) bool ReferencesResolver::visit(Return const& _return) { - _return.annotation().functionReturnParameters = m_returnParameters; + solAssert(!m_returnParameters.empty(), ""); + _return.annotation().functionReturnParameters = m_returnParameters.back(); return true; } diff --git a/libsolidity/analysis/ReferencesResolver.h b/libsolidity/analysis/ReferencesResolver.h index caa3a78fc..23ac6b07c 100644 --- a/libsolidity/analysis/ReferencesResolver.h +++ b/libsolidity/analysis/ReferencesResolver.h @@ -45,12 +45,10 @@ public: ReferencesResolver( ErrorList& _errors, NameAndTypeResolver& _resolver, - ParameterList const* _returnParameters, bool _resolveInsideCode = false ): m_errors(_errors), m_resolver(_resolver), - m_returnParameters(_returnParameters), m_resolveInsideCode(_resolveInsideCode) {} @@ -61,6 +59,10 @@ private: virtual bool visit(Block const&) override { return m_resolveInsideCode; } virtual bool visit(Identifier const& _identifier) override; virtual bool visit(ElementaryTypeName const& _typeName) override; + virtual bool visit(FunctionDefinition const& _functionDefinition) override; + virtual void endVisit(FunctionDefinition const& _functionDefinition) override; + virtual bool visit(ModifierDefinition const& _modifierDefinition) override; + virtual void endVisit(ModifierDefinition const& _modifierDefinition) override; virtual void endVisit(UserDefinedTypeName const& _typeName) override; virtual void endVisit(FunctionTypeName const& _typeName) override; virtual void endVisit(Mapping const& _typeName) override; @@ -83,7 +85,8 @@ private: ErrorList& m_errors; NameAndTypeResolver& m_resolver; - ParameterList const* m_returnParameters; + /// Stack of return parameters. + std::vector m_returnParameters; bool const m_resolveInsideCode; bool m_errorOccurred = false; }; diff --git a/libsolidity/analysis/SyntaxChecker.cpp b/libsolidity/analysis/SyntaxChecker.cpp index 0a4943fe4..890141335 100644 --- a/libsolidity/analysis/SyntaxChecker.cpp +++ b/libsolidity/analysis/SyntaxChecker.cpp @@ -26,9 +26,9 @@ using namespace dev; using namespace dev::solidity; -bool SyntaxChecker::checkSyntax(SourceUnit const& _sourceUnit) +bool SyntaxChecker::checkSyntax(ASTNode const& _astRoot) { - _sourceUnit.accept(*this); + _astRoot.accept(*this); return Error::containsOnlyWarnings(m_errors); } diff --git a/libsolidity/analysis/SyntaxChecker.h b/libsolidity/analysis/SyntaxChecker.h index c24bae092..308e128b5 100644 --- a/libsolidity/analysis/SyntaxChecker.h +++ b/libsolidity/analysis/SyntaxChecker.h @@ -39,7 +39,7 @@ public: /// @param _errors the reference to the list of errors and warnings to add them found during type checking. SyntaxChecker(ErrorList& _errors): m_errors(_errors) {} - bool checkSyntax(SourceUnit const& _sourceUnit); + bool checkSyntax(ASTNode const& _astRoot); private: /// Adds a new error to the list of errors. diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 0151d244a..29856d317 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1080,7 +1080,7 @@ BOOST_AUTO_TEST_CASE(modifier_returns_value) modifier mod(uint a) { _; return 7; } } )"; - CHECK_ERROR(text, TypeError, ""); + CHECK_ERROR(text, TypeError, "Return arguments not allowed."); } BOOST_AUTO_TEST_CASE(state_variable_accessors) From c87bafd2ede044361ff7ca849a14298e97bd8318 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 27 Jan 2017 23:29:03 +0100 Subject: [PATCH 108/234] Refactor type system to allow multiple entry points. --- libsolidity/analysis/NameAndTypeResolver.cpp | 30 +++++++++++++------- libsolidity/analysis/NameAndTypeResolver.h | 6 ++-- libsolidity/analysis/TypeChecker.cpp | 4 +-- libsolidity/analysis/TypeChecker.h | 2 +- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp index 2791fed7e..5fea91d6e 100644 --- a/libsolidity/analysis/NameAndTypeResolver.cpp +++ b/libsolidity/analysis/NameAndTypeResolver.cpp @@ -44,18 +44,12 @@ NameAndTypeResolver::NameAndTypeResolver( m_scopes[nullptr]->registerDeclaration(*declaration); } -bool NameAndTypeResolver::registerDeclarations(SourceUnit& _sourceUnit) +bool NameAndTypeResolver::registerDeclarations(ASTNode& _sourceUnit) { - if (!m_scopes[&_sourceUnit]) - // By importing, it is possible that the container already exists. - m_scopes[&_sourceUnit].reset(new DeclarationContainer(nullptr, m_scopes[nullptr].get())); - m_currentScope = m_scopes[&_sourceUnit].get(); - // The helper registers all declarations in m_scopes as a side-effect of its construction. try { DeclarationRegistrationHelper registrar(m_scopes, _sourceUnit, m_errors); - _sourceUnit.annotation().exportedSymbols = m_scopes[&_sourceUnit]->declarations(); } catch (FatalError const&) { @@ -458,11 +452,26 @@ DeclarationRegistrationHelper::DeclarationRegistrationHelper( ErrorList& _errors ): m_scopes(_scopes), - m_currentScope(&_astRoot), + m_currentScope(nullptr), m_errors(_errors) { - solAssert(!!m_scopes.at(m_currentScope), ""); _astRoot.accept(*this); + solAssert(m_currentScope == nullptr, "Scopes not correctly closed."); +} + +bool DeclarationRegistrationHelper::visit(SourceUnit& _sourceUnit) +{ + if (!m_scopes[&_sourceUnit]) + // By importing, it is possible that the container already exists. + m_scopes[&_sourceUnit].reset(new DeclarationContainer(nullptr, m_scopes[nullptr].get())); + m_currentScope = &_sourceUnit; + return true; +} + +void DeclarationRegistrationHelper::endVisit(SourceUnit& _sourceUnit) +{ + _sourceUnit.annotation().exportedSymbols = m_scopes[&_sourceUnit]->declarations(); + closeCurrentScope(); } bool DeclarationRegistrationHelper::visit(ImportDirective& _import) @@ -583,12 +592,13 @@ void DeclarationRegistrationHelper::enterNewSubScope(Declaration const& _declara void DeclarationRegistrationHelper::closeCurrentScope() { - solAssert(m_currentScope, "Closed non-existing scope."); + solAssert(m_currentScope && m_scopes.count(m_currentScope), "Closed non-existing scope."); m_currentScope = m_scopes[m_currentScope]->enclosingNode(); } void DeclarationRegistrationHelper::registerDeclaration(Declaration& _declaration, bool _opensScope) { + solAssert(m_currentScope && m_scopes.count(m_currentScope), "No current scope."); if (!m_scopes[m_currentScope]->registerDeclaration(_declaration, nullptr, !_declaration.isVisibleInContract())) { SourceLocation firstDeclarationLocation; diff --git a/libsolidity/analysis/NameAndTypeResolver.h b/libsolidity/analysis/NameAndTypeResolver.h index fb018d749..67a6c0e4b 100644 --- a/libsolidity/analysis/NameAndTypeResolver.h +++ b/libsolidity/analysis/NameAndTypeResolver.h @@ -43,9 +43,9 @@ class NameAndTypeResolver: private boost::noncopyable { public: NameAndTypeResolver(std::vector const& _globals, ErrorList& _errors); - /// Registers all declarations found in the source unit. + /// Registers all declarations found in the AST node, usually a source unit. /// @returns false in case of error. - bool registerDeclarations(SourceUnit& _sourceUnit); + bool registerDeclarations(ASTNode& _sourceUnit); /// Applies the effect of import directives. bool performImports(SourceUnit& _sourceUnit, std::map const& _sourceUnits); /// Resolves all names and types referenced from the given AST Node. @@ -133,6 +133,8 @@ public: ); private: + bool visit(SourceUnit& _sourceUnit) override; + void endVisit(SourceUnit& _sourceUnit) override; bool visit(ImportDirective& _declaration) override; bool visit(ContractDefinition& _contract) override; void endVisit(ContractDefinition& _contract) override; diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 533c787b7..be59d3d26 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -32,11 +32,11 @@ using namespace dev; using namespace dev::solidity; -bool TypeChecker::checkTypeRequirements(ContractDefinition const& _contract) +bool TypeChecker::checkTypeRequirements(ASTNode const& _contract) { try { - visit(_contract); + _contract.accept(*this); } catch (FatalError const&) { diff --git a/libsolidity/analysis/TypeChecker.h b/libsolidity/analysis/TypeChecker.h index 143b15b26..46d8230ab 100644 --- a/libsolidity/analysis/TypeChecker.h +++ b/libsolidity/analysis/TypeChecker.h @@ -47,7 +47,7 @@ public: /// Performs type checking on the given contract and all of its sub-nodes. /// @returns true iff all checks passed. Note even if all checks passed, errors() can still contain warnings - bool checkTypeRequirements(ContractDefinition const& _contract); + bool checkTypeRequirements(ASTNode const& _contract); /// @returns the type of an expression and asserts that it is present. TypePointer const& type(Expression const& _expression) const; From e67faa9839ebd0dadef2adf3ed1ef69fac6f65e1 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 31 Jan 2017 22:59:56 +0100 Subject: [PATCH 109/234] Extract scopes into compiler stack. --- libsolidity/analysis/NameAndTypeResolver.cpp | 2 ++ libsolidity/analysis/NameAndTypeResolver.h | 8 ++++++-- libsolidity/interface/CompilerStack.cpp | 3 ++- libsolidity/interface/CompilerStack.h | 3 +++ test/libsolidity/Assembly.cpp | 3 ++- test/libsolidity/SolidityExpressionCompiler.cpp | 3 ++- test/libsolidity/SolidityNameAndTypeResolution.cpp | 3 ++- 7 files changed, 19 insertions(+), 6 deletions(-) diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp index 5fea91d6e..ed1bd1d30 100644 --- a/libsolidity/analysis/NameAndTypeResolver.cpp +++ b/libsolidity/analysis/NameAndTypeResolver.cpp @@ -34,8 +34,10 @@ namespace solidity NameAndTypeResolver::NameAndTypeResolver( vector const& _globals, + map>& _scopes, ErrorList& _errors ) : + m_scopes(_scopes), m_errors(_errors) { if (!m_scopes[nullptr]) diff --git a/libsolidity/analysis/NameAndTypeResolver.h b/libsolidity/analysis/NameAndTypeResolver.h index 67a6c0e4b..1c7af0c92 100644 --- a/libsolidity/analysis/NameAndTypeResolver.h +++ b/libsolidity/analysis/NameAndTypeResolver.h @@ -42,7 +42,11 @@ namespace solidity class NameAndTypeResolver: private boost::noncopyable { public: - NameAndTypeResolver(std::vector const& _globals, ErrorList& _errors); + NameAndTypeResolver( + std::vector const& _globals, + std::map>& _scopes, + ErrorList& _errors + ); /// Registers all declarations found in the AST node, usually a source unit. /// @returns false in case of error. bool registerDeclarations(ASTNode& _sourceUnit); @@ -113,7 +117,7 @@ private: /// where nullptr denotes the global scope. Note that structs are not scope since they do /// not contain code. /// Aliases (for example `import "x" as y;`) create multiple pointers to the same scope. - std::map> m_scopes; + std::map>& m_scopes; DeclarationContainer* m_currentScope = nullptr; ErrorList& m_errors; diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 3335c40e4..9d8d872f4 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -88,6 +88,7 @@ void CompilerStack::reset(bool _keepSources) m_optimize = false; m_optimizeRuns = 200; m_globalContext.reset(); + m_scopes.clear(); m_sourceOrder.clear(); m_contracts.clear(); m_errors.clear(); @@ -165,7 +166,7 @@ bool CompilerStack::parse() noErrors = false; m_globalContext = make_shared(); - NameAndTypeResolver resolver(m_globalContext->declarations(), m_errors); + NameAndTypeResolver resolver(m_globalContext->declarations(), m_scopes, m_errors); for (Source const* source: m_sourceOrder) if (!resolver.registerDeclarations(*source->ast)) return false; diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index 9ee70215e..eddfea685 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -52,6 +52,7 @@ namespace solidity // forward declarations class Scanner; +class ASTNode; class ContractDefinition; class FunctionDefinition; class SourceUnit; @@ -59,6 +60,7 @@ class Compiler; class GlobalContext; class InterfaceHandler; class Error; +class DeclarationContainer; enum class DocumentationType: uint8_t { @@ -271,6 +273,7 @@ private: bool m_parseSuccessful; std::map m_sources; std::shared_ptr m_globalContext; + std::map> m_scopes; std::vector m_sourceOrder; std::map m_contracts; std::string m_formalTranslation; diff --git a/test/libsolidity/Assembly.cpp b/test/libsolidity/Assembly.cpp index 497bfc777..c4ec0d202 100644 --- a/test/libsolidity/Assembly.cpp +++ b/test/libsolidity/Assembly.cpp @@ -53,7 +53,8 @@ eth::AssemblyItems compileContract(const string& _sourceCode) BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared(CharStream(_sourceCode)))); BOOST_CHECK(!!sourceUnit); - NameAndTypeResolver resolver({}, errors); + map> scopes; + NameAndTypeResolver resolver({}, scopes, errors); solAssert(Error::containsOnlyWarnings(errors), ""); resolver.registerDeclarations(*sourceUnit); for (ASTPointer const& node: sourceUnit->nodes()) diff --git a/test/libsolidity/SolidityExpressionCompiler.cpp b/test/libsolidity/SolidityExpressionCompiler.cpp index a769776e9..3116aea8c 100644 --- a/test/libsolidity/SolidityExpressionCompiler.cpp +++ b/test/libsolidity/SolidityExpressionCompiler.cpp @@ -114,7 +114,8 @@ bytes compileFirstExpression( declarations.push_back(variable.get()); ErrorList errors; - NameAndTypeResolver resolver(declarations, errors); + map> scopes; + NameAndTypeResolver resolver(declarations, scopes, errors); resolver.registerDeclarations(*sourceUnit); vector inheritanceHierarchy; diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 29856d317..1a4f3cdc9 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -66,7 +66,8 @@ parseAnalyseAndReturnError(string const& _source, bool _reportWarnings = false, return make_pair(sourceUnit, errors.at(0)); std::shared_ptr globalContext = make_shared(); - NameAndTypeResolver resolver(globalContext->declarations(), errors); + map> scopes; + NameAndTypeResolver resolver(globalContext->declarations(), scopes, errors); solAssert(Error::containsOnlyWarnings(errors), ""); resolver.registerDeclarations(*sourceUnit); From b1bb228ab3a8ca0548ed5f08fdc5fda1fcb71b1a Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 31 Jan 2017 23:12:40 +0100 Subject: [PATCH 110/234] Allow different entry scope for registerDeclarations. --- libsolidity/analysis/NameAndTypeResolver.cpp | 13 +++++++------ libsolidity/analysis/NameAndTypeResolver.h | 11 +++++++++-- libsolidity/analysis/TypeChecker.cpp | 7 ++++++- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp index ed1bd1d30..fd6fc0587 100644 --- a/libsolidity/analysis/NameAndTypeResolver.cpp +++ b/libsolidity/analysis/NameAndTypeResolver.cpp @@ -46,12 +46,12 @@ NameAndTypeResolver::NameAndTypeResolver( m_scopes[nullptr]->registerDeclaration(*declaration); } -bool NameAndTypeResolver::registerDeclarations(ASTNode& _sourceUnit) +bool NameAndTypeResolver::registerDeclarations(ASTNode& _sourceUnit, ASTNode const* _currentScope) { // The helper registers all declarations in m_scopes as a side-effect of its construction. try { - DeclarationRegistrationHelper registrar(m_scopes, _sourceUnit, m_errors); + DeclarationRegistrationHelper registrar(m_scopes, _sourceUnit, m_errors, _currentScope); } catch (FatalError const&) { @@ -451,21 +451,22 @@ void NameAndTypeResolver::reportFatalTypeError(Error const& _e) DeclarationRegistrationHelper::DeclarationRegistrationHelper( map>& _scopes, ASTNode& _astRoot, - ErrorList& _errors + ErrorList& _errors, + ASTNode const* _currentScope ): m_scopes(_scopes), - m_currentScope(nullptr), + m_currentScope(_currentScope), m_errors(_errors) { _astRoot.accept(*this); - solAssert(m_currentScope == nullptr, "Scopes not correctly closed."); + solAssert(m_currentScope == _currentScope, "Scopes not correctly closed."); } bool DeclarationRegistrationHelper::visit(SourceUnit& _sourceUnit) { if (!m_scopes[&_sourceUnit]) // By importing, it is possible that the container already exists. - m_scopes[&_sourceUnit].reset(new DeclarationContainer(nullptr, m_scopes[nullptr].get())); + m_scopes[&_sourceUnit].reset(new DeclarationContainer(m_currentScope, m_scopes[m_currentScope].get())); m_currentScope = &_sourceUnit; return true; } diff --git a/libsolidity/analysis/NameAndTypeResolver.h b/libsolidity/analysis/NameAndTypeResolver.h index 1c7af0c92..4de40e87a 100644 --- a/libsolidity/analysis/NameAndTypeResolver.h +++ b/libsolidity/analysis/NameAndTypeResolver.h @@ -49,7 +49,9 @@ public: ); /// Registers all declarations found in the AST node, usually a source unit. /// @returns false in case of error. - bool registerDeclarations(ASTNode& _sourceUnit); + /// @param _currentScope should be nullptr but can be used to inject new declarations into + /// existing scopes, used by the snippets feature. + bool registerDeclarations(ASTNode& _sourceUnit, ASTNode const* _currentScope = nullptr); /// Applies the effect of import directives. bool performImports(SourceUnit& _sourceUnit, std::map const& _sourceUnits); /// Resolves all names and types referenced from the given AST Node. @@ -130,10 +132,15 @@ private: class DeclarationRegistrationHelper: private ASTVisitor { public: + /// Registers declarations in their scopes and creates new scopes as a side-effect + /// of construction. + /// @param _currentScope should be nullptr if we start at SourceUnit, but can be different + /// to inject new declarations into an existing scope, used by snippets. DeclarationRegistrationHelper( std::map>& _scopes, ASTNode& _astRoot, - ErrorList& _errors + ErrorList& _errors, + ASTNode const* _currentScope = nullptr ); private: diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index be59d3d26..06a9e1cea 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -427,7 +427,12 @@ bool TypeChecker::visit(StructDefinition const& _struct) bool TypeChecker::visit(FunctionDefinition const& _function) { - bool isLibraryFunction = dynamic_cast(*_function.scope()).isLibrary(); + bool isLibraryFunction = false; + if ( + dynamic_cast(_function.scope()) && + dynamic_cast(_function.scope())->isLibrary() + ) + isLibraryFunction = true; if (_function.isPayable()) { if (isLibraryFunction) From a791ec75e2e73130afee391958651453acc8d781 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 14 Feb 2017 13:32:48 +0100 Subject: [PATCH 111/234] Review comments. --- libsolidity/analysis/NameAndTypeResolver.cpp | 2 +- libsolidity/analysis/NameAndTypeResolver.h | 5 ++++- libsolidity/analysis/TypeChecker.cpp | 7 ++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp index fd6fc0587..013842602 100644 --- a/libsolidity/analysis/NameAndTypeResolver.cpp +++ b/libsolidity/analysis/NameAndTypeResolver.cpp @@ -139,7 +139,7 @@ bool NameAndTypeResolver::resolveNamesAndTypes(ASTNode& _node, bool _resolveInsi solAssert(!!m_currentScope, ""); for (ASTPointer const& baseContract: contract->baseContracts()) - if (!resolveNamesAndTypes(*baseContract, false)) + if (!resolveNamesAndTypes(*baseContract, true)) success = false; m_currentScope = m_scopes[contract].get(); diff --git a/libsolidity/analysis/NameAndTypeResolver.h b/libsolidity/analysis/NameAndTypeResolver.h index 4de40e87a..828b566fc 100644 --- a/libsolidity/analysis/NameAndTypeResolver.h +++ b/libsolidity/analysis/NameAndTypeResolver.h @@ -42,6 +42,9 @@ namespace solidity class NameAndTypeResolver: private boost::noncopyable { public: + /// Creates the resolver with the given declarations added to the global scope. + /// @param _scopes mapping of scopes to be used (usually default constructed), these + /// are filled during the lifetime of this object. NameAndTypeResolver( std::vector const& _globals, std::map>& _scopes, @@ -57,7 +60,7 @@ public: /// Resolves all names and types referenced from the given AST Node. /// This is usually only called at the contract level, but with a bit of care, it can also /// be called at deeper levels. - /// @param _avoidCode if false, does not descend into nodes that contain code. + /// @param _resolveInsideCode if false, does not descend into nodes that contain code. /// @returns false in case of error. bool resolveNamesAndTypes(ASTNode& _node, bool _resolveInsideCode = true); /// Updates the given global declaration (used for "this"). Not to be used with declarations diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 06a9e1cea..28cb9acc3 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -427,12 +427,9 @@ bool TypeChecker::visit(StructDefinition const& _struct) bool TypeChecker::visit(FunctionDefinition const& _function) { - bool isLibraryFunction = false; - if ( + bool isLibraryFunction = dynamic_cast(_function.scope()) && - dynamic_cast(_function.scope())->isLibrary() - ) - isLibraryFunction = true; + dynamic_cast(_function.scope())->isLibrary(); if (_function.isPayable()) { if (isLibraryFunction) From eeaa2bad955a86436a8bfcf8cf33ff9dc5495ca6 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 8 Feb 2017 13:56:23 +0100 Subject: [PATCH 112/234] Kill the right eth process in tests --- scripts/tests.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/tests.sh b/scripts/tests.sh index 88815f5f6..d47edd28d 100755 --- a/scripts/tests.sh +++ b/scripts/tests.sh @@ -52,6 +52,7 @@ fi # true and continue as normal, either processing further commands in a script # or returning the cursor focus back to the user in a Linux terminal. $ETH_PATH --test -d /tmp/test & +ETH_PID=$! # Wait until the IPC endpoint is available. That won't be available instantly. # The node needs to get a little way into its startup sequence before the IPC @@ -66,7 +67,7 @@ echo "--> Running tests without optimizer..." echo "--> Running tests WITH optimizer..." && \ "$REPO_ROOT"/build/test/soltest --show-progress -- --optimize --ipcpath /tmp/test/geth.ipc ERROR_CODE=$? -pkill eth || true +pkill "$ETH_PID" || true sleep 4 -pgrep eth && pkill -9 eth || true -exit $ERROR_CODE \ No newline at end of file +pgrep "$ETH_PID" && pkill -9 "$ETH_PID" || true +exit $ERROR_CODE From 80f72437864301562b485cb380eddcea5e6e575f Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 9 Feb 2017 14:04:23 +0100 Subject: [PATCH 113/234] Assembly printer. --- libsolidity/inlineasm/AsmPrinter.cpp | 125 +++++++++++++++++++++++++++ libsolidity/inlineasm/AsmPrinter.h | 61 +++++++++++++ libsolidity/inlineasm/AsmStack.cpp | 18 +++- libsolidity/inlineasm/AsmStack.h | 4 + 4 files changed, 204 insertions(+), 4 deletions(-) create mode 100644 libsolidity/inlineasm/AsmPrinter.cpp create mode 100644 libsolidity/inlineasm/AsmPrinter.h diff --git a/libsolidity/inlineasm/AsmPrinter.cpp b/libsolidity/inlineasm/AsmPrinter.cpp new file mode 100644 index 000000000..d829a4162 --- /dev/null +++ b/libsolidity/inlineasm/AsmPrinter.cpp @@ -0,0 +1,125 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see . +*/ +/** + * @author Christian + * @date 2017 + * Converts a parsed assembly into its textual form. + */ + +#include + +#include + +#include +#include +#include + +#include +#include + +using namespace std; +using namespace dev; +using namespace dev::solidity; +using namespace dev::solidity::assembly; + +//@TODO source locations + +string AsmPrinter::operator()(assembly::Instruction const& _instruction) +{ + return boost::to_lower_copy(instructionInfo(_instruction.instruction).name); +} + +string AsmPrinter::operator()(assembly::Literal const& _literal) +{ + if (_literal.isNumber) + return _literal.value; + string out; + for (char c: _literal.value) + if (c == '\\') + out += "\\\\"; + else if (c == '"') + out += "\\"; + else if (c == '\'') + out += "\\'"; + else if (c == '\b') + out += "\\b"; + else if (c == '\f') + out += "\\f"; + else if (c == '\n') + out += "\\n"; + else if (c == '\r') + out += "\\r"; + else if (c == '\t') + out += "\\t"; + else if (c == '\v') + out += "\\v"; + else if (!isprint(c, locale::classic())) + { + ostringstream o; + o << std::hex << setfill('0') << setw(2) << unsigned(c); + out += "0x" + o.str(); + } + else + out += c; + return out; +} + +string AsmPrinter::operator()(assembly::Identifier const& _identifier) +{ + return _identifier.name; +} + +string AsmPrinter::operator()(assembly::FunctionalInstruction const& _functionalInstruction) +{ + return + (*this)(_functionalInstruction.instruction); + + "(" + + boost::algorithm::join( + _functionalInstruction.arguments | boost::adaptors::transformed(boost::apply_visitor(*this)), + ", " ) + + ")"; +} + +string AsmPrinter::operator()(assembly::Label const& _label) +{ + return _label.name + ":"; +} + +string AsmPrinter::operator()(assembly::Assignment const& _assignment) +{ + return "=: " + (*this)(_assignment.variableName); +} + +string AsmPrinter::operator()(assembly::FunctionalAssignment const& _functionalAssignment) +{ + return (*this)(_functionalAssignment.variableName) + " := " + boost::apply_visitor(*this, *_functionalAssignment.value); +} + +string AsmPrinter::operator()(assembly::VariableDeclaration const& _variableDeclaration) +{ + return "let " + _variableDeclaration.name + " := " + boost::apply_visitor(*this, *_variableDeclaration.value); +} + +string AsmPrinter::operator()(Block const& _block) +{ + string body = boost::algorithm::join( + _block.statements | boost::adaptors::transformed(boost::apply_visitor(*this)), + "\n" + ); + boost::replace_all(body, "\n", "\n "); + return "{\n " + body + "\n}"; +} diff --git a/libsolidity/inlineasm/AsmPrinter.h b/libsolidity/inlineasm/AsmPrinter.h new file mode 100644 index 000000000..39069d021 --- /dev/null +++ b/libsolidity/inlineasm/AsmPrinter.h @@ -0,0 +1,61 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see . +*/ +/** + * @author Christian + * @date 2017 + * Converts a parsed assembly into its textual form. + */ + +#pragma once + +#include + +namespace dev +{ +namespace solidity +{ +namespace assembly +{ +struct Instruction; +struct Literal; +struct Identifier; +struct FunctionalInstruction; +struct Label; +struct Assignment; +struct FunctionalAssignment; +struct VariableDeclaration; +struct FunctionDefinition; +struct FunctionCall; +struct Block; + +class AsmPrinter: public boost::static_visitor +{ +public: + std::string operator()(assembly::Instruction const& _instruction); + std::string operator()(assembly::Literal const& _literal); + std::string operator()(assembly::Identifier const& _identifier); + std::string operator()(assembly::FunctionalInstruction const& _functionalInstruction); + std::string operator()(assembly::Label const& _label); + std::string operator()(assembly::Assignment const& _assignment); + std::string operator()(assembly::FunctionalAssignment const& _functionalAssignment); + std::string operator()(assembly::VariableDeclaration const& _variableDeclaration); + std::string operator()(assembly::Block const& _block); +}; + +} +} +} diff --git a/libsolidity/inlineasm/AsmStack.cpp b/libsolidity/inlineasm/AsmStack.cpp index b8e0e8572..6539e9bce 100644 --- a/libsolidity/inlineasm/AsmStack.cpp +++ b/libsolidity/inlineasm/AsmStack.cpp @@ -21,12 +21,17 @@ */ #include -#include -#include -#include -#include + #include #include +#include + +#include + +#include +#include + +#include using namespace std; using namespace dev; @@ -44,6 +49,11 @@ bool InlineAssemblyStack::parse(shared_ptr const& _scanner) return true; } +string InlineAssemblyStack::print() +{ + return AsmPrinter()(*m_parserResult); +} + eth::Assembly InlineAssemblyStack::assemble() { CodeGenerator codeGen(*m_parserResult, m_errors); diff --git a/libsolidity/inlineasm/AsmStack.h b/libsolidity/inlineasm/AsmStack.h index 1543cb2a5..71d6c7717 100644 --- a/libsolidity/inlineasm/AsmStack.h +++ b/libsolidity/inlineasm/AsmStack.h @@ -46,6 +46,10 @@ public: /// Parse the given inline assembly chunk starting with `{` and ending with the corresponding `}`. /// @return false or error. bool parse(std::shared_ptr const& _scanner); + /// Converts the parser result back into a string form (not necessarily the same form + /// as the source form, but it should parse into the same parsed form again). + std::string print(); + eth::Assembly assemble(); /// Parse and assemble a string in one run - for use in Solidity code generation itself. From ca71b7624db6c731670ddf69873dd9f0c8c6ccd2 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 14 Feb 2017 13:59:15 +0100 Subject: [PATCH 114/234] Review changes. --- libsolidity/inlineasm/AsmPrinter.cpp | 4 ++-- libsolidity/inlineasm/AsmStack.cpp | 2 +- libsolidity/inlineasm/AsmStack.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libsolidity/inlineasm/AsmPrinter.cpp b/libsolidity/inlineasm/AsmPrinter.cpp index d829a4162..66cf39c01 100644 --- a/libsolidity/inlineasm/AsmPrinter.cpp +++ b/libsolidity/inlineasm/AsmPrinter.cpp @@ -71,11 +71,11 @@ string AsmPrinter::operator()(assembly::Literal const& _literal) { ostringstream o; o << std::hex << setfill('0') << setw(2) << unsigned(c); - out += "0x" + o.str(); + out += "\\x" + o.str(); } else out += c; - return out; + return "\"" + out + "\""; } string AsmPrinter::operator()(assembly::Identifier const& _identifier) diff --git a/libsolidity/inlineasm/AsmStack.cpp b/libsolidity/inlineasm/AsmStack.cpp index 6539e9bce..38d688c13 100644 --- a/libsolidity/inlineasm/AsmStack.cpp +++ b/libsolidity/inlineasm/AsmStack.cpp @@ -49,7 +49,7 @@ bool InlineAssemblyStack::parse(shared_ptr const& _scanner) return true; } -string InlineAssemblyStack::print() +string InlineAssemblyStack::toString() { return AsmPrinter()(*m_parserResult); } diff --git a/libsolidity/inlineasm/AsmStack.h b/libsolidity/inlineasm/AsmStack.h index 71d6c7717..4d5a99a4b 100644 --- a/libsolidity/inlineasm/AsmStack.h +++ b/libsolidity/inlineasm/AsmStack.h @@ -48,7 +48,7 @@ public: bool parse(std::shared_ptr const& _scanner); /// Converts the parser result back into a string form (not necessarily the same form /// as the source form, but it should parse into the same parsed form again). - std::string print(); + std::string toString(); eth::Assembly assemble(); From 58849cb1d52c88daeb15ec34d19ef0dc143c0a33 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 14 Feb 2017 15:40:58 +0100 Subject: [PATCH 115/234] Tests for printing assembly. --- test/libsolidity/InlineAssembly.cpp | 56 +++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index 37d17495a..437c5866b 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -73,11 +73,22 @@ bool successAssemble(string const& _source, bool _allowWarnings = true) return successParse(_source, true, _allowWarnings); } +void parsePrintCompare(string const& _source) +{ + assembly::InlineAssemblyStack stack; + BOOST_REQUIRE(stack.parse(std::make_shared(CharStream(_source)))); + BOOST_REQUIRE(stack.errors().empty()); + BOOST_CHECK_EQUAL(stack.toString(), _source); +} + } BOOST_AUTO_TEST_SUITE(SolidityInlineAssembly) + +BOOST_AUTO_TEST_SUITE(Parsing) + BOOST_AUTO_TEST_CASE(smoke_test) { BOOST_CHECK(successParse("{ }")); @@ -148,6 +159,49 @@ BOOST_AUTO_TEST_CASE(blocks) BOOST_CHECK(successParse("{ let x := 7 { let y := 3 } { let z := 2 } }")); } +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(Printing) + +BOOST_AUTO_TEST_CASE(print_smoke) +{ + parsePrintCompare("{\n}"); +} + +BOOST_AUTO_TEST_CASE(print_instructions) +{ + parsePrintCompare("{\n 7\n 8\n mul\n dup10\n add\n}"); +} + +BOOST_AUTO_TEST_CASE(print_subblock) +{ + parsePrintCompare("{\n {\n dup4\n add\n }\n}"); +} + +BOOST_AUTO_TEST_CASE(print_functional) +{ + parsePrintCompare("{\n mul(sload(0x12), 7)\n}"); +} + +BOOST_AUTO_TEST_CASE(print_label) +{ + parsePrintCompare("{\n loop:\n jump(loop)\n}"); +} + +BOOST_AUTO_TEST_CASE(print_assignments) +{ + parsePrintCompare("{\n let x := mul(2, 3)\n 7\n =: x\n x := add(1, 2)\n}"); +} + +BOOST_AUTO_TEST_CASE(print_string_literals) +{ + parsePrintCompare("{\n \"\\n'\\xab\\x95\\\"\"\n}"); +} + +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(Analysis) + BOOST_AUTO_TEST_CASE(string_literals) { BOOST_CHECK(successAssemble("{ let x := \"12345678901234567890123456789012\" }")); @@ -212,6 +266,8 @@ BOOST_AUTO_TEST_CASE(revert) BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() + } } } // end namespaces From 24197a2b3f7f94dac03b6ac30802069011cf036c Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 14 Feb 2017 15:41:07 +0100 Subject: [PATCH 116/234] Assembly printing fixes. --- libsolidity/inlineasm/AsmPrinter.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libsolidity/inlineasm/AsmPrinter.cpp b/libsolidity/inlineasm/AsmPrinter.cpp index 66cf39c01..ab2a03ff0 100644 --- a/libsolidity/inlineasm/AsmPrinter.cpp +++ b/libsolidity/inlineasm/AsmPrinter.cpp @@ -52,9 +52,7 @@ string AsmPrinter::operator()(assembly::Literal const& _literal) if (c == '\\') out += "\\\\"; else if (c == '"') - out += "\\"; - else if (c == '\'') - out += "\\'"; + out += "\\\""; else if (c == '\b') out += "\\b"; else if (c == '\f') @@ -70,7 +68,7 @@ string AsmPrinter::operator()(assembly::Literal const& _literal) else if (!isprint(c, locale::classic())) { ostringstream o; - o << std::hex << setfill('0') << setw(2) << unsigned(c); + o << std::hex << setfill('0') << setw(2) << (unsigned)(unsigned char)(c); out += "\\x" + o.str(); } else @@ -86,7 +84,7 @@ string AsmPrinter::operator()(assembly::Identifier const& _identifier) string AsmPrinter::operator()(assembly::FunctionalInstruction const& _functionalInstruction) { return - (*this)(_functionalInstruction.instruction); + + (*this)(_functionalInstruction.instruction) + "(" + boost::algorithm::join( _functionalInstruction.arguments | boost::adaptors::transformed(boost::apply_visitor(*this)), @@ -116,6 +114,8 @@ string AsmPrinter::operator()(assembly::VariableDeclaration const& _variableDecl string AsmPrinter::operator()(Block const& _block) { + if (_block.statements.empty()) + return "{\n}"; string body = boost::algorithm::join( _block.statements | boost::adaptors::transformed(boost::apply_visitor(*this)), "\n" From 5e8a1e0ae6dcd269258fe4239060bcc890abacb5 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 15 Feb 2017 15:21:11 +0100 Subject: [PATCH 117/234] Test for unicode string literals. --- test/libsolidity/InlineAssembly.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index 437c5866b..8744d96f8 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -198,6 +198,17 @@ BOOST_AUTO_TEST_CASE(print_string_literals) parsePrintCompare("{\n \"\\n'\\xab\\x95\\\"\"\n}"); } +BOOST_AUTO_TEST_CASE(print_string_literal_unicode) +{ + string source = "{ \"\\u1bac\" }"; + string parsed = "{\n \"\\xe1\\xae\\xac\"\n}"; + assembly::InlineAssemblyStack stack; + BOOST_REQUIRE(stack.parse(std::make_shared(CharStream(source)))); + BOOST_REQUIRE(stack.errors().empty()); + BOOST_CHECK_EQUAL(stack.toString(), parsed); + parsePrintCompare(parsed); +} + BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE(Analysis) From 5d584aded8bcabaafddf2f61692f8663913be603 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 31 Jan 2017 23:59:41 +0100 Subject: [PATCH 118/234] Parsing function definitions. --- libsolidity/inlineasm/AsmCodeGen.cpp | 5 ++- libsolidity/inlineasm/AsmData.h | 5 ++- libsolidity/inlineasm/AsmParser.cpp | 49 +++++++++++++++++++++++++--- libsolidity/inlineasm/AsmParser.h | 2 ++ test/libsolidity/InlineAssembly.cpp | 10 ++++++ 5 files changed, 65 insertions(+), 6 deletions(-) diff --git a/libsolidity/inlineasm/AsmCodeGen.cpp b/libsolidity/inlineasm/AsmCodeGen.cpp index 43c3b27a9..1eab5df0f 100644 --- a/libsolidity/inlineasm/AsmCodeGen.cpp +++ b/libsolidity/inlineasm/AsmCodeGen.cpp @@ -249,7 +249,10 @@ public: _block.location ); } - + } + void operator()(assembly::FunctionDefinition const&) + { + solAssert(false, "Function definition not removed during desugaring phase."); } private: diff --git a/libsolidity/inlineasm/AsmData.h b/libsolidity/inlineasm/AsmData.h index d622ff54c..64dd7b8ec 100644 --- a/libsolidity/inlineasm/AsmData.h +++ b/libsolidity/inlineasm/AsmData.h @@ -48,8 +48,9 @@ struct Label { SourceLocation location; std::string name; }; struct Assignment { SourceLocation location; Identifier variableName; }; struct FunctionalAssignment; struct VariableDeclaration; +struct FunctionDefinition; struct Block; -using Statement = boost::variant; +using Statement = boost::variant; /// Functional assignment ("x := mload(20)", expects push-1-expression on the right hand /// side and requires x to occupy exactly one stack slot. struct FunctionalAssignment { SourceLocation location; Identifier variableName; std::shared_ptr value; }; @@ -59,6 +60,8 @@ struct FunctionalInstruction { SourceLocation location; Instruction instruction; struct VariableDeclaration { SourceLocation location; std::string name; std::shared_ptr value; }; /// Block that creates a scope (frees declared stack variables) struct Block { SourceLocation location; std::vector statements; }; +/// Function definition ("function f(a, b) -> (d, e) { ... }") +struct FunctionDefinition { SourceLocation location; std::string name; std::vector arguments; std::vector returns; Block body; }; struct LocationExtractor: boost::static_visitor { diff --git a/libsolidity/inlineasm/AsmParser.cpp b/libsolidity/inlineasm/AsmParser.cpp index 46a2730d9..019ec1a38 100644 --- a/libsolidity/inlineasm/AsmParser.cpp +++ b/libsolidity/inlineasm/AsmParser.cpp @@ -62,6 +62,8 @@ assembly::Statement Parser::parseStatement() { case Token::Let: return parseVariableDeclaration(); + case Token::Function: + return parseFunctionDefinition(); case Token::LBrace: return parseBlock(); case Token::Assign: @@ -214,10 +216,7 @@ assembly::VariableDeclaration Parser::parseVariableDeclaration() { VariableDeclaration varDecl = createWithLocation(); expectToken(Token::Let); - varDecl.name = m_scanner->currentLiteral(); - if (instructions().count(varDecl.name)) - fatalParserError("Cannot use instruction names for identifier names."); - expectToken(Token::Identifier); + varDecl.name = expectAsmIdentifier(); expectToken(Token::Colon); expectToken(Token::Assign); varDecl.value.reset(new Statement(parseExpression())); @@ -225,6 +224,39 @@ assembly::VariableDeclaration Parser::parseVariableDeclaration() return varDecl; } +assembly::FunctionDefinition Parser::parseFunctionDefinition() +{ + FunctionDefinition funDef = createWithLocation(); + expectToken(Token::Function); + funDef.name = expectAsmIdentifier(); + expectToken(Token::LParen); + while (m_scanner->currentToken() != Token::RParen) + { + funDef.arguments.push_back(expectAsmIdentifier()); + if (m_scanner->currentToken() == Token::RParen) + break; + expectToken(Token::Comma); + } + expectToken(Token::RParen); + if (m_scanner->currentToken() == Token::Sub) + { + expectToken(Token::Sub); + expectToken(Token::GreaterThan); + expectToken(Token::LParen); + while (true) + { + funDef.returns.push_back(expectAsmIdentifier()); + if (m_scanner->currentToken() == Token::RParen) + break; + expectToken(Token::Comma); + } + expectToken(Token::RParen); + } + funDef.body = parseBlock(); + funDef.location.end = funDef.body.location.end; + return funDef; +} + FunctionalInstruction Parser::parseFunctionalInstruction(assembly::Statement&& _instruction) { if (_instruction.type() != typeid(Instruction)) @@ -266,3 +298,12 @@ FunctionalInstruction Parser::parseFunctionalInstruction(assembly::Statement&& _ expectToken(Token::RParen); return ret; } + +string Parser::expectAsmIdentifier() +{ + string name = m_scanner->currentLiteral(); + if (instructions().count(name)) + fatalParserError("Cannot use instruction names for identifier names."); + expectToken(Token::Identifier); + return name; +} diff --git a/libsolidity/inlineasm/AsmParser.h b/libsolidity/inlineasm/AsmParser.h index 643548dd0..1da049f6d 100644 --- a/libsolidity/inlineasm/AsmParser.h +++ b/libsolidity/inlineasm/AsmParser.h @@ -67,7 +67,9 @@ protected: std::map const& instructions(); Statement parseElementaryOperation(bool _onlySinglePusher = false); VariableDeclaration parseVariableDeclaration(); + FunctionDefinition parseFunctionDefinition(); FunctionalInstruction parseFunctionalInstruction(Statement&& _instruction); + std::string expectAsmIdentifier(); }; } diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index 8744d96f8..5216ac060 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -159,6 +159,16 @@ BOOST_AUTO_TEST_CASE(blocks) BOOST_CHECK(successParse("{ let x := 7 { let y := 3 } { let z := 2 } }")); } +BOOST_AUTO_TEST_CASE(function_definitions) +{ + BOOST_CHECK(successParse("{ function f() { } function g(a) -> (x) { } }")); +} + +BOOST_AUTO_TEST_CASE(function_definitions_multiple_args) +{ + BOOST_CHECK(successParse("{ function f(a, d) { } function g(a, d) -> (x, y) { } }")); +} + BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE(Printing) From 49a919b3e012cfa0f7e0c93c29b93289740e9e44 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 1 Feb 2017 21:20:21 +0100 Subject: [PATCH 119/234] Parsing function calls. --- libsolidity/inlineasm/AsmCodeGen.cpp | 4 ++ libsolidity/inlineasm/AsmData.h | 4 +- libsolidity/inlineasm/AsmParser.cpp | 91 +++++++++++++++++----------- libsolidity/inlineasm/AsmParser.h | 2 +- test/libsolidity/InlineAssembly.cpp | 5 ++ 5 files changed, 69 insertions(+), 37 deletions(-) diff --git a/libsolidity/inlineasm/AsmCodeGen.cpp b/libsolidity/inlineasm/AsmCodeGen.cpp index 1eab5df0f..faa7dabdf 100644 --- a/libsolidity/inlineasm/AsmCodeGen.cpp +++ b/libsolidity/inlineasm/AsmCodeGen.cpp @@ -190,6 +190,10 @@ public: } (*this)(_instr.instruction); } + void operator()(assembly::FunctionCall const&) + { + solAssert(false, "Function call not removed during desugaring phase."); + } void operator()(Label const& _label) { m_state.assembly.setSourceLocation(_label.location); diff --git a/libsolidity/inlineasm/AsmData.h b/libsolidity/inlineasm/AsmData.h index 64dd7b8ec..d61b5803e 100644 --- a/libsolidity/inlineasm/AsmData.h +++ b/libsolidity/inlineasm/AsmData.h @@ -49,13 +49,15 @@ struct Assignment { SourceLocation location; Identifier variableName; }; struct FunctionalAssignment; struct VariableDeclaration; struct FunctionDefinition; +struct FunctionCall; struct Block; -using Statement = boost::variant; +using Statement = boost::variant; /// Functional assignment ("x := mload(20)", expects push-1-expression on the right hand /// side and requires x to occupy exactly one stack slot. struct FunctionalAssignment { SourceLocation location; Identifier variableName; std::shared_ptr value; }; /// Functional instruction, e.g. "mul(mload(20), add(2, x))" struct FunctionalInstruction { SourceLocation location; Instruction instruction; std::vector arguments; }; +struct FunctionCall { SourceLocation location; Identifier functionName; std::vector arguments; }; /// Block-scope variable declaration ("let x := mload(20)"), non-hoisted struct VariableDeclaration { SourceLocation location; std::string name; std::shared_ptr value; }; /// Block that creates a scope (frees declared stack variables) diff --git a/libsolidity/inlineasm/AsmParser.cpp b/libsolidity/inlineasm/AsmParser.cpp index 019ec1a38..0fc0a34f8 100644 --- a/libsolidity/inlineasm/AsmParser.cpp +++ b/libsolidity/inlineasm/AsmParser.cpp @@ -257,46 +257,67 @@ assembly::FunctionDefinition Parser::parseFunctionDefinition() return funDef; } -FunctionalInstruction Parser::parseFunctionalInstruction(assembly::Statement&& _instruction) +assembly::Statement Parser::parseFunctionalInstruction(assembly::Statement&& _instruction) { - if (_instruction.type() != typeid(Instruction)) - fatalParserError("Assembly instruction required in front of \"(\")"); - FunctionalInstruction ret; - ret.instruction = std::move(boost::get(_instruction)); - ret.location = ret.instruction.location; - solidity::Instruction instr = ret.instruction.instruction; - InstructionInfo instrInfo = instructionInfo(instr); - if (solidity::Instruction::DUP1 <= instr && instr <= solidity::Instruction::DUP16) - fatalParserError("DUPi instructions not allowed for functional notation"); - if (solidity::Instruction::SWAP1 <= instr && instr <= solidity::Instruction::SWAP16) - fatalParserError("SWAPi instructions not allowed for functional notation"); - - expectToken(Token::LParen); - unsigned args = unsigned(instrInfo.args); - for (unsigned i = 0; i < args; ++i) + if (_instruction.type() == typeid(Instruction)) { - ret.arguments.emplace_back(parseExpression()); - if (i != args - 1) + FunctionalInstruction ret; + ret.instruction = std::move(boost::get(_instruction)); + ret.location = ret.instruction.location; + solidity::Instruction instr = ret.instruction.instruction; + InstructionInfo instrInfo = instructionInfo(instr); + if (solidity::Instruction::DUP1 <= instr && instr <= solidity::Instruction::DUP16) + fatalParserError("DUPi instructions not allowed for functional notation"); + if (solidity::Instruction::SWAP1 <= instr && instr <= solidity::Instruction::SWAP16) + fatalParserError("SWAPi instructions not allowed for functional notation"); + expectToken(Token::LParen); + unsigned args = unsigned(instrInfo.args); + for (unsigned i = 0; i < args; ++i) { - if (m_scanner->currentToken() != Token::Comma) - fatalParserError(string( - "Expected comma (" + - instrInfo.name + - " expects " + - boost::lexical_cast(args) + - " arguments)" - )); - else - m_scanner->next(); + ret.arguments.emplace_back(parseExpression()); + if (i != args - 1) + { + if (m_scanner->currentToken() != Token::Comma) + fatalParserError(string( + "Expected comma (" + + instrInfo.name + + " expects " + + boost::lexical_cast(args) + + " arguments)" + )); + else + m_scanner->next(); + } } + ret.location.end = endPosition(); + if (m_scanner->currentToken() == Token::Comma) + fatalParserError( + string("Expected ')' (" + instrInfo.name + " expects " + boost::lexical_cast(args) + " arguments)") + ); + expectToken(Token::RParen); + return ret; } - ret.location.end = endPosition(); - if (m_scanner->currentToken() == Token::Comma) - fatalParserError( - string("Expected ')' (" + instrInfo.name + " expects " + boost::lexical_cast(args) + " arguments)") - ); - expectToken(Token::RParen); - return ret; + else if (_instruction.type() == typeid(Identifier)) + { + FunctionCall ret; + ret.functionName = std::move(boost::get(_instruction)); + ret.location = ret.functionName.location; + expectToken(Token::LParen); + while (m_scanner->currentToken() != Token::RParen) + { + ret.arguments.emplace_back(parseExpression()); + if (m_scanner->currentToken() == Token::RParen) + break; + expectToken(Token::Comma); + } + ret.location.end = endPosition(); + expectToken(Token::RParen); + return ret; + } + else + fatalParserError("Assembly instruction or function name required in front of \"(\")"); + + return {}; } string Parser::expectAsmIdentifier() diff --git a/libsolidity/inlineasm/AsmParser.h b/libsolidity/inlineasm/AsmParser.h index 1da049f6d..4b4a24ae5 100644 --- a/libsolidity/inlineasm/AsmParser.h +++ b/libsolidity/inlineasm/AsmParser.h @@ -68,7 +68,7 @@ protected: Statement parseElementaryOperation(bool _onlySinglePusher = false); VariableDeclaration parseVariableDeclaration(); FunctionDefinition parseFunctionDefinition(); - FunctionalInstruction parseFunctionalInstruction(Statement&& _instruction); + Statement parseFunctionalInstruction(Statement&& _instruction); std::string expectAsmIdentifier(); }; diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index 5216ac060..40135a06f 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -169,6 +169,11 @@ BOOST_AUTO_TEST_CASE(function_definitions_multiple_args) BOOST_CHECK(successParse("{ function f(a, d) { } function g(a, d) -> (x, y) { } }")); } +BOOST_AUTO_TEST_CASE(function_calls) +{ + BOOST_CHECK(successParse("{ g(1, 2, f(mul(2, 3))) x() }")); +} + BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE(Printing) From a5ce81100ef32654e351329fff5cd0e19622798c Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 9 Feb 2017 14:04:23 +0100 Subject: [PATCH 120/234] Assembly printer for functions. --- libsolidity/inlineasm/AsmPrinter.cpp | 18 ++++++++++++++++++ libsolidity/inlineasm/AsmPrinter.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/libsolidity/inlineasm/AsmPrinter.cpp b/libsolidity/inlineasm/AsmPrinter.cpp index ab2a03ff0..a70b0b786 100644 --- a/libsolidity/inlineasm/AsmPrinter.cpp +++ b/libsolidity/inlineasm/AsmPrinter.cpp @@ -112,6 +112,24 @@ string AsmPrinter::operator()(assembly::VariableDeclaration const& _variableDecl return "let " + _variableDeclaration.name + " := " + boost::apply_visitor(*this, *_variableDeclaration.value); } +string AsmPrinter::operator()(assembly::FunctionDefinition const& _functionDefinition) +{ + string out = "function " + _functionDefinition.name + "(" + boost::algorithm::join(_functionDefinition.arguments, ", ") + ")"; + if (!_functionDefinition.returns.empty()) + out += " -> (" + boost::algorithm::join(_functionDefinition.returns, ", ") + ")"; + return out + "\n" + (*this)(_functionDefinition.body); +} + +string AsmPrinter::operator()(assembly::FunctionCall const& _functionCall) +{ + return + (*this)(_functionCall.functionName) + "(" + + boost::algorithm::join( + _functionCall.arguments | boost::adaptors::transformed(boost::apply_visitor(*this)), + ", " ) + + ")"; +} + string AsmPrinter::operator()(Block const& _block) { if (_block.statements.empty()) diff --git a/libsolidity/inlineasm/AsmPrinter.h b/libsolidity/inlineasm/AsmPrinter.h index 39069d021..a7a1de0a5 100644 --- a/libsolidity/inlineasm/AsmPrinter.h +++ b/libsolidity/inlineasm/AsmPrinter.h @@ -53,6 +53,8 @@ public: std::string operator()(assembly::Assignment const& _assignment); std::string operator()(assembly::FunctionalAssignment const& _functionalAssignment); std::string operator()(assembly::VariableDeclaration const& _variableDeclaration); + std::string operator()(assembly::FunctionDefinition const& _functionDefinition); + std::string operator()(assembly::FunctionCall const& _functionCall); std::string operator()(assembly::Block const& _block); }; From 01fcd989b57d31fa8fc63720401ffc77698ee57b Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 14 Feb 2017 16:08:33 +0100 Subject: [PATCH 121/234] More tests. --- test/libsolidity/InlineAssembly.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index 40135a06f..ddbc3c632 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -224,6 +224,16 @@ BOOST_AUTO_TEST_CASE(print_string_literal_unicode) parsePrintCompare(parsed); } +BOOST_AUTO_TEST_CASE(function_definitions_multiple_args) +{ + parsePrintCompare("{\n function f(a, d)\n {\n mstore(a, d)\n }\n function g(a, d) -> (x, y)\n {\n }\n}"); +} + +BOOST_AUTO_TEST_CASE(function_calls) +{ + parsePrintCompare("{\n g(1, mul(2, x), f(mul(2, 3)))\n x()\n}"); +} + BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE(Analysis) From dcc16c81e26f31141ae766096873b5fd7741cdf5 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 16 Feb 2017 11:45:06 +0100 Subject: [PATCH 122/234] Some checks for the existence of mobile type. --- Changelog.md | 1 + libsolidity/ast/Types.cpp | 7 +++++-- libsolidity/codegen/ExpressionCompiler.cpp | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index bd514cfe6..5684adbdf 100644 --- a/Changelog.md +++ b/Changelog.md @@ -10,6 +10,7 @@ Bugfixes: * Commandline interface: Always escape filenames (replace ``/``, ``:`` and ``.`` with ``_``). * Commandline interface: Do not try creating paths ``.`` and ``..``. * Type system: Disallow arrays with negative length. + * Type system: Fix a crash related to invalid binary operators. ### 0.4.9 (2017-01-31) diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 5b7b4a2cd..75dee6dbb 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -252,9 +252,9 @@ TypePointer Type::commonType(TypePointer const& _a, TypePointer const& _b) { if (!_a || !_b) return TypePointer(); - else if (_b->isImplicitlyConvertibleTo(*_a->mobileType())) + else if (_a->mobileType() && _b->isImplicitlyConvertibleTo(*_a->mobileType())) return _a->mobileType(); - else if (_a->isImplicitlyConvertibleTo(*_b->mobileType())) + else if (_b->mobileType() && _a->isImplicitlyConvertibleTo(*_b->mobileType())) return _b->mobileType(); else return TypePointer(); @@ -1895,7 +1895,10 @@ TypePointer TupleType::closestTemporaryType(TypePointer const& _targetType) cons size_t si = fillRight ? i : components().size() - i - 1; size_t ti = fillRight ? i : targetComponents.size() - i - 1; if (components()[si] && targetComponents[ti]) + { tempComponents[ti] = components()[si]->closestTemporaryType(targetComponents[ti]); + solAssert(tempComponents[ti], ""); + } } return make_shared(tempComponents); } diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 2ed19a833..1c2883cd7 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -220,6 +220,7 @@ bool ExpressionCompiler::visit(Assignment const& _assignment) rightIntermediateType = _assignment.rightHandSide().annotation().type->closestTemporaryType( _assignment.leftHandSide().annotation().type ); + solAssert(rightIntermediateType, ""); utils().convertType(*_assignment.rightHandSide().annotation().type, *rightIntermediateType, cleanupNeeded); _assignment.leftHandSide().accept(*this); @@ -395,6 +396,7 @@ bool ExpressionCompiler::visit(BinaryOperation const& _binaryOperation) TypePointer leftTargetType = commonType; TypePointer rightTargetType = Token::isShiftOp(c_op) ? rightExpression.annotation().type->mobileType() : commonType; + solAssert(rightTargetType, ""); // for commutative operators, push the literal as late as possible to allow improved optimization auto isLiteral = [](Expression const& _e) @@ -808,6 +810,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) arguments[0]->accept(*this); // stack: newLength storageSlot slotOffset argValue TypePointer type = arguments[0]->annotation().type->closestTemporaryType(arrayType->baseType()); + solAssert(type, ""); utils().convertType(*arguments[0]->annotation().type, *type); utils().moveToStackTop(1 + type->sizeOnStack()); utils().moveToStackTop(1 + type->sizeOnStack()); From e629cf5bc3dc093a302b461273d89c8dd5999cb6 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 16 Feb 2017 14:54:17 +0100 Subject: [PATCH 123/234] Test case. --- .../SolidityNameAndTypeResolution.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 1a4f3cdc9..507d90575 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -5079,6 +5079,22 @@ BOOST_AUTO_TEST_CASE(invalid_address_length) CHECK_WARNING(text, "checksum"); } +BOOST_AUTO_TEST_CASE(early_exit_on_fatal_errors) +{ + // This tests a crash that occured because we did not stop for fatal errors. + char const* text = R"( + contract C { + struct S { + ftring a; + } + S public s; + function s() s { + } + } + )"; + CHECK_ERROR(text, DeclarationError, "Identifier not found or not unique"); +} + BOOST_AUTO_TEST_SUITE_END() } From c3c3cccbec058f7f220994da7d272ce41d49d3e8 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 16 Feb 2017 12:36:43 +0100 Subject: [PATCH 124/234] Fix early exist for fatal errors. --- Changelog.md | 1 + libsolidity/analysis/NameAndTypeResolver.cpp | 141 ++++++++++--------- libsolidity/analysis/NameAndTypeResolver.h | 3 + libsolidity/analysis/ReferencesResolver.cpp | 9 +- libsolidity/analysis/ReferencesResolver.h | 2 +- libsolidity/ast/Types.cpp | 4 + 6 files changed, 87 insertions(+), 73 deletions(-) diff --git a/Changelog.md b/Changelog.md index bd514cfe6..72947dab0 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,6 +9,7 @@ Features: Bugfixes: * Commandline interface: Always escape filenames (replace ``/``, ``:`` and ``.`` with ``_``). * Commandline interface: Do not try creating paths ``.`` and ``..``. + * Type system: Fix a crash caused by continuing on fatal errors in the code. * Type system: Disallow arrays with negative length. ### 0.4.9 (2017-01-31) diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp index 013842602..336dc894d 100644 --- a/libsolidity/analysis/NameAndTypeResolver.cpp +++ b/libsolidity/analysis/NameAndTypeResolver.cpp @@ -21,6 +21,7 @@ */ #include + #include #include #include @@ -130,62 +131,9 @@ bool NameAndTypeResolver::performImports(SourceUnit& _sourceUnit, map(&_node)) - { - m_currentScope = m_scopes[contract->scope()].get(); - solAssert(!!m_currentScope, ""); - - for (ASTPointer const& baseContract: contract->baseContracts()) - if (!resolveNamesAndTypes(*baseContract, true)) - success = false; - - m_currentScope = m_scopes[contract].get(); - - if (success) - { - linearizeBaseContracts(*contract); - vector properBases( - ++contract->annotation().linearizedBaseContracts.begin(), - contract->annotation().linearizedBaseContracts.end() - ); - - for (ContractDefinition const* base: properBases) - importInheritedScope(*base); - } - - // these can contain code, only resolve parameters for now - for (ASTPointer const& node: contract->subNodes()) - { - m_currentScope = m_scopes[contract].get(); - if (!resolveNamesAndTypes(*node, false)) - success = false; - } - - if (!success) - return false; - - if (!_resolveInsideCode) - return success; - - m_currentScope = m_scopes[contract].get(); - - // now resolve references inside the code - for (ASTPointer const& node: contract->subNodes()) - { - m_currentScope = m_scopes[contract].get(); - if (!resolveNamesAndTypes(*node, true)) - success = false; - } - } - else - { - if (m_scopes.count(&_node)) - m_currentScope = m_scopes[&_node].get(); - return ReferencesResolver(m_errors, *this, _resolveInsideCode).resolve(_node); - } + return resolveNamesAndTypesInternal(_node, _resolveInsideCode); } catch (FatalError const&) { @@ -193,7 +141,6 @@ bool NameAndTypeResolver::resolveNamesAndTypes(ASTNode& _node, bool _resolveInsi throw; // Something is weird here, rather throw again. return false; } - return success; } bool NameAndTypeResolver::updateDeclaration(Declaration const& _declaration) @@ -249,21 +196,25 @@ vector NameAndTypeResolver::cleanedDeclarations( solAssert(_declarations.size() > 1, ""); vector uniqueFunctions; - for (auto it = _declarations.begin(); it != _declarations.end(); ++it) + for (Declaration const* declaration: _declarations) { - solAssert(*it, ""); + solAssert(declaration, ""); // the declaration is functionDefinition, eventDefinition or a VariableDeclaration while declarations > 1 - solAssert(dynamic_cast(*it) || dynamic_cast(*it) || dynamic_cast(*it), - "Found overloading involving something not a function or a variable"); + solAssert( + dynamic_cast(declaration) || + dynamic_cast(declaration) || + dynamic_cast(declaration), + "Found overloading involving something not a function or a variable." + ); - shared_ptr functionType { (*it)->functionType(false) }; + FunctionTypePointer functionType { declaration->functionType(false) }; if (!functionType) - functionType = (*it)->functionType(true); - solAssert(functionType, "failed to determine the function type of the overloaded"); + functionType = declaration->functionType(true); + solAssert(functionType, "Failed to determine the function type of the overloaded."); for (auto parameter: functionType->parameterTypes() + functionType->returnParameterTypes()) if (!parameter) - reportFatalDeclarationError(_identifier.location(), "Function type can not be used in this context"); + reportFatalDeclarationError(_identifier.location(), "Function type can not be used in this context."); if (uniqueFunctions.end() == find_if( uniqueFunctions.begin(), @@ -276,11 +227,73 @@ vector NameAndTypeResolver::cleanedDeclarations( return newFunctionType && functionType->hasEqualArgumentTypes(*newFunctionType); } )) - uniqueFunctions.push_back(*it); + uniqueFunctions.push_back(declaration); } return uniqueFunctions; } +bool NameAndTypeResolver::resolveNamesAndTypesInternal(ASTNode& _node, bool _resolveInsideCode) +{ + if (ContractDefinition* contract = dynamic_cast(&_node)) + { + bool success = true; + m_currentScope = m_scopes[contract->scope()].get(); + solAssert(!!m_currentScope, ""); + + for (ASTPointer const& baseContract: contract->baseContracts()) + if (!resolveNamesAndTypes(*baseContract, true)) + success = false; + + m_currentScope = m_scopes[contract].get(); + + if (success) + { + linearizeBaseContracts(*contract); + vector properBases( + ++contract->annotation().linearizedBaseContracts.begin(), + contract->annotation().linearizedBaseContracts.end() + ); + + for (ContractDefinition const* base: properBases) + importInheritedScope(*base); + } + + // these can contain code, only resolve parameters for now + for (ASTPointer const& node: contract->subNodes()) + { + m_currentScope = m_scopes[contract].get(); + if (!resolveNamesAndTypes(*node, false)) + { + success = false; + break; + } + } + + if (!success) + return false; + + if (!_resolveInsideCode) + return success; + + m_currentScope = m_scopes[contract].get(); + + // now resolve references inside the code + for (ASTPointer const& node: contract->subNodes()) + { + m_currentScope = m_scopes[contract].get(); + if (!resolveNamesAndTypes(*node, true)) + success = false; + } + return success; + } + else + { + if (m_scopes.count(&_node)) + m_currentScope = m_scopes[&_node].get(); + return ReferencesResolver(m_errors, *this, _resolveInsideCode).resolve(_node); + } +} + void NameAndTypeResolver::importInheritedScope(ContractDefinition const& _base) { auto iterator = m_scopes.find(&_base); diff --git a/libsolidity/analysis/NameAndTypeResolver.h b/libsolidity/analysis/NameAndTypeResolver.h index 828b566fc..038a887b4 100644 --- a/libsolidity/analysis/NameAndTypeResolver.h +++ b/libsolidity/analysis/NameAndTypeResolver.h @@ -89,6 +89,9 @@ public: ); private: + /// Internal version of @a resolveNamesAndTypes (called from there) throws exceptions on fatal errors. + bool resolveNamesAndTypesInternal(ASTNode& _node, bool _resolveInsideCode = true); + /// Imports all members declared directly in the given contract (i.e. does not import inherited members) /// into the current scope if they are not present already. void importInheritedScope(ContractDefinition const& _base); diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp index c06181d89..37bcb2d9a 100644 --- a/libsolidity/analysis/ReferencesResolver.cpp +++ b/libsolidity/analysis/ReferencesResolver.cpp @@ -35,14 +35,7 @@ using namespace dev::solidity; bool ReferencesResolver::resolve(ASTNode const& _root) { - try - { - _root.accept(*this); - } - catch (FatalError const&) - { - solAssert(m_errorOccurred, ""); - } + _root.accept(*this); return !m_errorOccurred; } diff --git a/libsolidity/analysis/ReferencesResolver.h b/libsolidity/analysis/ReferencesResolver.h index 23ac6b07c..dce343d33 100644 --- a/libsolidity/analysis/ReferencesResolver.h +++ b/libsolidity/analysis/ReferencesResolver.h @@ -52,7 +52,7 @@ public: m_resolveInsideCode(_resolveInsideCode) {} - /// @returns true if no errors during resolving + /// @returns true if no errors during resolving and throws exceptions on fatal errors. bool resolve(ASTNode const& _root); private: diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 5b7b4a2cd..96b3ed170 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -1652,6 +1652,7 @@ MemberList::MemberMap StructType::nativeMembers(ContractDefinition const*) const for (ASTPointer const& variable: m_struct.members()) { TypePointer type = variable->annotation().type; + solAssert(type, ""); // Skip all mapping members if we are not in storage. if (location() != DataLocation::Storage && !type->canLiveOutsideStorage()) continue; @@ -1964,6 +1965,8 @@ FunctionType::FunctionType(VariableDeclaration const& _varDecl): if (auto structType = dynamic_cast(returnType.get())) { for (auto const& member: structType->members(nullptr)) + { + solAssert(member.type, ""); if (member.type->category() != Category::Mapping) { if (auto arrayType = dynamic_cast(member.type.get())) @@ -1972,6 +1975,7 @@ FunctionType::FunctionType(VariableDeclaration const& _varDecl): retParams.push_back(member.type); retParamNames.push_back(member.name); } + } } else { From 811bb770c51bc63f9ccb2bff014482ba9c760132 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 16 Feb 2017 15:49:59 +0100 Subject: [PATCH 125/234] Change effect of assert to invalid opcode. --- docs/control-structures.rst | 9 ++++++--- docs/miscellaneous.rst | 2 +- libsolidity/codegen/ExpressionCompiler.cpp | 5 ++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/control-structures.rst b/docs/control-structures.rst index df8ac729c..f1b2e6dac 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -398,10 +398,13 @@ Currently, Solidity automatically generates a runtime exception in the following While a user-provided exception is generated in the following situations: #. Calling ``throw``. -#. The condition of ``assert(condition)`` is not met. Internally, Solidity performs a revert operation (instruction ``0xfd``) when a user-provided exception is thrown. In contrast, it performs an invalid operation -(instruction ``0xfe``) if a runtime exception is encountered. In both cases, this causes +(instruction ``0xfe``) if a runtime exception is encountered or the condition of an ``assert`` call is not met. In both cases, this causes the EVM to revert all changes made to the state. The reason for this is that there is no safe way to continue execution, because an expected effect did not occur. Because we want to retain the atomicity of transactions, the safest thing to do is to revert all changes and make the whole transaction -(or at least call) without effect. \ No newline at end of file +(or at least call) without effect. + +If contracts are written so that ``assert`` is only used to test internal conditions and ``throw`` or +``revert`` is used in case of malformed input, a formal analysis tool that verifies that the invalid +opcode can never be reached can be used to check for the absence of errors assuming valid inputs. diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index 3c57507ef..80326bab2 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -461,7 +461,7 @@ Global Variables - ``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 - ``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`` - ``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(bool condition)``: throws if the condition is false +- ``assert(bool condition)``: throws if the condition is false (using an invalid opcode) - ``this`` (current contract's type): the current contract, explicitly convertible to ``address`` - ``super``: the contract one level higher in the inheritance hierarchy - ``selfdestruct(address recipient)``: destroy the current contract, sending its funds to the given address diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 2ed19a833..41cfcb69a 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -875,9 +875,8 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) // jump if condition was met m_context << Instruction::ISZERO << Instruction::ISZERO; auto success = m_context.appendConditionalJump(); - // condition was not met, abort - m_context << u256(0) << u256(0); - m_context << Instruction::REVERT; + // condition was not met, flag an error + m_context << Instruction::INVALID; // the success branch m_context << success; break; From f93f9fa3a0dc1fada5688c0433a85cad1231a881 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 16 Feb 2017 16:59:19 +0100 Subject: [PATCH 126/234] Add executable for use with AFL. --- test/CMakeLists.txt | 22 ++--------- test/fuzzer.cpp | 92 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 18 deletions(-) create mode 100644 test/fuzzer.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 609aaab36..4d56ec9d6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -7,23 +7,9 @@ aux_source_directory(libsolidity SRC_LIST) aux_source_directory(contracts SRC_LIST) aux_source_directory(liblll SRC_LIST) -get_filename_component(TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE) +list(REMOVE_ITEM SRC_LIST "./fuzzer.cpp") -# search for test names and create ctest tests -enable_testing() -foreach(file ${SRC_LIST}) - file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/${file} test_list_raw REGEX "BOOST_.*TEST_(SUITE|CASE)") - set(TestSuite "DEFAULT") - foreach(test_raw ${test_list_raw}) - string(REGEX REPLACE ".*TEST_(SUITE|CASE)\\(([^ ,\\)]*).*" "\\1 \\2" test ${test_raw}) - if(test MATCHES "^SUITE .*") - string(SUBSTRING ${test} 6 -1 TestSuite) - elseif(test MATCHES "^CASE .*") - string(SUBSTRING ${test} 5 -1 TestCase) - add_test(NAME ${TestSuite}/${TestCase} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test COMMAND test -t ${TestSuite}/${TestCase}) - endif(test MATCHES "^SUITE .*") - endforeach(test_raw) -endforeach(file) +get_filename_component(TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE) file(GLOB HEADERS "*.h" "*/*.h") set(EXECUTABLE soltest) @@ -34,5 +20,5 @@ eth_use(${EXECUTABLE} REQUIRED Solidity::solidity Solidity::lll) include_directories(BEFORE ..) target_link_libraries(${EXECUTABLE} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES}) -enable_testing() -set(CTEST_OUTPUT_ON_FAILURE TRUE) +add_executable(solfuzzer fuzzer.cpp) +target_link_libraries(solfuzzer soljson) diff --git a/test/fuzzer.cpp b/test/fuzzer.cpp new file mode 100644 index 000000000..5e46662e5 --- /dev/null +++ b/test/fuzzer.cpp @@ -0,0 +1,92 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see . +*/ +/** + * Executable for use with AFL . + * Reads a single source from stdin and signals a failure for internal errors. + */ + +#include + +#include +#include + +using namespace std; + +extern "C" +{ +extern char const* compileJSON(char const* _input, bool _optimize); +} + +string contains(string const& _haystack, vector const& _needles) +{ + for (string const& needle: _needles) + if (_haystack.find(needle) != string::npos) + return needle; + return ""; +} + +int main() +{ + string input; + while (!cin.eof()) + { + string s; + getline(cin, s); + input += s + '\n'; + } + + bool optimize = true; + string outputString(compileJSON(input.c_str(), optimize)); + Json::Value outputJson; + if (!Json::Reader().parse(outputString, outputJson)) + { + cout << "Compiler produced invalid JSON output." << endl; + return -1; + } + if (outputJson.isMember("errors")) + { + if (!outputJson["errors"].isArray()) + { + cout << "Output JSON has \"errors\" but it is not an array." << endl; + return -1; + } + for (Json::Value const& error: outputJson["errors"]) + { + string invalid = contains(error.asString(), vector{ + "Compiler error", + "Internal compiler error", + "Exception during compilation", + "Unknown exception during compilation", + "Unknown exception while generating contract data output", + "Unknown exception while generating formal method output", + "Unknown exception while generating source name output", + "Unknown error while generating JSON" + }); + if (!invalid.empty()) + { + cout << "Invalid error: \"" << invalid << "\"" << endl; + return -1; + } + } + } + else if (!outputJson.isMember("contracts")) + { + cout << "Output JSON has neither \"errors\" nor \"contracts\"." << endl; + return -1; + } + return 0; +} From 8be318e75bbed68520d3a3ef34f777804b6b60e0 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 16 Feb 2017 17:13:55 +0100 Subject: [PATCH 127/234] Include non-fuzzing fuzzer tests in commandline run. --- test/cmdlineTests.sh | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/test/cmdlineTests.sh b/test/cmdlineTests.sh index fc48654a0..cb714efe2 100755 --- a/test/cmdlineTests.sh +++ b/test/cmdlineTests.sh @@ -31,7 +31,7 @@ set -e REPO_ROOT="$(dirname "$0")"/.. SOLC="$REPO_ROOT/build/solc/solc" - # Compile all files in std and examples. +# Compile all files in std and examples. for f in "$REPO_ROOT"/std/*.sol do @@ -46,6 +46,21 @@ do test -z "$output" -a "$failed" -eq 0 done -# Test library checksum -echo 'contact C {}' | "$SOLC" --link --libraries a:0x90f20564390eAe531E810af625A22f51385Cd222 -! echo 'contract C {}' | "$SOLC" --link --libraries a:0x80f20564390eAe531E810af625A22f51385Cd222 2>/dev/null +echo "Testing library checksum..." +echo '' | "$SOLC" --link --libraries a:0x90f20564390eAe531E810af625A22f51385Cd222 +! echo '' | "$SOLC" --link --libraries a:0x80f20564390eAe531E810af625A22f51385Cd222 2>/dev/null + +echo "Testing soljson via the fuzzer..." +TMPDIR=$(mktemp -d) +( + cd "$REPO_ROOT" + REPO_ROOT=$(pwd) # make it absolute + cd "$TMPDIR" + "$REPO_ROOT"/scripts/isolate_tests.py "$REPO_ROOT"/test/contracts/* "$REPO_ROOT"/test/libsolidity/*EndToEnd* + for f in *.sol + do + "$REPO_ROOT"/build/test/solfuzzer < "$f" + done +) +rm -rf "$TMPDIR" +echo "Done." From f66ebbc8e2e07bc5e1b75b6708f2f209229f6bec Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 16 Feb 2017 18:05:11 +0100 Subject: [PATCH 128/234] Report failures correctly to AFL. --- test/fuzzer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/fuzzer.cpp b/test/fuzzer.cpp index 5e46662e5..85a8fe99b 100644 --- a/test/fuzzer.cpp +++ b/test/fuzzer.cpp @@ -55,14 +55,14 @@ int main() if (!Json::Reader().parse(outputString, outputJson)) { cout << "Compiler produced invalid JSON output." << endl; - return -1; + abort(); } if (outputJson.isMember("errors")) { if (!outputJson["errors"].isArray()) { cout << "Output JSON has \"errors\" but it is not an array." << endl; - return -1; + abort(); } for (Json::Value const& error: outputJson["errors"]) { @@ -79,14 +79,14 @@ int main() if (!invalid.empty()) { cout << "Invalid error: \"" << invalid << "\"" << endl; - return -1; + abort(); } } } else if (!outputJson.isMember("contracts")) { cout << "Output JSON has neither \"errors\" nor \"contracts\"." << endl; - return -1; + abort(); } return 0; } From 354f92f813704158e53267412fea91fb9a6ca8a8 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 17 Feb 2017 16:04:42 +0100 Subject: [PATCH 129/234] Check error messages for assembly tests. --- test/libsolidity/InlineAssembly.cpp | 98 ++++++++++++++++++++--------- 1 file changed, 68 insertions(+), 30 deletions(-) diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index ddbc3c632..aef2d59ca 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -20,14 +20,19 @@ * Unit tests for inline assembly. */ -#include -#include -#include -#include +#include "../TestHelper.h" + #include +#include #include #include -#include "../TestHelper.h" +#include +#include + +#include + +#include +#include using namespace std; @@ -41,31 +46,44 @@ namespace test namespace { -bool successParse(std::string const& _source, bool _assemble = false, bool _allowWarnings = true) +boost::optional parseAndReturnFirstError(string const& _source, bool _assemble = false, bool _allowWarnings = true) { assembly::InlineAssemblyStack stack; + bool success = false; try { - if (!stack.parse(std::make_shared(CharStream(_source)))) - return false; - if (_assemble) - { + success = stack.parse(std::make_shared(CharStream(_source))); + if (success && _assemble) stack.assemble(); - if (!stack.errors().empty()) - if (!_allowWarnings || !Error::containsOnlyWarnings(stack.errors())) - return false; + } + catch (FatalError const& e) + { + BOOST_FAIL("Fatal error leaked."); + success = false; + } + if (!success) + { + BOOST_CHECK_EQUAL(stack.errors().size(), 1); + return *stack.errors().front(); + } + else + { + // If success is true, there might still be an error in the assembly stage. + if (_allowWarnings && Error::containsOnlyWarnings(stack.errors())) + return {}; + else if (!stack.errors().empty()) + { + if (!_allowWarnings) + BOOST_CHECK_EQUAL(stack.errors().size(), 1); + return *stack.errors().front(); } } - catch (FatalError const&) - { - if (Error::containsErrorOfType(stack.errors(), Error::Type::ParserError)) - return false; - } - if (Error::containsErrorOfType(stack.errors(), Error::Type::ParserError)) - return false; + return {}; +} - BOOST_CHECK(Error::containsOnlyWarnings(stack.errors())); - return true; +bool successParse(std::string const& _source, bool _assemble = false, bool _allowWarnings = true) +{ + return !parseAndReturnFirstError(_source, _assemble, _allowWarnings); } bool successAssemble(string const& _source, bool _allowWarnings = true) @@ -73,6 +91,14 @@ bool successAssemble(string const& _source, bool _allowWarnings = true) return successParse(_source, true, _allowWarnings); } +Error expectError(std::string const& _source, bool _assemble, bool _allowWarnings = false) +{ + + auto error = parseAndReturnFirstError(_source, _assemble, _allowWarnings); + BOOST_REQUIRE(error); + return *error; +} + void parsePrintCompare(string const& _source) { assembly::InlineAssemblyStack stack; @@ -83,6 +109,21 @@ void parsePrintCompare(string const& _source) } +#define CHECK_ERROR(text, assemble, typ, substring) \ +do \ +{ \ + Error err = expectError((text), (assemble), false); \ + BOOST_CHECK(err.type() == (Error::Type::typ)); \ + BOOST_CHECK(searchErrorMessage(err, (substring))); \ +} while(0) + +#define CHECK_PARSE_ERROR(text, type, substring) \ +CHECK_ERROR(text, false, type, substring) + +#define CHECK_ASSEMBLE_ERROR(text, type, substring) \ +CHECK_ERROR(text, true, type, substring) + + BOOST_AUTO_TEST_SUITE(SolidityInlineAssembly) @@ -255,8 +296,8 @@ BOOST_AUTO_TEST_CASE(assignment_after_tag) BOOST_AUTO_TEST_CASE(magic_variables) { - BOOST_CHECK(!successAssemble("{ this }")); - BOOST_CHECK(!successAssemble("{ ecrecover }")); + CHECK_ASSEMBLE_ERROR("{ this pop }", DeclarationError, "Identifier not found or not unique"); + CHECK_ASSEMBLE_ERROR("{ ecrecover pop }", DeclarationError, "Identifier not found or not unique"); BOOST_CHECK(successAssemble("{ let ecrecover := 1 ecrecover }")); } @@ -279,20 +320,17 @@ BOOST_AUTO_TEST_CASE(designated_invalid_instruction) BOOST_AUTO_TEST_CASE(inline_assembly_shadowed_instruction_declaration) { - // Error message: "Cannot use instruction names for identifier names." - BOOST_CHECK(!successAssemble("{ let gas := 1 }")); + CHECK_ASSEMBLE_ERROR("{ let gas := 1 }", ParserError, "Cannot use instruction names for identifier names."); } BOOST_AUTO_TEST_CASE(inline_assembly_shadowed_instruction_assignment) { - // Error message: "Identifier expected, got instruction name." - BOOST_CHECK(!successAssemble("{ 2 =: gas }")); + CHECK_ASSEMBLE_ERROR("{ 2 =: gas }", ParserError, "Identifier expected, got instruction name."); } BOOST_AUTO_TEST_CASE(inline_assembly_shadowed_instruction_functional_assignment) { - // Error message: "Cannot use instruction names for identifier names." - BOOST_CHECK(!successAssemble("{ gas := 2 }")); + CHECK_ASSEMBLE_ERROR("{ gas := 2 }", ParserError, "Label name / variable name must precede \":\""); } BOOST_AUTO_TEST_CASE(revert) From d794d35e503e85d6fa2730eea9250a1c22ce430f Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 20 Feb 2017 11:42:23 +0100 Subject: [PATCH 130/234] Also check imbalanced stack. --- test/libsolidity/InlineAssembly.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index aef2d59ca..10a61777c 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -286,7 +286,7 @@ BOOST_AUTO_TEST_CASE(string_literals) BOOST_AUTO_TEST_CASE(oversize_string_literals) { - BOOST_CHECK(!successAssemble("{ let x := \"123456789012345678901234567890123\" }")); + CHECK_ASSEMBLE_ERROR("{ let x := \"123456789012345678901234567890123\" }", TypeError, "String literal too long"); } BOOST_AUTO_TEST_CASE(assignment_after_tag) @@ -304,7 +304,8 @@ BOOST_AUTO_TEST_CASE(magic_variables) BOOST_AUTO_TEST_CASE(imbalanced_stack) { BOOST_CHECK(successAssemble("{ 1 2 mul pop }", false)); - BOOST_CHECK(!successAssemble("{ 1 }", false)); + CHECK_ASSEMBLE_ERROR("{ 1 }", Warning, "Inline assembly block is not balanced. It leaves"); + CHECK_ASSEMBLE_ERROR("{ pop }", Warning, "Inline assembly block is not balanced. It takes"); BOOST_CHECK(successAssemble("{ let x := 4 7 add }", false)); } From 50894c6af84f5feedf4f6a1fcada75584e7dd4ac Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 20 Feb 2017 11:57:50 +0100 Subject: [PATCH 131/234] Fix compiler warning. --- test/libsolidity/InlineAssembly.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index 10a61777c..9035599ba 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -56,7 +56,7 @@ boost::optional parseAndReturnFirstError(string const& _source, bool _ass if (success && _assemble) stack.assemble(); } - catch (FatalError const& e) + catch (FatalError const&) { BOOST_FAIL("Fatal error leaked."); success = false; From 5cd01ab7d1efc108c3dc711ca76b4f75be4ac5c6 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 20 Feb 2017 12:32:31 +0100 Subject: [PATCH 132/234] Test for unbalanced stack due to loading two values from outside. --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 507d90575..a1ebc3008 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -4852,6 +4852,19 @@ BOOST_AUTO_TEST_CASE(inline_assembly_unbalanced_negative_stack) CHECK_WARNING(text, "Inline assembly block is not balanced"); } +BOOST_AUTO_TEST_CASE(inline_assembly_unbalanced_two_stack_load) +{ + char const* text = R"( + contract c { + uint8 x; + function f() { + assembly { x pop } + } + } + )"; + CHECK_WARNING(text, "Inline assembly block is not balanced"); +} + BOOST_AUTO_TEST_CASE(inline_assembly_in_modifier) { char const* text = R"( From c0961664f9666e5f4e8e35e80ef9a71426f6c394 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 16 Feb 2017 19:21:33 +0100 Subject: [PATCH 133/234] Deposit one stack item for non-value types in inline assembly type checking. --- Changelog.md | 1 + libsolidity/analysis/TypeChecker.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 72947dab0..45aaf04a5 100644 --- a/Changelog.md +++ b/Changelog.md @@ -11,6 +11,7 @@ Bugfixes: * Commandline interface: Do not try creating paths ``.`` and ``..``. * Type system: Fix a crash caused by continuing on fatal errors in the code. * Type system: Disallow arrays with negative length. + * Inline assembly: Charge one stack slot for non-value types during analysis. ### 0.4.9 (2017-01-31) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 28cb9acc3..4025831ea 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -611,7 +611,7 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly) fatalTypeError(SourceLocation(), "Constant variables not yet implemented for inline assembly."); if (var->isLocalVariable()) pushes = var->type()->sizeOnStack(); - else if (var->type()->isValueType()) + else if (!var->type()->isValueType()) pushes = 1; else pushes = 2; // slot number, intra slot offset From a2f92033e78abf3b3e04fca4bf8a5a2c27e465fb Mon Sep 17 00:00:00 2001 From: Dmitriy Merkurev Date: Tue, 21 Feb 2017 22:44:18 +0300 Subject: [PATCH 134/234] add payable attribute --- docs/common-patterns.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/common-patterns.rst b/docs/common-patterns.rst index fa5e68a69..a2d7ce719 100644 --- a/docs/common-patterns.rst +++ b/docs/common-patterns.rst @@ -81,7 +81,7 @@ This is as opposed to the more intuitive sending pattern: mostSent = msg.value; } - function becomeRichest() returns (bool) { + function becomeRichest() payable returns (bool) { if (msg.value > mostSent) { // Check if call succeeds to prevent an attacker // from trapping the previous person's funds in From c9e4e1d7cac6d27a578d738f4c199ff96fff365a Mon Sep 17 00:00:00 2001 From: Mikko Ohtamaa Date: Wed, 22 Feb 2017 00:45:15 +0200 Subject: [PATCH 135/234] Downgrade instructions for Homebrew Solidity Because 0.4.9+ causes a lot of havoc, breaking tools --- docs/installing-solidity.rst | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/installing-solidity.rst b/docs/installing-solidity.rst index 42905ede4..fb405475d 100644 --- a/docs/installing-solidity.rst +++ b/docs/installing-solidity.rst @@ -102,6 +102,22 @@ We will re-add the pre-built bottles soon. brew install solidity brew linkapps solidity +If you need a specific version of Solidity you can install a +Homebrew formula directly from Github. + +View +`solidity.rb commits on Github `_. + +Follow the history links until you have a raw file link of a +specific commit of ``solidity.rb``. + +Install it using ``brew``: + +.. code:: bash + + brew unlink solidity + # Install 0.4.8 + brew install https://raw.githubusercontent.com/ethereum/homebrew-ethereum/77cce03da9f289e5a3ffe579840d3c5dc0a62717/solidity.rb .. _building-from-source: @@ -264,4 +280,4 @@ Example: 3. a breaking change is introduced - version is bumped to 0.5.0 4. the 0.5.0 release is made -This behaviour works well with the version pragma. \ No newline at end of file +This behaviour works well with the version pragma. From 4b1e8111cc2469808d08e1718d3edd64b2cc4484 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 23 Feb 2017 19:42:38 +0100 Subject: [PATCH 136/234] Remove assert for now. --- docs/control-structures.rst | 6 +--- docs/miscellaneous.rst | 3 +- libsolidity/analysis/GlobalContext.cpp | 5 ++-- test/libsolidity/SolidityEndToEndTest.cpp | 36 +++++++++++------------ 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/docs/control-structures.rst b/docs/control-structures.rst index f1b2e6dac..019714f8e 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -400,11 +400,7 @@ While a user-provided exception is generated in the following situations: #. Calling ``throw``. Internally, Solidity performs a revert operation (instruction ``0xfd``) when a user-provided exception is thrown. In contrast, it performs an invalid operation -(instruction ``0xfe``) if a runtime exception is encountered or the condition of an ``assert`` call is not met. In both cases, this causes +(instruction ``0xfe``) if a runtime exception is encountered. In both cases, this causes the EVM to revert all changes made to the state. The reason for this is that there is no safe way to continue execution, because an expected effect did not occur. Because we want to retain the atomicity of transactions, the safest thing to do is to revert all changes and make the whole transaction (or at least call) without effect. - -If contracts are written so that ``assert`` is only used to test internal conditions and ``throw`` or -``revert`` is used in case of malformed input, a formal analysis tool that verifies that the invalid -opcode can never be reached can be used to check for the absence of errors assuming valid inputs. diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index 80326bab2..6e272eaa9 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -435,7 +435,7 @@ The following is the order of precedence for operators, listed in order of evalu | *16* | Comma operator | ``,`` | +------------+-------------------------------------+--------------------------------------------+ -.. index:: block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin, assert, revert, keccak256, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send +.. index:: block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin, revert, keccak256, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send Global Variables ================ @@ -461,7 +461,6 @@ Global Variables - ``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 - ``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`` - ``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(bool condition)``: throws if the condition is false (using an invalid opcode) - ``this`` (current contract's type): the current contract, explicitly convertible to ``address`` - ``super``: the contract one level higher in the inheritance hierarchy - ``selfdestruct(address recipient)``: destroy the current contract, sending its funds to the given address diff --git a/libsolidity/analysis/GlobalContext.cpp b/libsolidity/analysis/GlobalContext.cpp index 4f100cd0e..069d10f5f 100644 --- a/libsolidity/analysis/GlobalContext.cpp +++ b/libsolidity/analysis/GlobalContext.cpp @@ -66,8 +66,9 @@ m_magicVariables(vector>{make_shared< make_shared(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Location::ECRecover)), make_shared("ripemd160", make_shared(strings(), strings{"bytes20"}, FunctionType::Location::RIPEMD160, true)), - make_shared("assert", - make_shared(strings{"bool"}, strings{}, FunctionType::Location::Assert)), +// Disabled until decision about semantics of assert is made. +// make_shared("assert", +// make_shared(strings{"bool"}, strings{}, FunctionType::Location::Assert)), make_shared("revert", make_shared(strings(), strings(), FunctionType::Location::Revert))}) { diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 68f8fbef3..19665a26f 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -9083,24 +9083,24 @@ BOOST_AUTO_TEST_CASE(invalid_instruction) BOOST_CHECK(callContractFunction("f()") == encodeArgs()); } -BOOST_AUTO_TEST_CASE(assert) -{ - char const* sourceCode = R"( - contract C { - function f() { - assert(false); - } - function g(bool val) returns (bool) { - assert(val == true); - return true; - } - } - )"; - compileAndRun(sourceCode, 0, "C"); - BOOST_CHECK(callContractFunction("f()") == encodeArgs()); - BOOST_CHECK(callContractFunction("g(bool)", false) == encodeArgs()); - BOOST_CHECK(callContractFunction("g(bool)", true) == encodeArgs(true)); -} +//BOOST_AUTO_TEST_CASE(assert) +//{ +// char const* sourceCode = R"( +// contract C { +// function f() { +// assert(false); +// } +// function g(bool val) returns (bool) { +// assert(val == true); +// return true; +// } +// } +// )"; +// compileAndRun(sourceCode, 0, "C"); +// BOOST_CHECK(callContractFunction("f()") == encodeArgs()); +// BOOST_CHECK(callContractFunction("g(bool)", false) == encodeArgs()); +// BOOST_CHECK(callContractFunction("g(bool)", true) == encodeArgs(true)); +//} BOOST_AUTO_TEST_CASE(revert) { From 4264625c69a30c4534e977ce3ca709bb95103dad Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sun, 5 Feb 2017 20:21:14 +0000 Subject: [PATCH 137/234] Implement address.transfer() --- Changelog.md | 1 + libsolidity/ast/Types.cpp | 4 +++- libsolidity/ast/Types.h | 1 + libsolidity/codegen/ExpressionCompiler.cpp | 19 +++++++++++++++---- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Changelog.md b/Changelog.md index 45aaf04a5..37f20c716 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,7 @@ Features: * Add ``assert(condition)``, which throws if condition is false. + * Introduce ``.transfer(value)`` for sending Ether. * Code generator: Support ``revert()`` to abort with rolling back, but not consuming all gas. * Inline assembly: Support ``revert`` (EIP140) as an opcode. * Type system: Support explicit conversion of external function to address. diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 96b3ed170..7fccccbc0 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -464,7 +464,8 @@ MemberList::MemberMap IntegerType::nativeMembers(ContractDefinition const*) cons {"call", make_shared(strings(), strings{"bool"}, FunctionType::Location::Bare, true, false, true)}, {"callcode", make_shared(strings(), strings{"bool"}, FunctionType::Location::BareCallCode, true, false, true)}, {"delegatecall", make_shared(strings(), strings{"bool"}, FunctionType::Location::BareDelegateCall, true)}, - {"send", make_shared(strings{"uint"}, strings{"bool"}, FunctionType::Location::Send)} + {"send", make_shared(strings{"uint"}, strings{"bool"}, FunctionType::Location::Send)}, + {"transfer", make_shared(strings{"uint"}, strings(), FunctionType::Location::Transfer)} }; else return MemberList::MemberMap(); @@ -2097,6 +2098,7 @@ string FunctionType::identifier() const case Location::BareDelegateCall: id += "baredelegatecall"; break; case Location::Creation: id += "creation"; break; case Location::Send: id += "send"; break; + case Location::Transfer: id += "transfer"; break; case Location::SHA3: id += "sha3"; break; case Location::Selfdestruct: id += "selfdestruct"; break; case Location::Revert: id += "revert"; break; diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 3546e5220..022b67c48 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -826,6 +826,7 @@ public: BareDelegateCall, ///< DELEGATECALL without function hash Creation, ///< external call using CREATE Send, ///< CALL, but without data and gas + Transfer, ///< CALL, but without data and throws on error SHA3, ///< SHA3 Selfdestruct, ///< SELFDESTRUCT Revert, ///< REVERT diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 2ed19a833..b0031513c 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -616,6 +616,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) arguments.front()->accept(*this); break; case Location::Send: + case Location::Transfer: _functionCall.expression().accept(*this); // Provide the gas stipend manually at first because we may send zero ether. // Will be zeroed if we send more than zero ether. @@ -625,9 +626,12 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) *arguments.front()->annotation().type, *function.parameterTypes().front(), true ); - // gas <- gas * !value - m_context << Instruction::SWAP1 << Instruction::DUP2; - m_context << Instruction::ISZERO << Instruction::MUL << Instruction::SWAP1; + if (function.location() != Location::Transfer) + { + // gas <- gas * !value + m_context << Instruction::SWAP1 << Instruction::DUP2; + m_context << Instruction::ISZERO << Instruction::MUL << Instruction::SWAP1; + } appendExternalFunctionCall( FunctionType( TypePointers{}, @@ -644,6 +648,12 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) ), {} ); + if (function.location() == Location::Transfer) + { + // Check if zero (out of stack or not enough balance). + m_context << Instruction::ISZERO; + m_context.appendConditionalInvalid(); + } break; case Location::Selfdestruct: arguments.front()->accept(*this); @@ -960,6 +970,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) case FunctionType::Location::Bare: case FunctionType::Location::BareCallCode: case FunctionType::Location::BareDelegateCall: + case FunctionType::Location::Transfer: _memberAccess.expression().accept(*this); m_context << funType->externalIdentifier(); break; @@ -1041,7 +1052,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) ); m_context << Instruction::BALANCE; } - else if ((set{"send", "call", "callcode", "delegatecall"}).count(member)) + else if ((set{"send", "transfer", "call", "callcode", "delegatecall"}).count(member)) utils().convertType( *_memberAccess.expression().annotation().type, IntegerType(0, IntegerType::Modifier::Address), From 16e48219d3071038bf7f696f234b50f6370a1171 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sun, 5 Feb 2017 22:43:36 +0000 Subject: [PATCH 138/234] Add test for address.transfer() --- test/libsolidity/SolidityEndToEndTest.cpp | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 68f8fbef3..cb0cc1684 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1681,6 +1681,42 @@ BOOST_AUTO_TEST_CASE(send_ether) BOOST_CHECK_EQUAL(balanceAt(address), amount); } +BOOST_AUTO_TEST_CASE(transfer_ether) +{ + char const* sourceCode = R"( + contract A { + function A() payable {} + function a(address addr, uint amount) returns (uint) { + addr.transfer(amount); + return this.balance; + } + function b(address addr, uint amount) { + addr.transfer(amount); + } + } + + contract B { + } + + contract C { + function () payable { + throw; + } + } + )"; + compileAndRun(sourceCode, 0, "B"); + u160 const nonPayableRecipient = m_contractAddress; + compileAndRun(sourceCode, 0, "C"); + u160 const oogRecipient = m_contractAddress; + compileAndRun(sourceCode, 20, "A"); + u160 payableRecipient(23); + BOOST_CHECK(callContractFunction("a(address,uint256)", payableRecipient, 10) == encodeArgs(10)); + BOOST_CHECK_EQUAL(balanceAt(payableRecipient), 10); + BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 10); + BOOST_CHECK(callContractFunction("b(address,uint256)", nonPayableRecipient, 10) == encodeArgs()); + BOOST_CHECK(callContractFunction("b(address,uint256)", oogRecipient, 10) == encodeArgs()); +} + BOOST_AUTO_TEST_CASE(log0) { char const* sourceCode = R"( From ba437ef31a95f40f510a475e8b329f061e929b90 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 6 Feb 2017 16:14:43 +0000 Subject: [PATCH 139/234] Add type checking test for address methods --- .../SolidityNameAndTypeResolution.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index a1ebc3008..bb2746147 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -5108,6 +5108,24 @@ BOOST_AUTO_TEST_CASE(early_exit_on_fatal_errors) CHECK_ERROR(text, DeclarationError, "Identifier not found or not unique"); } +BOOST_AUTO_TEST_CASE(address_methods) +{ + char const* text = R"( + contract C { + function f() { + address addr; + uint balance = addr.balance; + bool callRet = addr.call(); + bool callcodeRet = addr.callcode(); + bool delegatecallRet = addr.delegatecall(); + bool sendRet = addr.send(1); + addr.transfer(1); + } + } + )"; + CHECK_SUCCESS(text); +} + BOOST_AUTO_TEST_SUITE_END() } From 81006dae98ee18c33994af0274de10857774ff70 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 6 Feb 2017 16:54:05 +0000 Subject: [PATCH 140/234] Support gas modifier on addr.transfer() --- libsolidity/ast/Types.cpp | 3 ++- libsolidity/codegen/ExpressionCompiler.cpp | 3 ++- test/libsolidity/SolidityEndToEndTest.cpp | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 7fccccbc0..3e3a3818c 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -2315,9 +2315,10 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con case Location::Bare: case Location::BareCallCode: case Location::BareDelegateCall: + case Location::Transfer: { MemberList::MemberMap members; - if (m_location != Location::BareDelegateCall && m_location != Location::DelegateCall) + if (m_location != Location::BareDelegateCall && m_location != Location::DelegateCall && m_location != Location::Transfer) { if (m_isPayable) members.push_back(MemberList::Member( diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index b0031513c..92b915639 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -620,7 +620,8 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) _functionCall.expression().accept(*this); // Provide the gas stipend manually at first because we may send zero ether. // Will be zeroed if we send more than zero ether. - m_context << u256(eth::GasCosts::callStipend); + if (!function.gasSet()) + m_context << u256(eth::GasCosts::callStipend); arguments.front()->accept(*this); utils().convertType( *arguments.front()->annotation().type, diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index cb0cc1684..30430aefe 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1693,6 +1693,10 @@ BOOST_AUTO_TEST_CASE(transfer_ether) function b(address addr, uint amount) { addr.transfer(amount); } + function c(address addr, uint amount, uint gas) returns (uint) { + addr.transfer.gas(gas)(amount); + return this.balance; + } } contract B { @@ -1715,6 +1719,8 @@ BOOST_AUTO_TEST_CASE(transfer_ether) BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 10); BOOST_CHECK(callContractFunction("b(address,uint256)", nonPayableRecipient, 10) == encodeArgs()); BOOST_CHECK(callContractFunction("b(address,uint256)", oogRecipient, 10) == encodeArgs()); + BOOST_CHECK(callContractFunction("c(address,uint256,uint256)", payableRecipient, 1, 9000) == encodeArgs(9)); + BOOST_CHECK(callContractFunction("c(address,uint256,uint256)", payableRecipient, 1, 0) == encodeArgs()); } BOOST_AUTO_TEST_CASE(log0) From a36e2ce0cbb7e1830e25dacd8d79f207c9bcca6a Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 8 Feb 2017 23:37:23 +0000 Subject: [PATCH 141/234] Document transfer() --- docs/control-structures.rst | 1 + docs/miscellaneous.rst | 5 +++-- docs/types.rst | 6 +++++- docs/units-and-global-variables.rst | 2 ++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/control-structures.rst b/docs/control-structures.rst index df8ac729c..ebc459657 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -395,6 +395,7 @@ Currently, Solidity automatically generates a runtime exception in the following #. If your contract receives Ether via a public function without ``payable`` modifier (including the constructor and the fallback function). #. If your contract receives Ether via a public getter function. #. If you call a zero-initialized variable of internal function type. +#. If a ``.transfer()`` fails. While a user-provided exception is generated in the following situations: #. Calling ``throw``. diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index 3c57507ef..7b0305d5a 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -465,8 +465,9 @@ Global Variables - ``this`` (current contract's type): the current contract, explicitly convertible to ``address`` - ``super``: the contract one level higher in the inheritance hierarchy - ``selfdestruct(address recipient)``: destroy the current contract, sending its funds to the given address -- ``
.balance`` (``uint256``): balance of the address in Wei -- ``
.send(uint256 amount) returns (bool)``: send given amount of Wei to address, returns ``false`` on failure +- ``
.balance`` (``uint256``): balance of the :ref:`address` in Wei +- ``
.send(uint256 amount) returns (bool)``: send given amount of Wei to :ref:`address`, returns ``false`` on failure +- ``
.transfer(uint256 amount)``: send given amount of Wei to :ref:`address`, throws on failure .. index:: visibility, public, private, external, internal diff --git a/docs/types.rst b/docs/types.rst index 69c23e6e0..342b67f4e 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -64,7 +64,7 @@ expression ``x << y`` is equivalent to ``x * 2**y`` and ``x >> y`` is equivalent to ``x / 2**y``. This means that shifting negative numbers sign extends. Shifting by a negative amount throws a runtime exception. -.. index:: address, balance, send, call, callcode, delegatecall +.. index:: address, balance, send, call, callcode, delegatecall, transfer .. _address: @@ -102,6 +102,10 @@ and to send Ether (in units of wei) to an address using the ``send`` function: to make safe Ether transfers, always check the return value of ``send`` or even better: Use a pattern where the recipient withdraws the money. +* ``transfer`` + +Transfer operates the same way as ``send``, with the exception that it will cause a exception if the transfer has failed. + * ``call``, ``callcode`` and ``delegatecall`` Furthermore, to interface with contracts that do not adhere to the ABI, diff --git a/docs/units-and-global-variables.rst b/docs/units-and-global-variables.rst index 72741b672..49fe5d84c 100644 --- a/docs/units-and-global-variables.rst +++ b/docs/units-and-global-variables.rst @@ -130,6 +130,8 @@ Address Related balance of the :ref:`address` in Wei ``
.send(uint256 amount) returns (bool)``: send given amount of Wei to :ref:`address`, returns ``false`` on failure +``
.transfer(uint256 amount)``: + send given amount of Wei to :ref:`address`, throws on failure For more information, see the section on :ref:`address`. From c674155e584d2a1d6a88c49485e281e2a12b85d0 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 10 Feb 2017 14:38:43 +0000 Subject: [PATCH 142/234] Do not keep the gas stipend if sending non-zero value --- libsolidity/codegen/ExpressionCompiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 92b915639..4956871d7 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -627,7 +627,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) *arguments.front()->annotation().type, *function.parameterTypes().front(), true ); - if (function.location() != Location::Transfer) + if (!function.gasSet()) { // gas <- gas * !value m_context << Instruction::SWAP1 << Instruction::DUP2; From c46c68dfd8a5a8d82c19335c20d2bfa3aa8dd9ec Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 10 Feb 2017 23:15:32 +0000 Subject: [PATCH 143/234] Prefer .transfer() over .send() in the documentation --- docs/types.rst | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/types.rst b/docs/types.rst index 342b67f4e..f7d1d54fa 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -80,31 +80,31 @@ Operators: Members of Addresses ^^^^^^^^^^^^^^^^^^^^ -* ``balance`` and ``send`` +* ``balance`` and ``transfer`` For a quick reference, see :ref:`address_related`. It is possible to query the balance of an address using the property ``balance`` -and to send Ether (in units of wei) to an address using the ``send`` function: +and to send Ether (in units of wei) to an address using the ``transfer`` function: :: address x = 0x123; address myAddress = this; - if (x.balance < 10 && myAddress.balance >= 10) x.send(10); + if (x.balance < 10 && myAddress.balance >= 10) x.transfer(10); .. note:: - If ``x`` is a contract address, its code (more specifically: its fallback function, if present) will be executed together with the ``send`` call (this is a limitation of the EVM and cannot be prevented). If that execution runs out of gas or fails in any way, the Ether transfer will be reverted. In this case, ``send`` returns ``false``. + If ``x`` is a contract address, its code (more specifically: its fallback function, if present) will be executed together with the ``transfer`` call (this is a limitation of the EVM and cannot be prevented). If that execution runs out of gas or fails in any way, the Ether transfer will be reverted and the current contract will stop with an exception. + +* ``send`` + +Send is the low-level counterpart of ``transfer``. If the execution fails, the current contract will not stop with an exception, but ``send`` will return ``false``. .. warning:: There are some dangers in using ``send``: The transfer fails if the call stack depth is at 1024 (this can always be forced by the caller) and it also fails if the recipient runs out of gas. So in order - to make safe Ether transfers, always check the return value of ``send`` or even better: - Use a pattern where the recipient withdraws the money. - -* ``transfer`` - -Transfer operates the same way as ``send``, with the exception that it will cause a exception if the transfer has failed. + 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. * ``call``, ``callcode`` and ``delegatecall`` From cde027d144643883106d8bcef034c9e8ace2b3b2 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sun, 12 Feb 2017 14:07:52 +0000 Subject: [PATCH 144/234] Fix test for gas overloading in .transfer() --- test/libsolidity/SolidityEndToEndTest.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 30430aefe..f77a8935b 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1707,11 +1707,22 @@ BOOST_AUTO_TEST_CASE(transfer_ether) throw; } } + + contract D { + // This takes about ~3600 gas, which exceeds the 2300 gas stipend. + function () payable { + bytes32 tmp = 1; + for (uint i = 0; i < 20; i++) + tmp = sha3(tmp); + } + } )"; compileAndRun(sourceCode, 0, "B"); u160 const nonPayableRecipient = m_contractAddress; compileAndRun(sourceCode, 0, "C"); u160 const oogRecipient = m_contractAddress; + compileAndRun(sourceCode, 0, "D"); + u160 const expensiveRecipient = m_contractAddress; compileAndRun(sourceCode, 20, "A"); u160 payableRecipient(23); BOOST_CHECK(callContractFunction("a(address,uint256)", payableRecipient, 10) == encodeArgs(10)); @@ -1719,8 +1730,8 @@ BOOST_AUTO_TEST_CASE(transfer_ether) BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 10); BOOST_CHECK(callContractFunction("b(address,uint256)", nonPayableRecipient, 10) == encodeArgs()); BOOST_CHECK(callContractFunction("b(address,uint256)", oogRecipient, 10) == encodeArgs()); - BOOST_CHECK(callContractFunction("c(address,uint256,uint256)", payableRecipient, 1, 9000) == encodeArgs(9)); - BOOST_CHECK(callContractFunction("c(address,uint256,uint256)", payableRecipient, 1, 0) == encodeArgs()); + BOOST_CHECK(callContractFunction("c(address,uint256,uint256)", expensiveRecipient, 1, 9000) == encodeArgs(9)); + BOOST_CHECK(callContractFunction("c(address,uint256,uint256)", expensiveRecipient, 1, 0) == encodeArgs()); } BOOST_AUTO_TEST_CASE(log0) From 59514d8268585f02aa1abb1fdb1b56bcf6e56ef4 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 13 Feb 2017 02:17:17 +0000 Subject: [PATCH 145/234] Remove obsolete .send() entry from FAQ --- docs/frequently-asked-questions.rst | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst index d2fc5b1ce..8a68ae5b9 100644 --- a/docs/frequently-asked-questions.rst +++ b/docs/frequently-asked-questions.rst @@ -660,16 +660,6 @@ https://github.com/ethereum/wiki/wiki/Subtleties After a successful CREATE operation's sub-execution, if the operation returns x, 5 * len(x) gas is subtracted from the remaining gas before the contract is created. If the remaining gas is less than 5 * len(x), then no gas is subtracted, the code of the created contract becomes the empty string, but this is not treated as an exceptional condition - no reverts happen. -How do I use ``.send()``? -========================= - -If you want to send 20 Ether from a contract to the address ``x``, you use ``x.send(20 ether);``. -Here, ``x`` can be a plain address or a contract. If the contract already explicitly defines -a function ``send`` (and thus overwrites the special function), you can use ``address(x).send(20 ether);``. - -Note that the call to ``send`` may fail in certain conditions, such as if you have insufficient funds, so you should always check the return value. -``send`` returns ``true`` if the send was successful and ``false`` otherwise. - What does the following strange check do in the Custom Token contract? ====================================================================== From 4d290e551c2d563671f9d56744883d3f3dff98ec Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 24 Feb 2017 00:27:36 +0000 Subject: [PATCH 146/234] Disallow setting .gas() on .transfer() --- libsolidity/ast/Types.cpp | 3 +-- libsolidity/codegen/ExpressionCompiler.cpp | 12 ++++-------- test/libsolidity/SolidityEndToEndTest.cpp | 17 ----------------- 3 files changed, 5 insertions(+), 27 deletions(-) diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 3e3a3818c..7fccccbc0 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -2315,10 +2315,9 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con case Location::Bare: case Location::BareCallCode: case Location::BareDelegateCall: - case Location::Transfer: { MemberList::MemberMap members; - if (m_location != Location::BareDelegateCall && m_location != Location::DelegateCall && m_location != Location::Transfer) + if (m_location != Location::BareDelegateCall && m_location != Location::DelegateCall) { if (m_isPayable) members.push_back(MemberList::Member( diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 4956871d7..fd4d87a58 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -620,19 +620,15 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) _functionCall.expression().accept(*this); // Provide the gas stipend manually at first because we may send zero ether. // Will be zeroed if we send more than zero ether. - if (!function.gasSet()) - m_context << u256(eth::GasCosts::callStipend); + m_context << u256(eth::GasCosts::callStipend); arguments.front()->accept(*this); utils().convertType( *arguments.front()->annotation().type, *function.parameterTypes().front(), true ); - if (!function.gasSet()) - { - // gas <- gas * !value - m_context << Instruction::SWAP1 << Instruction::DUP2; - m_context << Instruction::ISZERO << Instruction::MUL << Instruction::SWAP1; - } + // gas <- gas * !value + m_context << Instruction::SWAP1 << Instruction::DUP2; + m_context << Instruction::ISZERO << Instruction::MUL << Instruction::SWAP1; appendExternalFunctionCall( FunctionType( TypePointers{}, diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index f77a8935b..cb0cc1684 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1693,10 +1693,6 @@ BOOST_AUTO_TEST_CASE(transfer_ether) function b(address addr, uint amount) { addr.transfer(amount); } - function c(address addr, uint amount, uint gas) returns (uint) { - addr.transfer.gas(gas)(amount); - return this.balance; - } } contract B { @@ -1707,22 +1703,11 @@ BOOST_AUTO_TEST_CASE(transfer_ether) throw; } } - - contract D { - // This takes about ~3600 gas, which exceeds the 2300 gas stipend. - function () payable { - bytes32 tmp = 1; - for (uint i = 0; i < 20; i++) - tmp = sha3(tmp); - } - } )"; compileAndRun(sourceCode, 0, "B"); u160 const nonPayableRecipient = m_contractAddress; compileAndRun(sourceCode, 0, "C"); u160 const oogRecipient = m_contractAddress; - compileAndRun(sourceCode, 0, "D"); - u160 const expensiveRecipient = m_contractAddress; compileAndRun(sourceCode, 20, "A"); u160 payableRecipient(23); BOOST_CHECK(callContractFunction("a(address,uint256)", payableRecipient, 10) == encodeArgs(10)); @@ -1730,8 +1715,6 @@ BOOST_AUTO_TEST_CASE(transfer_ether) BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 10); BOOST_CHECK(callContractFunction("b(address,uint256)", nonPayableRecipient, 10) == encodeArgs()); BOOST_CHECK(callContractFunction("b(address,uint256)", oogRecipient, 10) == encodeArgs()); - BOOST_CHECK(callContractFunction("c(address,uint256,uint256)", expensiveRecipient, 1, 9000) == encodeArgs(9)); - BOOST_CHECK(callContractFunction("c(address,uint256,uint256)", expensiveRecipient, 1, 0) == encodeArgs()); } BOOST_AUTO_TEST_CASE(log0) From 46d3c2dd3d3101a3d9c0eba485cf4503c8a40890 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 16 Feb 2017 19:58:08 +0100 Subject: [PATCH 147/234] Print source location before items. --- libevmasm/Assembly.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp index b7859c1f0..f12e8aa87 100644 --- a/libevmasm/Assembly.cpp +++ b/libevmasm/Assembly.cpp @@ -130,8 +130,8 @@ public: if (!_item.location().isEmpty() && _item.location() != m_location) { flush(); - printLocation(); m_location = _item.location(); + printLocation(); } if (!( _item.canBeFunctional() && From de1317331f2607cc1e89779ccfd0ffa812628642 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 24 Feb 2017 08:25:01 +0100 Subject: [PATCH 148/234] Changelog entry. --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 45aaf04a5..1d61f09d5 100644 --- a/Changelog.md +++ b/Changelog.md @@ -12,6 +12,7 @@ Bugfixes: * Type system: Fix a crash caused by continuing on fatal errors in the code. * Type system: Disallow arrays with negative length. * Inline assembly: Charge one stack slot for non-value types during analysis. + * Assembly output: Print source location before the operation it refers to instead of after. ### 0.4.9 (2017-01-31) From 7a24a5764edf728f0caa14e7aa8f832d7e6f42e3 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 24 Feb 2017 19:31:20 +0100 Subject: [PATCH 149/234] Add line info to serious exceptions. --- libdevcore/Exceptions.h | 3 +++ libsolidity/interface/Exceptions.cpp | 14 ++++++++++++++ solc/jsonCompiler.cpp | 6 +++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/libdevcore/Exceptions.h b/libdevcore/Exceptions.h index 4622774a4..37cdbed96 100644 --- a/libdevcore/Exceptions.h +++ b/libdevcore/Exceptions.h @@ -41,6 +41,9 @@ struct Exception: virtual std::exception, virtual boost::exception Exception(std::string _message = std::string()): m_message(std::move(_message)) {} const char* what() const noexcept override { return m_message.empty() ? std::exception::what() : m_message.c_str(); } + /// @returns "FileName:LineNumber" referring to the point where the exception was thrown. + std::string lineInfo() const; + private: std::string m_message; }; diff --git a/libsolidity/interface/Exceptions.cpp b/libsolidity/interface/Exceptions.cpp index 90a680b4d..41890b91a 100644 --- a/libsolidity/interface/Exceptions.cpp +++ b/libsolidity/interface/Exceptions.cpp @@ -23,6 +23,7 @@ #include #include +using namespace std; using namespace dev; using namespace dev::solidity; @@ -56,3 +57,16 @@ Error::Error(Type _type): m_type(_type) break; } } + +string Exception::lineInfo() const +{ + char const* const* file = boost::get_error_info(*this); + int const* line = boost::get_error_info(*this); + string ret; + if (file) + ret += *file; + ret += ':'; + if (line) + ret += boost::lexical_cast(*line); + return ret; +} diff --git a/solc/jsonCompiler.cpp b/solc/jsonCompiler.cpp index d761b541c..6ebd1a55a 100644 --- a/solc/jsonCompiler.cpp +++ b/solc/jsonCompiler.cpp @@ -184,15 +184,15 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback } catch (CompilerError const& exception) { - errors.append(formatError(exception, "Compiler error", scannerFromSourceName)); + errors.append(formatError(exception, "Compiler error (" + exception.lineInfo() + ")", scannerFromSourceName)); } catch (InternalCompilerError const& exception) { - errors.append(formatError(exception, "Internal compiler error", scannerFromSourceName)); + errors.append(formatError(exception, "Internal compiler error (" + exception.lineInfo() + ")", scannerFromSourceName)); } catch (UnimplementedFeatureError const& exception) { - errors.append(formatError(exception, "Unimplemented feature", scannerFromSourceName)); + errors.append(formatError(exception, "Unimplemented feature (" + exception.lineInfo() + ")", scannerFromSourceName)); } catch (Exception const& exception) { From 8877d4a7819a589d41b87e10237fa281e453a604 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 24 Feb 2017 19:31:39 +0100 Subject: [PATCH 150/234] Compiler error is not a failure. --- test/fuzzer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/fuzzer.cpp b/test/fuzzer.cpp index 85a8fe99b..f957d4edd 100644 --- a/test/fuzzer.cpp +++ b/test/fuzzer.cpp @@ -67,7 +67,6 @@ int main() for (Json::Value const& error: outputJson["errors"]) { string invalid = contains(error.asString(), vector{ - "Compiler error", "Internal compiler error", "Exception during compilation", "Unknown exception during compilation", From 9acfdb80444e94c2fe8845f796f13f8dedc49b22 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 24 Feb 2017 19:31:52 +0100 Subject: [PATCH 151/234] Print full error on failure. --- test/fuzzer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fuzzer.cpp b/test/fuzzer.cpp index f957d4edd..410313c5c 100644 --- a/test/fuzzer.cpp +++ b/test/fuzzer.cpp @@ -77,7 +77,7 @@ int main() }); if (!invalid.empty()) { - cout << "Invalid error: \"" << invalid << "\"" << endl; + cout << "Invalid error: \"" << error.asString() << "\"" << endl; abort(); } } From 41360ccd57997edfd6807c75a33f4dbc4b65558b Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 24 Feb 2017 19:33:05 +0100 Subject: [PATCH 152/234] Script for filtering unique failures. --- scripts/uniqueErrors.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 scripts/uniqueErrors.sh diff --git a/scripts/uniqueErrors.sh b/scripts/uniqueErrors.sh new file mode 100755 index 000000000..eee1df903 --- /dev/null +++ b/scripts/uniqueErrors.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +REPO=$(dirname $0)/.. + +echo "Finding unique failures..." +( +for x in $* +do + echo -n $x " # " + # This subshell is a workaround to prevent the shell from printing + # "Aborted" + ("$REPO"/build/test/solfuzzer < "$x" || true) 2>&1 | head -n 1 +done +) | sort -u -t'#' -k 2 From 4305ecb0e7bca7f64324e0804df9543c4775aa6f Mon Sep 17 00:00:00 2001 From: chriseth Date: Sat, 25 Feb 2017 00:11:26 +0100 Subject: [PATCH 153/234] Try reading multiple times from IPC. --- test/RPCSession.cpp | 39 +++++++++++++++++++++++++-------------- test/RPCSession.h | 10 ++++++++-- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index ff00d7833..57829ff5c 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -16,19 +16,20 @@ The Implementation originally from https://msdn.microsoft.com/en-us/library/windows/desktop/aa365592(v=vs.85).aspx */ -/** @file RPCSession.cpp - * @author Dimtiry Khokhlov - * @author Alex Beregszaszi - * @date 2016 - */ +/// @file RPCSession.cpp +/// Low-level IPC communication between the test framework and the Ethereum node. + +#include "RPCSession.h" + +#include + +#include +#include #include #include #include -#include -#include -#include -#include "RPCSession.h" +#include using namespace std; using namespace dev; @@ -107,13 +108,23 @@ string IPCSocket::sendRequest(string const& _req) return string(m_readBuf, m_readBuf + cbRead); #else if (send(m_socket, _req.c_str(), _req.length(), 0) != (ssize_t)_req.length()) - BOOST_FAIL("Writing on IPC failed"); + BOOST_FAIL("Writing on IPC failed."); - ssize_t ret = recv(m_socket, m_readBuf, sizeof(m_readBuf), 0); + auto start = chrono::steady_clock::now(); + ssize_t ret; + do + { + ret = recv(m_socket, m_readBuf, sizeof(m_readBuf), 0); + // Also consider closed socket an error. + if (ret < 0) + BOOST_FAIL("Reading on IPC failed."); + } while ( + ret == 0 && + chrono::duration_cast(chrono::steady_clock::now() - start).count() < m_readTimeOutMS + ); - // Also consider closed socket an error. - if (ret <= 0) - BOOST_FAIL("Reading on IPC failed"); + if (ret == 0) + BOOST_FAIL("Timeout reading on IPC."); return string(m_readBuf, m_readBuf + ret); #endif diff --git a/test/RPCSession.h b/test/RPCSession.h index 414db3232..843036e14 100644 --- a/test/RPCSession.h +++ b/test/RPCSession.h @@ -28,11 +28,13 @@ #include #endif +#include + +#include + #include #include #include -#include -#include #if defined(_WIN32) class IPCSocket : public boost::noncopyable @@ -60,8 +62,12 @@ public: std::string const& path() const { return m_path; } private: + std::string m_path; int m_socket; + /// Socket read timeout in milliseconds. Needs to be large because the key generation routine + /// might take long. + unsigned static constexpr m_readTimeOutMS = 15000; char m_readBuf[512000]; }; #endif From 9f1a67caa5f532e8221b64225abd0b313afca097 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 1 Mar 2017 11:32:29 +0100 Subject: [PATCH 154/234] Some logging around account creation. --- test/RPCSession.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index 57829ff5c..a71ff2862 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -197,12 +197,17 @@ string RPCSession::eth_getStorageRoot(string const& _address, string const& _blo void RPCSession::personal_unlockAccount(string const& _address, string const& _password, int _duration) { - BOOST_REQUIRE(rpcCall("personal_unlockAccount", { quote(_address), quote(_password), to_string(_duration) }) == true); + BOOST_REQUIRE_MESSAGE( + rpcCall("personal_unlockAccount", { quote(_address), quote(_password), to_string(_duration) }), + "Error unlocking account " + _address + ); } string RPCSession::personal_newAccount(string const& _password) { - return rpcCall("personal_newAccount", { quote(_password) }).asString(); + string addr = rpcCall("personal_newAccount", { quote(_password) }).asString(); + BOOST_MESSAGE("Created account " + addr); + return addr; } void RPCSession::test_setChainParams(vector const& _accounts) From f35b70f3a325f7dd31eb51b0cff3eaf993bfffbb Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 1 Mar 2017 15:53:24 +0100 Subject: [PATCH 155/234] Test case for external function type with calldata argument. --- .../SolidityNameAndTypeResolution.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index bb2746147..866bd9aa4 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -4736,6 +4736,23 @@ BOOST_AUTO_TEST_CASE(delete_external_function_type_invalid) CHECK_ERROR(text, TypeError, ""); } +BOOST_AUTO_TEST_CASE(external_function_to_function_type_calldata_parameter) +{ + // This is a test that checks that the type of the `bytes` parameter is + // correctly changed from its own type `bytes calldata` to `bytes memory` + // when converting to a function type. + char const* text = R"( + contract C { + function f(function(bytes memory x) external g) { } + function callback(bytes x) external {} + function g() { + f(this.callback); + } + } + )"; + CHECK_SUCCESS(text); +} + BOOST_AUTO_TEST_CASE(external_function_type_to_address) { char const* text = R"( From a689152c4bcf21f6f1d7ffbc5e2444a4c2ff75ee Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 1 Mar 2017 16:02:36 +0100 Subject: [PATCH 156/234] Convert reference types to pointers in member function conversion. --- libsolidity/ast/Types.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 99d6f4a26..7f267cc9b 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -2493,7 +2493,7 @@ FunctionTypePointer FunctionType::asMemberFunction(bool _inLibrary, bool _bound) { auto refType = dynamic_cast(t.get()); if (refType && refType->location() == DataLocation::CallData) - parameterTypes.push_back(refType->copyForLocation(DataLocation::Memory, false)); + parameterTypes.push_back(refType->copyForLocation(DataLocation::Memory, true)); else parameterTypes.push_back(t); } From b832b70e1bf09087005f0e620fa5e20d57fd3310 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 1 Mar 2017 16:09:19 +0100 Subject: [PATCH 157/234] Changelog entry. --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index c46ba3bde..3eaadf21e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -13,6 +13,7 @@ Bugfixes: * Type system: Fix a crash caused by continuing on fatal errors in the code. * Type system: Disallow arrays with negative length. * Type system: Fix a crash related to invalid binary operators. + * Type system: Correctly convert function argument types to pointers for member functions. * Inline assembly: Charge one stack slot for non-value types during analysis. * Assembly output: Print source location before the operation it refers to instead of after. From ea7f5f96408bbdd06417480ac570f2b289f25581 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 2 Mar 2017 12:07:50 +0100 Subject: [PATCH 158/234] Style. --- test/RPCSession.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index a71ff2862..be8774bcf 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -118,7 +118,8 @@ string IPCSocket::sendRequest(string const& _req) // Also consider closed socket an error. if (ret < 0) BOOST_FAIL("Reading on IPC failed."); - } while ( + } + while ( ret == 0 && chrono::duration_cast(chrono::steady_clock::now() - start).count() < m_readTimeOutMS ); From 2600fa041319b285f43ac0c751756d422a4e2658 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 1 Mar 2017 15:42:41 +0100 Subject: [PATCH 159/234] Test for declaring variable with empty tuple type. --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 866bd9aa4..3b1375721 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -2950,6 +2950,19 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_6) CHECK_ERROR(text, TypeError, ""); } +BOOST_AUTO_TEST_CASE(tuple_assignment_from_void_function) +{ + char const* text = R"( + contract C { + function f() { } + function g() { + var (x,) = (f(), f()); + } + } + )"; + CHECK_ERROR(text, TypeError, "Cannot declare variable with void (empty tuple) type."); +} + BOOST_AUTO_TEST_CASE(member_access_parser_ambiguity) { char const* text = R"( From cc01d870ff642ee3c52f5473f6f2a2fba5ec15c8 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 1 Mar 2017 15:42:53 +0100 Subject: [PATCH 160/234] Disallow variable declaration with inferred empty tuple type. --- libsolidity/analysis/TypeChecker.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 4025831ea..ff55ef1f9 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -824,6 +824,11 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement) else solAssert(false, ""); } + else if (*var.annotation().type == TupleType()) + typeError( + var.location(), + "Cannot declare variable with void (empty tuple) type." + ); var.accept(*this); } else From 6a9df162fd30237e9313a28599d4b0f26f2ea4f2 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 1 Mar 2017 15:47:25 +0100 Subject: [PATCH 161/234] Changelog entry. --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 3eaadf21e..5eb1e401e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -13,6 +13,7 @@ Bugfixes: * Type system: Fix a crash caused by continuing on fatal errors in the code. * Type system: Disallow arrays with negative length. * Type system: Fix a crash related to invalid binary operators. + * Type system: Disallow ``var`` declaration with empty tuple type. * Type system: Correctly convert function argument types to pointers for member functions. * Inline assembly: Charge one stack slot for non-value types during analysis. * Assembly output: Print source location before the operation it refers to instead of after. From fd62adebf3e594298c171e43e78153dbefc42759 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 14 Feb 2017 18:14:40 +0100 Subject: [PATCH 162/234] Tests for labels with stack information. --- test/libsolidity/InlineAssembly.cpp | 10 +++++++++ test/libsolidity/SolidityEndToEndTest.cpp | 27 +++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index 9035599ba..824fce958 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -200,6 +200,11 @@ BOOST_AUTO_TEST_CASE(blocks) BOOST_CHECK(successParse("{ let x := 7 { let y := 3 } { let z := 2 } }")); } +BOOST_AUTO_TEST_CASE(labels_with_stack_info) +{ + BOOST_CHECK(successParse("{ x[-1]: y[a]: z[d, e]: h[100]: g[]: }")); +} + BOOST_AUTO_TEST_CASE(function_definitions) { BOOST_CHECK(successParse("{ function f() { } function g(a) -> (x) { } }")); @@ -244,6 +249,11 @@ BOOST_AUTO_TEST_CASE(print_label) parsePrintCompare("{\n loop:\n jump(loop)\n}"); } +BOOST_AUTO_TEST_CASE(print_label_with_stack) +{ + parsePrintCompare("{\n loop[x, y]:\n other[-2]:\n third[10]:\n}"); +} + BOOST_AUTO_TEST_CASE(print_assignments) { parsePrintCompare("{\n let x := mul(2, 3)\n 7\n =: x\n x := add(1, 2)\n}"); diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index cb0cc1684..d20283449 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -7418,6 +7418,33 @@ BOOST_AUTO_TEST_CASE(inline_assembly_function_access) BOOST_CHECK(callContractFunction("x()") == encodeArgs(u256(10))); } +BOOST_AUTO_TEST_CASE(inline_assembly_labels_with_stack_info) +{ + char const* sourceCode = R"( + contract C { + function f(uint y) { + assembly { + y 7 + jump(fun) + exit[-1]: + y add + 0 mstore + return(0, 0x20) + fun: + { + entry[a, b]: + a := div(a, b) + pop + jump(exit) + } + } + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("f(uint256)", u256(15)) == encodeArgs(15 / 7 + 15)); +} + BOOST_AUTO_TEST_CASE(index_access_with_type_conversion) { // Test for a bug where higher order bits cleanup was not done for array index access. From 98e343b3fc11f3e94297b016c3f625e3b319b09b Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 1 Feb 2017 21:40:50 +0100 Subject: [PATCH 163/234] Parsing of labels with stack info. --- libsolidity/inlineasm/AsmCodeGen.cpp | 1 + libsolidity/inlineasm/AsmData.h | 4 ++-- libsolidity/inlineasm/AsmParser.cpp | 32 ++++++++++++++++++++++++++++ libsolidity/inlineasm/AsmPrinter.cpp | 6 +++++- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/libsolidity/inlineasm/AsmCodeGen.cpp b/libsolidity/inlineasm/AsmCodeGen.cpp index faa7dabdf..abc0ca01b 100644 --- a/libsolidity/inlineasm/AsmCodeGen.cpp +++ b/libsolidity/inlineasm/AsmCodeGen.cpp @@ -91,6 +91,7 @@ public: void operator()(T const& /*_item*/) { } void operator()(Label const& _item) { + solAssert(_item.stackInfo.empty(), "Labels with stack info not yet supported."); if (m_state.labels.count(_item.name)) //@TODO secondary location m_state.addError( diff --git a/libsolidity/inlineasm/AsmData.h b/libsolidity/inlineasm/AsmData.h index d61b5803e..5969bf963 100644 --- a/libsolidity/inlineasm/AsmData.h +++ b/libsolidity/inlineasm/AsmData.h @@ -42,8 +42,8 @@ struct Literal { SourceLocation location; bool isNumber; std::string value; }; /// External / internal identifier or label reference struct Identifier { SourceLocation location; std::string name; }; struct FunctionalInstruction; -/// Jump label ("name:") -struct Label { SourceLocation location; std::string name; }; +/// Jump label ("name:" or "name [x, y, z]:" or "name [-3]:") +struct Label { SourceLocation location; std::string name; std::vector stackInfo; }; /// Assignemnt (":= x", moves stack top into x, potentially multiple slots) struct Assignment { SourceLocation location; Identifier variableName; }; struct FunctionalAssignment; diff --git a/libsolidity/inlineasm/AsmParser.cpp b/libsolidity/inlineasm/AsmParser.cpp index 0fc0a34f8..5d439b2f0 100644 --- a/libsolidity/inlineasm/AsmParser.cpp +++ b/libsolidity/inlineasm/AsmParser.cpp @@ -121,6 +121,38 @@ assembly::Statement Parser::parseStatement() return label; } } + case Token::LBrack: + { + if (statement.type() != typeid(assembly::Identifier)) + fatalParserError("Label name must precede \"[\"."); + assembly::Identifier const& identifier = boost::get(statement); + Label label = createWithLocation