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

Overflow checking for multiplication #767

Closed
yzhang90 opened this Issue Apr 9, 2018 · 0 comments

Comments

Projects
2 participants
@yzhang90

yzhang90 commented Apr 9, 2018

What's your issue about?

NOT in EVM is bitwise NOT, not logical NOT. So the overflow checking for multiplication (['assert', ['or', ['eq', ['sdiv', 'ans', 'l'], 'r'], ['not', 'l']]] ) is wrong. Consider the following the test cases:

def test_mul_overflow(t, assert_tx_failed, get_contract_with_gas_estimation, chain):
    mul_code = """

@public
def _num_mul(x: decimal, y: int128) -> decimal:
    return x * y

    """

    c = get_contract_with_gas_estimation(mul_code)

    t.s = chain
    NUM_1 = 85070591730234615865843651857942052864.0
    NUM_2 = 136112946768375385385349842973

    assert_tx_failed(lambda: c._num_mul(NUM_1, NUM_2))

NUM_1 * NUM_2 > 2**127, but no exception is thrown.

How can it be fixed?

Use ISZERO to test whether l is zero.

Cute Animal Picture

image

@jacqueswww jacqueswww added the bug label Apr 9, 2018

@jacqueswww jacqueswww moved this from Backlog to In Progress in Vyper - Final Countdown Apr 16, 2018

jacqueswww added a commit to jacqueswww/vyper that referenced this issue Apr 16, 2018

Vyper - Final Countdown automation moved this from In Progress to Done Apr 30, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment