diff options
| -rw-r--r-- | .travis.yml | 6 | ||||
| -rw-r--r-- | circle.yml | 2 | ||||
| -rw-r--r-- | cmake/EthCompilerSettings.cmake | 4 | ||||
| -rw-r--r-- | libevmasm/RuleList.h | 11 | ||||
| -rwxr-xr-x | test/externalTests.sh | 38 | ||||
| -rw-r--r-- | test/libjulia/Simplifier.cpp | 12 |
6 files changed, 58 insertions, 15 deletions
diff --git a/.travis.yml b/.travis.yml index 708d3620..ebe91939 100644 --- a/.travis.yml +++ b/.travis.yml @@ -97,12 +97,12 @@ matrix: sudo: required compiler: gcc node_js: - - "6" + - "7" services: - docker before_install: - - nvm install 6 - - nvm use 6 + - nvm install 7 + - nvm use 7 - docker pull trzeci/emscripten:sdk-tag-1.35.4-64bit env: - SOLC_EMSCRIPTEN=On @@ -76,7 +76,7 @@ jobs: export NVM_DIR="/usr/local/nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm nvm --version - nvm install 6 + nvm install 7 node --version npm --version - run: diff --git a/cmake/EthCompilerSettings.cmake b/cmake/EthCompilerSettings.cmake index ddb6c426..7199f537 100644 --- a/cmake/EthCompilerSettings.cmake +++ b/cmake/EthCompilerSettings.cmake @@ -120,7 +120,7 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA endif() if (EMSCRIPTEN) - # Do emit a separate memory initialiser file + # Do not emit a separate memory initialiser file set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --memory-init-file 0") # Leave only exported symbols as public and agressively remove others set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -ffunction-sections -Wl,--gc-sections -fvisibility=hidden") @@ -138,6 +138,8 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s ALLOW_MEMORY_GROWTH=1") # Disable eval() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s NO_DYNAMIC_EXECUTION=1") + # Disable greedy exception catcher + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s NODEJS_CATCH_EXIT=0") add_definitions(-DETH_EMSCRIPTEN=1) endif() endif() diff --git a/libevmasm/RuleList.h b/libevmasm/RuleList.h index 2312d673..da522cec 100644 --- a/libevmasm/RuleList.h +++ b/libevmasm/RuleList.h @@ -153,6 +153,17 @@ std::vector<SimplificationRule<Pattern>> simplificationRuleList( {{Instruction::OR, {{Instruction::NOT, {X}}, X}}, [=]{ return ~u256(0); }, true}, }; + // Replace MOD X, <power-of-two> with AND X, <power-of-two> - 1 + for (size_t i = 0; i < 256; ++i) + { + u256 value = u256(1) << i; + rules.push_back({ + {Instruction::MOD, {X, value}}, + [=]() -> Pattern { return {Instruction::AND, {X, value - 1}}; }, + false + }); + } + // Double negation of opcodes with boolean result for (auto const& op: std::vector<Instruction>{ Instruction::EQ, diff --git a/test/externalTests.sh b/test/externalTests.sh index 11972eae..2a5ff7ef 100755 --- a/test/externalTests.sh +++ b/test/externalTests.sh @@ -36,14 +36,32 @@ fi SOLJSON="$1" -DIR=$(mktemp -d) -( - echo "Running Zeppelin tests..." - git clone --depth 1 https://github.com/OpenZeppelin/zeppelin-solidity.git "$DIR" - cd "$DIR" - npm install - find . -name soljson.js -exec cp "$SOLJSON" {} \; +function test_truffle +{ + name="$1" + repo="$2" + echo "Running $name tests..." + DIR=$(mktemp -d) + ( + git clone --depth 1 "$repo" "$DIR" + cd "$DIR" + npm install + find . -name soljson.js -exec cp "$SOLJSON" {} \; + if [ "$name" == "Zeppelin" ]; then + # Fix some things that look like bugs (only seemed to fail on Node 6 and not Node 8) + # FIXME: report upstream or to web3.js? + sed -i -e 's/let token = await ERC827TokenMock.new();//;' test/token/ERC827/ERC827Token.js + sed -i -e 's/CappedCrowdsale.new(this.startTime, this.endTime, rate, wallet, 0)/CappedCrowdsale.new(this.startTime, this.endTime, rate, wallet, 0, this.token.address)/' test/crowdsale/CappedCrowdsale.test.js + sed -i -e 's/RefundableCrowdsale.new(this.startTime, this.endTime, rate, wallet, 0, { from: owner })/RefundableCrowdsale.new(this.startTime, this.endTime, rate, wallet, 0, this.token.address, { from: owner })/' test/crowdsale/RefundableCrowdsale.test.js + fi + if [ "$name" == "Gnosis" ]; then + # Replace fixed-version pragmas in Gnosis (part of Consensys best practice) + find contracts test -name '*.sol' -type f -print0 | xargs -0 sed -i -e 's/pragma solidity 0/pragma solidity ^0/' + fi + npm run test + ) + rm -rf "$DIR" +} - npm run test -) -rm -rf "$DIR" +test_truffle Gnosis https://github.com/gnosis/gnosis-contracts.git +test_truffle Zeppelin https://github.com/OpenZeppelin/zeppelin-solidity.git diff --git a/test/libjulia/Simplifier.cpp b/test/libjulia/Simplifier.cpp index b48d45c8..4d4e8d53 100644 --- a/test/libjulia/Simplifier.cpp +++ b/test/libjulia/Simplifier.cpp @@ -127,4 +127,16 @@ BOOST_AUTO_TEST_CASE(inside_for) ); } +BOOST_AUTO_TEST_CASE(mod_and) +{ + CHECK( + "{ mstore(0, mod(calldataload(0), exp(2, 8))) }", + "{ mstore(0, and(calldataload(0), 255)) }" + ); + CHECK( + "{ mstore(0, mod(calldataload(0), exp(2, 255))) }", + "{ mstore(0, and(calldataload(0), 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)) }" + ); +} + BOOST_AUTO_TEST_SUITE_END() |
