blinklabs-io / gouroboros

Go implementation of the Cardano Ouroboros family of protocols
Apache License 2.0
70 stars 13 forks source link

Transaction fails parsing: #665

Closed wolf31o2 closed 4 months ago

wolf31o2 commented 5 months ago

Reported via Discord (latest gOuroboros):

"Any idea why the following snippet of code might be unable to unwrap the cbor?

func getTxIdHex(txRawBytes []byte) (string, error) {
    // Unwrap raw transaction bytes into a CBOR array
    var txUnwrap []cbor.RawMessage
    if err := cbor.Unmarshal(txRawBytes, &txUnwrap); err != nil {
        return "", err
    }
    // index 0 is the transaction body
    // Store index 0 (transaction body) as byte array
    txBody := txUnwrap[0]
    // Convert the body into a blake2b256 hash string
    txIdHash := blake2b.Sum256(txBody)
    // Encode hash string as byte array to hex string
    txIdHex := hex.EncodeToString(txIdHash[:])
    return txIdHex, nil
}

Error: cbor: 8 bytes of extraneous data starting at index 1

Transactions are indeed valid. Here is an example where it was unable to unwrap yet the tx went through: https://preprod.cardanoscan.io/transaction/ac935bfaaeb0b8b5bd379d220c37dd02ddda004e752f86bd779eed48d33fab22"

We tried switching to deserializing to a ledger.Transaction with Hash() and are still seeing the same behavior.

"github.com/blinklabs-io/gouroboros v0.89.1

func getTxIdHex(txRawBytes []byte) (string, error) {
    // Determine transaction type (era)
    txType, err := ledger.DetermineTransactionType(txRawBytes)
    if err != nil {
        return "", err
    }
    tx, err := ledger.NewTransactionFromCbor(txType, txRawBytes)
    if err != nil {
        return "", err
    }

    return tx.Hash(), nil
}

"

Add this transaction to the unit tests when we resolve this issue.

wolf31o2 commented 4 months ago

There was a secondary issue causing the input bytes to be modified.