Skip to content

Commit

Permalink
Merge branch 'master' into feat/venom/inliner
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Oct 28, 2024
2 parents 8e71219 + 658f0c4 commit 20a70c0
Show file tree
Hide file tree
Showing 99 changed files with 1,772 additions and 924 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
name: Bug Report
about: Any general feedback or bug reports about the Vyper Compiler. No new features proposals.
labels: ["needs triage"]
---

### Version Information
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/vip.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
name: Vyper Improvement Proposal (VIP)
about: This is the suggested template for new VIPs.
labels: ["needs triage"]
---
## Simple Summary
"If you can't explain it simply, you don't understand it well enough." Provide a simplified and layman-accessible explanation of the VIP.
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ jobs:
# need to fetch unshallow so that setuptools_scm can infer the version
fetch-depth: 0

# debug
- name: Git shorthash
run: git rev-parse --short HEAD

- name: Python
uses: actions/setup-python@v5
with:
Expand Down Expand Up @@ -60,6 +64,10 @@ jobs:
# need to fetch unshallow so that setuptools_scm can infer the version
fetch-depth: 0

# debug
- name: Git shorthash
run: git rev-parse --short HEAD

- name: Python
uses: actions/setup-python@v5
with:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/release-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
# fetch unshallow so commit hash matches github release.
# see https://github.com/vyperlang/vyper/blob/8f9a8cac49aafb3fbc9dde78f0f6125c390c32f0/.github/workflows/build.yml#L27-L32
fetch-depth: 0

# debug
- name: Git shorthash
run: git rev-parse --short HEAD

- name: Python
uses: actions/setup-python@v5
Expand Down
75 changes: 55 additions & 20 deletions docs/installing-vyper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,55 @@ any errors.

.. note::

The easiest way to experiment with the language is to use the `Remix online compiler <https://remix.ethereum.org>`_.
(Activate the vyper-remix plugin in the Plugin manager.)
The easiest way to experiment with the language is to use either `Try Vyper! <https://try.vyperlang.org>`_ (maintained by the Vyper team) or the `Remix online compiler <https://remix.ethereum.org>`_ (maintained by the Ethereum Foundation).
- To use Try Vyper, go to https://try.vyperlang.org and log in (requires Github login).
- To use remix, go to https://remix.ethereum.org and activate the vyper-remix plugin in the Plugin manager.

Docker
******

Vyper can be downloaded as docker image from `dockerhub <https://hub.docker.com/r/vyperlang/vyper/tags?page=1&ordering=last_updated>`_:
::
Standalone
**********

docker pull vyperlang/vyper
The Vyper CLI can be installed with any ``pip`` compatible tool, for example, ``pipx`` or ``uv tool``. If you do not have ``pipx`` or ``uv`` installed, first, go to the respective tool's installation page:

To run the compiler use the ``docker run`` command:
::
- https://github.com/pypa/pipx?tab=readme-ov-file
- https://github.com/astral-sh/uv?tab=readme-ov-file#uv

docker run -v $(pwd):/code vyperlang/vyper /code/<contract_file.vy>
Then, the command to install Vyper would be

Alternatively you can log into the docker image and execute vyper on the prompt.
::

docker run -v $(pwd):/code/ -it --entrypoint /bin/bash vyperlang/vyper
root@d35252d1fb1b:/code# vyper <contract_file.vy>
pipx install vyper

Or,

The normal parameters are also supported, for example:
::

docker run -v $(pwd):/code vyperlang/vyper -f abi /code/<contract_file.vy>
[{'name': 'test1', 'outputs': [], 'inputs': [{'type': 'uint256', 'name': 'a'}, {'type': 'bytes', 'name': 'b'}], 'constant': False, 'payable': False, 'type': 'function', 'gas': 441}, {'name': 'test2', 'outputs': [], 'inputs': [{'type': 'uint256', 'name': 'a'}], 'constant': False, 'payable': False, 'type': 'function', 'gas': 316}]
uv tool install vyper

.. note::

If you would like to know how to install Docker, please follow their `documentation <https://docs.docker.com/get-docker/>`_.
Binaries
********

Alternatively, prebuilt Vyper binaries for Windows, Mac and Linux are available for download from the GitHub releases page: https://github.com/vyperlang/vyper/releases.


PIP
***

Installing Python
=================

Vyper can only be built using Python 3.6 and higher. If you need to know how to install the correct version of python,
Vyper can only be built using Python 3.10 and higher. If you need to know how to install the correct version of python,
follow the instructions from the official `Python website <https://wiki.python.org/moin/BeginnersGuide/Download>`_.

Creating a virtual environment
==============================

Because pip installations are not isolated by default, this method of
installation is meant for more experienced Python developers who are using
Vyper as a library, or want to use it within a Python project with other
pip dependencies.

It is **strongly recommended** to install Vyper in **a virtual Python
environment**, so that new packages installed and dependencies built are
strictly contained in your Vyper project and will not alter or affect your
Expand All @@ -76,13 +81,43 @@ Each tagged version of vyper is uploaded to `pypi <https://pypi.org/project/vype
To install a specific version use:
::

pip install vyper==0.3.7
pip install vyper==0.4.0

You can check if Vyper is installed completely or not by typing the following in your terminal/cmd:
::

vyper --version


Docker
******

Vyper can be downloaded as docker image from `dockerhub <https://hub.docker.com/r/vyperlang/vyper/tags?page=1&ordering=last_updated>`_:
::

docker pull vyperlang/vyper

To run the compiler use the ``docker run`` command:
::

docker run -v $(pwd):/code vyperlang/vyper /code/<contract_file.vy>

Alternatively you can log into the docker image and execute vyper on the prompt.
::

docker run -v $(pwd):/code/ -it --entrypoint /bin/bash vyperlang/vyper
root@d35252d1fb1b:/code# vyper <contract_file.vy>

The normal parameters are also supported, for example:
::

docker run -v $(pwd):/code vyperlang/vyper -f abi /code/<contract_file.vy>
[{'name': 'test1', 'outputs': [], 'inputs': [{'type': 'uint256', 'name': 'a'}, {'type': 'bytes', 'name': 'b'}], 'constant': False, 'payable': False, 'type': 'function', 'gas': 441}, {'name': 'test2', 'outputs': [], 'inputs': [{'type': 'uint256', 'name': 'a'}], 'constant': False, 'payable': False, 'type': 'function', 'gas': 316}]

.. note::

If you would like to know how to install Docker, please follow their `documentation <https://docs.docker.com/get-docker/>`_.

nix
***

Expand Down
3 changes: 2 additions & 1 deletion docs/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,12 @@ A byte array with a max size.
The syntax being ``Bytes[maxLen]``, where ``maxLen`` is an integer which denotes the maximum number of bytes.
On the ABI level the Fixed-size bytes array is annotated as ``bytes``.

Bytes literals may be given as bytes strings.
Bytes literals may be given as bytes strings or as hex strings.

.. code-block:: vyper
bytes_string: Bytes[100] = b"\x01"
bytes_string: Bytes[100] = x"01"
.. index:: !string

Expand Down
8 changes: 1 addition & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from tests.utils import working_directory
from vyper import compiler
from vyper.codegen.ir_node import IRnode
from vyper.compiler.input_bundle import FilesystemInputBundle, InputBundle
from vyper.compiler.input_bundle import FilesystemInputBundle
from vyper.compiler.settings import OptimizationLevel, Settings, set_global_settings
from vyper.exceptions import EvmVersionException
from vyper.ir import compile_ir, optimizer
Expand Down Expand Up @@ -166,12 +166,6 @@ def fn(sources_dict):
return fn


# for tests which just need an input bundle, doesn't matter what it is
@pytest.fixture
def dummy_input_bundle():
return InputBundle([])


@pytest.fixture(scope="module")
def gas_limit():
# set absurdly high gas limit so that london basefee never adjusts
Expand Down
10 changes: 5 additions & 5 deletions tests/functional/builtins/codegen/test_empty.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,11 +672,11 @@ def test_empty_array_in_event_logging(get_contract, get_logs):
@external
def foo():
log MyLog(
b'hellohellohellohellohellohellohellohellohello',
empty(int128[2][3]),
314159,
b'helphelphelphelphelphelphelphelphelphelphelp',
empty(uint256[3])
arg1=b'hellohellohellohellohellohellohellohellohello',
arg2=empty(int128[2][3]),
arg3=314159,
arg4=b'helphelphelphelphelphelphelphelphelphelphelp',
arg5=empty(uint256[3])
)
"""

Expand Down
18 changes: 16 additions & 2 deletions tests/functional/builtins/codegen/test_raw_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ def __default__():
assert env.message_call(caller.address, data=sig) == b""


def _strip_initcode_suffix(bytecode):
bs = bytes.fromhex(bytecode.removeprefix("0x"))
to_strip = int.from_bytes(bs[-2:], "big")
return bs[:-to_strip].hex()


# check max_outsize=0 does same thing as not setting max_outsize.
# compile to bytecode and compare bytecode directly.
def test_max_outsize_0():
Expand All @@ -276,7 +282,11 @@ def test_raw_call(_target: address):
"""
output1 = compile_code(code1, output_formats=["bytecode", "bytecode_runtime"])
output2 = compile_code(code2, output_formats=["bytecode", "bytecode_runtime"])
assert output1 == output2
assert output1["bytecode_runtime"] == output2["bytecode_runtime"]

bytecode1 = output1["bytecode"]
bytecode2 = output2["bytecode"]
assert _strip_initcode_suffix(bytecode1) == _strip_initcode_suffix(bytecode2)


# check max_outsize=0 does same thing as not setting max_outsize,
Expand All @@ -298,7 +308,11 @@ def test_raw_call(_target: address) -> bool:
"""
output1 = compile_code(code1, output_formats=["bytecode", "bytecode_runtime"])
output2 = compile_code(code2, output_formats=["bytecode", "bytecode_runtime"])
assert output1 == output2
assert output1["bytecode_runtime"] == output2["bytecode_runtime"]

bytecode1 = output1["bytecode"]
bytecode2 = output2["bytecode"]
assert _strip_initcode_suffix(bytecode1) == _strip_initcode_suffix(bytecode2)


# test functionality of max_outsize=0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_basic_default(env, get_logs, get_contract):
@external
@payable
def __default__():
log Sent(msg.sender)
log Sent(sender=msg.sender)
"""
c = get_contract(code)
env.set_balance(env.deployer, 10**18)
Expand All @@ -46,13 +46,13 @@ def test_basic_default_default_param_function(env, get_logs, get_contract):
@external
@payable
def fooBar(a: int128 = 12345) -> int128:
log Sent(empty(address))
log Sent(sender=empty(address))
return a
@external
@payable
def __default__():
log Sent(msg.sender)
log Sent(sender=msg.sender)
"""
c = get_contract(code)
env.set_balance(env.deployer, 10**18)
Expand All @@ -69,7 +69,7 @@ def test_basic_default_not_payable(env, tx_failed, get_contract):
@external
def __default__():
log Sent(msg.sender)
log Sent(sender=msg.sender)
"""
c = get_contract(code)
env.set_balance(env.deployer, 10**17)
Expand Down Expand Up @@ -103,7 +103,7 @@ def test_always_public_2(assert_compile_failed, get_contract):
sender: indexed(address)
def __default__():
log Sent(msg.sender)
log Sent(sender=msg.sender)
"""
assert_compile_failed(lambda: get_contract(code))

Expand All @@ -119,12 +119,12 @@ def test_zero_method_id(env, get_logs, get_contract, tx_failed):
@payable
# function selector: 0x00000000
def blockHashAskewLimitary(v: uint256) -> uint256:
log Sent(2)
log Sent(sig=2)
return 7
@external
def __default__():
log Sent(1)
log Sent(sig=1)
"""
c = get_contract(code)

Expand Down Expand Up @@ -165,12 +165,12 @@ def test_another_zero_method_id(env, get_logs, get_contract, tx_failed):
@payable
# function selector: 0x00000000
def wycpnbqcyf() -> uint256:
log Sent(2)
log Sent(sig=2)
return 7
@external
def __default__():
log Sent(1)
log Sent(sig=1)
"""
c = get_contract(code)

Expand Down Expand Up @@ -205,12 +205,12 @@ def test_partial_selector_match_trailing_zeroes(env, get_logs, get_contract):
@payable
# function selector: 0xd88e0b00
def fow() -> uint256:
log Sent(2)
log Sent(sig=2)
return 7
@external
def __default__():
log Sent(1)
log Sent(sig=1)
"""
c = get_contract(code)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def i_am_me() -> bool:
@external
@nonpayable
def whoami() -> address:
log Addr(self._whoami())
log Addr(addr=self._whoami())
return self._whoami()
"""

Expand Down
4 changes: 2 additions & 2 deletions tests/functional/codegen/features/test_clampers.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def foo(b: int128[6][1][2]) -> int128[6][1][2]:

c = get_contract(code)
with tx_failed():
_make_tx(env, c.address, "foo(int128[6][1][2]])", values)
_make_tx(env, c.address, "foo(int128[6][1][2])", values)


@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)])
Expand All @@ -453,7 +453,7 @@ def test_int128_dynarray_clamper_failing(env, tx_failed, get_contract, bad_value
# ensure the invalid value is detected at all locations in the array
code = """
@external
def foo(b: int128[5]) -> int128[5]:
def foo(b: DynArray[int128, 5]) -> DynArray[int128, 5]:
return b
"""

Expand Down
Loading

0 comments on commit 20a70c0

Please sign in to comment.