From a7909385ec9fe4aea46a46937da23f2c0a253237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Wed, 5 Apr 2023 21:01:54 -0300 Subject: [PATCH 1/4] solc-select: improve testing on ARM Running solc itself requires an Intel system or Rosetta. Account for that fact in the brew test. --- Formula/solc-select.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Formula/solc-select.rb b/Formula/solc-select.rb index 88b065d9c2a57..72eedb0cd956d 100644 --- a/Formula/solc-select.rb +++ b/Formula/solc-select.rb @@ -38,6 +38,11 @@ def install system bin/"solc-select", "install", "0.8.0" system bin/"solc-select", "use", "0.5.7" + assert_match(/0\.5\.7.*current/, shell_output("#{bin}/solc-select versions")) + + # running solc itself requires an Intel system or Rosetta + return if Hardware::CPU.arm? + assert_match("0.5.7", shell_output("#{bin}/solc --version")) with_env(SOLC_VERSION: "0.8.0") do assert_match("0.8.0", shell_output("#{bin}/solc --version")) From e04575567df841da4bcc8d721e7532df146dddb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Wed, 5 Apr 2023 21:01:54 -0300 Subject: [PATCH 2/4] crytic-compile: improve testing on ARM Running solc (through solc-select) requires an Intel system or Rosetta. Implement testing with a precompiled project instead, which should work on all platforms. --- Formula/crytic-compile.rb | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/Formula/crytic-compile.rb b/Formula/crytic-compile.rb index cf6e37720990a..9207c8dc01fa3 100644 --- a/Formula/crytic-compile.rb +++ b/Formula/crytic-compile.rb @@ -38,18 +38,14 @@ def install end test do - (testpath/"test.sol").write <<~EOS - pragma solidity ^0.8.0; - contract Test { - function f() public pure returns (bool) { - return false; - } - } - EOS - - system "solc-select", "install", "0.8.0" - with_env(SOLC_VERSION: "0.8.0") do - system bin/"crytic-compile", testpath/"test.sol", "--export-format=solc", "--export-dir=#{testpath}/export" + resource "testdata" do + url "https://github.com/crytic/slither/raw/d0a4f5595d7177b3b7d4bd35e1384bf35ebc22d4/tests/ast-parsing/compile/variable-0.8.0.sol-0.8.15-compact.zip", using: :nounzip + sha256 "2f165f629882d0250d03a56cb67a84e9741375349195915a04385b0666394478" + end + + resource("testdata").stage do + system bin/"crytic-compile", "variable-0.8.0.sol-0.8.15-compact.zip", \ + "--export-format=solc", "--export-dir=#{testpath}/export" end assert_predicate testpath/"export/combined_solc.json", :exist? From 1e36c79ee0dcf29ceba336a514848c0a6a179370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Wed, 5 Apr 2023 21:01:54 -0300 Subject: [PATCH 3/4] slither-analyzer: improve testing on ARM Running solc (through solc-select) requires an Intel system or Rosetta. Implement testing with a pre-compiled project instead, which should work across all platforms. --- Formula/slither-analyzer.rb | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/Formula/slither-analyzer.rb b/Formula/slither-analyzer.rb index f549b6baf45b0..6b0d0e478abd9 100644 --- a/Formula/slither-analyzer.rb +++ b/Formula/slither-analyzer.rb @@ -216,23 +216,16 @@ def install end test do - (testpath/"test.sol").write <<~EOS - pragma solidity ^0.8.0; - contract Test { - function incorrect_shift() internal returns (uint a) { - assembly { - a := shr(a, 8) - } - } - } - EOS - - system "solc-select", "install", "0.8.0" - - with_env(SOLC_VERSION: "0.8.0") do + resource "testdata" do + url "https://github.com/crytic/slither/raw/d0a4f5595d7177b3b7d4bd35e1384bf35ebc22d4/tests/ast-parsing/compile/variable-0.8.0.sol-0.8.15-compact.zip", using: :nounzip + sha256 "2f165f629882d0250d03a56cb67a84e9741375349195915a04385b0666394478" + end + + resource("testdata").stage do # slither exits with code 255 if high severity findings are found - assert_match("1 result(s) found", - shell_output("#{bin}/slither --detect incorrect-shift --fail-high #{testpath}/test.sol 2>&1", 255)) + assert_match("5 result(s) found", + shell_output("#{bin}/slither --detect uninitialized-state --fail-high " \ + "variable-0.8.0.sol-0.8.15-compact.zip 2>&1", 255)) end end end From 2aa150dd9d9741943033a758c932452de4b34ca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Wed, 5 Apr 2023 13:55:18 -0300 Subject: [PATCH 4/4] echidna: improve testing on ARM `solc` binaries (through `solc-select`) are only available for Intel platforms or through Rosetta. Switch `echidna` to test with a Truffle project instead, which can be built on all platforms. --- Formula/echidna.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Formula/echidna.rb b/Formula/echidna.rb index 60922cc11504f..8ea4dbdab31b9 100644 --- a/Formula/echidna.rb +++ b/Formula/echidna.rb @@ -18,6 +18,8 @@ class Echidna < Formula depends_on "ghc@9.2" => :build depends_on "haskell-stack" => :build + depends_on "truffle" => :test + depends_on "crytic-compile" depends_on "libff" depends_on "secp256k1" @@ -48,9 +50,10 @@ def install end test do - system "solc-select", "install", "0.7.0" + system "truffle", "init" - (testpath/"test.sol").write <<~EOS + (testpath/"contracts/test.sol").write <<~EOS + pragma solidity ^0.8.0; contract True { function f() public returns (bool) { return(false); @@ -61,9 +64,7 @@ def install } EOS - with_env(SOLC_VERSION: "0.7.0") do - assert_match(/echidna_true:(\s+)passed!/, - shell_output("#{bin}/echidna --format text #{testpath}/test.sol")) - end + assert_match(/echidna_true:(\s+)passed!/, + shell_output("#{bin}/echidna --format text #{testpath}")) end end