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

Make a plan for Cardano Paribus token throws SwiftProtobuf.BinaryDecodingError error 2 #3969

Open
Balashov152 opened this issue Aug 5, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@Balashov152
Copy link
Contributor

Balashov152 commented Aug 5, 2024

To Reproduce
Steps to reproduce the behavior:
Xcode 15.2 / iOS
Token: https://cardanoscan.io/token/cc8d1b026353022abbfcc2e1e71159f9e308d9c6e905ac1db24c7fb650617269627573

Try to build CardanoSigingInput and update plan via input.plan = AnySigner.plan(input: input, coin: coinType)
I received the SwiftProtobuf.BinaryDecodingError error 2 with this this description

[libprotobuf ERROR */wallet-core/swift/protobuf/google/protobuf/wire_format_lite.cc:581] String field 'TW.Cardano.Proto.TokenAmount.asset_name' contains invalid UTF-8 data when serializing a protocol buffer. Use the 'bytes' type if you intend to send raw bytes. 
[libprotobuf ERROR */wallet-core/swift/protobuf/google/protobuf/wire_format_lite.cc:581] String field 'TW.Cardano.Proto.TokenAmount.asset_name' contains invalid UTF-8 data when serializing a protocol buffer. Use the 'bytes' type if you intend to send raw bytes. 
[libprotobuf ERROR */wallet-core/swift/protobuf/google/protobuf/wire_format_lite.cc:581] String field 'TW.Cardano.Proto.TokenAmount.asset_name' contains invalid UTF-8 data when serializing a protocol buffer. Use the 'bytes' type if you intend to send raw bytes. 

I filled in this way:

        CardanoTokenAmount.with {
            $0.policyID = asset.policyID // cc8d1b026353022abbfcc2e1e71159f9e308d9c6e905ac1db24c7fb6
            $0.assetNameHex = asset.assetNameHex // 50617269627573
            $0.amount = amount.serialize() // 01312d00
        }

Looks like the problem in the assetNameHex but I have no idea why ?
With other tokens everything is good.

@Balashov152 Balashov152 added the bug Something isn't working label Aug 5, 2024
@satoshiotomakan
Copy link
Collaborator

Hi @Balashov152, please make sure assetNameHex is a hexadecimal string, but not a byte array, eg

$0.assetNameHex = "50617269627573"

@Balashov152
Copy link
Contributor Author

Hi @Balashov152, please make sure assetNameHex is a hexadecimal string, but not a byte array, eg

$0.assetNameHex = "50617269627573"

Yes, I tried to do it in that way. Just like raw data.
And also I tried to hardcode $0.assetName = "Paribus" instead of assetNameHex

Same problem :(

@satoshiotomakan
Copy link
Collaborator

satoshiotomakan commented Aug 9, 2024

@Balashov152 please provide a full example. From what I see, I don't have an idea what's wrong.
Please also refer to the examples in Swift:


$0.assetNameHex = "53554e444145"

@siblockchaina
Copy link

Hello, there is an update regarding this issue. The problem involves Cardano tokens whose names are implemented according to CIP-0067. The hex representation of these names does not encode correctly into a UTF-8 string.
The reproduction steps remain the same.

let token = CardanoTokenAmount.with {
            $0.policyID = "f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a"
            $0.assetNameHex = "000de14064655f76696c6c69657273"
            $0.amount = Data(hexString: "04d3e8d9")!
}

@satoshiotomakan
Copy link
Collaborator

satoshiotomakan commented Aug 27, 2024

@siblockchaina @Balashov152 could you please provide the whole code from creating a SigningInput Protobuf message to using AnySigner.sign() function?
IMPORTANT leave privateKey empty to avoid funds loss.
It would be great if you could share a serialized SigningInput Protobuf message in hex as well, for example, like this:

let input = CardanoSigningInput.with {
  // TODO
}
let serializedInput = input.serializedData().hexString

@siblockchaina
Copy link

This is a complete example of a reproduced crash

        let toToken = CardanoTokenAmount.with {
            $0.policyID = "f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a"
            $0.assetNameHex = "000de14064655f76696c6c69657273"
            $0.amount = Data(hexString: "01312D00")! // 20000000
        }
        var toTokenBundle = CardanoTokenBundle();
        toTokenBundle.token.append(toToken)
        
        // check min ADA amount, set it
        let inputTokenAmountSerialized = try toTokenBundle.serializedData()
        let minAmount = CardanoMinAdaAmount(tokenBundle: inputTokenAmountSerialized)
        
        var input = CardanoSigningInput.with {
            $0.transferMessage.toAddress = "addr1q92cmkgzv9h4e5q7mnrzsuxtgayvg4qr7y3gyx97ukmz3dfx7r9fu73vqn25377ke6r0xk97zw07dqr9y5myxlgadl2s0dgke5"
            $0.transferMessage.changeAddress = "addr1qxxe304qg9py8hyyqu8evfj4wln7dnms943wsugpdzzsxnkvvjljtzuwxvx0pnwelkcruy95ujkq3aw6rl0vvg32x35qc92xkq"
            $0.transferMessage.amount = minAmount
            $0.transferMessage.useMaxAmount = false
            $0.transferMessage.tokenAmount = toTokenBundle
            $0.ttl = 53333333
        }
        
        var utxo = CardanoTxInput.with {
            $0.outPoint.txHash = Data(hexString: "f074134aabbfb13b8aec7cf5465b1e5a862bde5cb88532cc7e64619179b3e767")!
            $0.outPoint.outputIndex = 2
            $0.address = "addr1q8043m5heeaydnvtmmkyuhe6qv5havvhsf0d26q3jygsspxlyfpyk6yqkw0yhtyvtr0flekj84u64az82cufmqn65zdsylzk23"
            $0.amount = 2000000
        }
        let token = CardanoTokenAmount.with {
            $0.policyID = "f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a"
            $0.assetNameHex = "000de14064655f76696c6c69657273"
            $0.amount = Data(hexString: "04d3e8d9")!
        }

        utxo.tokenAmount.append(token)
        input.utxos.append(utxo)
        
        let serializedInput = try input.serializedData().hexString
        
        print(serializedInput)
        
        /*
       Serialized input hex:
       0af5010a240a20f074134aabbfb13b8aec7cf5465b1e5a862bde5cb88532cc7e64619179b3e76710021267616464723171383034336d356865656179646e76746d6d6b7975686536717635686176766873663064323671336a7967737370786c796670796b3679716b77307968747976747230666c656b6a3834753634617a38326375666d716e36357a6473796c7a6b32331880897a22600a3866306666343862626237626265396435396134306631636539306539653964306666353030326563343866323332623439636130666239611a0404d3e8d9221e3030306465313430363436353566373636393663366336393635373237331aba020a676164647231713932636d6b677a76396834653571376d6e727a7375787467617976673471723779336779783937756b6d7a336466783772396675373376716e32353337376b65367230786b39377a7730376471723979356d79786c6761646c32733064676b653512676164647231717878653330347167397079386879797175386576666a34776c6e37646e6d733934337773756770647a7a73786e6b76766a6c6a747a757778767830706e77656c6b637275793935756a6b7133617736726c30767667333278333571633932786b711888b65a22620a600a3866306666343862626237626265396435396134306631636539306539653964306666353030326563343866323332623439636130666239611a0401312d00221e30303064653134303634363535663736363936633663363936353732373320d59ab719
        */
        
        input.plan = AnySigner.plan(input: input, coin: .cardano) // Crash 
        
        if input.plan.error != .ok {
            //Do some
        }
        
        let output: CardanoSigningOutput = AnySigner.sign(input: input, coin: .cardano)

@satoshiotomakan
Copy link
Collaborator

Hi @siblockchaina, thank you for the code snippet. I found the problem. Looks like AnySigner.plan doesn't handle hexed assetName properly, and we don't even use it in our production environment, that's why we didn't know about it.
I'll make a fix this week as soon as I can

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

3 participants