neo-python icon indicating copy to clipboard operation
neo-python copied to clipboard

MUL can be more computationally costly than what is reflected in its gas price

Open udoprog opened this issue 7 years ago • 1 comments

Current behavior

Calling MUL with large operands will cause the VM to perform large computations that could prevent it from making progress.

Expected behavior

MUL should have a relatively constant cost in computation to reflect its gas cost.

How to reproduce

Consider calling the following contract:

def Main():
    a = 10

    while True:
        a = a * a

24 iterations of this loop takes about 30 seconds for me to execute and costs ~0.5 gas. This is an operation with relatively low gas cost but with a high computational cost. It could possibly be used as a an inexpensive vehicle to cause VMs to be busy performing large computations.

A similar contract that only performs a busy loop consumes around 500 gas.

This works because integers are arbitrarily large bignums, that has a variable cost for multiplication that depends on their size. And the multiplication is currently performed regardless of operand sizes.

A solution could be to limit numeric types to 32 bytes, as neo does.

Your environment

Not applicable

udoprog avatar Aug 22 '18 18:08 udoprog

Thanks for reporting 👍 . Should be addressed in the development branch shortly.

ixje avatar Oct 14 '18 13:10 ixje