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

Calling constant functions that use msg.sender in non-constant functions fails #315

Closed
fubuloubu opened this issue Aug 9, 2017 · 4 comments

Comments

@fubuloubu
Copy link
Member

fubuloubu commented Aug 9, 2017

I was testing some updates I was making with one of my example contracts and I think I may have stumbled upon a bug, or at least something I don't understand why it should fail (and it's not very clear why)

To summarize, I have a contract that contains a constant method to return the balance of some map (address -> record) for the address associated with the message sender. I decided to use this function in my other functions so I didn't duplicate this access in multiple spots, basically assuming that if I called this @constant function, the msg.sender attribute would be passed to that @constant function. However, when I do this I get the TransactionFailed exception from pyethereum.

Here's an example:

from ethereum.tools import tester
from viper import compiler

chain = tester.Chain()
tester.languages['viper'] = compiler.Compiler()
chain.head_state.gas_limit = 10**9

code="""
bal: num[address]

def __init__():
    self.bal[msg.sender] = 1

@constant
def get_my_bal() -> num:
    return self.bal[msg.sender]

def foo():
    assert self.bal[msg.sender] > 0

def bar():
    assert self.get_my_bal() > 0
"""

c = chain.contract(code, language='viper')
c.get_my_bal() # Works fine
c.foo() # Works fine as well
c.bar() # Fails with ethereum.tools.tester.TransactionFailed()

Please let me know if I am misunderstanding how the @constant is supposed to be used (I am assuming you should be allowed to call @constant functions from other functions) (I am also assuming that implicit values such as msg.sender are passed to @constant functions as well).

Not totally certain what the problem is...

@fubuloubu
Copy link
Member Author

I believe that msg.sender and other "internal"quantities are not passed to an internal call to a function in a Viper program. Still trying to figure out why, would appreciate any help!

@DavidKnott
Copy link
Contributor

@fubuloubu Great catch! I'll help with this, off the top of my head I'm guessing it's an issue with how function contexts are being made.

@fubuloubu
Copy link
Member Author

I narrowed it down to a test case that we can use to debug. I'll create a pull request for that, and then maybe you can help me debug the issue further.

@fubuloubu
Copy link
Member Author

Created #320

Further collaboration on that please.

fubuloubu referenced this issue in fubuloubu/vyper Aug 24, 2017
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

2 participants