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

[Bug] TxEnvelop json decoding fails with confusing error message #1689

Open
ufoscout opened this issue Nov 25, 2024 · 3 comments
Open

[Bug] TxEnvelop json decoding fails with confusing error message #1689

ufoscout opened this issue Nov 25, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@ufoscout
Copy link

Component

serde

What version of Alloy are you on?

alloy v0.6.4

Operating System

Linux

Describe the bug

Deserializing a TxEnvelop produces a confusing error message: Error("data did not match any variant of untagged enum MaybeTaggedTxEnvelope", line: 0, column: 0) independently of the real error.

For example, this fails and there's no way to know why:

#[test]
fn test_serde_tx_envelop() {
    let data = r#"
    {
        "hash":"0x0000000000000000000000000000000000000000000000000000000000000000",
        "input":"0x",
        "r": "0x1",
        "s": "0x0",
        "v": "0x1",
        "gas":"0x2710",
        "from":"0x0202020202020202020202020202020202020202",
        "to":null,
        "value":"0x0",
        "nonce":"0x0",
        "gasPrice":"0x4e20",
        "type":"0x0"
    }
    "#;
    let _tx: TxEnvelope = serde_json::from_str(data).unwrap();
}

I am not sure why, but the error disappears if you change from "v": "0x1" to "v": "0x1c".

This test also fails because the hash length is 63 instead of 64, but the error reported makes it impossible to find it:

#[test]
fn test_serde_tx_envelop() {
    let data = r#"
    {
        "hash":"0x00000000000000000000000000000000000000000000000000000000000000",
        "input":"0x",
        "r": "0x1",
        "s": "0x0",
        "v": "0x1c",
        "gas":"0x2710",
        "from":"0x0202020202020202020202020202020202020202",
        "to":null,
        "value":"0x0",
        "nonce":"0x0",
        "gasPrice":"0x4e20"
    }
    "#;
    let _tx: TxEnvelope = serde_json::from_str(data).unwrap();
}
@ufoscout ufoscout added the bug Something isn't working label Nov 25, 2024
@klkvr
Copy link
Member

klkvr commented Nov 26, 2024

Did you get this JSON payload from a real RPC response? This transaction matches legacy transaction and for them we are expecting v as 27/28. If it's not the case for some endpoint, we can look into adapting this

@mattsse
Copy link
Member

mattsse commented Nov 26, 2024

we can def improve the error message by handrolling the deserde impl which would have the benefit of making this a lot more efficient, but would be a bit messy

@Toeplitz
Copy link

Toeplitz commented Nov 30, 2024

I'm getting the same error on my base network provider with this code:

    let block = provider.get_block_by_number(block_num, BlockTransactionsKind::Hashes).await?;

    if let Some(block) = block {
        let txs = block.transactions.as_hashes().unwrap();

        for hash in txs {
            let tx = provider.get_transaction_by_hash(*hash).await?;
            println!("tx = {:#?}", tx)
        }

Gives error:

Error: deserialization error: data did not match any variant of untagged enum MaybeTaggedTxEnvelope at line 1 column 888

Caused by:
data did not match any variant of untagged enum MaybeTaggedTxEnvelope at line 1 column 888

Related to the bug I reported here: #1716

The code works fine on the ethereum network.

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
Development

No branches or pull requests

4 participants