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

TM34 Events can't be Parsed when the Value is Binary Data #1400

Closed
ryanrossiter opened this issue Mar 16, 2024 · 8 comments · Fixed by #1405
Closed

TM34 Events can't be Parsed when the Value is Binary Data #1400

ryanrossiter opened this issue Mar 16, 2024 · 8 comments · Fixed by #1405
Labels
bug Something isn't working

Comments

@ryanrossiter
Copy link

ryanrossiter commented Mar 16, 2024

What went wrong?

When querying for tx/block results from a TM34 chain (i.e. events are base64-encoded), the parsing fails when the event data is binary and not utf8 because the deserialize_to_string conversion uses String.from_utf8 which asserts the data is valid utf8 here.

Steps to reproduce

Parse an event containing binary data formatted as base64, using the TM34 compatability mode. This event from the Canto chain as an example:

{
    "type": "block_bloom",
    "attributes": [
        {
            "key": "Ymxvb20=",
            "value": "ACAAABAAAAgAAAAAAAAAABIAAAIAABAAAAAAIgAAAQAEAAAAAAIAAIBAAAAAACAAAAQAgAAAAIACAAAEASAkiACAAIAAAAAgCAAADAAAACAAAAAAEAIAABQAABAAAACAAAAAAAAEAEAAQEAgABAAAAAAAAEACAAAAAAEEAAAAAAAAEAAAAQAAACAAAAAABAAAQAQAAAAAAAAAABABAAgAAIAAAAAAAAAQAAAAAAACAABBAQAAAAAAAKAAAAAAggIAQAAAgAAAAAAAAAEAAAAAAAAAAAAAAAAAAgAAAAAAAAAEQgAAAAAAAAAQAAAAAAAEAACAgAQAAABAAAAAAQAQA==",
            "index": true
        }
    ]
}

Definition of "done"

Parsing should not fail when the encoded data is binary. Perhaps it should leave any values which aren't utf8 as base64 strings.

@ryanrossiter ryanrossiter added the bug Something isn't working label Mar 16, 2024
@romac
Copy link
Member

romac commented Mar 16, 2024

Thanks for bringing this to our attention!

Can you please post a minimal reproduction of the problem for us to take a look at?

@romac
Copy link
Member

romac commented Mar 17, 2024

It seems indeed that we are wrongly modeling EventAttribute's key and value as String instead of Vec for Tendermint/CometBFT v0.34, whereas those are only required to be valid UTF-8 encoded strings since Tendermint/CometBFT v0.37.

@penso
Copy link
Contributor

penso commented Mar 28, 2024

Yes indeed, this is also breaking on early osmosis blocks. I can't fetch block 1423377 (v0.34) because some EventAttribute have :

      {
        "type": "distribution",
        "attributes": [
          {
            "key": "Z2F1Z2VfaWQ=",
            "value": "MTQ1Mg==",
            "index": true
          },
          {
            "key": "cmVjZWl2ZXI=",
            "value": "V0RfatpWKg/BJHrErklu9FjLhBM=",
            "index": true
          },
          {
            "key": "YW1vdW50",
            "value": "Mzg2dW9zbW8=",
            "index": true
          }
        ]
      }

and V0RfatpWKg/BJHrErklu9FjLhBM= isn't base64 encoded UTF8.

@romac
Copy link
Member

romac commented Mar 28, 2024

We'll fix this in v0.36, would gladly accept a PR if anyone has time to put one together otherwise I'll get to it next week together with the release.

@penso
Copy link
Contributor

penso commented Mar 28, 2024

We'll fix this in v0.36, would gladly accept a PR if anyone has time to put one together otherwise I'll get to it next week together with the release.

How do you expect to fix this, use Vec<u8> only for v0.34 and String for later versions?

@romac
Copy link
Member

romac commented Mar 28, 2024

Yes exactly!

@penso
Copy link
Contributor

penso commented Mar 29, 2024

Yes exactly!

I'm not really familiar with tendermint and the code so I looked quickly out of curiosity since I need this to fetch early Osmosis blocks. Not sure how I'd get to do this in a small change.

@penso
Copy link
Contributor

penso commented Mar 29, 2024

We'll fix this in v0.36, would gladly accept a PR if anyone has time to put one together otherwise I'll get to it next week together with the release.

Tried my luck, would love feedback. Never contributed to tendermint so not sure that's the right way to fix it.

penso added a commit to penso/tendermint-rs that referenced this issue Mar 30, 2024
…ems#1400)

0.34 doesn't enforce UTF8 for event attribute values. Adding a Vec<u8>
for those, and keeping String for later versions.
penso added a commit to penso/tendermint-rs that referenced this issue Mar 30, 2024
…ems#1400)

0.34 doesn't enforce UTF8 for event attribute values. Adding a Vec<u8>
for those, and keeping String for later versions.
romac added a commit that referenced this issue Apr 22, 2024
…c<u8>` for Tendermint v0.34 (#1405)

* tendermint: Add `Vec<u8>` for `EventAttribute` for 0.34 (#1400)

0.34 doesn't enforce UTF8 for event attribute values. Adding a Vec<u8>
for those, and keeping String for later versions.

* Fix clippy warnings

* Rename `value_as_bytes` to `value_bytes`

* Change v0.34 event attribute key type to `Vec<u8>`

* Update doc comments

* !fixup 0d93c60

* Fix deserialization of untagged `EventAttribute`

* Fix tests

* Update changelog entry

* Remove TODO

* Fix no_std compat

* Fix warnings on nightly

* Update tendermint/src/abci/event.rs

Co-authored-by: Erwan Or <erwan.ounn.84@gmail.com>

* Update tendermint/src/abci/event.rs

Co-authored-by: Erwan Or <erwan.ounn.84@gmail.com>

* Formatting

* Fix compilation errors in tests

---------

Co-authored-by: Romain Ruetschi <romain@informal.systems>
Co-authored-by: Erwan Or <erwan.ounn.84@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants