Skip to content

Commit

Permalink
Viper -> Vyper
Browse files Browse the repository at this point in the history
Rename Viper -> Vyper inside files (with case sensitive changes)
Rename all files and folders Viper -> Vyper
  • Loading branch information
Unknown authored and Unknown committed Mar 15, 2018
1 parent 4a560e8 commit b48f8de
Show file tree
Hide file tree
Showing 819 changed files with 111 additions and 111 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# KViper: Semantics of Viper in K
# KVyper: Semantics of Vyper in K

In this repository we present a formal semantics of [Viper](https://github.com/ethereum/viper).
For more details, refer to [wiki](https://github.com/kframework/viper-semantics/wiki).
In this repository we present a formal semantics of [Vyper](https://github.com/ethereum/vyper).
For more details, refer to [wiki](https://github.com/kframework/vyper-semantics/wiki).

**WARNING: This repository has not been independently audited for security. Use with caution.**

## Running KViper
## Running KVyper

KViper can be used to compile Viper programs to EVM bytecode, being comparable to the production Viper compiler.
KVyper can be used to compile Vyper programs to EVM bytecode, being comparable to the production Vyper compiler.

First, build K after installing the prerequisites in `k/README.md` (after the first command):
```
Expand All @@ -20,24 +20,24 @@ Add the bin directory [to your path](https://www.java.com/en/download/help/path.
$ export PATH="`pwd`/k-distribution/target/release/k/bin:$PATH"
```

Then, build KViper:
Then, build KVyper:
```
$ kompile --syntax-module VIPER-ABSTRACT-SYNTAX viper-lll/viper-lll-post.k
$ kompile --syntax-module VYPER-ABSTRACT-SYNTAX vyper-lll/vyper-lll-post.k
$ kompile --syntax-module LLL-EVM-INTERFACE lll-evm/lll-evm.k
```

Now you can run KViper (Python 3.6 required):
Now you can run KVyper (Python 3.6 required):
```
$ python3.6 kviper.py <pgm>.v.py
$ python3.6 kvyper.py <pgm>.v.py
```

For example,
```
$ python3.6 kviper.py tests/examples/token/ERC20.v.py
$ python3.6 kvyper.py tests/examples/token/ERC20.v.py
```

## Contributing to KViper
## Contributing to KVyper

To contribute to KViper: file issues, submit pull requests, and join the
To contribute to KVyper: file issues, submit pull requests, and join the
community [K Riot channel](https://riot.im/app/#/room/#k:matrix.org), which
includes a number of K experts.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
requires "domains.k"

module VIPER-ABSTRACT-SYNTAX
module VYPER-ABSTRACT-SYNTAX
imports DOMAINS

syntax Pgm ::= "%pgm" "(" Events "," Globals "," Defs "," Contracts ")"
Expand Down
10 changes: 5 additions & 5 deletions kviper.py → kvyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import subprocess
import re

from scripts.viper_parser import main as parse # string -> string
from scripts.vyper_parser import main as parse # string -> string
from scripts.op2byte import encode as op2byte # string list -> bytes

path = os.path.dirname(os.path.realpath(__file__))
Expand All @@ -23,11 +23,11 @@ def krun(kdir, pgm): # string * string -> string
else:
raise RuntimeError(p.stderr)

def viper2lll(ast): # string -> string
out = krun('viper-lll', ast)
def vyper2lll(ast): # string -> string
out = krun('vyper-lll', ast)
lll = re.search(r'<lll> (.*) </lll>', out).group(1)
if lll == ".":
raise RuntimeError("viper-lll computation got stuck:\n\n" + out + "\n\n")
raise RuntimeError("vyper-lll computation got stuck:\n\n" + out + "\n\n")

return lll

Expand All @@ -38,7 +38,7 @@ def lll2evm(lll): # string -> string list

def compile(code): # string -> bytes
ast = parse(code)
lll = viper2lll(ast)
lll = vyper2lll(ast)
evm = lll2evm(lll) # list of opcodes
return op2byte(evm)

Expand Down
2 changes: 1 addition & 1 deletion lll-evm/lll-xevm.k
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ module LLL-XEVM
rule $clamp_nonzero(X)
=> X ~> DUP(1) ~> assertNonZero

// TODO:DJ: viper could be wrong in the order of arguments
// TODO:DJ: vyper could be wrong in the order of arguments
rule $sha3_32(X) => X ~> PUSH(1, FREE_VAR_SPACE) ~> MSTORE ~> PUSH(1, FREE_VAR_SPACE) ~> PUSH(1, 32) ~> SHA3

rule $ne(X, Y) => $iszero( $eq(X, Y))
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ type kompile >/dev/null || die 'kompile not in $PATH'
dir="$(dirname "$0")"/..

set -x
kompile --syntax-module VIPER-ABSTRACT-SYNTAX "$dir"/viper-lll/viper-lll-post.k
kompile --syntax-module VYPER-ABSTRACT-SYNTAX "$dir"/vyper-lll/vyper-lll-post.k
kompile --syntax-module LLL-EVM-INTERFACE "$dir"/lll-evm/lll-evm.k
12 changes: 6 additions & 6 deletions scripts/kpytest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import py
from viper import compiler
from vyper import compiler

import sys
import os.path

# importing parent dir, where kviper.py is located
# importing parent dir, where kvyper.py is located
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from kviper import compile
from kvyper import compile


def gas_estimate(origcode, *args, **kwargs):
Expand All @@ -18,14 +18,14 @@ def gas_estimate(origcode, *args, **kwargs):


if __name__ == '__main__':
# patching viper.compiler.Compiler.compile
# patching vyper.compiler.Compiler.compile
compiler.Compiler.compile = lambda self, code, *args, **kwargs: compile(code)
compiler.compile = lambda code, *args, **kwargs: compile(code)

# disabling gas estimation
compiler.Compiler.gas_estimate = lambda self, code, *args, **kwargs: gas_estimate(code, args, kwargs)

# changing working directory to viper repo. Required for tests that load other files.
os.chdir("../viper")
# changing working directory to vyper repo. Required for tests that load other files.
os.chdir("../vyper")

py.test.cmdline.main() # invoking pytest with args received from command line
4 changes: 2 additions & 2 deletions scripts/kviper.sh → scripts/kvyper.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pgm="$1"
ast="$pgm".ast
lll="$pgm".lll

python3 "$dir"/scripts/viper_parser.py "$pgm" >"$ast"
krun -d "$dir"/viper-lll "$ast" | sed 's/.*<lll> \(.*\) <\/lll>.*/\1/' >"$lll"
python3 "$dir"/scripts/vyper_parser.py "$pgm" >"$ast"
krun -d "$dir"/vyper-lll "$ast" | sed 's/.*<lll> \(.*\) <\/lll>.*/\1/' >"$lll"
krun -d "$dir"/lll-evm "$lll" | sed 's/.*<evm> ListItem ( \(.*\) ) <\/evm>.*/\1/' | sed 's/ ) ListItem ( / /g' | \
python3 "$dir"/scripts/op2byte.py
2 changes: 1 addition & 1 deletion scripts/print_lll.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from viper.parser.parser import LLLnode
from vyper.parser.parser import LLLnode

lll_opcodes = ['if', 'repeat', 'break', 'with', 'set', 'seq', 'pass', 'assert',
'ne', 'le', 'ge', 'sle', 'sge', 'uclamplt', 'uclample', 'uclampgt',
Expand Down
10 changes: 5 additions & 5 deletions scripts/test_harness_instructions.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
How to run tests from viper repository with kviper:
How to run tests from vyper repository with kvyper:

- install viper: https://viper.readthedocs.io/en/latest/installing-viper.html
- switch to viper virtual env
- run scripts/kpytest.py <test file or dir from viper repository>
- install vyper: https://vyper.readthedocs.io/en/latest/installing-vyper.html
- switch to vyper virtual env
- run scripts/kpytest.py <test file or dir from vyper repository>
Example:
python scripts/kpytest.py ../viper/tests/parser/types/numbers/test_num.py
python scripts/kpytest.py ../vyper/tests/parser/types/numbers/test_num.py
12 changes: 6 additions & 6 deletions scripts/viper_parser.py → scripts/vyper_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def parseVar(var):
raise ParserException("Unsupported Var format: " + str(var))


# taken from viper compiler.
# taken from vyper compiler.
DECIMAL_DIVISOR = 10000000000


Expand Down Expand Up @@ -772,10 +772,10 @@ def parseProgram(nodeList):
inputLines: List[str]


def main(viperPgm):
def main(vyperPgm):
global inputLines
inputLines = viperPgm.splitlines()
astList = parse(viperPgm)
inputLines = vyperPgm.splitlines()
astList = parse(vyperPgm)
return parseProgram(astList)


Expand All @@ -785,5 +785,5 @@ def main(viperPgm):
sys.exit(1)
fileName = sys.argv[1]
with open(fileName, "r") as fin:
viperPgm = fin.read()
print(main(viperPgm))
vyperPgm = fin.read()
print(main(vyperPgm))
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -u # Using undefined variables is an error. Exit immediately
# get the directory of this script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

python3 ${DIR}/../../scripts/viper_parser.py $1
python3 ${DIR}/../../scripts/vyper_parser.py $1
2 changes: 1 addition & 1 deletion tests/harness/test_parser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

cd ${DIR}

java -jar test-runner.jar -gen aux_viper_parser_for_test.sh -taskExt py ../
java -jar test-runner.jar -gen aux_vyper_parser_for_test.sh -taskExt py ../

rm -rf .test
10 changes: 5 additions & 5 deletions tests/viper-lll/test.sh → tests/vyper-lll/test.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

SCRIPT_DIR=`dirname $(python -c "import os, sys; print(os.path.realpath(\"$0\"))")`
SEMTANTICS_DIR=$(dirname $(dirname ${SCRIPT_DIR}))/viper-lll
SEMTANTICS_DIR=$(dirname $(dirname ${SCRIPT_DIR}))/vyper-lll

test_count=0

Expand All @@ -15,13 +15,13 @@ run_tests() {
expected_out=${f/%.ast/.ast.out}
echo "running ${file_name}"
test_count=$(($test_count + 1))
krun $f --output nowrap --debug -d ${SCRIPT_DIR} | sed 's/.*<lll> \(.*\) <\/lll>.*/\1/' | sed 's/ , .LLLExps//g' > /tmp/viper.txt
diff /tmp/viper.txt ${expected_out}
krun $f --output nowrap --debug -d ${SCRIPT_DIR} | sed 's/.*<lll> \(.*\) <\/lll>.*/\1/' | sed 's/ , .LLLExps//g' > /tmp/vyper.txt
diff /tmp/vyper.txt ${expected_out}
done
}

echo "kompile ${SEMTANTICS_DIR}/viper-lll.k"
kompile ${SEMTANTICS_DIR}/viper-lll.k --syntax-module VIPER-ABSTRACT-SYNTAX --debug -d ${SCRIPT_DIR}
echo "kompile ${SEMTANTICS_DIR}/vyper-lll.k"
kompile ${SEMTANTICS_DIR}/vyper-lll.k --syntax-module VYPER-ABSTRACT-SYNTAX --debug -d ${SCRIPT_DIR}

#parser/features
TESTS_DIR=${SCRIPT_DIR}/parser/features/arithmetic/test_modulo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Viper Port of MyToken
# Vyper Port of MyToken
# THIS CONTRACT HAS NOT BEEN AUDITED!
# ERC20 details at:
# https://theethereum.wiki/w/index.php/ERC20_Token_Standard
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Viper Port of MyToken
# Vyper Port of MyToken
# THIS CONTRACT HAS NOT BEEN AUDITED!
# ERC20 details at:
# https://theethereum.wiki/w/index.php/ERC20_Token_Standard
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Viper Port of MyToken
# Vyper Port of MyToken
# THIS CONTRACT HAS NOT BEEN AUDITED!
# ERC20 details at:
# https://theethereum.wiki/w/index.php/ERC20_Token_Standard
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Viper Port of MyToken
# Vyper Port of MyToken
# THIS CONTRACT HAS NOT BEEN AUDITED!
# ERC20 details at:
# https://theethereum.wiki/w/index.php/ERC20_Token_Standard
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Safe Remote Purchase (https://github.com/ethereum/solidity/blob/develop/docs/solidity-by-example.rst) ported to viper and optimized
#Safe Remote Purchase (https://github.com/ethereum/solidity/blob/develop/docs/solidity-by-example.rst) ported to vyper and optimized

#Rundown of the transaction:
#1. Seller posts item for sale and posts safety deposit of double the item value. Balance is 2*value.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Safe Remote Purchase (https://github.com/ethereum/solidity/blob/develop/docs/solidity-by-example.rst) ported to viper and optimized
#Safe Remote Purchase (https://github.com/ethereum/solidity/blob/develop/docs/solidity-by-example.rst) ported to vyper and optimized

#Rundown of the transaction:
#1. Seller posts item for sale and posts safety deposit of double the item value. Balance is 2*value.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Safe Remote Purchase (https://github.com/ethereum/solidity/blob/develop/docs/solidity-by-example.rst) ported to viper and optimized
#Safe Remote Purchase (https://github.com/ethereum/solidity/blob/develop/docs/solidity-by-example.rst) ported to vyper and optimized

#Rundown of the transaction:
#1. Seller posts item for sale and posts safety deposit of double the item value. Balance is 2*value.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Safe Remote Purchase (https://github.com/ethereum/solidity/blob/develop/docs/solidity-by-example.rst) ported to viper and optimized
#Safe Remote Purchase (https://github.com/ethereum/solidity/blob/develop/docs/solidity-by-example.rst) ported to vyper and optimized

#Rundown of the transaction:
#1. Seller posts item for sale and posts safety deposit of double the item value. Balance is 2*value.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Safe Remote Purchase (https://github.com/ethereum/solidity/blob/develop/docs/solidity-by-example.rst) ported to viper and optimized
#Safe Remote Purchase (https://github.com/ethereum/solidity/blob/develop/docs/solidity-by-example.rst) ported to vyper and optimized

#Rundown of the transaction:
#1. Seller posts item for sale and posts safety deposit of double the item value. Balance is 2*value.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Safe Remote Purchase (https://github.com/ethereum/solidity/blob/develop/docs/solidity-by-example.rst) ported to viper and optimized
#Safe Remote Purchase (https://github.com/ethereum/solidity/blob/develop/docs/solidity-by-example.rst) ported to vyper and optimized

#Rundown of the transaction:
#1. Seller posts item for sale and posts safety deposit of double the item value. Balance is 2*value.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Viper Port of MyToken
# Vyper Port of MyToken
# THIS CONTRACT HAS NOT BEEN AUDITED!
# ERC20 details at:
# https://theethereum.wiki/w/index.php/ERC20_Token_Standard
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Viper Port of MyToken
# Vyper Port of MyToken
# THIS CONTRACT HAS NOT BEEN AUDITED!
# ERC20 details at:
# https://theethereum.wiki/w/index.php/ERC20_Token_Standard
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Viper Port of MyToken
# Vyper Port of MyToken
# THIS CONTRACT HAS NOT BEEN AUDITED!
# ERC20 details at:
# https://theethereum.wiki/w/index.php/ERC20_Token_Standard
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Viper Port of MyToken
# Vyper Port of MyToken
# THIS CONTRACT HAS NOT BEEN AUDITED!
# ERC20 details at:
# https://theethereum.wiki/w/index.php/ERC20_Token_Standard
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Viper Port of MyToken
# Vyper Port of MyToken
# THIS CONTRACT HAS NOT BEEN AUDITED!
# ERC20 details at:
# https://theethereum.wiki/w/index.php/ERC20_Token_Standard
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Viper Port of MyToken
# Vyper Port of MyToken
# THIS CONTRACT HAS NOT BEEN AUDITED!
# ERC20 details at:
# https://theethereum.wiki/w/index.php/ERC20_Token_Standard
Expand Down
Loading

0 comments on commit b48f8de

Please sign in to comment.