graph-node icon indicating copy to clipboard operation
graph-node copied to clipboard

Unexpected hashing for `indexed string` params

Open samigabor opened this issue 2 years ago • 6 comments

Bug report

Considering this event MyEvent(indexed string myIndexedString, string myString):

  • string works as expected and can be retrieved and indexed (e.g. event.params.myString is the emitted string)
  • indexed string has unexpected hashed value, and unable to decode back to the emitted value (e.g. event.params.myIndexedString is a hash of the emitted string)

Relevant log output

My actual contract event is:
`event ConfigChanged(string indexed key, uint indexed newValue, address indexed newAddress);` 

And the error output is:
Nov 13 07:31:48.050 WARN Bytes contain invalid UTF8. This may be caused by attempting to convert a value such as an address that cannot be parsed to a unicode string. You may want to use 'toHexString()' instead. String (truncated to 1024 chars): '\u{0008}y��Ԃ�\u{000b}��㛥��\u{0012}Jᙺ󂏧� 7�\u{0013}K!'', sgd: 1, subgraph_id: QmQDMB7r7TxH2YyvPcsPwFiidzjZTksFrSQnmqrXfBCs6a, component: SubgraphInstanceManager
Nov 13 07:31:48.050 INFO handleConfigChanged: key=\u{0008}y��Ԃ�\u{000b}��㛥��\u{0012}Jᙺ󂏧� 7�\u{0013}K!' newValue=3600 newAddress=0x0000000000000000000000000000000000000000 blockNumber=88, data_source: StreamrConfig, sgd: 1, subgraph_id: QmQDMB7r7TxH2YyvPcsPwFiidzjZTksFrSQnmqrXfBCs6a, component: SubgraphInstanceManager > UserMapping
Nov 13 07:31:48.050 ERRO handleConfigChanged: unknown key=\u{0008}y��Ԃ�\u{000b}��㛥��\u{0012}Jᙺ󂏧� 7�\u{0013}K!', data_source: StreamrConfig, sgd: 1, subgraph_id: QmQDMB7r7TxH2YyvPcsPwFiidzjZTksFrSQnmqrXfBCs6a, component: SubgraphInstanceManager > UserMapping


### IPFS hash

_No response_

### Subgraph name or link to explorer

_No response_

### Some information to help us out

- [ ] Tick this box if this bug is caused by a regression found in the latest release.
- [ ] Tick this box if this bug is specific to the hosted service.
- [X] I have searched the issue tracker to make sure this issue is not a duplicate.

### OS information

macOS

samigabor avatar Nov 13 '23 09:11 samigabor

Hi @samigabor can you share the assemblyscript handler code that causes this error?

azf20 avatar Nov 14 '23 09:11 azf20

When that error occured I had it like this:

export function handleConfigChanged(event: ConfigChanged): void {
    let key = event.params.key.toString()
    let newValue = event.params.newValue
    let newAddress = event.params.newAddress.toHexString()

    log.info('handleConfigChanged: key={} newValue={} newAddress={} blockNumber={}', 
        [key, newValue.toString(), newAddress, event.block.number.toString()])

    if (event.params.key == "slashingFraction") { network.slashingFraction = newValue }
    else if (key == "voterRegistry") { network.voterRegistry = newAddress }
    // ...
}

samigabor avatar Nov 14 '23 10:11 samigabor

But changing

let key = event.params.key.toString()

to

let key = event.params.key.toHexString()

would display the actual hash, not that gibberish thing...

samigabor avatar Nov 14 '23 10:11 samigabor

My workaround was to generate the hashes on the side (e.g. from strings like the "slashingFraction") and do that comparison instead. Changed from:

if (event.params.key.toHexString() == "slashingFraction") { /*...*/ }

to

if (event.params.key.toHexString() == "0x1244ece3f5099e14b39eb81a51e3cd18b792bc2a2335d9222b07f97c2fe13326") { /*...*/ }

samigabor avatar Nov 14 '23 10:11 samigabor

It may not even be a subgraph-related behavior, though, and can be viewed on Etherscan logs where indexed strings are handled differently. The data field is empty... If that were just a string instead, it would have been added to data. config-changed-log

samigabor avatar Nov 14 '23 11:11 samigabor

Looks like this issue has been open for 6 months with no activity. Is it still relevant? If not, please remember to close it.

github-actions[bot] avatar May 14 '24 00:05 github-actions[bot]