Skip to content

Commit

Permalink
Merge branch 'master' into feat/venom/calloca
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Jan 19, 2025
2 parents 79be32a + c208b95 commit 319ddd4
Show file tree
Hide file tree
Showing 54 changed files with 1,402 additions and 381 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ jobs:
- name: Upload Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: vyper-${{ runner.os }}
path: dist/vyper.*

windows-build:
Expand Down Expand Up @@ -81,8 +82,9 @@ jobs:
./make.cmd freeze
- name: Upload Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: vyper-${{ runner.os }}
path: dist/vyper.*

publish-release-assets:
Expand All @@ -92,14 +94,13 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
path: artifacts/
merge-multiple: true

- name: Upload assets
# fun - artifacts are downloaded into "artifact/".
# TODO: this needs to be tested when upgrading to upload-artifact v4
working-directory: artifacts/artifact
working-directory: artifacts
run: |
set -Eeuxo pipefail
for BIN_NAME in $(ls)
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ jobs:
# docs: documentation
# test: test suite
# lang: language changes
# stdlib: changes to the stdlib
# ux: language changes (UX)
# parser: parser changes
# tool: integration
# ir: (old) IR/codegen changes
# codegen: lowering from vyper AST to codegen
Expand All @@ -43,7 +45,9 @@ jobs:
docs
test
lang
stdlib
ux
parser
tool
ir
codegen
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ jobs:
tests/
- name: Upload Coverage
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
Expand Down Expand Up @@ -215,7 +215,7 @@ jobs:
tests/
- name: Upload Coverage
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ be a bit behind the latest version found in the master branch of this repository

```bash
make dev-init
python setup.py test
./quicktest.sh -m "not fuzzing"
```

## Developing (working on the compiler)
Expand Down
23 changes: 20 additions & 3 deletions docs/compiling-a-contract.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Online Compilers
Try VyperLang!
-----------------

`Try VyperLang! <https://try.vyperlang.org>`_ is a JupterHub instance hosted by the Vyper team as a sandbox for developing and testing contracts in Vyper. It requires github for login, and supports deployment via the browser.
`Try VyperLang! <https://try.vyperlang.org>`_ is a JupyterHub instance hosted by the Vyper team as a sandbox for developing and testing contracts in Vyper. It requires github for login, and supports deployment via the browser.

Remix IDE
---------
Expand Down Expand Up @@ -203,7 +203,7 @@ The following is a list of supported EVM versions, and changes in the compiler i
Integrity Hash
==============

To help tooling detect whether two builds are the same, Vyper provides the ``-f integrity`` output, which outputs the integrity hash of a contract. The integrity hash is recursively defined as the sha256 of the source code with the integrity hashes of its dependencies (imports).
To help tooling detect whether two builds are the same, Vyper provides the ``-f integrity`` output, which outputs the integrity hash of a contract. The integrity hash is recursively defined as the sha256 of the source code with the integrity hashes of its dependencies (imports) and storage layout overrides (if provided).

.. _vyper-archives:

Expand All @@ -219,15 +219,17 @@ A Vyper archive is a compileable bundle of input sources and settings. Technical
├── compilation_targets
├── compiler_version
├── integrity
├── settings.json
├── searchpaths
└── settings.json
└── storage_layout.json [OPTIONAL]

* ``cli_settings.txt`` is a text representation of the settings that were used on the compilation run that generated this archive.
* ``compilation_targets`` is a newline separated list of compilation targets. Currently only one compilation is supported
* ``compiler_version`` is a text representation of the compiler version used to generate this archive
* ``integrity`` is the :ref:`integrity hash <integrity-hash>` of the input contract
* ``searchpaths`` is a newline-separated list of the search paths used on this compilation run
* ``settings.json`` is a json representation of the settings used on this compilation run. It is 1:1 with ``cli_settings.txt``, but both are provided as they are convenient for different workflows (typically, manually vs automated).
* ``storage_layout.json`` is a json representation of the storage layout overrides to be used on this compilation run. It is optional.

A Vyper archive file can be produced by requesting the ``-f archive`` output format. The compiler can also produce the archive in base64 encoded form using the ``--base64`` flag. The Vyper compiler can accept both ``.vyz`` and base64-encoded Vyper archives directly as input.

Expand Down Expand Up @@ -281,6 +283,14 @@ The following example describes the expected input format of ``vyper-json``. (Co
}
},
// Optional
// Storage layout overrides for the contracts that are compiled
"storage_layout_overrides": {
"contracts/foo.vy": {
"a": {"type": "uint256", "slot": 1, "n_slots": 1},
"b": {"type": "uint256", "slot": 0, "n_slots": 1},
}
},
// Optional
"settings": {
"evmVersion": "cancun", // EVM version to compile for. Can be london, paris, shanghai or cancun (default).
// optional, optimization mode
Expand Down Expand Up @@ -364,6 +374,13 @@ The following example describes the output format of ``vyper-json``. Comments ar
"formattedMessage": "line 5:11 Unsupported type conversion: int128 to bool"
}
],
// Optional: not present if there are no storage layout overrides
"storage_layout_overrides": {
"contracts/foo.vy": {
"a": {"type": "uint256", "slot": 1, "n_slots": 1},
"b": {"type": "uint256", "slot": 0, "n_slots": 1},
}
},
// This contains the file-level outputs. Can be limited/filtered by the outputSelection settings.
"sources": {
"source_file.vy": {
Expand Down
24 changes: 22 additions & 2 deletions docs/control-structures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ External functions (marked with the ``@external`` decorator) are a part of the c
A Vyper contract cannot call directly between two external functions. If you must do this, you can use an :ref:`interface <interfaces>`.

.. note::
For external functions with default arguments like ``def my_function(x: uint256, b: uint256 = 1)`` the Vyper compiler will generate ``N+1`` overloaded function selectors based on ``N`` default arguments.
For external functions with default arguments like ``def my_function(x: uint256, b: uint256 = 1)`` the Vyper compiler will generate ``N+1`` overloaded function selectors based on ``N`` default arguments. Consequently, the ABI signature for a function (this includes interface functions) excludes optional arguments when their default values are used in the function call.

.. code-block:: vyper
from ethereum.ercs import IERC4626
@external
def foo(x: IERC4626):
extcall x.withdraw(0, self, self) # keccak256("withdraw(uint256,address,address)")[:4] = 0xb460af94
extcall x.withdraw(0) # keccak256("withdraw(uint256)")[:4] = 0x2e1a7d4d
.. _structure-functions-internal:

Expand All @@ -75,6 +84,14 @@ Or for internal functions which are defined in :ref:`imported modules <modules>`
def calculate(amount: uint256) -> uint256:
return calculator_library._times_two(amount)
Marking an internal function as ``payable`` specifies that the function can interact with ``msg.value``. A ``nonpayable`` internal function can be called from an external ``payable`` function, but it cannot access ``msg.value``.

.. code-block:: vyper
@payable
def _foo() -> uint256:
return msg.value % 2
.. note::
As of v0.4.0, the ``@internal`` decorator is optional. That is, functions with no visibility decorator default to being ``internal``.

Expand Down Expand Up @@ -110,7 +127,7 @@ You can optionally declare a function's mutability by using a :ref:`decorator <f
* ``@pure``: does not read from the contract state or any environment variables.
* ``@view``: may read from the contract state, but does not alter it.
* ``@nonpayable`` (default): may read from and write to the contract state, but cannot receive Ether.
* ``@payable``: may read from and write to the contract state, and can receive Ether.
* ``@payable``: may read from and write to the contract state, and can receive and access Ether via ``msg.value``.

.. code-block:: vyper
Expand All @@ -132,6 +149,9 @@ Functions marked with ``@view`` cannot call mutable (``payable`` or ``nonpayable

Functions marked with ``@pure`` cannot call non-``pure`` functions.

.. note::
The ``@nonpayable`` decorator is not strictly enforced on ``internal`` functions when they are invoked through an ``external`` ``payable`` function. As a result, an ``external`` ``payable`` function can invoke an ``internal`` ``nonpayable`` function. However, the ``nonpayable`` ``internal`` function cannot have access to ``msg.value``.

Re-entrancy Locks
-----------------

Expand Down
4 changes: 4 additions & 0 deletions docs/interfaces.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ This imports the defined interface from the vyper file at ``an_interface.vyi`` (

Prior to v0.4.0, ``implements`` required that events defined in an interface were re-defined in the "implementing" contract. As of v0.4.0, this is no longer required because events can be used just by importing them. Any events used in a contract will automatically be exported in the ABI output.

.. note::

An interface function with default parameters (e.g. ``deposit(assets: uint256, receiver: address = msg.sender)``) implies that the contract being interfaced with supports these default arguments via the ABI-encoded function signatures (e.g. ``keccak256("deposit(uint256,address)")[:4]`` and ``keccak256("deposit(uint256)")[:4]``). It is the responsibility of the callee to implement the behavior associated with these defaults.

Standalone Interfaces
=====================

Expand Down
11 changes: 10 additions & 1 deletion quicktest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

# examples:
# ./quicktest.sh
# ./quicktest.sh -m "not fuzzing"
# ./quicktest.sh -m "not fuzzing" -n<cpu cores - 2> (this is the most useful)
# ./quicktest.sh -m "not fuzzing" -n0
# ./quicktest.sh tests/.../mytest.py

# run pytest but bail out on first error
# useful for dev workflow
# useful for dev workflow.

pytest -q -s --instafail -x --disable-warnings "$@"

# useful options include:
# -n0 (uses only one core but faster startup)
# -nauto (uses only one core but faster startup)
# -m "not fuzzing" - skip slow/fuzzing tests
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ def _global_version(version):
"importlib-metadata",
"wheel",
],
setup_requires=["pytest-runner", "setuptools_scm>=7.1.0,<8.0.0"],
tests_require=extras_require["test"],
setup_requires=["setuptools_scm>=7.1.0,<8.0.0"],
extras_require=extras_require,
entry_points={
"console_scripts": [
Expand Down
25 changes: 25 additions & 0 deletions tests/ast_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from vyper.ast.nodes import VyperNode


def deepequals(node: VyperNode, other: VyperNode):
# checks two nodes are recursively equal, ignoring metadata
# like line info.
if not isinstance(other, type(node)):
return False

if isinstance(node, list):
if len(node) != len(other):
return False
return all(deepequals(a, b) for a, b in zip(node, other))

if not isinstance(node, VyperNode):
return node == other

if getattr(node, "node_id", None) != getattr(other, "node_id", None):
return False
for field_name in (i for i in node.get_fields() if i not in VyperNode.__slots__):
lhs = getattr(node, field_name, None)
rhs = getattr(other, field_name, None)
if not deepequals(lhs, rhs):
return False
return True
105 changes: 105 additions & 0 deletions tests/functional/codegen/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,3 +876,108 @@ def bar() -> uint256:
input_bundle = make_input_bundle({"lib1.vy": lib1})
c = get_contract(main, input_bundle=input_bundle)
assert c.bar() == 1


def test_interface_with_flags():
code = """
struct MyStruct:
a: address
flag Foo:
BOO
MOO
POO
event Transfer:
sender: indexed(address)
@external
def bar():
pass
flag BAR:
BIZ
BAZ
BOO
@external
@view
def foo(s: MyStruct) -> MyStruct:
return s
"""

out = compile_code(code, contract_path="code.vy", output_formats=["interface"])["interface"]

assert "# Flags" in out
assert "flag Foo:" in out
assert "flag BAR" in out
assert "BOO" in out
assert "MOO" in out

compile_code(out, contract_path="code.vyi", output_formats=["interface"])


vyi_filenames = [
"test__test.vyi",
"test__t.vyi",
"t__test.vyi",
"t__t.vyi",
"t_t.vyi",
"test_test.vyi",
"t_test.vyi",
"test_t.vyi",
"_test_t__t_tt_.vyi",
"foo_bar_baz.vyi",
]


@pytest.mark.parametrize("vyi_filename", vyi_filenames)
def test_external_interface_names(vyi_filename):
code = """
@external
def foo():
...
"""

compile_code(code, contract_path=vyi_filename, output_formats=["external_interface"])


def test_external_interface_with_flag():
code = """
flag Foo:
Blah
@external
def foo() -> Foo:
...
"""

out = compile_code(code, contract_path="test__test.vyi", output_formats=["external_interface"])[
"external_interface"
]
assert "-> Foo:" in out


def test_external_interface_compiles_again():
code = """
@external
def foo() -> uint256:
...
@external
def bar(a:int32) -> uint256:
...
"""

out = compile_code(code, contract_path="test.vyi", output_formats=["external_interface"])[
"external_interface"
]
compile_code(out, contract_path="test.vyi", output_formats=["external_interface"])


@pytest.mark.xfail
def test_weird_interface_name():
# based on comment https://github.com/vyperlang/vyper/pull/4290#discussion_r1884137428
# we replace "_" for "" which results in an interface without name
out = compile_code("", contract_path="_.vyi", output_formats=["external_interface"])[
"external_interface"
]
assert "interface _:" in out
Loading

0 comments on commit 319ddd4

Please sign in to comment.