Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment allowed to invalid variables in contract body #410

Closed
pdaian opened this issue Oct 18, 2017 · 3 comments
Closed

Assignment allowed to invalid variables in contract body #410

pdaian opened this issue Oct 18, 2017 · 3 comments

Comments

@pdaian
Copy link
Contributor

pdaian commented Oct 18, 2017

  • viper Version: 0.0.2
  • pyethereum Version: 2.1.0
  • OS: linux
  • Python Version (python --version): 3.6

What's your issue about?

It appears that some programs parse which perhaps should not, including assigning to a global-style declaration in function bodies. These programs then behave unexpectedly. Below is a minimal example:

from ethereum.tools import tester as t
from ethereum.slogging import configure_logging

#configure_logging(':trace')
s = t.Chain()
from viper import com
piler

code = """
def foo() -> num:
    q:num = 1
    return q

def foo2() -> num:
    q = 1
    return q
"""

t.languages['viper'] = compiler.Compiler() 

c = s.contract(code, language='viper')

print(c.foo())  # Should not parse? returns 0
print(c.foo2()) # Should return 1; returns 1

This bug was discovered by Yi Zhang of the KEVM project. (@yzhang90)

How can it be fixed?

Make parsing consistent with what is specified in the old README.

Specifically, the offending statement can parse under these top-level rules:

 <varname> = <type>
        OR <var> = <expr>

with "q:num" being neither a valid varname or var (assuming varnames cannot contain colons, which would be sane).

Parsing should therefore likely fail in this case.

Cute Animal Picture

             ,,,,,,,,
           ,|||````||||
     ,,,,|||||       ||,
  ,||||```````       `||
,|||`                 |||,
||`     ....,          `|||
||     ::::::::          |||,
||     :::::::'     ||    ``|||,
||,     :::::'               `|||
`||,                           |||
 `|||,       ||          ||    ,||
   `||                        |||`
    ||                   ,,,||||
    ||              ,||||||```
   ,||         ,,|||||`
  ,||`   ||   |||`
 |||`         ||
,||           ||
||`           ||
|||,         |||
 `|||,,    ,|||
   ``||||||||`
@pdaian pdaian changed the title Assignment allowed to types in contract body Assignment allowed to invalid variables in contract body Oct 18, 2017
@DavidKnott
Copy link
Contributor

@pdaian Thanks for making an issue, I'll look into it right away!

@pdaian
Copy link
Contributor Author

pdaian commented Oct 19, 2017

Interestingly enough the following works as tested, as spotted by @yzhang90

def foo() -> num:
    p:{x:num, y:num}
    p.x = 2
    p.y = 3
    return p.y

@jacqueswww
Copy link
Contributor

jacqueswww commented Oct 20, 2017

@pdaian @yzhang90 good catch ! 🐟

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants