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

Incorrect logging of indexed byte arrays #739

Closed
denis-bogdanas opened this issue Mar 30, 2018 · 1 comment
Closed

Incorrect logging of indexed byte arrays #739

denis-bogdanas opened this issue Mar 30, 2018 · 1 comment
Labels
bug Bug that shouldn't change language semantics when fixed.

Comments

@denis-bogdanas
Copy link

What's your issue about?

Logging indexed byte arrays works either if they have runtime length precisely 3! or are literals.

Here is a test that fails:

def test_event_logging_with_multiple_topics(get_contract_with_gas_estimation, chain, utils):
    loggy_code = """
MyLog: event({arg1: indexed(bytes <= 3), arg2: indexed(bytes <= 4), arg3: indexed(address)})

@public
def foo():
    a : bytes <= 4 = 'home'
    log.MyLog('bar', a, self)
    """

    c = get_contract_with_gas_estimation(loggy_code)
    c.foo()
    logs = chain.head_state.receipts[-1].logs[-1]
    event_id = utils.bytes_to_int(utils.sha3(bytes('MyLog(bytes3,bytes4,address)', 'utf-8')))
    # Event id is always the first topic
    assert logs.topics[0] == event_id
    # Event id is calculated correctly
    assert c.translator.event_data[event_id]
    # Event abi is created correctly
    assert c.translator.event_data[event_id] == (
        {'types': ['bytes3', 'bytes4', 'address'],
        'name': 'MyLog',
        'names': ['arg1', 'arg2', 'arg3'],
        'indexed': [True, True, True],
        'anonymous': False}
    )
    # Event is decoded correctly
    assert c.translator.decode_event(logs.topics, logs.data) == {'arg1': b'bar', 'arg2': b'home', 'arg3': '0x' + c.address.hex(), '_event_type': b'MyLog'}

How can it be fixed?

The issue is in the way size is used on these lines:

https://github.com/ethereum/vyper/blob/9eebb7c575545fcf880d815b9c888665dccbea51/vyper/parser/parser.py#L725-L726

Cute Animal Picture

put a cute animal picture here.

@jacqueswww jacqueswww added the bug Bug that shouldn't change language semantics when fixed. label Apr 3, 2018
@jacqueswww
Copy link
Contributor

Starting on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug that shouldn't change language semantics when fixed.
Projects
None yet
Development

No branches or pull requests

2 participants