Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into covDuringDeploy2
Browse files Browse the repository at this point in the history
  • Loading branch information
elopez committed Sep 19, 2024
2 parents 72c4bb7 + 4ee7099 commit a2e3527
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 90 deletions.
8 changes: 4 additions & 4 deletions .github/scripts/install-libsecp256k1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ if [ -f $HOME/.local/lib/libsecp256k1.a ]; then
exit 0
fi

gitRef="21ffe4b22a9683cf24ae0763359e401d1284cc7a"
curl -LO "https://github.com/bitcoin-core/secp256k1/archive/$gitRef.zip"
INSTALL_VERSION=0.5.0
curl -LO "https://github.com/bitcoin-core/secp256k1/archive/v$INSTALL_VERSION.zip"

unzip "$gitRef.zip"
cd "secp256k1-$gitRef"
unzip "v$INSTALL_VERSION.zip" && rm "v$INSTALL_VERSION.zip"
cd "secp256k1-$INSTALL_VERSION"

./autogen.sh
# hevm needs reecovery module
Expand Down
24 changes: 15 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ jobs:
if: runner.os == 'Windows'
with:
msystem: CLANG64
release: false
path-type: minimal
update: true
install: >-
Expand All @@ -65,7 +64,7 @@ jobs:
id: stack
if: matrix.container == ''
with:
ghc-version: '9.6'
ghc-version: '9.6.5'
enable-stack: true
stack-version: 'latest'

Expand All @@ -82,16 +81,19 @@ jobs:
echo "$EXTRA_LIB_WIN";
echo;
echo "ghc-options:";
echo -n ' "$locals": -Werror'
"$REPLACE_LINKER_WIN" && echo ' -pgml=C:/msys64/clang64/bin/clang.exe -pgml-supports-no-pie' || echo;
echo ' "$locals": -Werror'
"$REPLACE_LINKER_WIN" && echo ' "$everything": -pgml=D:/a/_temp/msys64/clang64/bin/clang.exe -pgml-supports-no-pie';
echo;
"$SKIP_MSYS" && echo "skip-msys: true" || true
echo "system-ghc: true";
echo "install-ghc: false";
echo "skip-ghc-check: true";
} >> "$STACK_ROOT/config.yaml"
cat "$STACK_ROOT/config.yaml"
env:
STACK_ROOT: ${{ steps.stack.outputs.stack-root || '/etc/stack' }}
EXTRA_INCLUDE_WIN: ${{ (runner.os == 'Windows' && '- C:/msys64/clang64/include') || '' }}
EXTRA_LIB_WIN: ${{ (runner.os == 'Windows' && '- C:/msys64/clang64/lib') || '' }}
EXTRA_INCLUDE_WIN: ${{ (runner.os == 'Windows' && '- D:/a/_temp/msys64/clang64/include') || '' }}
EXTRA_LIB_WIN: ${{ (runner.os == 'Windows' && '- D:/a/_temp/msys64/clang64/lib') || '' }}
REPLACE_LINKER_WIN: ${{ (runner.os == 'Windows' && 'true') || 'false' }}
SKIP_MSYS: ${{ (runner.os == 'Windows' && 'true') || 'false' }}

Expand All @@ -113,9 +115,13 @@ jobs:
with:
path: |
~/.local
C:\msys64\home\runneradmin\.local
D:\a\_temp\msys64\home\runneradmin\.local
key: ${{ runner.os }}-local-${{ env.CACHE_VERSION }}-${{ hashFiles('.github/scripts/install-*') }}

- name: Configure static build flags
run: |
printf "\nflags:\n hevm:\n static-secp256k1: true\n echidna:\n static: true\n" >> stack.yaml
- name: Cache Stack & Cabal
uses: actions/cache@v4
with:
Expand Down Expand Up @@ -143,7 +149,7 @@ jobs:
- name: Build and install echidna
run: |
export PATH="$HASKELL_PATHS:$PATH"
stack install --flag echidna:static --ghc-options="-Werror"
stack install --ghc-options="-Werror"
- name: Amend and compress binaries (macOS)
if: runner.os == 'macOS'
Expand All @@ -167,7 +173,7 @@ jobs:
if: runner.os != 'macOS'
run: |
export PATH="$HASKELL_PATHS:$PATH"
stack build --flag echidna:static --test --no-run-tests --ghc-options="-Werror"
stack build --test --no-run-tests --ghc-options="-Werror"
cp "$(find "$PWD" -name 'echidna-testsuite*' -type f)" .
- name: Upload testsuite
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/hlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions/checkout@v4

- name: Install Nix
uses: cachix/install-nix-action@V27
uses: cachix/install-nix-action@V28
with:
nix_path: nixpkgs=channel:nixos-unstable

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
uses: actions/checkout@v4

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v13
uses: DeterminateSystems/nix-installer-action@v14

- name: Configure Cachix
uses: cachix/cachix-action@v15
Expand All @@ -45,7 +45,7 @@ jobs:
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}

- name: Configure Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v7
uses: DeterminateSystems/magic-nix-cache-action@v8
with:
upstream-cache: https://trailofbits.cachix.org

Expand Down
82 changes: 75 additions & 7 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 18 additions & 42 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,25 @@
url = "github:3noch/nix-bundle-exe";
flake = false;
};
solc-pkgs = {
url = "github:hellwolf/solc.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, flake-utils, nix-bundle-exe, ... }:
outputs = { self, nixpkgs, flake-utils, nix-bundle-exe, solc-pkgs, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
pkgs = import nixpkgs {
inherit system;
overlays = [solc-pkgs.overlay];
};

# prefer musl on Linux, static glibc + threading does not work properly
# TODO: maybe only override it for echidna-redistributable?
pkgsStatic = if pkgs.stdenv.hostPlatform.isLinux then pkgs.pkgsStatic else pkgs;
# this is not perfect for development as it hardcodes solc to 0.5.7, test suite runs fine though
# would be great to integrate solc-select to be more flexible, improve this in future
solc = pkgs.stdenv.mkDerivation {
name = "solc";
src = if pkgs.stdenv.isDarwin then
pkgs.fetchurl {
url = "https://binaries.soliditylang.org/macosx-amd64/solc-macosx-amd64-v0.5.7+commit.6da8b019";
sha256 = "095mlw5x9lpdcdl9jzlvkvw46ag03xr4nj4vly4hgn92rgivimm7";
}
else
pkgs.fetchurl {
url = "https://binaries.soliditylang.org/linux-amd64/solc-linux-amd64-v0.5.7+commit.6da8b019";
sha256 = "0dsvzck5jh8rvdxs7zyn2ga9hif024msx8gr8ifgj4cmyb7m4341";
};
phases = ["installPhase" "patchPhase"];
installPhase = ''
mkdir -p $out/bin
cp $src $out/bin/solc
chmod +x $out/bin/solc
'';
};
solc = solc-pkgs.mkDefault pkgs pkgs.solc_0_5_7;

secp256k1-static = pkgsStatic.secp256k1.overrideAttrs (attrs: {
configureFlags = attrs.configureFlags ++ [ "--enable-static" ];
Expand All @@ -54,28 +43,19 @@
if (with ps.stdenv; hostPlatform.isDarwin && hostPlatform.isx86)
then ps.haskell.lib.compose.overrideCabal (_ : { extraLibraries = [ps.libiconv]; }) hprev.with-utf8
else hprev.with-utf8;
# TODO: temporary fix for static build which is still on 9.4
witch = ps.haskell.lib.doJailbreak hprev.witch;
};
};

cc-workaround-nix-23138 =
pkgs.writeScriptBin "cc-workaround-nix-23138" ''
if [ "$1" = "--print-file-name" ] && [ "$2" = "c++" ]; then
echo c++
else
exec cc "$@"
fi
'';

hevm = pkgs: pkgs.lib.pipe ((hsPkgs pkgs).callCabal2nix "hevm" (pkgs.fetchFromGitHub {
owner = "trail-of-forks";
repo = "hevm";
rev = "3aba82f06a2d1e0a4a4c26458f747a46dad0e7e2";
sha256 = "sha256-NXXhEqHTQEL2N9RhXa1eczIsQtIM3mvPfyWXlBXpxK4=";
owner = "ethereum";
repo = "hevm";
rev = "c779777d18c8ff60867f009d434b44ce08188e01";
sha256 = "sha256-JnJUZ9AxhxTP+TBMThksh0D4R6KFdzjgu1+fBeBERws=";
}) { secp256k1 = pkgs.secp256k1; })
([
pkgs.haskell.lib.compose.dontCheck
] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
(pkgs.haskell.lib.compose.appendConfigureFlag "--ghc-options=-pgml=${cc-workaround-nix-23138}/bin/cc-workaround-nix-23138")
]);

echidna = pkgs: with pkgs; lib.pipe
Expand All @@ -86,8 +66,6 @@
haskell.lib.compose.dontCheck
(haskell.lib.compose.addTestToolDepends [ haskellPackages.hpack slither-analyzer solc ])
(haskell.lib.compose.disableCabalFlag "static")
] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
(pkgs.haskell.lib.compose.appendConfigureFlag "--ghc-options=-pgml=${cc-workaround-nix-23138}/bin/cc-workaround-nix-23138")
]);

echidna-static = with pkgsStatic; lib.pipe
Expand Down Expand Up @@ -173,9 +151,7 @@
packages = _: [ (echidna pkgs) ];
shellHook = ''
hpack
'' + (if pkgs.stdenv.isDarwin then ''
cabal configure --ghc-options=-pgml=${cc-workaround-nix-23138}/bin/cc-workaround-nix-23138
'' else "");
'';
buildInputs = [
solc
slither-analyzer
Expand Down
16 changes: 12 additions & 4 deletions lib/Echidna/ABI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ makeArrayAbiValues b =
fmap (\n -> AbiBytes n . BS.append b $ BS.replicate (n - size) 0) [size..32]

-- | Pretty-print some 'AbiValue'.
ppAbiValue :: AbiValue -> String
ppAbiValue = \case
ppAbiValue :: Map Addr Text -> AbiValue -> String
ppAbiValue labels = \case
AbiUInt _ n -> show n
AbiInt _ n -> show n
AbiAddress n -> "0x" <> showHex n ""
AbiAddress n -> ppAddr labels n
AbiBool b -> if b then "true" else "false"
AbiBytes _ b -> show b
AbiBytesDynamic b -> show b
Expand All @@ -78,7 +78,15 @@ ppAbiValue = \case
AbiArray _ _ v -> "[" <> commaSeparated v <> "]"
AbiTuple v -> "(" <> commaSeparated v <> ")"
AbiFunction v -> show v
where commaSeparated v = intercalate ", " (ppAbiValue <$> toList v)
where
commaSeparated v = intercalate ", " $ ppAbiValue labels <$> toList v

ppAddr :: Map Addr Text -> Addr -> String
ppAddr labels addr = "0x" <> showHex addr "" <> label
where
label = case Map.lookup addr labels of
Nothing -> ""
Just l -> " «" <> T.unpack l <> "»"

-- | Get the signature from a Solidity function.
signatureCall :: SolCall -> SolSignature
Expand Down
2 changes: 1 addition & 1 deletion lib/Echidna/Output/JSON.hs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@ mapTest dappInfo test =

mapCall = \case
SolCreate _ -> ("<CREATE>", Nothing)
SolCall (name, args) -> (name, Just $ ppAbiValue <$> args)
SolCall (name, args) -> (name, Just $ ppAbiValue <$> mempty <*> args)
NoCall -> ("*wait*", Nothing)
SolCalldata x -> (decodeUtf8 $ "0x" <> BS16.encode x, Nothing)
Loading

0 comments on commit a2e3527

Please sign in to comment.