ethereum / serpent

Other
366 stars 107 forks source link

Loops of Length 311 are Too Big for init Functions #32

Open xcthulhu opened 9 years ago

xcthulhu commented 9 years ago

I am having problems with using while loops in def init(): functions in Contracts.

Specifically, I have installed the following versions of serpent and pyethereum:

pip install -q --upgrade \
  git+git://github.com/ethereum/serpent.git@86649c54c209a662c943d664819fe01b8ebc3e2b \
  git+git://github.com/ethereum/pyethereum.git@23c7d1e551c3c94d11fdea66cfdb7d29b17b8a50

Here's my contract:

# array_init.se
data arr[312]

def init():
    i = 0
    while i < 311:
        self.arr[i] = 1
        i = i + 1

def foo():
    return 1

312 happens to be the length of the buffer used by Mersenne Twister.

If I replace 311 with 310, there are no problems.

Here's how I am testing this code:

from pyethereum import tester as t
s = t.state()
c = s.contract('array_init.se')
for _ in range(5):
    gas_start = s.block.gas_used
    print s.send(t.k0, c, 0, funid=0, abi=[])[0]

Should print 1 five times. Instead here's my exception and stacktrace:

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-37-fa2ff0671689> in <module>()
      1 from pyethereum import tester as t
      2 s = t.state()
----> 3 c = s.contract('array_init.se')
      4 for _ in range(5):
      5     gas_start = s.block.gas_used

/usr/local/lib/python2.7/site-packages/pyethereum/tester.pyc in contract(self, code, sender, endowment)
     60     def contract(self, code, sender=k0, endowment=0):
     61         evm = serpent.compile(code)
---> 62         o = self.evm(evm, sender, endowment)
     63         assert len(self.block.get_code(o)), "Contract code empty"
     64         return o

/usr/local/lib/python2.7/site-packages/pyethereum/tester.pyc in evm(self, evm, sender, endowment)
     70         (s, a) = pb.apply_transaction(self.block, tx)
     71         if not s:
---> 72             raise Exception("Contract creation failed")
     73         return a
     74 

Exception: Contract creation failed
joeykrug commented 8 years ago

You're using so much gas contract creation is failing. So this would never work on the current live chain. That said if you want to use it anyway for w/e reason do t.gas_limit = 200000000 and then it'll have a higher gas limit and work