Giter Site home page Giter Site logo

apeworx / ape-solidity Goto Github PK

View Code? Open in Web Editor NEW
15.0 5.0 24.0 442 KB

Solidity compiler plugin for the Ape Framework

Home Page: https://www.apeworx.io/

License: Apache License 2.0

Python 85.92% Solidity 13.91% Vyper 0.16%
python ethereum solidity smart-contracts solidity-compiler apeworx ape

ape-solidity's Issues

Feat Request: Allow specifying version in config

Sometimes, it would be nice to have manual control of the compiler version(s) used.

Perhaps it can be a list to allow more than one version since the compiler is pretty good at multi-version now.

Otherwise, just specifying the version is a bit of an optimization for many projects.

Conflicting licenses found preventing flattening contract

Environment information

  • ape and plugin versions:
  • Ape: 0.7.14
    • alchemy 0.7.1
    • etherscan 0.7.2
    • hardhat 0.7.2
    • infura 0.7.2
    • solidity 0.7.1
  • Python Version: 3.10.12
  • OS: macOS

What went wrong?

CompilerError preventing from getting a flattened contract.

# If we have more than one unique license identifier, raise an error.
if len(unique_license_identifiers) > 1:
raise CompilerError(f"Conflicting licenses found: {unique_license_identifiers}")

image

How can it be fixed?

Change to a warning.

Support evm-version config

Overview

Allow specifying the evmVersion

Specification

solidity:
  evm_version: <fork-name>
  • Include in get_compiler_settings() under key evmVersion
  • Include in compiler call solc.compile_file()call as kwargevm_version`

Dependencies

Include links to any open issues that must be resolved before this feature can be implemented.

Ape tests failing due to "invalid opcode 0x5f" [APE-942]

Environment information

  • ape and plugin versions:
$ ape --version
0.6.8

$ ape plugins list
Installed Plugins:
  solidity    0.6.3
  • Python Version: 3.8
  • OS: macOS

What went wrong?

Running into the following issues running tests for our project that uses ape. The ape config file specifies solidity version 0.8.17. The test suite was previously passing but is now failing without code changes:

The failures manifest as:
With Invalid opcode 0x5f for a variety of tests

/home/runner/work/nucypher-contracts/nucypher-contracts/tests/test_subscription_manager.py:12: in proxy_admin
    return accounts[0].deploy(dependency.ProxyAdmin)
E   ape.exceptions.ContractLogicError: Invalid opcode 0x5f @ 31

You can view more error logs here - https://github.com/nucypher/nucypher-contracts/pull/80/checks

Please include information like:

How can it be fixed?

Fill this in if you have ideas on how the bug could be fixed.

Could be the incorrect version of solidity, 0.8.20 being used even though 0.8.17 is specified (?)

From ApeWorX Discord:

fubuloubu — Today at 2:02 PM

It's using 0.8.20 by accident. What is your config file saying? We might have a bug if you're pinning a specific version and it is not recognizing it

derek — Today at 2:02 PM
solidity:
  version: 0.8.17
  import_remapping:
    - "@openzeppelin/contracts=openzeppelin/v4.8.1"
    - "@openzeppelin-upgradeable/contracts=openzeppelin-upgradeable/v4.8.1"
    
fubuloubu — Today at 2:03 PM
Yup, that's a bug then, it should be pinning to the specific version you state. Can you open an issue in ape-solidity and we can get that fixed?

default evm version to paris [APE-1269]

What went wrong?

push0 rollout went bad, with many networks not supporting the latest evm version yet, possibly resulting in potentially broken deploys.

How can it be fixed?

instead of latest (shanghai), it would be better to default to paris unless explicitly overriden by a user who knows what they are doing.

Solidity Compiler Not Installed When Running Tests

Environment information

  • OS: macOS 10.14.6
  • Python Version: 3.9.13
  • ape and plugin versions:
$ ape --version
0.3.5.dev1+gcf0ee464

$ ape plugins list
Installed Plugins:
  template    0.3.0
  solidity    0.3.1
  alchemy     0.3.0
  vyper       0.3.0
  • Contents of your ape-config.yaml (NOTE: do not post anything private like RPC urls or secrets!):
$ cat ape-config.yaml
plugins:
  - name: solidity

What went wrong?

Running tests without any changes errors if the relevant solc versions are not installed for the contracts attempting to be compiled by the tests

How can it be fixed?

Looks like it's a false-positive issue when checking if a version of solc is installed, compiler.py:411 likely

bug: unable to import local sol files

(brownie) sabotage@sabotage:~/ape$ brownie bake token
Brownie v1.15.1 - Python development framework for Ethereum

Downloading from https://github.com/brownie-mix/token-mix/archive/master.zip...
9.13kiB [00:00, 3.69MiB/s]
SUCCESS: Brownie mix 'token' has been initiated at /home/sabotage/ape/token
(brownie) sabotage@sabotage:~/ape$ pyenv deactivate
sabotage@sabotage:~/ape$ pyenv activate apeworx
pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
(apeworx) sabotage@sabotage:~/ape$ cd token/
(apeworx) sabotage@sabotage:~/ape/token$ ape compile
INFO: Compiling 'contracts/Token.sol'
INFO: Compiling 'contracts/SafeMath.sol'
Traceback (most recent call last):
  File "/home/sabotage/.pyenv/versions/apeworx/bin/ape", line 8, in <module>
    sys.exit(cli())
  File "/home/sabotage/.pyenv/versions/3.8.10/envs/apeworx/lib/python3.8/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/home/sabotage/.pyenv/versions/3.8.10/envs/apeworx/lib/python3.8/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/home/sabotage/.pyenv/versions/3.8.10/envs/apeworx/lib/python3.8/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/sabotage/.pyenv/versions/3.8.10/envs/apeworx/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/sabotage/.pyenv/versions/3.8.10/envs/apeworx/lib/python3.8/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/home/sabotage/.pyenv/versions/3.8.10/envs/apeworx/lib/python3.8/site-packages/ape_compile/_cli.py", line 75, in cli
    contract_types = project.load_contracts(use_cache)
  File "/home/sabotage/.pyenv/versions/3.8.10/envs/apeworx/lib/python3.8/site-packages/ape/managers/project.py", line 117, in load_contracts
    contract_types.update(self.compilers.compile(list(needs_compiling)))
  File "/home/sabotage/.pyenv/versions/3.8.10/envs/apeworx/lib/python3.8/site-packages/ape/managers/compilers.py", line 49, in compile
    for contract_type in self.registered_compilers[extension].compile(paths_to_compile):
  File "/home/sabotage/ape/ape-solidity/ape_solidity/compiler.py", line 77, in compile
    for result in solcx.compile_source(
  File "/home/sabotage/.pyenv/versions/3.8.10/envs/apeworx/lib/python3.8/site-packages/solcx/main.py", line 112, in compile_source
    return _compile_combined_json(
  File "/home/sabotage/.pyenv/versions/3.8.10/envs/apeworx/lib/python3.8/site-packages/solcx/main.py", line 288, in _compile_combined_json
    stdoutdata, stderrdata, command, proc = wrapper.solc_wrapper(
  File "/home/sabotage/.pyenv/versions/3.8.10/envs/apeworx/lib/python3.8/site-packages/solcx/wrapper.py", line 158, in solc_wrapper
    raise SolcError(
solcx.exceptions.SolcError: An error occurred during execution
> command: `/home/sabotage/.solcx/solc-v0.6.12 --combined-json abi,bin,bin-runtime,devdoc,userdoc -`
> return code: `1`
> stdout:

> stderr:
Error: Source "SafeMath.sol" not found: File not found.
 --> <stdin>:5:1:
  |
5 | import "./SafeMath.sol";
  | ^^^^^^^^^^^^^^^^^^^^^^^^

Attempting to compile Solidity contracts without Solidity installed yields unclear error

Environment information

  • OS: macOS 10.14.6
  • Python Version: 3.9.13
  • ape and plugin versions:
$ ape --version
0.3.5.dev1+gcf0ee464

$ ape plugins list
Installed Plugins:
  template    0.3.0
  solidity    0.3.1
  alchemy     0.3.0
  vyper       0.3.0
  • Contents of your ape-config.yaml (NOTE: do not post anything private like RPC urls or secrets!):
$ cat ape-config.yaml
plugins:
  - name: solidity

What went wrong?

This came about while I was playing around with setting up a template project.
My steps were basically this:

  1. Setup virtual env, Install Ape, plugins listed above, etc.
  2. Generate template from the ERC20 template
  3. Replace the Vyper contract with any basic Solidity one, but leave off the pragma solidity <version> so the contract is not specifying a version
  4. Attempt to compile the project, and ape-solidity will actually skip the steps of auto-installing any compiler version. Once it gets to get_best_version() it will fail due to the call to max() with an empty list

Version is skipped early due to pragma_spec is None

def _get_pragma_spec(path: Path) -> Optional[NpmSpec]:
pragma_spec = get_pragma_spec(path)
if not pragma_spec:
return None
# Check if we need to install specified compiler version
if pragma_spec is pragma_spec.select(self.installed_versions):
return pragma_spec
solc_version = pragma_spec.select(self.available_versions)
if solc_version:
solcx.install_solc(solc_version, show_progress=False)
else:
raise CompilerError(
f"Solidity version specification '{pragma_spec}' could not be met."
)
return pragma_spec

No pragma specs falls back on max installed version, but no versions were ever installed:

def get_best_version(path: Path) -> Version:
pragma_spec = source_by_pragma_spec[path]
return (
pragma_spec.select(self.installed_versions)
if pragma_spec
else max(self.installed_versions)
)

The resulting error is a ValueError: max() arg is an empty sequence which isn't super cryptic, but doesn't really describe the underlying issue:

INFO: Compiling 'Token.sol'.
Traceback (most recent call last):
  File "../.venv/ape/bin/ape", line 33, in <module>
    sys.exit(load_entry_point('eth-ape', 'console_scripts', 'ape')())
  File "../.venv/ape/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "../.venv/ape/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "../Documents/Code/Python/ape/src/ape/_cli.py", line 40, in invoke
    return super().invoke(ctx)
  File "../.venv/ape/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "../.venv/ape/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "../.venv/ape/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "../.venv/ape/lib/python3.9/site-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "../.venv/ape/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "../Documents/Code/Python/ape/src/ape_compile/_cli.py", line 53, in cli
    contract_types = cli_ctx.project_manager.load_contracts(
  File "../Documents/Code/Python/ape/src/ape/managers/project/manager.py", line 422, in load_contracts
    manifest = self._project.create_manifest(file_paths, use_cache=use_cache)
  File "../Documents/Code/Python/ape/src/ape/managers/project/types.py", line 158, in create_manifest
    compiled_contract_types = self.compiler_manager.compile(list(needs_compiling))
  File "../Documents/Code/Python/ape/src/ape/managers/compilers.py", line 98, in compile
    compiled_contracts = self.registered_compilers[extension].compile(
  File "../.venv/ape/lib/python3.9/site-packages/ape_solidity/compiler.py", line 214, in compile
    files_by_solc_version = self.get_version_map(contract_filepaths, base_path=contracts_path)
  File "../.venv/ape/lib/python3.9/site-packages/ape_solidity/compiler.py", line 437, in get_version_map
    solc_version = get_best_version(source_file_path)
  File "../.venv/ape/lib/python3.9/site-packages/ape_solidity/compiler.py", line 431, in get_best_version
    else max(self.installed_versions)
ValueError: max() arg is an empty sequence

How can it be fixed?

During the resolution of the pragma specs / installation of Solidity versions, we will need to check if we have any contracts where a spec has not been defined. If there are any, then we need to ensure that we also install the latest version of Solidity, so that we can rely on it later in get_best_version()

Plugin does not handle multiple solidity versions

Error: Source file requires different compiler version (current compiler is 0.8.12+commit.f00d7308.Darwin.appleclang) - note that nightly builds are considered to be strictly less than the released version
 --> test/ERC20.sol:1:1:
  |
1 | pragma solidity =0.5.16;

Looking at code, it seems like we only using in version in the compile call

Use Clean Solc Installation Path When Running Tests

Currently py-solc-x will utilize the default installation path of ~/.solcx (on *nix) when ape-solidity tests are running.

This means that the tests may run differently based on the running system's current solc installations, and that the user's installed solc versions will be different after the tests have been run.

To rectify this we can use an autouse, session scoped test fixture to set the environment variable specified solcx.install.SOLCX_BINARY_PATH_VARIABLE to a temporary directory. This way the tests will start with a clean slate, and will only install compilers in a temporary directory that won't interfere with the user's installation (or vice versa).

At the end of the test suite the temporary directory can be removed

Customizable solc output [APE-1316]

Currently there is no way to specify which fields in abi is needed. For example when AST added to output files our abi folder size grew 5 times comparing to old one. If we can select which fields do we want in output that would be great. (really mandatory ones can be protected like abi, runtimeBytecode, deploymentBytecode these are really the most important ones.)

Cannot compile wider version pins

ape-config.yaml:

plugins:
    - name: solidity

dependencies:
    - name: v3-core
      github: Uniswap/v3-core
      branch: main

error:

Error: Source file requires different compiler version (current compiler is 0.8.14+commit.80d49f37.Linux.g++) - note that nightly builds are considered to be strictly less than the released version
 --> libraries/FullMath.sol:2:1:
  |
2 | pragma solidity >=0.4.0 <0.8.0;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Allow libraries to be listed in config

Overview

.add_library is great for pre-compile scripts but it'd be nice to have a way to list the libraries in the ape-config.yaml file as well.

Specification

solidity:
  libraries:
    ethereum:
      mainnet:
        MyLibrary: 0x003123012312412541241241242   # pretend is address

And then (not sure about this next part): Have compile() detect if we are connected to a provider and if the network matches anything we have listed in libraries: and if it does, grab those addresses and add the libraries.

Dependencies

Include links to any open issues that must be resolved before this feature can be implemented.

Support `--optimize-runs` flag to allow changing the run during optimization

Overview

Currently, there is no way to configure optimization runs in the plugin.
The runs are included in the published package manifest.
Right now they are always defaulted to 200.

Specification

ape-config.yaml:

solidity:
  optimize_runs: 200

Dependencies

Include links to any open issues that must be resolved before this feature can be implemented.

Issues using Slither on .cache directory

Environment information

Latest ape and plugin

  • Python Version: 3.9.7
  • OS: macOS

What went wrong?

It has been reported that it is challenging to run Slither on the .cache directory from dependencies.

How can it be fixed?

Not sure! We should experiment with Slither and consider integrating with the tool more officially.

Receiving `ValueError: substring not found` while compiling

Any idea on why this error reverted? I've tried to compile that solidity interface in another development framework and didn't receive that kind of issue.

(venv) mbp:truhuis-smart-contracts mac$ ape compile contracts/interfaces/ITruhuisAuction.sol 
INFO: Compiling 'interfaces/ITruhuisAuction.sol'.
Traceback (most recent call last):
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/bin/ape", line 8, in <module>
    sys.exit(cli())
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/ape/_cli.py", line 40, in invoke
    return super().invoke(ctx)
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/ape_compile/_cli.py", line 53, in cli
    contract_types = cli_ctx.project_manager.load_contracts(
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/ape/managers/project/manager.py", line 422, in load_contracts
    manifest = self._project.create_manifest(file_paths, use_cache=use_cache)
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/ape/managers/project/types.py", line 158, in create_manifest
    compiled_contract_types = self.compiler_manager.compile(list(needs_compiling))
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/ape/managers/compilers.py", line 98, in compile
    compiled_contracts = self.registered_compilers[extension].compile(
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/ape_solidity/compiler.py", line 214, in compile
    files_by_solc_version = self.get_version_map(contract_filepaths, base_path=contracts_path)
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/ape_solidity/compiler.py", line 369, in get_version_map
    imports = self.get_imports(get_all_files_in_directory(contracts_path), contracts_path)
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/ape_solidity/compiler.py", line 353, in get_imports
    import_item = import_str_to_source_id(import_str=import_str, source_path=filepath)
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/ape_solidity/compiler.py", line 301, in import_str_to_source_id
    end_index = import_str.index(quote) + 1
ValueError: substring not found

Receiving `UnicodeDecodeError` while compiling

Overview

Receiving the error UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 3131: invalid start byte while compiling solidity smart contracts.

The error occurs evidently from the ape-solidity plugin.

(venv) mbp:truhuis-smart-contracts mac$ ape compile
WARNING: Unprocessed plugin config(s): scripts_folder, tests_folder. Plugins may not be installed yet or keys may be mis-spelled.
WARNING: Unprocessed plugin config(s): scripts_folder, tests_folder. Plugins may not be installed yet or keys may be mis-spelled.
WARNING: Unprocessed plugin config(s): scripts_folder, tests_folder. Plugins may not be installed yet or keys may be mis-spelled.
WARNING: Unprocessed plugin config(s): scripts_folder, tests_folder. Plugins may not be installed yet or keys may be mis-spelled.
INFO: Compiling 'BrownieContract.sol'.
Traceback (most recent call last):
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/bin/ape", line 8, in <module>
    sys.exit(cli())
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/ape/_cli.py", line 40, in invoke
    return super().invoke(ctx)
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/ape_compile/_cli.py", line 53, in cli
    contract_types = cli_ctx.project_manager.load_contracts(
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/ape/managers/project/manager.py", line 422, in load_contracts
    manifest = self._project.create_manifest(file_paths, use_cache=use_cache)
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/ape/managers/project/types.py", line 158, in create_manifest
    compiled_contract_types = self.compiler_manager.compile(list(needs_compiling))
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/ape/managers/compilers.py", line 98, in compile
    compiled_contracts = self.registered_compilers[extension].compile(
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/ape_solidity/compiler.py", line 214, in compile
    files_by_solc_version = self.get_version_map(contract_filepaths, base_path=contracts_path)
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/ape_solidity/compiler.py", line 369, in get_version_map
    imports = self.get_imports(get_all_files_in_directory(contracts_path), contracts_path)
  File "/Users/mac/P_D_V/projects-current/truhuis/tmp/truhuis-smart-contracts/venv/lib/python3.10/site-packages/ape_solidity/compiler.py", line 334, in get_imports
    source_lines = filepath.read_text().splitlines()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/pathlib.py", line 1133, in read_text
    return f.read()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 3131: invalid start byte
(venv) mbp:truhuis-smart-contracts mac$ ls -al

How to solve

In order to escape the error and compile I have to remove .DS_Store file inside of contracts folder each time and after that run ape compile. It would be nice to avoid manually remove that file or to modify the plugin so that the error not occurs.

bug: Ape-solidity is not using compile_files and causing an error when importing

(brownie) sabotage@sabotage:~/ape/token$ docker run --volume $HOME/.ape:/root/ape --volume $HOME/.vvm:/root/.vvm --volume $HOME/.solcx:/root/.solcx --volume $PWD:/root/project --workdir /root/project apeworx/ape ape compile
INFO: Compiling 'contracts/Token.sol'
INFO: Compiling 'contracts/SafeMath.sol'
Traceback (most recent call last):
  File "/usr/local/bin/ape", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/ape_compile/_cli.py", line 75, in cli
    contract_types = project.load_contracts(use_cache)
  File "/usr/local/lib/python3.8/dist-packages/ape/managers/project.py", line 117, in load_contracts
    contract_types.update(self.compilers.compile(list(needs_compiling)))
  File "/usr/local/lib/python3.8/dist-packages/ape/managers/compilers.py", line 49, in compile
    for contract_type in self.registered_compilers[extension].compile(paths_to_compile):
  File "/usr/local/lib/python3.8/dist-packages/ape_solidity/compiler.py", line 77, in compile
    for result in solcx.compile_source(
  File "/usr/local/lib/python3.8/dist-packages/solcx/main.py", line 112, in compile_source
    return _compile_combined_json(
  File "/usr/local/lib/python3.8/dist-packages/solcx/main.py", line 288, in _compile_combined_json
    stdoutdata, stderrdata, command, proc = wrapper.solc_wrapper(
  File "/usr/local/lib/python3.8/dist-packages/solcx/wrapper.py", line 158, in solc_wrapper
    raise SolcError(
solcx.exceptions.SolcError: An error occurred during execution
> command: `/root/.solcx/solc-v0.6.12 --combined-json abi,bin,bin-runtime,devdoc,userdoc -`
> return code: `1`
> stdout:

> stderr:
Error: Source "SafeMath.sol" not found: File not found.
 --> <stdin>:5:1:
  |
5 | import "./SafeMath.sol";
  | ^^^^^^^^^^^^^^^^^^^^^^^^

Originally posted by @sabotagebeats in ApeWorX/ape#127 (comment)

Enable usage of `viaIR` compiler flag for compatible solidity versions [APE-840]

Overview

Provide a simple overview of what you wish to see added. Please include:

  • What you are trying to do
  • Why Ape's current functionality is inadequate to address your goal

As of v0.8.13, the solidity compiler allows code generation through the Yul IR via the --via-ir flag. One noticeable benefit of using this flag is handling stack too deep errors.

Currently, the ape-solidity plugin doesn't have the ability to enable the --via-ir flag, and it would be useful to have the option to do so.

Specification

A simple config file option via_ir would be sufficient.

Recompile when compiler setting changes

Right now, if you compile something once, and then change a compiler setting in your ape-config.yaml (such as optimize), it does not detect that it needs to recompile.

It might be nice to do this somehow.

Contract Flattener [APE-794]

Overview

Would be nice to have a simple way to get the fully flattened contract including all dependencies that can be printed out or exported to a designated file.

Verification post deployment using the etherscan API, especially on non-ethereum chains can cause issues with the verification process when the locally compiled files dont't exactly match what Etherscans compiler expects.

One of the easiest ways to avoid this is to get the flattened source file and deploy through Remix since they use the exact same compiler as etherscan. Being able to easily get the full flattened source would make this process much simpilier.

Specification

A syntax similar to Brownies version or Foundrys command would be sufficient.

Brownie Ex:
Using the Brownie console you could use

ContractContainer.get_verification_info()[
ContractContainer._flattener.flattened_source

Foundry Ex:
from the command line you can enter

forge flatten --output src/Contract.flattened.sol src/Contract.sol

Any variation or something similar would work fine.

Dependencies

Would close out issue ApeWorX/ape#788

Reference to original Brownie issue eth-brownie/brownie#849
Reference to original Brownie implementation eth-brownie/brownie#914

Failed to compile a contract that depends on openzeppelin 2.0.0 with solidity 0.4.26

Environment information

  • ape and plugin versions:
$ ape --version
0.4.3

$ ape plugins list
Installed Plugins:
  solidity    0.4.0
  • Python Version: 3.9.13
  • OS: osx

What went wrong?

Fail to compile a contract:

import "@openzeppelin/token/ERC20/IERC20.sol";

contract Test {}

with ape-config.yaml:

name: test

plugins:
  - name: solidity

dependencies:
  - name: OpenZeppelin
    github: OpenZeppelin/openzeppelin-contracts
    version: 2.0.0
    exclude:
      - package.json    # Ignore package.json files.
      - mocks/**/*      # Ignore all files in the 'mocks' directory

solidity:
  import_remapping:
    - "@openzeppelin=OpenZeppelin/2.0.0"
$ ape -v DEBUG compile
INFO: Compiling 'Test.sol'.
DEBUG: Compiling using Solidity compiler '0.4.26'
Traceback (most recent call last):
  File "/Users/folk/Library/Caches/pypoetry/virtualenvs/lido-withdrawals-ZlTFoF_3-py3.9/bin/ape", line 8, in <module>
    sys.exit(cli())
  File "/Users/folk/Library/Caches/pypoetry/virtualenvs/lido-withdrawals-ZlTFoF_3-py3.9/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/Users/folk/Library/Caches/pypoetry/virtualenvs/lido-withdrawals-ZlTFoF_3-py3.9/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Users/folk/Library/Caches/pypoetry/virtualenvs/lido-withdrawals-ZlTFoF_3-py3.9/lib/python3.9/site-packages/ape/_cli.py", line 40, in invoke
    return super().invoke(ctx)
  File "/Users/folk/Library/Caches/pypoetry/virtualenvs/lido-withdrawals-ZlTFoF_3-py3.9/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/folk/Library/Caches/pypoetry/virtualenvs/lido-withdrawals-ZlTFoF_3-py3.9/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/folk/Library/Caches/pypoetry/virtualenvs/lido-withdrawals-ZlTFoF_3-py3.9/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/folk/Library/Caches/pypoetry/virtualenvs/lido-withdrawals-ZlTFoF_3-py3.9/lib/python3.9/site-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/Users/folk/Library/Caches/pypoetry/virtualenvs/lido-withdrawals-ZlTFoF_3-py3.9/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/folk/Library/Caches/pypoetry/virtualenvs/lido-withdrawals-ZlTFoF_3-py3.9/lib/python3.9/site-packages/ape_compile/_cli.py", line 53, in cli
    contract_types = cli_ctx.project_manager.load_contracts(
  File "/Users/folk/Library/Caches/pypoetry/virtualenvs/lido-withdrawals-ZlTFoF_3-py3.9/lib/python3.9/site-packages/ape/managers/project/manager.py", line 473, in load_contracts
    manifest = self._project.create_manifest(file_paths, use_cache=use_cache)
  File "/Users/folk/Library/Caches/pypoetry/virtualenvs/lido-withdrawals-ZlTFoF_3-py3.9/lib/python3.9/site-packages/ape/managers/project/types.py", line 158, in create_manifest
    compiled_contract_types = self.compiler_manager.compile(list(needs_compiling))
  File "/Users/folk/Library/Caches/pypoetry/virtualenvs/lido-withdrawals-ZlTFoF_3-py3.9/lib/python3.9/site-packages/ape/managers/compilers.py", line 98, in compile
    compiled_contracts = self.registered_compilers[extension].compile(
  File "/Users/folk/Library/Caches/pypoetry/virtualenvs/lido-withdrawals-ZlTFoF_3-py3.9/lib/python3.9/site-packages/ape_solidity/compiler.py", line 243, in compile
    output = solcx.compile_files([f for f in files], **kwargs)
  File "/Users/folk/Library/Caches/pypoetry/virtualenvs/lido-withdrawals-ZlTFoF_3-py3.9/lib/python3.9/site-packages/solcx/main.py", line 216, in compile_files
    return _compile_combined_json(
  File "/Users/folk/Library/Caches/pypoetry/virtualenvs/lido-withdrawals-ZlTFoF_3-py3.9/lib/python3.9/site-packages/solcx/main.py", line 291, in _compile_combined_json
    stdoutdata, stderrdata, command, proc = wrapper.solc_wrapper(
  File "/Users/folk/Library/Caches/pypoetry/virtualenvs/lido-withdrawals-ZlTFoF_3-py3.9/lib/python3.9/site-packages/solcx/wrapper.py", line 158, in solc_wrapper
    raise SolcError(
solcx.exceptions.SolcError: An error occurred during execution
> command: `/Users/folk/.solcx/solc-v0.4.26 /Users/folk/Projects/lido/lido-withdrawals/contracts/.cache/OpenZeppelin/v2.0.0/token/ERC20/IERC20.sol /Users/folk/Projects/lido/lido-withdrawals/contracts/Test.sol @openzeppelin=.cache/OpenZeppelin/v2.0.0 --combined-json abi,bin,bin-runtime,devdoc,userdoc --optimize`
> return code: `1`
> stdout:

> stderr:
/Users/folk/Projects/lido/lido-withdrawals/contracts/Test.sol:5:1: Error: Source ".cache/OpenZeppelin/v2.0.0/token/ERC20/IERC20.sol" not found: File outside of allowed directories.
import "@openzeppelin/token/ERC20/IERC20.sol";
^--------------------------------------------^

How can it be fixed?

Since solc versions before 0.6.9 does not support --base-path, it can't figure out how to find a relative path like .cache/OpenZeppelin/v2.0.0/token/ERC20/IERC20.sol. There is a two theoretically possible ways to fix it:

  • run solc from contracts path, but it will require a modification in solcx package and, according to documentation, can lead to Windows compatibility problems
  • pass an import remappings with an absolute path to dependency like this: @OpenZeppelin=/<path_to_project>/contracts/.cache/OpenZeppelin/v2.0.0

Looks, like we can remove these lines to achieve this, but it can break something else

Output `evm.gasEstimates`

Overview

Output evm.gasEstimates for potential integrations with configuring automatic gas values.

Specification

  • set evm.gasEstimates in output_values list of compiler.
  • trace estimates in .ape/solidity/<contract_name>/gas_estimates.json
  • maybe add method to compiler like estimate_gas_cost(txn)

Dependencies

Include links to any open issues that must be resolved before this feature can be implemented.

Tests don't work out of the box

Environment information

Main branch

What went wrong?

Seems like tests don't run out of the box on main. Lots of Missing sources: errors and packages not installed.

How can it be fixed?

Looks like what needs to happen is npm install in the tests/ dir. Should clean up this devex a bit. At a minimum it should be documented in README. Alternatively, maybe a setuptools post-install command.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.