Skip to content

Commit

Permalink
Merge branch 'dev' into fix/config-path
Browse files Browse the repository at this point in the history
  • Loading branch information
0xalpharush authored Jan 16, 2024
2 parents 4b59781 + bb7af17 commit 8e4445f
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 10 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-2022"]
python: ${{ (github.event_name == 'pull_request' && fromJSON('["3.8", "3.12"]')) || fromJSON('["3.8", "3.9", "3.10", "3.11", "3.12"]') }}
type: ["brownie", "buidler", "dapp", "embark", "hardhat", "solc", "truffle", "waffle", "foundry", "standard", "vyper", "solc_multi_file", "hardhat_multi_file"]
exclude:
# Currently broken, tries to pull git:// which is blocked by GH
Expand All @@ -32,6 +33,18 @@ jobs:
# Explore foundry support in windows
- os: windows-2022
type: foundry
# brownie does not install correctly with Python 3.10
- python: 3.10
type: brownie
# brownie does not install correctly with Python 3.11
- python: 3.11
type: brownie
# brownie does not install correctly with Python 3.12
- python: 3.12
type: brownie
# TODO: review failure executing npx on Windows
- os: windows-2022
python: 3.12
steps:
- uses: actions/checkout@v4
- name: Set up shell
Expand All @@ -43,15 +56,14 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 18.15
- name: Set up Python 3.8
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: ${{ matrix.python }}
- name: Install dependencies
run: |
pip install "solc-select>=v1.0.0b1"
solc-select use 0.5.7 --always-install
pip install .
solc-select use 0.5.7 --always-install
- name: Set up nix
if: matrix.type == 'dapp'
uses: cachix/install-nix-action@v24
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
python -m build
- name: Upload distributions
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: crytic-compile-dists
path: dist/
Expand Down
5 changes: 2 additions & 3 deletions crytic_compile/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
This is the Slither cli script
"""
import argparse
from importlib.metadata import version
import json
import logging
import os
import sys
from typing import TYPE_CHECKING, Any, Optional

from pkg_resources import require

from crytic_compile.crytic_compile import compile_all, get_platforms
from crytic_compile.cryticparser import DEFAULTS_FLAG_IN_CONFIG, cryticparser
from crytic_compile.platform import InvalidCompilation
Expand Down Expand Up @@ -109,7 +108,7 @@ def parse_args() -> argparse.Namespace:
parser.add_argument(
"--version",
help="displays the current version",
version=require("crytic-compile")[0].version,
version=version("crytic-compile"),
action="version",
)

Expand Down
9 changes: 9 additions & 0 deletions crytic_compile/platform/etherscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,19 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
working_dir: Optional[str] = None
remappings: Optional[List[str]] = None

dict_source_code: Optional[Dict] = None
try:
# etherscan might return an object with two curly braces, {{ content }}
dict_source_code = json.loads(source_code[1:-1])
assert isinstance(dict_source_code, dict)
filenames, working_dir, remappings = _handle_multiple_files(
dict_source_code, addr, prefix, contract_name, export_dir
)
except JSONDecodeError:
try:
# or etherscan might return an object with single curly braces, { content }
dict_source_code = json.loads(source_code)
assert isinstance(dict_source_code, dict)
filenames, working_dir, remappings = _handle_multiple_files(
dict_source_code, addr, prefix, contract_name, export_dir
)
Expand All @@ -390,6 +393,11 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
_handle_single_file(source_code, addr, prefix, contract_name, export_dir)
]

# viaIR is not exposed on the top level JSON offered by etherscan, so we need to inspect the settings
via_ir_enabled: Optional[bool] = None
if isinstance(dict_source_code, dict):
via_ir_enabled = dict_source_code.get("settings", {}).get("viaIR", None)

compilation_unit = CompilationUnit(crytic_compile, contract_name)

compilation_unit.compiler_version = CompilerVersion(
Expand All @@ -413,6 +421,7 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
working_dir=working_dir,
remappings=remappings,
evm_version=evm_version,
via_ir=via_ir_enabled,
)

def clean(self, **_kwargs: str) -> None:
Expand Down
20 changes: 20 additions & 0 deletions crytic_compile/platform/solc_standard_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
LOGGER = logging.getLogger("CryticCompile")


# pylint: disable=too-many-arguments
def standalone_compile(
filenames: List[str],
compilation_unit: CompilationUnit,
working_dir: Optional[str] = None,
remappings: Optional[List[str]] = None,
evm_version: Optional[str] = None,
via_ir: Optional[bool] = None,
) -> None:
"""
Boilerplate function to run the the standardjson. compilation_unit.compiler_version must be set before calling this function
Expand All @@ -48,6 +50,7 @@ def standalone_compile(
working_dir (Optional[str]): working directory
remappings (Optional[List[str]]): list of solc remaps to use
evm_version (Optional[str]): EVM version to target. None for default
via_ir (Optional[bool]): whether to enable the viaIR compilation flag. None for unset
Returns:
Expand All @@ -70,6 +73,9 @@ def standalone_compile(
if evm_version is not None:
add_evm_version(standard_json_dict, evm_version)

if via_ir is not None:
add_via_ir(standard_json_dict, via_ir)

add_optimization(
standard_json_dict,
compilation_unit.compiler_version.optimized,
Expand Down Expand Up @@ -278,6 +284,20 @@ def add_evm_version(json_dict: Dict, version: str) -> None:
json_dict["settings"]["evmVersion"] = version


def add_via_ir(json_dict: Dict, enabled: bool) -> None:
"""
Enable or disable the "viaIR" compilation flag.
Args:
json_dict (Dict): solc standard json input
enabled (bool): whether viaIR is enabled
Returns:
"""
json_dict["settings"]["viaIR"] = enabled


def parse_standard_json_output(
targets_json: Dict, compilation_unit: CompilationUnit, solc_working_dir: Optional[str] = None
) -> None:
Expand Down
16 changes: 14 additions & 2 deletions crytic_compile/platform/vyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,21 @@ def _run_vyper_standard_json(
) # convert bytestrings to unicode strings

vyper_standard_output = json.loads(stdout)

if "errors" in vyper_standard_output:
# TODO format errors
raise InvalidCompilation(vyper_standard_output["errors"])

has_errors = False
for diagnostic in vyper_standard_output["errors"]:

if diagnostic["severity"] == "warning":
continue

msg = diagnostic.get("formattedMessage", diagnostic["message"])
LOGGER.error(msg)
has_errors = True

if has_errors:
raise InvalidCompilation("Vyper compilation errored")

return vyper_standard_output

Expand Down
13 changes: 13 additions & 0 deletions scripts/ci_test_etherscan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,16 @@ then
exit 255
fi
echo "::endgroup::"

delay_etherscan

# via-ir test for crytic/crytic-compile#517
echo "::group::Etherscan #7"
crytic-compile 0x9AB6b21cDF116f611110b048987E58894786C244 --compile-remove-metadata --etherscan-apikey "$GITHUB_ETHERSCAN"

if [ $? -ne 0 ]
then
echo "Etherscan #7 test failed"
exit 255
fi
echo "::endgroup::"

0 comments on commit 8e4445f

Please sign in to comment.