Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

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

Open
udoprog opened this issue Aug 22, 2018 · 1 comment

Comments

@udoprog
Copy link

udoprog commented Aug 22, 2018

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

@ixje
Copy link
Member

ixje commented Oct 14, 2018

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

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

No branches or pull requests

2 participants