Merge pull request #9467 from ethereum/develop

Merge develop into release for 0.6.12
This commit is contained in:
chriseth 2020-07-22 15:34:41 +02:00 committed by GitHub
commit 27d51765c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
721 changed files with 4585 additions and 1002 deletions

View File

@ -7,18 +7,21 @@
# - ems: Emscripten # - ems: Emscripten
version: 2.1 version: 2.1
parameters: parameters:
ubuntu-1804-docker-image-rev: ubuntu-1804-docker-image:
type: string type: string
default: "4" default: "solbuildpackpusher/solidity-buildpack-deps@sha256:4484ac3da8fdc337cc77a7a7be1af71cd0f28f9c890d934f1d6ae7532beb66b1"
ubuntu-2004-docker-image-rev: ubuntu-2004-docker-image:
type: string type: string
default: "2" default: "solbuildpackpusher/solidity-buildpack-deps@sha256:48b5bb6b91ac7dddfe9345c88876ebed126c652258800f114caed69db73b29bf"
ubuntu-2004-clang-docker-image-rev: ubuntu-2004-clang-docker-image:
type: string type: string
default: "2" default: "solbuildpackpusher/solidity-buildpack-deps@sha256:d8775de58167db5a11690fdb6ef639317fe1e579ec5d46e9732d2d903b55d135"
ubuntu-1604-clang-ossfuzz-docker-image-rev: ubuntu-1604-clang-ossfuzz-docker-image:
type: string type: string
default: "2" default: "solbuildpackpusher/solidity-buildpack-deps@sha256:db52f3257396814215744a19904e42c07e040ab36b68be72a27ba71ad2f1083c"
emscripten-docker-image:
type: string
default: "solbuildpackpusher/solidity-buildpack-deps@sha256:d557d015918c3cf68b0d22839bab41013f0757b651a7fef21595f89721dbebcc"
defaults: defaults:
@ -33,26 +36,11 @@ defaults:
- run_build: &run_build - run_build: &run_build
name: Build name: Build
command: | command: scripts/ci/build.sh
set -ex
if [ "$CIRCLE_BRANCH" = release -o -n "$CIRCLE_TAG" -o -n "$FORCE_RELEASE" ]; then echo -n > prerelease.txt; else date -u +"nightly.%Y.%-m.%-d" > prerelease.txt; fi
echo -n "$CIRCLE_SHA1" > commit_hash.txt
mkdir -p build
cd build
[ -n "$COVERAGE" -a "$CIRCLE_BRANCH" != release -a -z "$CIRCLE_TAG" ] && CMAKE_OPTIONS="$CMAKE_OPTIONS -DCOVERAGE=ON"
cmake .. -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Release} $CMAKE_OPTIONS -G "Unix Makefiles"
make -j4
- run_build_ossfuzz: &run_build_ossfuzz - run_build_ossfuzz: &run_build_ossfuzz
name: Build_ossfuzz name: Build_ossfuzz
command: | command: scripts/ci/build_ossfuzz.sh
mkdir -p build
cd build
protoc --proto_path=../test/tools/ossfuzz yulProto.proto --cpp_out=../test/tools/ossfuzz
protoc --proto_path=../test/tools/ossfuzz abiV2Proto.proto --cpp_out=../test/tools/ossfuzz
protoc --proto_path=../test/tools/ossfuzz solProto.proto --cpp_out=../test/tools/ossfuzz
cmake .. -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Release} $CMAKE_OPTIONS
make ossfuzz ossfuzz_proto ossfuzz_abiv2 -j4
- run_proofs: &run_proofs - run_proofs: &run_proofs
name: Correctness proofs for optimization rules name: Correctness proofs for optimization rules
@ -97,6 +85,7 @@ defaults:
- test/tools/ossfuzz/strictasm_diff_ossfuzz - test/tools/ossfuzz/strictasm_diff_ossfuzz
- test/tools/ossfuzz/strictasm_opt_ossfuzz - test/tools/ossfuzz/strictasm_opt_ossfuzz
- test/tools/ossfuzz/yul_proto_diff_ossfuzz - test/tools/ossfuzz/yul_proto_diff_ossfuzz
- test/tools/ossfuzz/yul_proto_diff_custom_mutate_ossfuzz
- test/tools/ossfuzz/yul_proto_ossfuzz - test/tools/ossfuzz/yul_proto_ossfuzz
- test/tools/ossfuzz/sol_proto_ossfuzz - test/tools/ossfuzz/sol_proto_ossfuzz
@ -130,7 +119,7 @@ defaults:
- test_ubuntu1604_clang: &test_ubuntu1604_clang - test_ubuntu1604_clang: &test_ubuntu1604_clang
docker: docker:
- image: ethereum/solidity-buildpack-deps:ubuntu1604-clang-ossfuzz-<< pipeline.parameters.ubuntu-1604-clang-ossfuzz-docker-image-rev >> - image: << pipeline.parameters.ubuntu-1604-clang-ossfuzz-docker-image >>
steps: steps:
- checkout - checkout
- attach_workspace: - attach_workspace:
@ -141,7 +130,7 @@ defaults:
- test_ubuntu2004_clang: &test_ubuntu2004_clang - test_ubuntu2004_clang: &test_ubuntu2004_clang
docker: docker:
- image: ethereum/solidity-buildpack-deps:ubuntu2004-clang-<< pipeline.parameters.ubuntu-2004-clang-docker-image-rev >> - image: << pipeline.parameters.ubuntu-2004-clang-docker-image >>
steps: steps:
- checkout - checkout
- attach_workspace: - attach_workspace:
@ -152,7 +141,8 @@ defaults:
- test_ubuntu2004: &test_ubuntu2004 - test_ubuntu2004: &test_ubuntu2004
docker: docker:
- image: ethereum/solidity-buildpack-deps:ubuntu2004-<< pipeline.parameters.ubuntu-2004-docker-image-rev >> - image: << pipeline.parameters.ubuntu-2004-docker-image >>
parallelism: 6
steps: steps:
- checkout - checkout
- attach_workspace: - attach_workspace:
@ -387,7 +377,7 @@ jobs:
chk_docs_pragma_min_version: chk_docs_pragma_min_version:
docker: docker:
- image: ethereum/solidity-buildpack-deps:ubuntu2004-<< pipeline.parameters.ubuntu-2004-docker-image-rev >> - image: << pipeline.parameters.ubuntu-2004-docker-image >>
environment: environment:
TERM: xterm TERM: xterm
steps: steps:
@ -396,7 +386,7 @@ jobs:
b_ubu_clang: &build_ubuntu2004_clang b_ubu_clang: &build_ubuntu2004_clang
docker: docker:
- image: ethereum/solidity-buildpack-deps:ubuntu2004-clang-<< pipeline.parameters.ubuntu-2004-clang-docker-image-rev >> - image: << pipeline.parameters.ubuntu-2004-clang-docker-image >>
environment: environment:
CC: clang CC: clang
CXX: clang++ CXX: clang++
@ -409,7 +399,7 @@ jobs:
b_ubu_asan_clang: &build_ubuntu2004_clang b_ubu_asan_clang: &build_ubuntu2004_clang
docker: docker:
- image: ethereum/solidity-buildpack-deps:ubuntu2004-clang-<< pipeline.parameters.ubuntu-2004-clang-docker-image-rev >> - image: << pipeline.parameters.ubuntu-2004-clang-docker-image >>
environment: environment:
CC: clang CC: clang
CXX: clang++ CXX: clang++
@ -421,8 +411,11 @@ jobs:
- persist_to_workspace: *artifacts_executables - persist_to_workspace: *artifacts_executables
b_ubu: &build_ubuntu2004 b_ubu: &build_ubuntu2004
resource_class: xlarge
docker: docker:
- image: ethereum/solidity-buildpack-deps:ubuntu2004-<< pipeline.parameters.ubuntu-2004-docker-image-rev >> - image: << pipeline.parameters.ubuntu-2004-docker-image >>
environment:
MAKEFLAGS: -j 10
steps: steps:
- checkout - checkout
- run: *run_build - run: *run_build
@ -437,7 +430,7 @@ jobs:
b_ubu18: &build_ubuntu1804 b_ubu18: &build_ubuntu1804
docker: docker:
- image: ethereum/solidity-buildpack-deps:ubuntu1804-<< pipeline.parameters.ubuntu-1804-docker-image-rev >> - image: << pipeline.parameters.ubuntu-1804-docker-image >>
environment: environment:
CMAKE_OPTIONS: -DCMAKE_CXX_FLAGS=-O2 CMAKE_OPTIONS: -DCMAKE_CXX_FLAGS=-O2
CMAKE_BUILD_TYPE: RelWithDebugInfo CMAKE_BUILD_TYPE: RelWithDebugInfo
@ -491,7 +484,7 @@ jobs:
b_ubu_ossfuzz: &build_ubuntu1604_clang b_ubu_ossfuzz: &build_ubuntu1604_clang
docker: docker:
- image: ethereum/solidity-buildpack-deps:ubuntu1604-clang-ossfuzz-<< pipeline.parameters.ubuntu-1604-clang-ossfuzz-docker-image-rev >> - image: << pipeline.parameters.ubuntu-1604-clang-ossfuzz-docker-image >>
environment: environment:
CC: clang CC: clang
CXX: clang++ CXX: clang++
@ -597,9 +590,11 @@ jobs:
- store_artifacts: *artifacts_test_results - store_artifacts: *artifacts_test_results
b_ems: b_ems:
resource_class: xlarge
docker: docker:
- image: ethereum/solidity-buildpack-deps:emsdk-1.39.15-2 - image: << pipeline.parameters.emscripten-docker-image >>
environment: environment:
MAKEFLAGS: -j 10
TERM: xterm TERM: xterm
steps: steps:
- checkout - checkout
@ -633,7 +628,7 @@ jobs:
b_docs: b_docs:
docker: docker:
- image: ethereum/solidity-buildpack-deps:ubuntu2004-<< pipeline.parameters.ubuntu-2004-docker-image-rev >> - image: << pipeline.parameters.ubuntu-2004-docker-image >>
steps: steps:
- checkout - checkout
- run: *setup_prerelease_commit_hash - run: *setup_prerelease_commit_hash
@ -649,7 +644,7 @@ jobs:
t_ubu_soltest_enforce_yul: &t_ubu_soltest_enforce_yul t_ubu_soltest_enforce_yul: &t_ubu_soltest_enforce_yul
docker: docker:
- image: ethereum/solidity-buildpack-deps:ubuntu2004-<< pipeline.parameters.ubuntu-2004-docker-image-rev >> - image: << pipeline.parameters.ubuntu-2004-docker-image >>
environment: environment:
EVM: constantinople EVM: constantinople
SOLTEST_FLAGS: --enforce-via-yul SOLTEST_FLAGS: --enforce-via-yul
@ -675,7 +670,7 @@ jobs:
t_ubu_cli: &t_ubu_cli t_ubu_cli: &t_ubu_cli
docker: docker:
- image: ethereum/solidity-buildpack-deps:ubuntu2004-<< pipeline.parameters.ubuntu-2004-docker-image-rev >> - image: << pipeline.parameters.ubuntu-2004-docker-image >>
environment: environment:
TERM: xterm TERM: xterm
steps: steps:

View File

@ -54,7 +54,7 @@ get_logfile_basename() {
echo -ne "${filename}" echo -ne "${filename}"
} }
BOOST_TEST_ARGS="--color_output=no --show_progress=yes --logger=JUNIT,error,test_results/`get_logfile_basename`.xml" BOOST_TEST_ARGS="--color_output=no --show_progress=yes --logger=JUNIT,error,test_results/`get_logfile_basename`.xml ${BOOST_TEST_ARGS}"
SOLTEST_ARGS="--evm-version=$EVM $SOLTEST_FLAGS" SOLTEST_ARGS="--evm-version=$EVM $SOLTEST_FLAGS"
test "${OPTIMIZE}" = "1" && SOLTEST_ARGS="${SOLTEST_ARGS} --optimize" test "${OPTIMIZE}" = "1" && SOLTEST_ARGS="${SOLTEST_ARGS} --optimize"
test "${ABI_ENCODER_V2}" = "1" && SOLTEST_ARGS="${SOLTEST_ARGS} --abiencoderv2" test "${ABI_ENCODER_V2}" = "1" && SOLTEST_ARGS="${SOLTEST_ARGS} --abiencoderv2"

View File

@ -28,10 +28,49 @@ set -e
REPODIR="$(realpath $(dirname $0)/..)" REPODIR="$(realpath $(dirname $0)/..)"
for OPTIMIZE in 0 1; do EVM_VALUES=(homestead byzantium constantinople petersburg istanbul)
for EVM in homestead byzantium constantinople petersburg istanbul; do OPTIMIZE_VALUES=(0 1)
EVM=$EVM OPTIMIZE=$OPTIMIZE ${REPODIR}/.circleci/soltest.sh STEPS=$(( 1 + ${#EVM_VALUES[@]} * ${#OPTIMIZE_VALUES[@]} ))
if (( $CIRCLE_NODE_TOTAL )) && (( $CIRCLE_NODE_TOTAL > 1 ))
then
# Run step 1 as the only step on the first executor
# and evenly distribute the other steps among
# the other executors.
# The first step takes much longer than the other steps.
if (( $CIRCLE_NODE_INDEX == 0 ))
then
RUN_STEPS="1"
else
export CIRCLE_NODE_INDEX=$(($CIRCLE_NODE_INDEX - 1))
export CIRCLE_NODE_TOTAL=$(($CIRCLE_NODE_TOTAL - 1))
RUN_STEPS=$(seq 2 "$STEPS" | circleci tests split)
fi
else
RUN_STEPS=$(seq "$STEPS")
fi
# turn newlines into spaces
RUN_STEPS=$(echo $RUN_STEPS)
echo "Running steps $RUN_STEPS..."
STEP=1
[[ " $RUN_STEPS " =~ " $STEP " ]] && EVM=istanbul OPTIMIZE=1 ABI_ENCODER_V2=1 "${REPODIR}/.circleci/soltest.sh"
STEP=$(($STEP + 1))
for OPTIMIZE in ${OPTIMIZE_VALUES[@]}
do
for EVM in ${EVM_VALUES[@]}
do
[[ " $RUN_STEPS " =~ " $STEP " ]] && EVM="$EVM" OPTIMIZE="$OPTIMIZE" BOOST_TEST_ARGS="-t !@nooptions" "${REPODIR}/.circleci/soltest.sh"
STEP=$(($STEP + 1))
done done
done done
EVM=istanbul OPTIMIZE=1 ABI_ENCODER_V2=1 ${REPODIR}/.circleci/soltest.sh if (($STEP != $STEPS + 1))
then
echo "Step counter not properly adjusted!" >2
exit 1
fi

43
.github/workflows/buildpack-deps.yml vendored Normal file
View File

@ -0,0 +1,43 @@
name: buildpack-deps
on:
pull_request:
branches: [ develop ]
paths:
- 'scripts/docker/buildpack-deps/Dockerfile.emscripten'
- 'scripts/docker/buildpack-deps/Dockerfile.ubuntu1604.clang.ossfuzz'
- 'scripts/docker/buildpack-deps/Dockerfile.ubuntu1804'
- 'scripts/docker/buildpack-deps/Dockerfile.ubuntu2004.clang'
- 'scripts/docker/buildpack-deps/Dockerfile.ubuntu2004'
jobs:
buildpack-deps:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
DOCKER_REPOSITORY: solbuildpackpusher/solidity-buildpack-deps
IMAGE_NAME: buildpack-deps
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
image_variant: [emscripten, ubuntu1604.clang.ossfuzz, ubuntu1804, ubuntu2004.clang, ubuntu2004]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Upgrade ${{ env.IMAGE_NAME }}-${{ matrix.image_variant }}
run: |
echo ${DOCKERHUB_TOKEN} | docker login -u solbuildpackpusher --password-stdin
scripts/ci/docker_upgrade.sh ${{ env.IMAGE_NAME }} ${{ matrix.image_variant }} ${{ env.DOCKER_REPOSITORY }}
docker logout
- name: comment PR
if: "env.DOCKER_IMAGE"
uses: aarlt/comment-on-pr@v1.2.0
with:
msg: "`${{ env.DOCKER_IMAGE }} ${{ env.DOCKER_REPO_DIGEST }}`."

4
.gitignore vendored
View File

@ -32,10 +32,10 @@ prerelease.txt
# Build directory # Build directory
build/ build/
build*/ /build*/
emscripten_build/ emscripten_build/
docs/_build docs/_build
docs/utils/__pycache__ __pycache__
docs/utils/*.pyc docs/utils/*.pyc
/deps/downloads/ /deps/downloads/
deps/install deps/install

View File

@ -47,6 +47,7 @@ env:
- SOLC_TESTS=On - SOLC_TESTS=On
- SOLC_STOREBYTECODE=Off - SOLC_STOREBYTECODE=Off
- SOLC_DOCKER=Off - SOLC_DOCKER=Off
- MAKEFLAGS="-j 4"
matrix: matrix:
include: include:
@ -112,7 +113,7 @@ matrix:
before_install: before_install:
- nvm install 10 - nvm install 10
- nvm use 10 - nvm use 10
- docker pull ethereum/solidity-buildpack-deps:emsdk-1.39.15-2 - docker pull solbuildpackpusher/solidity-buildpack-deps@sha256:d557d015918c3cf68b0d22839bab41013f0757b651a7fef21595f89721dbebcc
env: env:
- SOLC_EMSCRIPTEN=On - SOLC_EMSCRIPTEN=On
- SOLC_INSTALL_DEPS_TRAVIS=Off - SOLC_INSTALL_DEPS_TRAVIS=Off

View File

@ -10,7 +10,7 @@ include(EthPolicy)
eth_policy() eth_policy()
# project name and version should be set after cmake_policy CMP0048 # project name and version should be set after cmake_policy CMP0048
set(PROJECT_VERSION "0.6.11") set(PROJECT_VERSION "0.6.12")
# OSX target needed in order to support std::visit # OSX target needed in order to support std::visit
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14") set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14")
project(solidity VERSION ${PROJECT_VERSION} LANGUAGES C CXX) project(solidity VERSION ${PROJECT_VERSION} LANGUAGES C CXX)

View File

@ -1,3 +1,32 @@
### 0.6.12 (2020-07-22)
Language Features:
* NatSpec: Implement tag ``@inheritdoc`` to copy documentation from a specific base contract.
* Wasm backend: Add ``i32.ctz``, ``i64.ctz``, ``i32.popcnt``, and ``i64.popcnt``.
Compiler Features:
* Code Generator: Avoid double cleanup when copying to memory.
* Code Generator: Evaluate ``keccak256`` of string literals at compile-time.
* Optimizer: Add rule to remove shifts inside the byte opcode.
* Peephole Optimizer: Add rule to remove swap after dup.
* Peephole Optimizer: Remove unnecessary masking of tags.
* Yul EVM Code Transform: Free stack slots directly after visiting the right-hand-side of variable declarations instead of at the end of the statement only.
Bugfixes:
* SMTChecker: Fix error in events with indices of type static array.
* SMTChecker: Fix internal error in sequential storage array pushes (``push().push()``).
* SMTChecker: Fix internal error when using bitwise operators on fixed bytes type.
* SMTChecker: Fix internal error when using compound bitwise operator assignments on array indices inside branches.
* Type Checker: Fix internal compiler error related to oversized types.
* Type Checker: Fix overload resolution in combination with ``{value: ...}``.
Build System:
* Update internal dependency of jsoncpp to 1.9.3.
### 0.6.11 (2020-07-07) ### 0.6.11 (2020-07-07)
Language Features: Language Features:

View File

@ -50,6 +50,7 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA
add_compile_options(-pedantic) add_compile_options(-pedantic)
add_compile_options(-Wno-unknown-pragmas) add_compile_options(-Wno-unknown-pragmas)
add_compile_options(-Wimplicit-fallthrough) add_compile_options(-Wimplicit-fallthrough)
add_compile_options(-Wsign-conversion)
# Configuration-specific compiler settings. # Configuration-specific compiler settings.
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -DETH_DEBUG") set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -DETH_DEBUG")

View File

@ -37,15 +37,16 @@ endif()
ExternalProject_Add(jsoncpp-project ExternalProject_Add(jsoncpp-project
PREFIX "${prefix}" PREFIX "${prefix}"
DOWNLOAD_DIR "${CMAKE_SOURCE_DIR}/deps/downloads" DOWNLOAD_DIR "${CMAKE_SOURCE_DIR}/deps/downloads"
DOWNLOAD_NAME jsoncpp-1.9.2.tar.gz DOWNLOAD_NAME jsoncpp-1.9.3.tar.gz
URL https://github.com/open-source-parsers/jsoncpp/archive/1.9.2.tar.gz URL https://github.com/open-source-parsers/jsoncpp/archive/1.9.3.tar.gz
URL_HASH SHA256=77a402fb577b2e0e5d0bdc1cf9c65278915cdb25171e3452c68b6da8a561f8f0 URL_HASH SHA256=8593c1d69e703563d94d8c12244e2e18893eeb9a8a9f8aa3d09a327aa45c8f7d
CMAKE_COMMAND ${JSONCPP_CMAKE_COMMAND} CMAKE_COMMAND ${JSONCPP_CMAKE_COMMAND}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_LIBDIR=lib
# Build static lib but suitable to be included in a shared lib. # Build static lib but suitable to be included in a shared lib.
-DCMAKE_POSITION_INDEPENDENT_CODE=${BUILD_SHARED_LIBS} -DCMAKE_POSITION_INDEPENDENT_CODE=${BUILD_SHARED_LIBS}
-DJSONCPP_WITH_EXAMPLE=OFF
-DJSONCPP_WITH_TESTS=OFF -DJSONCPP_WITH_TESTS=OFF
-DJSONCPP_WITH_PKGCONFIG_SUPPORT=OFF -DJSONCPP_WITH_PKGCONFIG_SUPPORT=OFF
-DCMAKE_CXX_FLAGS=${JSONCPP_CXX_FLAGS} -DCMAKE_CXX_FLAGS=${JSONCPP_CXX_FLAGS}

View File

@ -1113,6 +1113,10 @@
"bugs": [], "bugs": [],
"released": "2020-07-07" "released": "2020-07-07"
}, },
"0.6.12": {
"bugs": [],
"released": "2020-07-22"
},
"0.6.2": { "0.6.2": {
"bugs": [ "bugs": [
"MissingEscapingInFormatting", "MissingEscapingInFormatting",

View File

@ -77,7 +77,7 @@ version stands as a reference.
* `Japanese <https://solidity-jp.readthedocs.io>`_ * `Japanese <https://solidity-jp.readthedocs.io>`_
* `Korean <http://solidity-kr.readthedocs.io>`_ (in progress) * `Korean <http://solidity-kr.readthedocs.io>`_ (in progress)
* `Russian <https://github.com/ethereum/wiki/wiki/%5BRussian%5D-%D0%A0%D1%83%D0%BA%D0%BE%D0%B2%D0%BE%D0%B4%D1%81%D1%82%D0%B2%D0%BE-%D0%BF%D0%BE-Solidity>`_ (rather outdated) * `Russian <https://github.com/ethereum/wiki/wiki/%5BRussian%5D-%D0%A0%D1%83%D0%BA%D0%BE%D0%B2%D0%BE%D0%B4%D1%81%D1%82%D0%B2%D0%BE-%D0%BF%D0%BE-Solidity>`_ (rather outdated)
* `Simplified Chinese <http://solidity-cn.readthedocs.io>`_ (in progress) * `Simplified Chinese <https://learnblockchain.cn/docs/solidity/>`_ (in progress)
* `Spanish <https://solidity-es.readthedocs.io>`_ * `Spanish <https://solidity-es.readthedocs.io>`_
* `Turkish <https://github.com/denizozzgur/Solidity_TR/blob/master/README.md>`_ (partial) * `Turkish <https://github.com/denizozzgur/Solidity_TR/blob/master/README.md>`_ (partial)

View File

@ -49,7 +49,7 @@ The following example shows a contract and a function using all available tags.
.. code:: solidity .. code:: solidity
// SPDX-License-Identifier: GPL-3.0 // SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 <0.7.0; pragma solidity >0.6.10 <0.7.0;
/// @title A simulator for trees /// @title A simulator for trees
/// @author Larry A. Gardner /// @author Larry A. Gardner
@ -60,9 +60,33 @@ The following example shows a contract and a function using all available tags.
/// @dev The Alexandr N. Tetearing algorithm could increase precision /// @dev The Alexandr N. Tetearing algorithm could increase precision
/// @param rings The number of rings from dendrochronological sample /// @param rings The number of rings from dendrochronological sample
/// @return age in years, rounded up for partial years /// @return age in years, rounded up for partial years
function age(uint256 rings) external pure returns (uint256) { function age(uint256 rings) external virtual pure returns (uint256) {
return rings + 1; return rings + 1;
} }
/// @notice Returns the amount of leaves the tree has.
/// @dev Returns only a fixed number.
function leaves() external virtual pure returns(uint256) {
return 2;
}
}
contract Plant {
function leaves() external virtual pure returns(uint256) {
return 3;
}
}
contract KumquatTree is Tree, Plant {
function age(uint256 rings) external override pure returns (uint256) {
return rings + 2;
}
/// Return the amount of leaves that this specific kind of tree has
/// @inheritdoc Tree
function leaves() external override(Tree, Plant) pure returns(uint256) {
return 3;
}
} }
.. _header-tags: .. _header-tags:
@ -75,16 +99,17 @@ NatSpec tag and where it may be used. As a special case, if no tags are
used then the Solidity compiler will interpret a ``///`` or ``/**`` comment used then the Solidity compiler will interpret a ``///`` or ``/**`` comment
in the same way as if it were tagged with ``@notice``. in the same way as if it were tagged with ``@notice``.
=========== =============================================================================== ============================= =============== ====================================================================================== =============================
Tag Context Tag Context
=========== =============================================================================== ============================= =============== ====================================================================================== =============================
``@title`` A title that should describe the contract/interface contract, interface ``@title`` A title that should describe the contract/interface contract, interface
``@author`` The name of the author contract, interface ``@author`` The name of the author contract, interface
``@notice`` Explain to an end user what this does contract, interface, function, public state variable, event ``@notice`` Explain to an end user what this does contract, interface, function, public state variable, event
``@dev`` Explain to a developer any extra details contract, interface, function, state variable, event ``@dev`` Explain to a developer any extra details contract, interface, function, state variable, event
``@param`` Documents a parameter just like in doxygen (must be followed by parameter name) function, event ``@param`` Documents a parameter just like in doxygen (must be followed by parameter name) function, event
``@return`` Documents the return variables of a contract's function function, public state variable ``@return`` Documents the return variables of a contract's function function, public state variable
=========== =============================================================================== ============================= ``@inheritdoc`` Copies all missing tags from the base function (must be followed by the contract name) function, public state variable
=============== ====================================================================================== =============================
If your function returns multiple values, like ``(int quotient, int remainder)`` If your function returns multiple values, like ``(int quotient, int remainder)``
then use multiple ``@return`` statements in the same format as the then use multiple ``@return`` statements in the same format as the
@ -127,6 +152,7 @@ base function. Exceptions to this are:
* When the parameter names are different. * When the parameter names are different.
* When there is more than one base function. * When there is more than one base function.
* When there is an explicit ``@inheritdoc`` tag which specifies which contract should be used to inherit.
.. _header-output: .. _header-output:

View File

@ -237,6 +237,23 @@ memory arrays, i.e. the following is not possible:
It is planned to remove this restriction in the future, but it creates some It is planned to remove this restriction in the future, but it creates some
complications because of how arrays are passed in the ABI. complications because of how arrays are passed in the ABI.
If you want to initialize dynamically-sized arrays, you have to assign the
individual elements:
::
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.0 <0.7.0;
contract C {
function f() public pure {
uint[] memory x = new uint[](3);
x[0] = 1;
x[1] = 3;
x[2] = 4;
}
}
.. index:: ! array;length, length, push, pop, !array;push, !array;pop .. index:: ! array;length, length, push, pop, !array;push, !array;pop
.. _array-members: .. _array-members:

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** @file Assembly.cpp /** @file Assembly.cpp
* @author Gav Wood <i@gavwood.com> * @author Gav Wood <i@gavwood.com>
* @date 2014 * @date 2014
@ -91,8 +92,8 @@ string locationFromSources(StringMap const& _sourceCodes, SourceLocation const&
class Functionalizer class Functionalizer
{ {
public: public:
Functionalizer (ostream& _out, string const& _prefix, StringMap const& _sourceCodes): Functionalizer (ostream& _out, string const& _prefix, StringMap const& _sourceCodes, Assembly const& _assembly):
m_out(_out), m_prefix(_prefix), m_sourceCodes(_sourceCodes) m_out(_out), m_prefix(_prefix), m_sourceCodes(_sourceCodes), m_assembly(_assembly)
{} {}
void feed(AssemblyItem const& _item) void feed(AssemblyItem const& _item)
@ -103,6 +104,9 @@ public:
m_location = _item.location(); m_location = _item.location();
printLocation(); printLocation();
} }
string expression = _item.toAssemblyText(m_assembly);
if (!( if (!(
_item.canBeFunctional() && _item.canBeFunctional() &&
_item.returnValues() <= 1 && _item.returnValues() <= 1 &&
@ -110,10 +114,9 @@ public:
)) ))
{ {
flush(); flush();
m_out << m_prefix << (_item.type() == Tag ? "" : " ") << _item.toAssemblyText() << endl; m_out << m_prefix << (_item.type() == Tag ? "" : " ") << expression << endl;
return; return;
} }
string expression = _item.toAssemblyText();
if (_item.arguments() > 0) if (_item.arguments() > 0)
{ {
expression += "("; expression += "(";
@ -159,13 +162,14 @@ private:
ostream& m_out; ostream& m_out;
string const& m_prefix; string const& m_prefix;
StringMap const& m_sourceCodes; StringMap const& m_sourceCodes;
Assembly const& m_assembly;
}; };
} }
void Assembly::assemblyStream(ostream& _out, string const& _prefix, StringMap const& _sourceCodes) const void Assembly::assemblyStream(ostream& _out, string const& _prefix, StringMap const& _sourceCodes) const
{ {
Functionalizer f(_out, _prefix, _sourceCodes); Functionalizer f(_out, _prefix, _sourceCodes, *this);
for (auto const& i: m_items) for (auto const& i: m_items)
f.feed(i); f.feed(i);
@ -521,6 +525,7 @@ map<u256, u256> Assembly::optimiseInternal(
LinkerObject const& Assembly::assemble() const LinkerObject const& Assembly::assemble() const
{ {
assertThrow(!m_invalid, AssemblyException, "Attempted to assemble invalid Assembly object.");
// Return the already assembled object, if present. // Return the already assembled object, if present.
if (!m_assembledObject.bytecode.empty()) if (!m_assembledObject.bytecode.empty())
return m_assembledObject; return m_assembledObject;
@ -637,7 +642,7 @@ LinkerObject const& Assembly::assemble() const
case PushSubSize: case PushSubSize:
{ {
assertThrow(i.data() <= numeric_limits<size_t>::max(), AssemblyException, ""); assertThrow(i.data() <= numeric_limits<size_t>::max(), AssemblyException, "");
auto s = m_subs.at(static_cast<size_t>(i.data()))->assemble().bytecode.size(); auto s = subAssemblyById(static_cast<size_t>(i.data()))->assemble().bytecode.size();
i.setPushedValue(u256(s)); i.setPushedValue(u256(s));
uint8_t b = max<unsigned>(1, util::bytesRequired(s)); uint8_t b = max<unsigned>(1, util::bytesRequired(s));
ret.bytecode.push_back((uint8_t)Instruction::PUSH1 - 1 + b); ret.bytecode.push_back((uint8_t)Instruction::PUSH1 - 1 + b);
@ -705,25 +710,20 @@ LinkerObject const& Assembly::assemble() const
// Append an INVALID here to help tests find miscompilation. // Append an INVALID here to help tests find miscompilation.
ret.bytecode.push_back(uint8_t(Instruction::INVALID)); ret.bytecode.push_back(uint8_t(Instruction::INVALID));
for (size_t i = 0; i < m_subs.size(); ++i) for (auto const& [subIdPath, bytecodeOffset]: subRef)
{ {
auto references = subRef.equal_range(i); bytesRef r(ret.bytecode.data() + bytecodeOffset, bytesPerDataRef);
if (references.first == references.second) toBigEndian(ret.bytecode.size(), r);
continue; ret.append(subAssemblyById(subIdPath)->assemble());
for (auto ref = references.first; ref != references.second; ++ref)
{
bytesRef r(ret.bytecode.data() + ref->second, bytesPerDataRef);
toBigEndian(ret.bytecode.size(), r);
}
ret.append(m_subs[i]->assemble());
} }
for (auto const& i: tagRef) for (auto const& i: tagRef)
{ {
size_t subId; size_t subId;
size_t tagId; size_t tagId;
tie(subId, tagId) = i.second; tie(subId, tagId) = i.second;
assertThrow(subId == numeric_limits<size_t>::max() || subId < m_subs.size(), AssemblyException, "Invalid sub id"); assertThrow(subId == numeric_limits<size_t>::max() || subId < m_subs.size(), AssemblyException, "Invalid sub id");
std::vector<size_t> const& tagPositions = vector<size_t> const& tagPositions =
subId == numeric_limits<size_t>::max() ? subId == numeric_limits<size_t>::max() ?
m_tagPositionsInBytecode : m_tagPositionsInBytecode :
m_subs[subId]->m_tagPositionsInBytecode; m_subs[subId]->m_tagPositionsInBytecode;
@ -756,3 +756,51 @@ LinkerObject const& Assembly::assemble() const
} }
return ret; return ret;
} }
vector<size_t> Assembly::decodeSubPath(size_t _subObjectId) const
{
if (_subObjectId < m_subs.size())
return {_subObjectId};
auto subIdPathIt = find_if(
m_subPaths.begin(),
m_subPaths.end(),
[_subObjectId](auto const& subId) { return subId.second == _subObjectId; }
);
assertThrow(subIdPathIt != m_subPaths.end(), AssemblyException, "");
return subIdPathIt->first;
}
size_t Assembly::encodeSubPath(vector<size_t> const& _subPath)
{
assertThrow(!_subPath.empty(), AssemblyException, "");
if (_subPath.size() == 1)
{
assertThrow(_subPath[0] < m_subs.size(), AssemblyException, "");
return _subPath[0];
}
if (m_subPaths.find(_subPath) == m_subPaths.end())
{
size_t objectId = numeric_limits<size_t>::max() - m_subPaths.size();
assertThrow(objectId >= m_subs.size(), AssemblyException, "");
m_subPaths[_subPath] = objectId;
}
return m_subPaths[_subPath];
}
Assembly const* Assembly::subAssemblyById(size_t _subId) const
{
vector<size_t> subIds = decodeSubPath(_subId);
Assembly const* currentAssembly = this;
for (size_t currentSubId: subIds)
{
currentAssembly = currentAssembly->m_subs.at(currentSubId).get();
assertThrow(currentAssembly, AssemblyException, "");
}
assertThrow(currentAssembly != this, AssemblyException, "");
return currentAssembly;
}

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#pragma once #pragma once
@ -142,6 +143,12 @@ public:
std::map<std::string, unsigned> const& _sourceIndices = std::map<std::string, unsigned>() std::map<std::string, unsigned> const& _sourceIndices = std::map<std::string, unsigned>()
) const; ) const;
/// Mark this assembly as invalid. Calling ``assemble`` on it will throw.
void markAsInvalid() { m_invalid = true; }
std::vector<size_t> decodeSubPath(size_t _subObjectId) const;
size_t encodeSubPath(std::vector<size_t> const& _subPath);
protected: protected:
/// Does the same operations as @a optimise, but should only be applied to a sub and /// Does the same operations as @a optimise, but should only be applied to a sub and
/// returns the replaced tags. Also takes an argument containing the tags of this assembly /// returns the replaced tags. Also takes an argument containing the tags of this assembly
@ -161,6 +168,10 @@ private:
); );
static std::string toStringInHex(u256 _value); static std::string toStringInHex(u256 _value);
bool m_invalid = false;
Assembly const* subAssemblyById(size_t _subId) const;
protected: protected:
/// 0 is reserved for exception /// 0 is reserved for exception
unsigned m_usedTags = 1; unsigned m_usedTags = 1;
@ -174,6 +185,10 @@ protected:
std::map<util::h256, std::string> m_libraries; ///< Identifiers of libraries to be linked. std::map<util::h256, std::string> m_libraries; ///< Identifiers of libraries to be linked.
std::map<util::h256, std::string> m_immutables; ///< Identifiers of immutables. std::map<util::h256, std::string> m_immutables; ///< Identifiers of immutables.
/// Map from a vector representing a path to a particular sub assembly to sub assembly id.
/// This map is used only for sub-assemblies which are not direct sub-assemblies (where path is having more than one value).
std::map<std::vector<size_t>, size_t> m_subPaths;
mutable LinkerObject m_assembledObject; mutable LinkerObject m_assembledObject;
mutable std::vector<size_t> m_tagPositionsInBytecode; mutable std::vector<size_t> m_tagPositionsInBytecode;

View File

@ -14,10 +14,14 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#include <libevmasm/AssemblyItem.h> #include <libevmasm/AssemblyItem.h>
#include <libevmasm/Assembly.h>
#include <libsolutil/CommonData.h> #include <libsolutil/CommonData.h>
#include <libsolutil/StringUtils.h>
#include <libsolutil/FixedHash.h> #include <libsolutil/FixedHash.h>
#include <liblangutil/SourceLocation.h> #include <liblangutil/SourceLocation.h>
@ -169,7 +173,7 @@ string AssemblyItem::getJumpTypeAsString() const
} }
} }
string AssemblyItem::toAssemblyText() const string AssemblyItem::toAssemblyText(Assembly const& _assembly) const
{ {
string text; string text;
switch (type()) switch (type())
@ -207,11 +211,18 @@ string AssemblyItem::toAssemblyText() const
text = string("data_") + util::toHex(data()); text = string("data_") + util::toHex(data());
break; break;
case PushSub: case PushSub:
text = string("dataOffset(sub_") + to_string(static_cast<size_t>(data())) + ")";
break;
case PushSubSize: case PushSubSize:
text = string("dataSize(sub_") + to_string(static_cast<size_t>(data())) + ")"; {
vector<string> subPathComponents;
for (size_t subPathComponentId: _assembly.decodeSubPath(static_cast<size_t>(data())))
subPathComponents.emplace_back("sub_" + to_string(subPathComponentId));
text =
(type() == PushSub ? "dataOffset"s : "dataSize"s) +
"(" +
solidity::util::joinHumanReadable(subPathComponents, ".") +
")";
break; break;
}
case PushProgramSize: case PushProgramSize:
text = string("bytecodeSize"); text = string("bytecodeSize");
break; break;

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** @file AssemblyItem.h /** @file AssemblyItem.h
* @author Gav Wood <i@gavwood.com> * @author Gav Wood <i@gavwood.com>
* @date 2014 * @date 2014
@ -151,7 +152,7 @@ public:
void setPushedValue(u256 const& _value) const { m_pushedValue = std::make_shared<u256>(_value); } void setPushedValue(u256 const& _value) const { m_pushedValue = std::make_shared<u256>(_value); }
u256 const* pushedValue() const { return m_pushedValue.get(); } u256 const* pushedValue() const { return m_pushedValue.get(); }
std::string toAssemblyText() const; std::string toAssemblyText(Assembly const& _assembly) const;
size_t m_modifierDepth = 0; size_t m_modifierDepth = 0;

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @file BlockDeduplicator.cpp * @file BlockDeduplicator.cpp
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @file BlockDeduplicator.h * @file BlockDeduplicator.h
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @file CommonSubexpressionEliminator.cpp * @file CommonSubexpressionEliminator.cpp
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @file CommonSubexpressionEliminator.h * @file CommonSubexpressionEliminator.h
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** @file ConstantOptimiser.cpp /** @file ConstantOptimiser.cpp
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>
* @date 2015 * @date 2015

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** @file ConstantOptimiser.cpp /** @file ConstantOptimiser.cpp
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>
* @date 2015 * @date 2015

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @file ControlFlowGraph.cpp * @file ControlFlowGraph.cpp
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @file ControlFlowGraph.h * @file ControlFlowGraph.h
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** @file Exceptions.h /** @file Exceptions.h
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>
* @date 2014 * @date 2014

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @file ExpressionClasses.cpp * @file ExpressionClasses.cpp
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @file ExpressionClasses.h * @file ExpressionClasses.h
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#include <libevmasm/GasMeter.h> #include <libevmasm/GasMeter.h>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** @file GasMeter.cpp /** @file GasMeter.cpp
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>
* @date 2015 * @date 2015

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** @file Instruction.cpp /** @file Instruction.cpp
* @author Gav Wood <i@gavwood.com> * @author Gav Wood <i@gavwood.com>
* @date 2014 * @date 2014

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** @file Instruction.h /** @file Instruction.h
* @author Gav Wood <i@gavwood.com> * @author Gav Wood <i@gavwood.com>
* @date 2014 * @date 2014
@ -174,16 +175,16 @@ enum class Instruction: uint8_t
LOG3, ///< Makes a log entry; 3 topics. LOG3, ///< Makes a log entry; 3 topics.
LOG4, ///< Makes a log entry; 4 topics. LOG4, ///< Makes a log entry; 4 topics.
JUMPTO = 0xb0, ///< alter the program counter to a jumpdest -- not part of Instructions.cpp EIP615_JUMPTO = 0xb0, ///< alter the program counter to a jumpdest -- not part of Instructions.cpp
JUMPIF, ///< conditionally alter the program counter -- not part of Instructions.cpp EIP615_JUMPIF, ///< conditionally alter the program counter -- not part of Instructions.cpp
JUMPV, ///< alter the program counter to a jumpdest -- not part of Instructions.cpp EIP615_JUMPV, ///< alter the program counter to a jumpdest -- not part of Instructions.cpp
JUMPSUB, ///< alter the program counter to a beginsub -- not part of Instructions.cpp EIP615_JUMPSUB, ///< alter the program counter to a beginsub -- not part of Instructions.cpp
JUMPSUBV, ///< alter the program counter to a beginsub -- not part of Instructions.cpp EIP615_JUMPSUBV, ///< alter the program counter to a beginsub -- not part of Instructions.cpp
BEGINSUB, ///< set a potential jumpsub destination -- not part of Instructions.cpp EIP615_BEGINSUB, ///< set a potential jumpsub destination -- not part of Instructions.cpp
BEGINDATA, ///< begin the data section -- not part of Instructions.cpp EIP615_BEGINDATA, ///< begin the data section -- not part of Instructions.cpp
RETURNSUB, ///< return to subroutine jumped from -- not part of Instructions.cpp EIP615_RETURNSUB, ///< return to subroutine jumped from -- not part of Instructions.cpp
PUTLOCAL, ///< pop top of stack to local variable -- not part of Instructions.cpp EIP615_PUTLOCAL, ///< pop top of stack to local variable -- not part of Instructions.cpp
GETLOCAL, ///< push local variable to top of stack -- not part of Instructions.cpp EIP615_GETLOCAL, ///< push local variable to top of stack -- not part of Instructions.cpp
CREATE = 0xf0, ///< create a new account with associated code CREATE = 0xf0, ///< create a new account with associated code
CALL, ///< message-call into an account CALL, ///< message-call into an account

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @author Alex Beregszaszi * @author Alex Beregszaszi
* Removes unused JUMPDESTs. * Removes unused JUMPDESTs.

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @author Alex Beregszaszi * @author Alex Beregszaszi
* Removes unused JUMPDESTs. * Removes unused JUMPDESTs.

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @file KnownState.cpp * @file KnownState.cpp
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @file KnownState.h * @file KnownState.h
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** @file LinkerObject.cpp /** @file LinkerObject.cpp
* @author Christian R <c@ethdev.com> * @author Christian R <c@ethdev.com>
* @date 2015 * @date 2015

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** @file Assembly.h /** @file Assembly.h
* @author Gav Wood <i@gavwood.com> * @author Gav Wood <i@gavwood.com>
* @date 2014 * @date 2014

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** @file PathGasMeter.cpp /** @file PathGasMeter.cpp
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>
* @date 2015 * @date 2015

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** @file PathGasMeter.cpp /** @file PathGasMeter.cpp
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>
* @date 2015 * @date 2015

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @file PeepholeOptimiser.cpp * @file PeepholeOptimiser.cpp
* Performs local optimising code changes to assembly. * Performs local optimising code changes to assembly.
@ -205,6 +206,30 @@ struct SwapComparison: SimplePeepholeOptimizerMethod<SwapComparison, 2>
} }
}; };
/// Remove swapN after dupN
struct DupSwap: SimplePeepholeOptimizerMethod<DupSwap, 2>
{
static size_t applySimple(
AssemblyItem const& _dupN,
AssemblyItem const& _swapN,
std::back_insert_iterator<AssemblyItems> _out
)
{
if (
SemanticInformation::isDupInstruction(_dupN) &&
SemanticInformation::isSwapInstruction(_swapN) &&
getDupNumber(_dupN.instruction()) == getSwapNumber(_swapN.instruction())
)
{
*_out = _dupN;
return true;
}
else
return false;
}
};
struct IsZeroIsZeroJumpI: SimplePeepholeOptimizerMethod<IsZeroIsZeroJumpI, 4> struct IsZeroIsZeroJumpI: SimplePeepholeOptimizerMethod<IsZeroIsZeroJumpI, 4>
{ {
static size_t applySimple( static size_t applySimple(
@ -266,9 +291,10 @@ struct TagConjunctions: SimplePeepholeOptimizerMethod<TagConjunctions, 3>
std::back_insert_iterator<AssemblyItems> _out std::back_insert_iterator<AssemblyItems> _out
) )
{ {
if (_and != Instruction::AND)
return false;
if ( if (
_pushTag.type() == PushTag && _pushTag.type() == PushTag &&
_and == Instruction::AND &&
_pushConstant.type() == Push && _pushConstant.type() == Push &&
(_pushConstant.data() & u256(0xFFFFFFFF)) == u256(0xFFFFFFFF) (_pushConstant.data() & u256(0xFFFFFFFF)) == u256(0xFFFFFFFF)
) )
@ -276,6 +302,16 @@ struct TagConjunctions: SimplePeepholeOptimizerMethod<TagConjunctions, 3>
*_out = _pushTag; *_out = _pushTag;
return true; return true;
} }
else if (
// tag and constant are swapped
_pushConstant.type() == PushTag &&
_pushTag.type() == Push &&
(_pushTag.data() & u256(0xFFFFFFFF)) == u256(0xFFFFFFFF)
)
{
*_out = _pushConstant;
return true;
}
else else
return false; return false;
} }
@ -357,7 +393,7 @@ bool PeepholeOptimiser::optimise()
applyMethods( applyMethods(
state, state,
PushPop(), OpPop(), DoublePush(), DoubleSwap(), CommutativeSwap(), SwapComparison(), PushPop(), OpPop(), DoublePush(), DoubleSwap(), CommutativeSwap(), SwapComparison(),
IsZeroIsZeroJumpI(), JumpToNext(), UnreachableCode(), DupSwap(), IsZeroIsZeroJumpI(), JumpToNext(), UnreachableCode(),
TagConjunctions(), TruthyAnd(), Identity() TagConjunctions(), TruthyAnd(), Identity()
); );
if (m_optimisedItems.size() < m_items.size() || ( if (m_optimisedItems.size() < m_items.size() || (

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @file PeepholeOptimiser.h * @file PeepholeOptimiser.h
* Performs local optimising code changes to assembly. * Performs local optimising code changes to assembly.

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @date 2018 * @date 2018
* Templatized list of simplification rules. * Templatized list of simplification rules.
@ -571,6 +572,20 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleListPart7(
feasibilityFunction feasibilityFunction
}); });
rules.push_back({
Builtins::BYTE(A, Builtins::SHL(B, X)),
[=]() -> Pattern { return Builtins::BYTE(A.d() + B.d() / 8, X); },
false,
[=] { return B.d() % 8 == 0 && A.d() <= 32 && B.d() <= 256; }
});
rules.push_back({
Builtins::BYTE(A, Builtins::SHR(B, X)),
[=]() -> Pattern { return A.d() < B.d() / 8 ? Word(0) : Builtins::BYTE(A.d() - B.d() / 8, X); },
false,
[=] { return B.d() % 8 == 0 && A.d() < Pattern::WordSize / 8 && B.d() <= Pattern::WordSize; }
});
return rules; return rules;
} }

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @file SemanticInformation.cpp * @file SemanticInformation.cpp
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @file SemanticInformation.h * @file SemanticInformation.h
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* Expression simplification pattern. * Expression simplification pattern.
*/ */

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @file ExpressionClasses.cpp * @file ExpressionClasses.cpp
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @file SimplificationRules * @file SimplificationRules
* @author Christian <chris@ethereum.org> * @author Christian <chris@ethereum.org>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* EVM versioning. * EVM versioning.
*/ */

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* EVM versioning. * EVM versioning.
*/ */

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @author Rhett <roadriverrail@gmail.com> * @author Rhett <roadriverrail@gmail.com>
* @date 2017 * @date 2017

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @author Rhett <roadriverrail@gmail.com> * @author Rhett <roadriverrail@gmail.com>
* @date 2017 * @date 2017

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @author Liana <liana@ethdev.com> * @author Liana <liana@ethdev.com>
* @date 2015 * @date 2015

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>
* @date 2014 * @date 2014

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>
* @date 2016 * @date 2016

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>
* @date 2016 * @date 2016

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @author Christian <chris@ethereum.org> * @author Christian <chris@ethereum.org>
* @date 2016 * @date 2016
@ -245,14 +246,14 @@ unsigned SemVerMatchExpressionParser::parseVersionPart()
return 0; return 0;
else if ('1' <= c && c <= '9') else if ('1' <= c && c <= '9')
{ {
unsigned v(c - '0'); auto v = static_cast<unsigned>(c - '0');
// If we skip to the next token, the current number is terminated. // If we skip to the next token, the current number is terminated.
while (m_pos == startPos && '0' <= currentChar() && currentChar() <= '9') while (m_pos == startPos && '0' <= currentChar() && currentChar() <= '9')
{ {
c = currentChar(); c = currentChar();
if (v * 10 < v || v * 10 + unsigned(c - '0') < v * 10) if (v * 10 < v || v * 10 + static_cast<unsigned>(c - '0') < v * 10)
throw SemVerError(); throw SemVerError();
v = v * 10 + unsigned(c - '0'); v = v * 10 + static_cast<unsigned>(c - '0');
nextChar(); nextChar();
} }
return v; return v;

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @author Christian <chris@ethereum.org> * @author Christian <chris@ethereum.org>
* @date 2016 * @date 2016

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#include <liblangutil/Exceptions.h> #include <liblangutil/Exceptions.h>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @author Lefteris Karapetsas <lefteris@ethdev.com> * @author Lefteris Karapetsas <lefteris@ethdev.com>
* @date 2015 * @date 2015

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#include <liblangutil/SourceReferenceExtractor.h> #include <liblangutil/SourceReferenceExtractor.h>
#include <liblangutil/CharStream.h> #include <liblangutil/CharStream.h>
#include <liblangutil/Exceptions.h> #include <liblangutil/Exceptions.h>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#pragma once #pragma once
#include <liblangutil/Exceptions.h> #include <liblangutil/Exceptions.h>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>
* @date 2014 * @date 2014

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>
* @date 2014 * @date 2014

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* Formatting functions for errors referencing positions and locations in the source. * Formatting functions for errors referencing positions and locations in the source.
*/ */

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* Formatting functions for errors referencing positions and locations in the source. * Formatting functions for errors referencing positions and locations in the source.
*/ */

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** @file UndefMacros.h /** @file UndefMacros.h
* @author Lefteris <lefteris@ethdev.com> * @author Lefteris <lefteris@ethdev.com>
* @date 2015 * @date 2015

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#include <libsmtutil/CHCSmtLib2Interface.h> #include <libsmtutil/CHCSmtLib2Interface.h>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* Interface for solving Horn systems via smtlib2. * Interface for solving Horn systems via smtlib2.

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* Interface for constrained Horn solvers. * Interface for constrained Horn solvers.

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#include <libsmtutil/CVC4Interface.h> #include <libsmtutil/CVC4Interface.h>
@ -191,7 +192,7 @@ CVC4::Expr CVC4Interface::toCVC4Expr(Expression const& _expr)
return m_context.mkExpr(CVC4::kind::BITVECTOR_AND, arguments[0], arguments[1]); return m_context.mkExpr(CVC4::kind::BITVECTOR_AND, arguments[0], arguments[1]);
else if (n == "int2bv") else if (n == "int2bv")
{ {
size_t size = std::stoi(_expr.arguments[1].name); size_t size = std::stoul(_expr.arguments[1].name);
auto i2bvOp = m_context.mkConst(CVC4::IntToBitVector(size)); auto i2bvOp = m_context.mkConst(CVC4::IntToBitVector(size));
// CVC4 treats all BVs as unsigned, so we need to manually apply 2's complement if needed. // CVC4 treats all BVs as unsigned, so we need to manually apply 2's complement if needed.
return m_context.mkExpr( return m_context.mkExpr(

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#pragma once #pragma once

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#pragma once #pragma once

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#include <libsmtutil/SMTLib2Interface.h> #include <libsmtutil/SMTLib2Interface.h>
@ -139,7 +140,7 @@ string SMTLib2Interface::toSExpr(Expression const& _expr)
std::string sexpr = "("; std::string sexpr = "(";
if (_expr.name == "int2bv") if (_expr.name == "int2bv")
{ {
size_t size = std::stoi(_expr.arguments[1].name); size_t size = std::stoul(_expr.arguments[1].name);
auto arg = toSExpr(_expr.arguments.front()); auto arg = toSExpr(_expr.arguments.front());
auto int2bv = "(_ int2bv " + to_string(size) + ")"; auto int2bv = "(_ int2bv " + to_string(size) + ")";
// Some solvers treat all BVs as unsigned, so we need to manually apply 2's complement if needed. // Some solvers treat all BVs as unsigned, so we need to manually apply 2's complement if needed.

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#pragma once #pragma once

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#include <libsmtutil/SMTPortfolio.h> #include <libsmtutil/SMTPortfolio.h>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#pragma once #pragma once

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#pragma once #pragma once
@ -59,10 +60,10 @@ class Expression
public: public:
explicit Expression(bool _v): Expression(_v ? "true" : "false", Kind::Bool) {} explicit Expression(bool _v): Expression(_v ? "true" : "false", Kind::Bool) {}
explicit Expression(std::shared_ptr<SortSort> _sort, std::string _name = ""): Expression(std::move(_name), {}, _sort) {} explicit Expression(std::shared_ptr<SortSort> _sort, std::string _name = ""): Expression(std::move(_name), {}, _sort) {}
Expression(size_t _number): Expression(std::to_string(_number), Kind::Int) {} Expression(size_t _number): Expression(std::to_string(_number), {}, SortProvider::sintSort) {}
Expression(u256 const& _number): Expression(_number.str(), Kind::Int) {} Expression(u256 const& _number): Expression(_number.str(), {}, SortProvider::sintSort) {}
Expression(s256 const& _number): Expression(_number.str(), Kind::Int) {} Expression(s256 const& _number): Expression(_number.str(), {}, SortProvider::sintSort) {}
Expression(bigint const& _number): Expression(_number.str(), Kind::Int) {} Expression(bigint const& _number): Expression(_number.str(), {}, SortProvider::sintSort) {}
Expression(Expression const&) = default; Expression(Expression const&) = default;
Expression(Expression&&) = default; Expression(Expression&&) = default;
@ -262,23 +263,28 @@ public:
} }
friend Expression operator+(Expression _a, Expression _b) friend Expression operator+(Expression _a, Expression _b)
{ {
return Expression("+", std::move(_a), std::move(_b), Kind::Int); auto intSort = _a.sort;
return Expression("+", {std::move(_a), std::move(_b)}, intSort);
} }
friend Expression operator-(Expression _a, Expression _b) friend Expression operator-(Expression _a, Expression _b)
{ {
return Expression("-", std::move(_a), std::move(_b), Kind::Int); auto intSort = _a.sort;
return Expression("-", {std::move(_a), std::move(_b)}, intSort);
} }
friend Expression operator*(Expression _a, Expression _b) friend Expression operator*(Expression _a, Expression _b)
{ {
return Expression("*", std::move(_a), std::move(_b), Kind::Int); auto intSort = _a.sort;
return Expression("*", {std::move(_a), std::move(_b)}, intSort);
} }
friend Expression operator/(Expression _a, Expression _b) friend Expression operator/(Expression _a, Expression _b)
{ {
return Expression("/", std::move(_a), std::move(_b), Kind::Int); auto intSort = _a.sort;
return Expression("/", {std::move(_a), std::move(_b)}, intSort);
} }
friend Expression operator%(Expression _a, Expression _b) friend Expression operator%(Expression _a, Expression _b)
{ {
return Expression("mod", std::move(_a), std::move(_b), Kind::Int); auto intSort = _a.sort;
return Expression("mod", {std::move(_a), std::move(_b)}, intSort);
} }
friend Expression operator&(Expression _a, Expression _b) friend Expression operator&(Expression _a, Expression _b)
{ {

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#include <libsmtutil/Sorts.h> #include <libsmtutil/Sorts.h>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#pragma once #pragma once

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#include <libsmtutil/Z3CHCInterface.h> #include <libsmtutil/Z3CHCInterface.h>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* Z3 specific Horn solver interface. * Z3 specific Horn solver interface.

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#include <libsmtutil/Z3Interface.h> #include <libsmtutil/Z3Interface.h>
@ -184,7 +185,7 @@ z3::expr Z3Interface::toZ3Expr(Expression const& _expr)
return arguments[0] & arguments[1]; return arguments[0] & arguments[1];
else if (n == "int2bv") else if (n == "int2bv")
{ {
size_t size = std::stoi(_expr.arguments[1].name); size_t size = std::stoul(_expr.arguments[1].name);
return z3::int2bv(size, arguments[0]); return z3::int2bv(size, arguments[0]);
} }
else if (n == "bv2int") else if (n == "bv2int")

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#pragma once #pragma once

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>
* @date 2014 * @date 2014

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>
* @date 2014 * @date 2014

View File

@ -16,6 +16,8 @@ set(sources
analysis/DeclarationTypeChecker.h analysis/DeclarationTypeChecker.h
analysis/DocStringAnalyser.cpp analysis/DocStringAnalyser.cpp
analysis/DocStringAnalyser.h analysis/DocStringAnalyser.h
analysis/DocStringTagParser.cpp
analysis/DocStringTagParser.h
analysis/ImmutableValidator.cpp analysis/ImmutableValidator.cpp
analysis/ImmutableValidator.h analysis/ImmutableValidator.h
analysis/GlobalContext.cpp analysis/GlobalContext.cpp

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>
* @date 2015 * @date 2015

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>
* @date 2015 * @date 2015

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* Component that verifies overloads, abstract contracts, function clashes and others * Component that verifies overloads, abstract contracts, function clashes and others
* checks at contract or function level. * checks at contract or function level.
@ -60,6 +61,7 @@ bool ContractLevelChecker::check(ContractDefinition const& _contract)
checkLibraryRequirements(_contract); checkLibraryRequirements(_contract);
checkBaseABICompatibility(_contract); checkBaseABICompatibility(_contract);
checkPayableFallbackWithoutReceive(_contract); checkPayableFallbackWithoutReceive(_contract);
checkStorageSize(_contract);
return Error::containsOnlyWarnings(m_errorReporter.errors()); return Error::containsOnlyWarnings(m_errorReporter.errors());
} }
@ -458,3 +460,20 @@ void ContractLevelChecker::checkPayableFallbackWithoutReceive(ContractDefinition
SecondarySourceLocation{}.append("The payable fallback function is defined here.", fallback->location()) SecondarySourceLocation{}.append("The payable fallback function is defined here.", fallback->location())
); );
} }
void ContractLevelChecker::checkStorageSize(ContractDefinition const& _contract)
{
bigint size = 0;
vector<VariableDeclaration const*> variables;
for (ContractDefinition const* contract: boost::adaptors::reverse(_contract.annotation().linearizedBaseContracts))
for (VariableDeclaration const* variable: contract->stateVariables())
if (!(variable->isConstant() || variable->immutable()))
{
size += variable->annotation().type->storageSizeUpperBound();
if (size >= bigint(1) << 256)
{
m_errorReporter.typeError(7676_error, _contract.location(), "Contract too large for storage.");
break;
}
}
}

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* Component that verifies overloads, abstract contracts, function clashes and others * Component that verifies overloads, abstract contracts, function clashes and others
* checks at contract or function level. * checks at contract or function level.
@ -83,6 +84,8 @@ private:
/// Warns if the contract has a payable fallback, but no receive ether function. /// Warns if the contract has a payable fallback, but no receive ether function.
void checkPayableFallbackWithoutReceive(ContractDefinition const& _contract); void checkPayableFallbackWithoutReceive(ContractDefinition const& _contract);
/// Error if the contract requires too much storage
void checkStorageSize(ContractDefinition const& _contract);
OverrideChecker m_overrideChecker; OverrideChecker m_overrideChecker;
langutil::ErrorReporter& m_errorReporter; langutil::ErrorReporter& m_errorReporter;

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#include <libsolidity/analysis/ControlFlowAnalyzer.h> #include <libsolidity/analysis/ControlFlowAnalyzer.h>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#pragma once #pragma once

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#include <libsolidity/analysis/ControlFlowBuilder.h> #include <libsolidity/analysis/ControlFlowBuilder.h>
#include <libyul/AsmData.h> #include <libyul/AsmData.h>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#pragma once #pragma once

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#include <libsolidity/analysis/ControlFlowGraph.h> #include <libsolidity/analysis/ControlFlowGraph.h>

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
#pragma once #pragma once

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>
* @date 2014 * @date 2014

View File

@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
// SPDX-License-Identifier: GPL-3.0
/** /**
* @author Christian <c@ethdev.com> * @author Christian <c@ethdev.com>
* @date 2014 * @date 2014

Some files were not shown because too many files have changed in this diff Show More