Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync master <> dev #501

Merged
merged 58 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
665d5c8
Add CompilationUnit.implementation_address
SheldonHolmgren Jun 15, 2023
5297ed2
Appease mypy
SheldonHolmgren Jun 29, 2023
24bc098
Fix proxy resolution for non-Ethereum networks
SheldonHolmgren Jun 29, 2023
a6a33a8
feat: compile vyper 0.3.7 via standard json input
0xalpharush Aug 8, 2023
1833299
Add config function
smonicas Aug 9, 2023
a7a5080
Add default config function
smonicas Aug 9, 2023
c65f67b
Parse foundry configuration
smonicas Aug 9, 2023
e34b0cc
Add auto-compile option
smonicas Aug 9, 2023
1e73671
Don't change the global solc version
smonicas Aug 9, 2023
94911af
chore: add base, gnosis, polygonzkevm
vikramarun Aug 9, 2023
b91b88a
Add PlatformConfig class
smonicas Aug 10, 2023
677075c
Add scripts path in PlatformConfig
smonicas Aug 11, 2023
0d3e8e8
Update foundry link
smonicas Aug 11, 2023
7e186a8
Skip compiling foundry test and script
smonicas Aug 11, 2023
3bd3729
Lint
smonicas Aug 11, 2023
0b8f205
Lint
smonicas Aug 11, 2023
80f3050
Bump pypa/gh-action-pypi-publish from 1.8.8 to 1.8.10
dependabot[bot] Aug 14, 2023
48f5cce
Bump sigstore/gh-action-sigstore-python from 2.0.0 to 2.0.1
dependabot[bot] Aug 14, 2023
d4f3fb8
Merge pull request #490 from crytic/dependabot/github_actions/dev/sig…
0xalpharush Aug 15, 2023
75383f8
Merge pull request #489 from crytic/dependabot/github_actions/dev/pyp…
0xalpharush Aug 15, 2023
a7c32c0
split srcmap
0xalpharush Aug 29, 2023
1150349
use tempfiles
0xalpharush Aug 31, 2023
852d59a
fix bug causing standard json to be shared across classes instances
0xalpharush Aug 31, 2023
1396844
use stdin/stdout
0xalpharush Aug 31, 2023
55429bf
chore: add flags for base, gnosis, polygonzkevm
ZaneH Sep 2, 2023
373e25b
Bump cachix/install-nix-action from 20 to 23
dependabot[bot] Sep 4, 2023
b224c54
Bump actions/checkout from 3 to 4
dependabot[bot] Sep 4, 2023
1ac8941
Merge pull request #1 from ZaneH/master
vikramarun Sep 6, 2023
6103fea
Merge branch 'dev' into master
vikramarun Sep 6, 2023
821d6fe
Merge pull request #487 from vikramarun/master
0xalpharush Sep 8, 2023
2b2a5a5
Merge branch 'dev' into dev-auto-compile
montyly Sep 15, 2023
d5f6c1b
Bump sigstore/gh-action-sigstore-python from 2.0.1 to 2.1.0
dependabot[bot] Oct 2, 2023
feac1a1
Merge pull request #498 from crytic/dependabot/github_actions/dev/sig…
0xalpharush Oct 3, 2023
fb5de47
Improvements
montyly Oct 5, 2023
41577ea
Fix linter
montyly Oct 5, 2023
7f85442
Minor
montyly Oct 5, 2023
2ac11ee
- Fix bug (missing add_source_files)
montyly Oct 5, 2023
fa60e8d
Merge pull request #488 from crytic/dev-auto-compile
montyly Oct 5, 2023
8fdc90e
Fix mypy
montyly Oct 5, 2023
83473a0
Tests for file ordering
samalws-tob Oct 5, 2023
938913a
Add vyper ci test
montyly Oct 12, 2023
8b0bc8f
Allow for more vyper versions
montyly Oct 12, 2023
bc69c9e
fix logging
montyly Oct 12, 2023
1401fb4
Merge pull request #492 from crytic/feat/vyper-standard-json
montyly Oct 12, 2023
9402459
Merge branch 'dev' into dependabot/github_actions/dev/actions/checkout-4
montyly Oct 12, 2023
4b3a290
Merge branch 'dev' into file-ordering-test
montyly Oct 12, 2023
9c086fc
Merge branch 'master' into implementation_address
montyly Oct 12, 2023
a8b933c
Add more delay on the etherscan CI test
montyly Oct 12, 2023
ef42535
Undo change to vyper test
montyly Oct 12, 2023
84f073d
Push to 2 seconds
montyly Oct 12, 2023
ee04ee3
Merge pull request #500 from crytic/etherscan-api-delay
montyly Oct 12, 2023
8c24df2
Merge branch 'dev' into implementation_address
montyly Oct 12, 2023
c9c27e2
Merge pull request #452 from SheldonHolmgren/implementation_address
montyly Oct 12, 2023
934e278
Merge pull request #499 from crytic/file-ordering-test
montyly Oct 12, 2023
b0717ae
Merge branch 'dev' into dependabot/github_actions/dev/actions/checkout-4
montyly Oct 12, 2023
0cb4251
Merge pull request #497 from crytic/dependabot/github_actions/dev/act…
montyly Oct 12, 2023
097b336
Merge branch 'dev' into dependabot/github_actions/dev/cachix/install-…
montyly Oct 12, 2023
c4f47cd
Merge pull request #496 from crytic/dependabot/github_actions/dev/cac…
montyly Oct 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python 3.8
uses: actions/setup-python@v4
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-2022"]
type: ["brownie", "buidler", "dapp", "embark", "hardhat", "solc", "truffle", "waffle", "foundry", "standard"]
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
- type: embark
Expand All @@ -33,7 +33,7 @@ jobs:
- os: windows-2022
type: foundry
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up shell
if: runner.os == 'Windows'
run: |
Expand All @@ -54,7 +54,7 @@ jobs:
pip install .
- name: Set up nix
if: matrix.type == 'dapp'
uses: cachix/install-nix-action@v20
uses: cachix/install-nix-action@v23
- name: Set up cachix
if: matrix.type == 'dapp'
uses: cachix/cachix-action@v12
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/darglint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v3
- uses: actions/setup-python@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/etherscan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
os: ["ubuntu-latest", "windows-2022"]
type: ["etherscan"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up shell
if: runner.os == 'Windows'
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python 3.8
uses: actions/setup-python@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python 3.8
uses: actions/setup-python@v4
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
Expand Down Expand Up @@ -45,10 +45,10 @@ jobs:
path: dist/

- name: publish
uses: pypa/[email protected].8
uses: pypa/[email protected].10

- name: sign
uses: sigstore/gh-action-sigstore-python@v2.0.0
uses: sigstore/gh-action-sigstore-python@v2.1.0
with:
inputs: ./dist/*.tar.gz ./dist/*.whl
release-signing-artifacts: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python 3.8
uses: actions/setup-python@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
Expand Down
22 changes: 22 additions & 0 deletions crytic_compile/compilation_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def __init__(self, crytic_compile: "CryticCompile", unique_id: str):
compiler="N/A", version="N/A", optimized=False
)

# if the compilation unit comes from etherscan-like service and is a proxy,
# store the implementation address
self._implementation_address: Optional[str] = None

self._crytic_compile: "CryticCompile" = crytic_compile

if unique_id == ".":
Expand Down Expand Up @@ -130,6 +134,24 @@ def create_source_unit(self, filename: Filename) -> SourceUnit:
self.filenames.append(filename)
return self._source_units[filename]

@property
def implementation_address(self) -> Optional[str]:
"""Return the implementation address if the compilation unit is a proxy

Returns:
Optional[str]: Implementation address
"""
return self._implementation_address

@implementation_address.setter
def implementation_address(self, implementation: str) -> None:
"""Set the implementation address

Args:
implementation (str): Implementation address
"""
self._implementation_address = implementation

# endregion
###################################################################################
###################################################################################
Expand Down
97 changes: 77 additions & 20 deletions crytic_compile/crytic_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@
from pathlib import Path
from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple, Type, Union

from solc_select.solc_select import (
install_artifacts,
installed_versions,
current_version,
artifact_path,
)
from crytic_compile.compilation_unit import CompilationUnit
from crytic_compile.platform import all_platforms, solc_standard_json
from crytic_compile.platform import all_platforms
from crytic_compile.platform.solc_standard_json import SolcStandardJson
from crytic_compile.platform.vyper import VyperStandardJson
from crytic_compile.platform.abstract_platform import AbstractPlatform
from crytic_compile.platform.all_export import PLATFORMS_EXPORT
from crytic_compile.platform.solc import Solc
Expand Down Expand Up @@ -84,6 +92,7 @@ class CryticCompile:
Main class.
"""

# pylint: disable=too-many-branches
def __init__(self, target: Union[str, AbstractPlatform], **kwargs: str) -> None:
"""See https://github.com/crytic/crytic-compile/wiki/Configuration
Target is usually a file or a project directory. It can be an AbstractPlatform
Expand Down Expand Up @@ -114,8 +123,55 @@ def __init__(self, target: Union[str, AbstractPlatform], **kwargs: str) -> None:

self._working_dir = Path.cwd()

# pylint: disable=too-many-nested-blocks
if isinstance(target, str):
platform = self._init_platform(target, **kwargs)
# If the platform is Solc it means we are trying to compile a single
# we try to see if we are in a known compilation framework to retrieve
# information like remappings and solc version
if isinstance(platform, Solc):
# Try to get the platform of the current working directory
platform_wd = next(
(
p(target)
for p in get_platforms()
if p.is_supported(str(self._working_dir), **kwargs)
),
None,
)
# If no platform has been found or if it's a Solc we can't do anything
if platform_wd and not isinstance(platform_wd, Solc):
platform_config = platform_wd.config(str(self._working_dir))
if platform_config:
kwargs["solc_args"] = ""
kwargs["solc_remaps"] = ""

if platform_config.remappings:
kwargs["solc_remaps"] = platform_config.remappings
if (
platform_config.solc_version
and platform_config.solc_version != current_version()[0]
):
solc_version = platform_config.solc_version
if solc_version in installed_versions():
kwargs["solc"] = str(artifact_path(solc_version).absolute())
else:
# Respect foundry offline option and don't install a missing solc version
if not platform_config.offline:
install_artifacts([solc_version])
kwargs["solc"] = str(artifact_path(solc_version).absolute())
if platform_config.optimizer:
kwargs["solc_args"] += "--optimize"
if platform_config.optimizer_runs:
kwargs[
"solc_args"
] += f"--optimize-runs {platform_config.optimizer_runs}"
if platform_config.via_ir:
kwargs["solc_args"] += "--via-ir"
if platform_config.allow_paths:
kwargs["solc_args"] += f"--allow-paths {platform_config.allow_paths}"
if platform_config.evm_version:
kwargs["solc_args"] += f"--evm-version {platform_config.evm_version}"
else:
platform = target

Expand Down Expand Up @@ -622,18 +678,14 @@ def compile_all(target: str, **kwargs: str) -> List[CryticCompile]:
**kwargs: optional arguments. Used: "solc_standard_json"

Raises:
ValueError: If the target could not be compiled
NotImplementedError: If the target could not be compiled

Returns:
List[CryticCompile]: Returns a list of CryticCompile instances for all compilations which occurred.
"""
use_solc_standard_json = kwargs.get("solc_standard_json", False)

# Attempt to perform glob expansion of target/filename
globbed_targets = glob.glob(target, recursive=True)

# Check if the target refers to a valid target already.
# If it does not, we assume it's a glob pattern.
compilations: List[CryticCompile] = []
if os.path.isfile(target) or is_supported(target):
if target.endswith(".zip"):
Expand All @@ -645,28 +697,33 @@ def compile_all(target: str, **kwargs: str) -> List[CryticCompile]:
compilations = load_from_zip(tmp.name)
else:
compilations.append(CryticCompile(target, **kwargs))
elif os.path.isdir(target) or len(globbed_targets) > 0:
# We create a new glob to find solidity files at this path (in case this is a directory)
filenames = glob.glob(os.path.join(target, "*.sol"))
if not filenames:
filenames = glob.glob(os.path.join(target, "*.vy"))
if not filenames:
filenames = globbed_targets

elif os.path.isdir(target):
solidity_filenames = glob.glob(os.path.join(target, "*.sol"))
vyper_filenames = glob.glob(os.path.join(target, "*.vy"))
# Determine if we're using --standard-solc option to
# aggregate many files into a single compilation.
if use_solc_standard_json:
# If we're using standard solc, then we generated our
# input to create a single compilation with all files
standard_json = solc_standard_json.SolcStandardJson()
for filename in filenames:
standard_json.add_source_file(filename)
compilations.append(CryticCompile(standard_json, **kwargs))
solc_standard_json = SolcStandardJson()
solc_standard_json.add_source_files(solidity_filenames)
compilations.append(CryticCompile(solc_standard_json, **kwargs))
else:
# We compile each file and add it to our compilations.
for filename in filenames:
for filename in solidity_filenames:
compilations.append(CryticCompile(filename, **kwargs))

if vyper_filenames:
vyper_standard_json = VyperStandardJson()
vyper_standard_json.add_source_files(vyper_filenames)
compilations.append(CryticCompile(vyper_standard_json, **kwargs))
else:
raise ValueError(f"{str(target)} is not a file or directory.")
raise NotImplementedError()
# TODO split glob into language
# # Attempt to perform glob expansion of target/filename
# globbed_targets = glob.glob(target, recursive=True)
# print(globbed_targets)

# raise ValueError(f"{str(target)} is not a file or directory.")

return compilations
32 changes: 32 additions & 0 deletions crytic_compile/cryticparser/cryticparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,30 @@ def _init_etherscan(parser: ArgumentParser) -> None:
default=DEFAULTS_FLAG_IN_CONFIG["etherscan_api_key"],
)

group_etherscan.add_argument(
"--base-apikey",
help="Basescan API key.",
action="store",
dest="base_api_key",
default=DEFAULTS_FLAG_IN_CONFIG["etherscan_api_key"],
)

group_etherscan.add_argument(
"--gno-apikey",
help="Gnosisscan API key.",
action="store",
dest="gno_api_key",
default=DEFAULTS_FLAG_IN_CONFIG["etherscan_api_key"],
)

group_etherscan.add_argument(
"--polyzk-apikey",
help="zkEVM Polygonscan API key.",
action="store",
dest="polyzk_api_key",
default=DEFAULTS_FLAG_IN_CONFIG["etherscan_api_key"],
)

group_etherscan.add_argument(
"--etherscan-export-directory",
help="Directory in which to save the analyzed contracts.",
Expand Down Expand Up @@ -496,3 +520,11 @@ def _init_foundry(parser: ArgumentParser) -> None:
dest="foundry_out_directory",
default=DEFAULTS_FLAG_IN_CONFIG["foundry_out_directory"],
)

group_foundry.add_argument(
"--foundry-compile-all",
help="Don't skip compiling test and script",
action="store_true",
dest="foundry_compile_all",
default=DEFAULTS_FLAG_IN_CONFIG["foundry_compile_all"],
)
1 change: 1 addition & 0 deletions crytic_compile/cryticparser/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"hardhat_artifacts_directory": None,
"foundry_ignore_compile": False,
"foundry_out_directory": "out",
"foundry_compile_all": False,
"export_dir": "crytic-export",
"compile_libraries": None,
}
Loading