Skip to content
Permalink
Browse files

Update to master (#6)

* Added get_logs method to return a list of logs with optional filtering; changed get_log fixture to use last entry in get_logs list for specific log name

* WIP overhaul of types

* Draft of viper-by-example.

* fixes voting with delegation example

* use falsey-ness of 0x0000000000000000000000000000000000000000

* use falsey-ness of 0x0000000000000000000000000000000000000000 (reverted from commit 21cc53a)

* use falsey-ness of 0x0000000000000000000000000000000000000000

* iff --> if and only if

* Adds basic for loop for in memory list.

* Adds test for literal list.

* Adds for i in list support from storage and list literals.

* Adds support for i in list of other BaseTypes.

* Add StructureException testcase for iterating over a nested list.

* Allow skip of the event name

* Change function to func

* Changed get_log() to get_last_log(), removed optional log name from usages

* Make corrections according to suggestions.

* Minor typo.

* Adds basic bytes as map keys support.

* Adds support for mapping literal bytes.

* fix the problems when install viper in Ubuntu16.04

* Adds test for long than 32 bytes keys.

* Adds test for mismatched bytes size map assign.

* Adds variable name to i_pos, so it doesn't conflict.

* Adds exceptions for altering lists whilst iterating them.

* Fixe for altering list in iteration exception check.

* Adds tests for assert x in list

* Added reference types.

* Add the packaging metadata to build the viper snap

* Improves ownership test - to be more realistic.

* Modified assert_tx_failed() to remove reference to tester as tester reference inside setup_transaction_tests.py was referencing the same module

* Add 65 and 25 gas to CLAMP and ASSERT pseudo opcodes, based on test_decimals.py

* Various changes to gas estimation.

- Fixes with statement estimation to total all underlying args.
- Adds add_gas parameter to LLLNode to allow more advanced gas calculations to
be assigned to an LLLNode, see make_byte_array_copier as an example.

* Replace get_contract with get_contract_with_gas_estimation.

* Adds test for keys with a very long byte length.

* Removed compound calling, small touchups

* Minor spelling fix

* Remove empty test

* Refactor code parsing

* Fix typo in folder name

* Make pseudo opcode gas estimate a single value.

* Add test for colored gas estimate output when using -f ir.

* Remove tester from assert_tx_failed.

* Move test_company file into proper folder

* Fix constant clamp checks / change constant clamp checks to compile time

* Add fixture to directly test LLL

* Add clamp tests at the LLL level

* Break out `test_parser.py` into test specific files

* Change to assert_tx_failed

* Add staticcall opcode for constant function calls

* Test constant external function calls

* Remove repetitive assert_tx_failed

* Create Viper VIP template

* Add link to VIP template to the issue template

* Improve rlp decoding gas estimation

* Add VIP link to contributing docs

* fix issue ethereum#453

* use clamp constants for literals as well

* fix num_min_literal parsing failure

* fix test coverage

* fix issue ethereum#448: compile_lll.py: buggy translation of LLL operator `sha3_32`

* add sha3_32 compilation test

* Add checks preventing assigning values on defining types.

* Fix gas estimation error

* Fix repeat LLL with <= 0 iteration

* Add test for repat lll

* Add depth check to with "set" statement

* Require function visibility declaration

* Add tests for public decorator

* Add public decorator to tests (ethereum#474)

* Document function visibility requirements

* Clarifies expectation in error message

This would have helped me when I saw this error learning Viper for the first time.

* Note internal or public decorator requirement

* Fixes test with for function visibility.

* Add the install instructions for the Viper snap

This requries ethereum#445, and enabling the continuous delivery on https://build.snapcraft.io

* Allow for gas estimation tests for constants

* Add gas estimation for create_with_code_of

* ad logs to company.v.py with tests

* document event in structure of a contract

* move events before global declarations

* remove unused import

* types.py: Remove duplicated method

Fix ethereum#488

* Adds support -f bytecode_runtime.

* cleans up test_logs

* Use revert opcode for assert statements

* Show lineno of base_type_conversion error

Fix ethereum#498

* Show lineno of undeclared function visibility

Fix ethereum#489

* Adds basic test for bytecode_runtime generation.

* add clamp_nonzero to modulo arithemetic

* Add modulo tests and refactor simple auction example

* Use `with` to decrease repetition

* Change vipercoin from returning false to throwing

* Add check to as_num256 to make sure number is greater than 0

* Improve contributing .rst

- Fixes a link that wasn't displaying correctly.
- Makes some instructions more concise.
- Changes old `:ref:building-from-source`, to link to installation instructions.

* Added testing and deployment doc

* Fix augassignment checks

* Test for in list invalids

* Remove repetitive error and fix typo

* Begin adding built in erc20 external call functionality

* Add implied erc20 token abi fucntionality

* Add on chain market maker example

* Test implied erc20 abi functionality

* Update on chain market maker and erc20 abi

* Change @Internal decorator to @Private decorator.

* Add support for logging a variable of list type.

* Adds tests for logging of list types.

* Fix for log packing on list variable.

* Add error if log has wrong number of arguments

* Add log test and improve bytes as input

* Improve variable naming / fix bytes as input

* Clean up tests

* Adds Fix ethereum#531. Check return type of lists match.

* Adds more tests for logging of lists.

* Adds Fix ethereum#504 for clamping decimal literals correctly.

* Use revert for clamps

* Fix exponents with units

* Create a contract data type

* Remove .python-version, update .gitignore

* Improve vipercoin example: link out to resources describing attack vectors

* Test the contract data type

* Update version of ethereum

* Improves gas estimate on internal call.

* Removed suicide keyword

* Carry over add_gas_estimate in optimizer.

* Adds gas estimation for internal calls.

* Added test for invalid keyword

* not official a language > officially

* Changing notes to be indented blocks starting on the line after .. note:: 

https://sublime-and-sphinx-guide.readthedocs.io/en/latest/notes_warnings.html

* Adds storage list logging support.

* Adds test to check list logging is of correct (sub)type.

* Splitting comments over two lines where necessary to fit on the page on readthedocs

* Update to use conftest; fix some incorrect tests

* Update Safe Remote Purchases: line numbers, minor edits

* Updates from code review

* Add modulo math checks

* Adds support for logging bytes from storage.

* Adds exception to limit to 32 bytes of bytes type logging (restriction for the time being).

* virtualenv -p /usr/local/lib/python3.6/bin/python3 > virtualenv -p python3.6

Related: ethereum#558

* Add a note on how to fix `fatal error: openssl/aes.h: No such file or directory` in the `make` output

* removed extraneous backtick `

* Minor edits

with ``num`` type > with the ``num`` type
crowdfunding period is over - as determined> crowdfunding period is over—as determined

* Minor edits voting

add a comma > to vote, and each
add a comma > to vote, or

* Improve for loop error

* Adds test for logging a decimal list.

* :ref:`function-calls` > :ref:`Function-calls`

* Minor edits types.rst

* Add length check to event topics

* Fix and test logging with units

* Improve type parsing error message

* Add valid call keyword list to utils

* Add length check to event topics

* Partial fix for ethereum#590. Adds check for a minimum of one return statement.

* Fixes test that were missing return statements.

* Adds example of return checker behaving incorrectly.

* Update dockerfile to use slim image base

* Remove commented out directives

* Reduce num256_add gas cost

* Tag built image as viper

* Add built-in function docs

* Fix on chain market maker

* Add comments to on chain market maker

* Change badges from viper to vyper
  • Loading branch information...
Dexaran committed Dec 25, 2017
1 parent 35e8ace commit 9c1992f56c2b78416f981452f0457449f7670d1a
Showing with 6,399 additions and 2,334 deletions.
  1. +2 −0 .github/ISSUE_TEMPLATE.md
  2. +31 −0 .github/VIP_TEMPLATE.md
  3. +2 −0 .gitignore
  4. +0 −1 .python-version
  5. +18 −7 Dockerfile
  6. +5 −0 Makefile
  7. +7 −7 README.md
  8. +9 −1 bin/viper
  9. +230 −0 docs/built-in-functions.rst
  10. +1 −1 docs/compiling-a-contract.rst
  11. +15 −8 docs/contributing.rst
  12. +14 −11 docs/index.rst
  13. +16 −3 docs/installing-viper.rst
  14. +15 −15 docs/old_readme.txt
  15. +23 −3 docs/structure-of-a-contract.rst
  16. +49 −0 docs/testing-deploying-contracts.rst
  17. +338 −103 docs/types.rst
  18. +612 −0 docs/viper-by-example.rst
  19. +1 −0 docs/viper-in-depth.rst
  20. +4 −1 examples/auctions/simple_open_auction.v.py
  21. +4 −0 examples/crowdfund.v.py
  22. +52 −0 examples/market_maker/on_chain_market_maker.v.py
  23. +31 −17 examples/safe_remote_purchase/safe_remote_purchase.v.py
  24. +34 −6 examples/stock/company.v.py
  25. +95 −0 examples/tokens/ERC20.v.py
  26. +8 −0 examples/tokens/ERC20_solidity_compatible/ERC20.v.py
  27. +31 −26 examples/tokens/vipercoin.v.py
  28. +76 −29 examples/voting/ballot.v.py
  29. +2 −0 examples/wallet/wallet.v.py
  30. +2 −3 setup.cfg
  31. +1 −1 setup.py
  32. +41 −0 snap/snapcraft.yaml
  33. +9 −0 tests/compiler/LLL/test_repeat.py
  34. +36 −0 tests/compiler/LLL/test_with.py
  35. +15 −0 tests/compiler/test_bytecode_runtime.py
  36. +97 −0 tests/compiler/test_clamps.py
  37. +9 −0 tests/compiler/test_sha3_32.py
  38. +153 −0 tests/conftest.py
  39. +20 −30 tests/examples/auctions/test_simple_open_auction.py
  40. +55 −28 {examples/stock → tests/examples/company}/test_company.py
  41. +81 −0 tests/examples/market_maker/test_on_chain_market_maker.py
  42. +8 −9 tests/examples/safe_remote_purchase/test_safe_remote_purchase.py
  43. +8 −16 tests/examples/tokens/test_vipercoin.py
  44. +102 −7 tests/examples/voting/test_ballot.py
  45. +4 −6 tests/examples/wallet/test_wallet.py
  46. +7 −0 tests/parser/exceptions/test_constancy_exception.py
  47. +26 −1 tests/parser/exceptions/test_invalid_literal_exception.py
  48. +4 −0 tests/parser/exceptions/test_invalid_payable.py
  49. +2 −0 tests/parser/exceptions/test_invalid_type_exception.py
  50. +34 −0 tests/parser/exceptions/test_structure_exception.py
  51. +16 −0 tests/parser/exceptions/test_variable_declaration_exception.py
  52. +54 −0 tests/parser/features/arithmetic/test_modulo.py
  53. +12 −0 tests/parser/features/decorators/test_constant.py
  54. +0 −19 tests/parser/features/decorators/test_internal.py
  55. +15 −0 tests/parser/features/decorators/test_private.py
  56. +21 −0 tests/parser/features/decorators/test_public.py
  57. +96 −0 tests/parser/features/external_contracts/test_erc20_abi.py
  58. +542 −0 tests/parser/features/external_contracts/test_external_contract_calls.py
  59. +6 −8 tests/parser/features/iteration/test_break.py
  60. +294 −0 tests/parser/features/iteration/test_for_in_list.py
  61. +47 −12 tests/parser/features/iteration/test_range_in.py
  62. +10 −11 tests/parser/features/iteration/test_repeater.py
  63. +16 −0 tests/parser/features/test_assert.py
  64. +26 −5 tests/parser/features/test_assignment.py
  65. +95 −0 tests/parser/features/test_bytes_map_keys.py
  66. +3 −7 tests/parser/features/test_clampers.py
  67. +2 −7 tests/parser/features/test_comments.py
  68. +2 −6 tests/parser/features/test_conditionals.py
  69. +89 −0 tests/parser/features/test_constructor.py
  70. +0 −324 tests/parser/features/test_external_contract_calls.py
  71. +18 −5 tests/parser/features/test_gas.py
  72. +38 −19 tests/parser/features/test_internal_call.py
  73. +346 −94 tests/parser/features/test_logging.py
  74. +46 −0 tests/parser/features/test_packing.py
  75. +28 −0 tests/parser/functions/rlp/conftest.py
  76. +92 −0 tests/parser/functions/rlp/test_rlp_list.py
  77. +17 −0 tests/parser/functions/test_as_num256.py
  78. +40 −0 tests/parser/functions/test_bitwise.py
  79. +10 −0 tests/parser/functions/test_block_number.py
  80. +101 −0 tests/parser/functions/test_concat.py
  81. +77 −0 tests/parser/functions/test_ec.py
  82. +22 −0 tests/parser/functions/test_ecrecover.py
  83. +99 −0 tests/parser/functions/test_extract32.py
  84. +14 −17 tests/parser/functions/test_is_contract.py
  85. +14 −0 tests/parser/functions/test_length.py
  86. +14 −0 tests/parser/functions/test_method_id.py
  87. +16 −0 tests/parser/functions/test_minmax.py
  88. +2 −0 tests/parser/functions/test_only_init_abi.py
  89. +89 −0 tests/parser/functions/test_raw_call.py
  90. +14 −10 tests/parser/functions/test_return_tuple.py
  91. +14 −0 tests/parser/functions/test_send.py
  92. +70 −0 tests/parser/functions/test_sha3.py
  93. +109 −0 tests/parser/functions/test_slice.py
  94. +7 −9 tests/parser/globals/test_getters.py
  95. +17 −0 tests/parser/globals/test_globals.py
  96. +26 −13 tests/parser/globals/test_setters.py
  97. +48 −0 tests/parser/integration/test_basics.py
  98. +37 −25 tests/parser/{intergration → integration}/test_crowdfund.py
  99. +8 −7 tests/parser/{intergration → integration}/test_escrow.py
  100. +0 −25 tests/parser/intergration/test_basics.py
  101. +5 −0 tests/parser/syntax/test_as_num256.py
  102. +6 −0 tests/parser/syntax/test_as_wei.py
  103. +21 −0 tests/parser/syntax/test_block.py
  104. +14 −0 tests/parser/syntax/test_bool.py
  105. +2 −12 tests/parser/syntax/test_byte_string.py
  106. +13 −0 tests/parser/syntax/test_bytes.py
  107. +3 −0 tests/parser/syntax/test_code_size.py
  108. +10 −0 tests/parser/syntax/test_concat.py
  109. +4 −0 tests/parser/syntax/test_create_with_code_of.py
  110. +4 −0 tests/parser/syntax/test_extract32.py
  111. +3 −0 tests/parser/syntax/test_for_range.py
  112. +41 −3 tests/parser/syntax/test_invalids.py
  113. +3 −0 tests/parser/syntax/test_len.py
  114. +52 −7 tests/parser/syntax/test_list.py
  115. +46 −0 tests/parser/syntax/test_logging.py
  116. +27 −0 tests/parser/syntax/test_maps.py
  117. +2 −0 tests/parser/syntax/test_minmax.py
  118. +40 −0 tests/parser/syntax/test_missing_return.py
  119. +25 −4 tests/parser/syntax/test_nested_list.py
  120. +1 −0 tests/parser/syntax/test_public.py
  121. +6 −0 tests/parser/syntax/test_raw_call.py
  122. +1 −0 tests/parser/syntax/test_return_tuple.py
  123. +8 −0 tests/parser/syntax/test_rlplist.py
  124. +2 −0 tests/parser/syntax/test_selfdestruct.py
  125. +11 −0 tests/parser/syntax/test_send.py
  126. +3 −0 tests/parser/syntax/test_sha3.py
  127. +6 −0 tests/parser/syntax/test_slice.py
  128. +31 −0 tests/parser/syntax/test_timestamp_timedelta.py
  129. +25 −11 tests/parser/types/numbers/test_decimals.py
  130. +96 −5 tests/parser/types/numbers/test_num.py
  131. +59 −26 tests/parser/types/numbers/test_num256.py
  132. +33 −39 tests/parser/types/test_bytes.py
  133. +25 −11 tests/parser/types/test_lists.py
  134. +13 −9 tests/parser/types/test_string_literal.py
  135. +6 −6 tests/parser/types/value/test_wei.py
  136. +0 −135 tests/setup_transaction_tests.py
  137. +0 −911 tests/test_parser.py
  138. +35 −15 viper/compile_lll.py
  139. +1 −1 viper/compiler.py
  140. +16 −10 viper/function_signature.py
  141. +12 −11 viper/functions.py
  142. +5 −4 viper/opcodes.py
  143. +3 −3 viper/optimizer.py
  144. +22 −5 viper/parser/expr.py
  145. +188 −86 viper/parser/parser.py
  146. +45 −14 viper/parser/parser_utils.py
  147. +159 −21 viper/parser/stmt.py
  148. +21 −0 viper/premade_contracts.py
  149. +7 −10 viper/signatures/event_signature.py
  150. +16 −11 viper/types.py
  151. +4 −1 viper/utils.py
@@ -1,3 +1,5 @@
If you're proposing a new feature please follow the [VIP Template] (https://github.com/ethereum/viper/tree/master/.github/VIP_TEMPLATE.md)

* viper Version: x.x.x
* pyethereum Version: x.x.x
* OS: osx/linux/win
@@ -0,0 +1,31 @@
This is the suggested template for new VIPs.

## Preamble

VIP: <to be assigned>
Title: <VIP title>
Author: <list of authors' names and optionally, email addresses>
Type: <Standard Track | Informational | Meta>
Status: Draft
Created: <date created on, in ISO 8601 (yyyy-mm-dd) format>
Requires (*optional): <VIP number(s)>
Replaces (*optional): <VIP number(s)>
## 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.
## Abstract
A short description of the technical issue being addressed.
## Motivation
The motivation is critical for VIPs that add or change Viper's functionality. It should clearly explain why the existing Viper functionality is inadequate to address the problem that the VIP solves as well as how the VIP is in line with Viper's goals and design philosopy.
## Specification
The technical specification should describe the syntax and semantics of any new feature. The specification should be detailed enough to allow any developer to implement the functionality
## Backwards Compatibility
All VIPs that introduce backwards incompatibilities must include a section describing these incompatibilities and their severity. The VIP must explain how the author proposes to deal with these incompatibilities.
## Copyright
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/)
@@ -29,3 +29,5 @@ htmlcov/
docs/_build
docs/modules.rst

# IDEs
.idea/

This file was deleted.

@@ -1,13 +1,24 @@
FROM python:3.6
FROM python:3.6-slim

MAINTAINER Obul <obulpathi@merkletree.vc>
# Specify label-schema specific arguments and labels.
ARG BUILD_DATE
ARG VCS_REF
LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="viper" \
org.label-schema.description="Viper is an experimental programming language" \
org.label-schema.url="https://viper.readthedocs.io/en/latest/" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://github.com/ethereum/viper" \
org.label-schema.vendor="Ethereum" \
org.label-schema.schema-version="1.0"

# coincurve requires libgmp
RUN apt-get update && \
apt-get install -y libgmp-dev
apt-get install -y --no-install-recommends apt-utils gcc libc6-dev libc-dev libssl-dev libgmp-dev && \
rm -rf /var/lib/apt/lists/*

ADD . /code

# download and install Viper
WORKDIR /code
RUN git clone https://github.com/ethereum/viper.git
WORKDIR /code/viper
RUN python setup.py install
RUN python setup.py install && \
apt-get purge -y --auto-remove apt-utils gcc libc6-dev libc-dev libssl-dev
@@ -25,3 +25,8 @@ docs:
$(MAKE) -C docs clean
$(MAKE) -C docs html
open docs/_build/html/index.html

docker-build:
@docker build -t viper \
--build-arg VCS_REF=`git rev-parse --short HEAD` \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` .
@@ -1,7 +1,7 @@
[![Join the chat at https://gitter.im/bethereum/viper](https://badges.gitter.im/ethereum/viper.svg)](https://gitter.im/ethereum/viper?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status](https://travis-ci.org/ethereum/viper.svg?branch=master)](https://travis-ci.org/ethereum/viper)
[![Documentation Status](https://readthedocs.org/projects/viper/badge/?version=latest)](http://viper.readthedocs.io/en/latest/?badge=latest)
[![Coverage Status](https://coveralls.io/repos/github/ethereum/viper/badge.svg?branch=master)](https://coveralls.io/github/ethereum/viper?branch=master)
[![Join the chat at https://gitter.im/bethereum/vyper](https://badges.gitter.im/ethereum/vyper.svg)](https://gitter.im/ethereum/vyper?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status](https://travis-ci.org/ethereum/vyper.svg?branch=master)](https://travis-ci.org/ethereum/vyper)
[![Documentation Status](https://readthedocs.org/projects/vyper/badge/?version=latest)](http://vyper.readthedocs.io/en/latest/?badge=latest)
[![Coverage Status](https://coveralls.io/repos/github/ethereum/vyper/badge.svg?branch=master)](https://coveralls.io/github/ethereum/vyper?branch=master)

# Principles and Goals

@@ -31,7 +31,7 @@ Viper does NOT strive to be a 100% replacement for everything that can be done i
**Note: Viper is still alpha software, use with care**

# Installation
See the [Viper documentation](https://viper.readthedocs.io/en/latest/installing-viper.html)
See the [Viper documentation](https://vyper.readthedocs.io/en/latest/installing-viper.html)
for build instructions.

# Compiling a contract
@@ -59,5 +59,5 @@ For testing strategy, please see [Testing](no-link)
# Contributing
* See Issues tab, and feel free to submit your own issues
* Add PRs if you discover a solution to an existing issue
* For further discussions and questions talk to us on [gitter](https://gitter.im/ethereum/viper)
* For more information, see [Contributing](http://viper.readthedocs.io/en/latest/contributing.html)
* For further discussions and questions talk to us on [gitter](https://gitter.im/ethereum/vyper)
* For more information, see [Contributing](http://vyper.readthedocs.io/en/latest/contributing.html)
@@ -6,22 +6,30 @@ import viper

from viper import compiler, optimizer
from viper.parser.parser import parse_to_lll
from viper.parser import parser_utils


parser = argparse.ArgumentParser(description='Viper {0} programming language for Ethereum'.format(viper.__version__))
parser.add_argument('input_file', help='Viper sourcecode to compile')
parser.add_argument('-f', help='Format to print', choices=['abi', 'json', 'bytecode', 'ir'], default='bytecode', dest='format')
parser.add_argument('-f', help='Format to print', choices=['abi', 'json', 'bytecode', 'bytecode_runtime', 'ir'], default='bytecode', dest='format')
parser.add_argument('--show-gas-estimates', help='Show gas estimates in ir output mode.', action="store_true")

args = parser.parse_args()

if __name__ == '__main__':

with open(args.input_file) as fh:
code = fh.read()
if args.show_gas_estimates:
parser_utils.LLLnode.repr_show_gas = True

if args.format == 'abi':
print(compiler.mk_full_signature(code))
elif args.format == 'json':
print(json.dumps(compiler.mk_full_signature(code)))
elif args.format == 'bytecode':
print('0x' + compiler.compile(code).hex())
elif args.format == 'bytecode_runtime':
print('0x' + compiler.compile(code, bytecode_runtime=True).hex())
elif args.format == 'ir':
print(optimizer.optimize(parse_to_lll(code)))
@@ -0,0 +1,230 @@
.. index:: function, built-in;

.. _built_in_functions:

***********************
Built in Functions
***********************

Viper contains a set amount of built in functions that would be timely and/or unachievable to write in Viper.

.. _functions:

Functions
=========
* **floor**
::

def floor(a) -> b:
"""
:param a: value to round down
:type a: either decimal or num

:output b: integer
"""
Rounds a decimal down to the nearest integer.

* **decimal**
::

def decimal(a) -> b:
"""
:param a: value to turn into decimal
:type a: either decimal or num

:output b: decimal
"""
Turns a number into a decimal.

* **as_unitless_number**
::

def as_unitless_number(a) -> b:
"""
:param a: value to remove units from
:type a: either decimal or num

:output b: either decimal or num
"""
Turns a ``num`` or ``decimal`` with units into one without units (used for assignment and math).

* **as_num128**
::

def as_num128(a) -> b:
"""
:param a: value to turn into int128
:type a: either num, bytes32, num256, or bytes

:output b: num
"""
Turns input into a ``num`` (int128).

* **as_num256**
::

def as_num256(a) -> b:
"""
:param a: value to turn into num256
:type a: either num_literal, num, bytes32, or address

:output b: num256
"""
Turns input into a ``num256`` (uint256).

* **as_bytes32**
::

def as_bytes32(a) -> b:
"""
:param a: value to turn into bytes32
:type a: either num, num256, address

:output b: bytes32
"""
Turns input into a ``bytes32``.
* **slice**
::

def slice(a, start=b, length=c) -> d:
"""
:param a: bytes to be sliced
:type a: either bytes or bytes32
:param b: start position of the slice
:type b: num
:param c: length of the slice
:type c: num

:output d: bytes
"""
Takes a list of bytes and copies, then returns a specified chunk.

* **len**
::

def len(a) -> b:
"""
:param a: value to get the length of
:type a: bytes

:output b: num
"""
Returns the length of a given list of bytes.

* **concat**
::

def concat(a, b, ...) -> c:
"""
:param a: value to combine
:type a: bytes
:param b: value to combine
:type b: bytes

:output b: bytes
"""
Takes 2 or more bytes arrays of type ``bytes32`` or ``bytes`` and combines them into one.

* **keccak256 (sha3)**
::

def keccak256(a) -> b:
"""
:param a: value to hash
:type a: either str_literal, bytes, bytes32

:output b: bytes32
"""
Returns ``keccak_256`` (Ethereums sha3) hash of input.

* **method_id**
::

def method_id(a) -> b:
"""
:param a: method declaration
:type a: str_literal

:output b: bytes
"""

Takes a function declaration and returns its method_id (used in data field to call it).

* **ecrecover**
::

def ecrecover(hash, v, r, s) -> b:
"""
:param hash: a signed hash
:type hash: bytes32
:param v:
:type v: num256
:param r: elliptic curve point
:type r: num256
:param s: elliptic curve point
:type s: num256

:output b: address
"""

Takes a signed hash and vrs and returns the public key of the signer.

* **ecadd**
::

def ecadd(a, b) -> sum:
"""
:param a: pair to be added
:type a: num252[2]
:param b: pair to be added
:type b: num252[2]

:output sum: num256[2]
"""

Takes two elliptical curves and adds them together.

* **ecmul**
::

def ecmul(a, b) -> product:
"""
:param a: pair to be multiplied
:type a: num252[2]
:param b: pair to be multiplied
:type b: num252[2]

:output product: num256[2]
"""

Takes two elliptical curves and multiplies them together.

* **extract32**
::

def extract32(a, b, type=c) -> d:
"""
:param a: where 32 bytes are extracted from
:type a: bytes
:param b: start point of bytes to be extracted
:type b: num
:param c: type of output
:type c: either bytes32, num128, or address

:output d: either bytes32, num128, or address
"""

Takes a byte array and extracts 32 bytes from it.

* **bytes_to_num**
::

def bytes_to_num(a) -> b:
"""
:param a: bytes to be transformed
:type a: bytes

:output d: num
"""

Transforms bytes to num.
@@ -6,7 +6,7 @@ To compile a contract, use:
viper yourFileName.v.py

.. note::
Since .vy is not official a language supported by any syntax highlighters or linters,
Since .vy is not officially a language supported by any syntax highlighters or linters,
it is recommended to name your Viper file ending with `.v.py` in order to have Python syntax highlighting.

An `online compiler <https://viper.tools/>`_ is available as well, which lets you experiment with

0 comments on commit 9c1992f

Please sign in to comment.
You can’t perform that action at this time.