Candid question regarding `ref(r)`

I am trying to understand the meaning of this paragraph in the Candid Spec:


Most Candid values are self-explanatory, except for references. There are two forms of Candid values for service references and principal references:

  • ref(r) indicates an opaque reference, understood only by the underlying system.
  • id(b), indicates a transparent reference to a service addressed by the blob b.

Likewise, there are two forms of Candid values for function references:

  • ref(r) indicates an opaque reference, understood only by the underlying system.
  • pub(s,n), indicates the public method name n of the service referenced by s.

And then I am trying to understand how to interpret ref(r) and i8(0) in this section on Memory:

M(ref(r) : principal) = i8(0)
M(id(v*) : principal) = i8(1) M(v* : vec nat8)

The M(id(v*) : principal) is clear, but not the M(ref(r))?

I have reviewed the different implementations of Candid, and the M(ref(r):principal) seems to be implemented differently by the different toolkits.

Would somebody be able to put some color to this?

From what i understand the memory M(ref(r) : principal) = i8(0) puts a 0 value to flag that’s is an opaque reference (it has no idea how to interpret the bytes). But then after all of the memory bytes, there are the reference bytes where you put all the data.

When looking around, i don’t think i saw anyone actually implementing this part, but i could be wrong. Doesn’t seem like it’s a used feature right now

1 Like

Right. Opaque reference is currently not in use. It simply puts 0 in the message, and relies on the system to provide the real reference. It was envisioned to support capability based access control, but never got implemented at the system level.

2 Likes

@chenyan is it still planned to be implemented at some point? I have two different libraries for encoding and just curious if I’ll have to update things anytime soon

Not anytime soon. You can assume that byte is always 1, and error out otherwise in the implementation.

1 Like