Skip to content

Commit 8e4445f

Browse files
authored
Merge branch 'dev' into fix/config-path
2 parents 4b59781 + bb7af17 commit 8e4445f

File tree

7 files changed

+75
-10
lines changed

7 files changed

+75
-10
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
fail-fast: false
2323
matrix:
2424
os: ["ubuntu-latest", "windows-2022"]
25+
python: ${{ (github.event_name == 'pull_request' && fromJSON('["3.8", "3.12"]')) || fromJSON('["3.8", "3.9", "3.10", "3.11", "3.12"]') }}
2526
type: ["brownie", "buidler", "dapp", "embark", "hardhat", "solc", "truffle", "waffle", "foundry", "standard", "vyper", "solc_multi_file", "hardhat_multi_file"]
2627
exclude:
2728
# Currently broken, tries to pull git:// which is blocked by GH
@@ -32,6 +33,18 @@ jobs:
3233
# Explore foundry support in windows
3334
- os: windows-2022
3435
type: foundry
36+
# brownie does not install correctly with Python 3.10
37+
- python: 3.10
38+
type: brownie
39+
# brownie does not install correctly with Python 3.11
40+
- python: 3.11
41+
type: brownie
42+
# brownie does not install correctly with Python 3.12
43+
- python: 3.12
44+
type: brownie
45+
# TODO: review failure executing npx on Windows
46+
- os: windows-2022
47+
python: 3.12
3548
steps:
3649
- uses: actions/checkout@v4
3750
- name: Set up shell
@@ -43,15 +56,14 @@ jobs:
4356
uses: actions/setup-node@v4
4457
with:
4558
node-version: 18.15
46-
- name: Set up Python 3.8
59+
- name: Set up Python ${{ matrix.python }}
4760
uses: actions/setup-python@v5
4861
with:
49-
python-version: 3.8
62+
python-version: ${{ matrix.python }}
5063
- name: Install dependencies
5164
run: |
52-
pip install "solc-select>=v1.0.0b1"
53-
solc-select use 0.5.7 --always-install
5465
pip install .
66+
solc-select use 0.5.7 --always-install
5567
- name: Set up nix
5668
if: matrix.type == 'dapp'
5769
uses: cachix/install-nix-action@v24

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
python -m build
2525
2626
- name: Upload distributions
27-
uses: actions/upload-artifact@v3
27+
uses: actions/upload-artifact@v4
2828
with:
2929
name: crytic-compile-dists
3030
path: dist/

crytic_compile/__main__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
This is the Slither cli script
33
"""
44
import argparse
5+
from importlib.metadata import version
56
import json
67
import logging
78
import os
89
import sys
910
from typing import TYPE_CHECKING, Any, Optional
1011

11-
from pkg_resources import require
12-
1312
from crytic_compile.crytic_compile import compile_all, get_platforms
1413
from crytic_compile.cryticparser import DEFAULTS_FLAG_IN_CONFIG, cryticparser
1514
from crytic_compile.platform import InvalidCompilation
@@ -109,7 +108,7 @@ def parse_args() -> argparse.Namespace:
109108
parser.add_argument(
110109
"--version",
111110
help="displays the current version",
112-
version=require("crytic-compile")[0].version,
111+
version=version("crytic-compile"),
113112
action="version",
114113
)
115114

crytic_compile/platform/etherscan.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,16 +372,19 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
372372
working_dir: Optional[str] = None
373373
remappings: Optional[List[str]] = None
374374

375+
dict_source_code: Optional[Dict] = None
375376
try:
376377
# etherscan might return an object with two curly braces, {{ content }}
377378
dict_source_code = json.loads(source_code[1:-1])
379+
assert isinstance(dict_source_code, dict)
378380
filenames, working_dir, remappings = _handle_multiple_files(
379381
dict_source_code, addr, prefix, contract_name, export_dir
380382
)
381383
except JSONDecodeError:
382384
try:
383385
# or etherscan might return an object with single curly braces, { content }
384386
dict_source_code = json.loads(source_code)
387+
assert isinstance(dict_source_code, dict)
385388
filenames, working_dir, remappings = _handle_multiple_files(
386389
dict_source_code, addr, prefix, contract_name, export_dir
387390
)
@@ -390,6 +393,11 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
390393
_handle_single_file(source_code, addr, prefix, contract_name, export_dir)
391394
]
392395

396+
# viaIR is not exposed on the top level JSON offered by etherscan, so we need to inspect the settings
397+
via_ir_enabled: Optional[bool] = None
398+
if isinstance(dict_source_code, dict):
399+
via_ir_enabled = dict_source_code.get("settings", {}).get("viaIR", None)
400+
393401
compilation_unit = CompilationUnit(crytic_compile, contract_name)
394402

395403
compilation_unit.compiler_version = CompilerVersion(
@@ -413,6 +421,7 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
413421
working_dir=working_dir,
414422
remappings=remappings,
415423
evm_version=evm_version,
424+
via_ir=via_ir_enabled,
416425
)
417426

418427
def clean(self, **_kwargs: str) -> None:

crytic_compile/platform/solc_standard_json.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
LOGGER = logging.getLogger("CryticCompile")
2626

2727

28+
# pylint: disable=too-many-arguments
2829
def standalone_compile(
2930
filenames: List[str],
3031
compilation_unit: CompilationUnit,
3132
working_dir: Optional[str] = None,
3233
remappings: Optional[List[str]] = None,
3334
evm_version: Optional[str] = None,
35+
via_ir: Optional[bool] = None,
3436
) -> None:
3537
"""
3638
Boilerplate function to run the the standardjson. compilation_unit.compiler_version must be set before calling this function
@@ -48,6 +50,7 @@ def standalone_compile(
4850
working_dir (Optional[str]): working directory
4951
remappings (Optional[List[str]]): list of solc remaps to use
5052
evm_version (Optional[str]): EVM version to target. None for default
53+
via_ir (Optional[bool]): whether to enable the viaIR compilation flag. None for unset
5154
5255
Returns:
5356
@@ -70,6 +73,9 @@ def standalone_compile(
7073
if evm_version is not None:
7174
add_evm_version(standard_json_dict, evm_version)
7275

76+
if via_ir is not None:
77+
add_via_ir(standard_json_dict, via_ir)
78+
7379
add_optimization(
7480
standard_json_dict,
7581
compilation_unit.compiler_version.optimized,
@@ -278,6 +284,20 @@ def add_evm_version(json_dict: Dict, version: str) -> None:
278284
json_dict["settings"]["evmVersion"] = version
279285

280286

287+
def add_via_ir(json_dict: Dict, enabled: bool) -> None:
288+
"""
289+
Enable or disable the "viaIR" compilation flag.
290+
291+
Args:
292+
json_dict (Dict): solc standard json input
293+
enabled (bool): whether viaIR is enabled
294+
295+
Returns:
296+
297+
"""
298+
json_dict["settings"]["viaIR"] = enabled
299+
300+
281301
def parse_standard_json_output(
282302
targets_json: Dict, compilation_unit: CompilationUnit, solc_working_dir: Optional[str] = None
283303
) -> None:

crytic_compile/platform/vyper.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,21 @@ def _run_vyper_standard_json(
206206
) # convert bytestrings to unicode strings
207207

208208
vyper_standard_output = json.loads(stdout)
209+
209210
if "errors" in vyper_standard_output:
210-
# TODO format errors
211-
raise InvalidCompilation(vyper_standard_output["errors"])
211+
212+
has_errors = False
213+
for diagnostic in vyper_standard_output["errors"]:
214+
215+
if diagnostic["severity"] == "warning":
216+
continue
217+
218+
msg = diagnostic.get("formattedMessage", diagnostic["message"])
219+
LOGGER.error(msg)
220+
has_errors = True
221+
222+
if has_errors:
223+
raise InvalidCompilation("Vyper compilation errored")
212224

213225
return vyper_standard_output
214226

scripts/ci_test_etherscan.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,16 @@ then
8686
exit 255
8787
fi
8888
echo "::endgroup::"
89+
90+
delay_etherscan
91+
92+
# via-ir test for crytic/crytic-compile#517
93+
echo "::group::Etherscan #7"
94+
crytic-compile 0x9AB6b21cDF116f611110b048987E58894786C244 --compile-remove-metadata --etherscan-apikey "$GITHUB_ETHERSCAN"
95+
96+
if [ $? -ne 0 ]
97+
then
98+
echo "Etherscan #7 test failed"
99+
exit 255
100+
fi
101+
echo "::endgroup::"

0 commit comments

Comments
 (0)