Deserialize error: binary parser error: Opaque reference not supported at byte offset

Hi,

Why does the deserialisation fail for the following scenario, where didc encode is successful:

Let’s assume the following script, which calls a method in Service X. The argument that is passed are serialised by didc encode and passed as a raw argument via dfx canister call.

Here’s how it looks:

#!/bin/bash

# Test 1: start
# Works!
RECORD="(record {
            \"foobar\";
            variant {
              Id = principal \"$DFX_USER_PRINCIPAL\"
            };
      })"


# Fails! Does not throw error
RAW=$(didc encode "$RECORD")

dfx canister call "$CANISTER_ID" method "$RAW" --type=raw

# Test 1: end

# Test 2: start

# Deserialization error
RECORD="(record {
            \"foobar\";
            variant {
              Id = (25000:nat64)
            };
      })"

# Does not throw error
RAW=$(didc encode "$RECORD")

dfx canister call "$CANISTER_ID" method "$RAW" --type=raw

# Test 2: end
1 Like

When the raw is generated in Rust, it works, but not through the didc tool.

The Replica returned an error: code 5, message: "Canister xxxxx trapped explicitly: Custom(Fail to decode argument 0 from table0 to record
1: Deserialize error: binary parser error: Opaque reference not supported at byte offset 129)

Tested with:

didc 0.1.0

Will now update and test again

Nope! Latest didc 0.1.1 does not work either.

Guess would be best to report to the repo at some point, but in case I’m missing something, let know! Thanks

Why are you passing Id as principal in the first test, and nat64 in the second test?

Also, if you are writing scripts about canister calls, I recommend you checking out ic-repl (GitHub - chenyan2002/ic-repl).

Take it as pseudo-code, to expose the issue, as principal works but not any other type; of course that it reflects the method signature.

I’ll check the ic-repl, wasn’t aware of it.

Thanks!

1 Like

There is no issue here. The target method expects a principal type. Providing a different type will cause decoding errors.

1 Like

@chenyan the example above was just to highlight the fact that when the target method expects a different type, it fails with the error above, but not when principal.

When:

source sends principal -> method expects principal works
source sends any other type -> method expects other types fails

On the other hand, when the raw data is encoded via rust and passed to the dfx cli, it works.

Works:

dfx canister call "$CANISTER_ID" method "$RAW_FROM_RUST" --type=raw

Fails:

dfx canister call "$CANISTER_ID" method "$RAW_FROM_DIDC_ENCODE" --type=raw

When possible for me, I’ll try to provide a reproducible example

What does RAW_FROM_RUST mean? didc is written in Rust and is using the same candid crate. I need a concrete example to understand your problem.