Assessment reports>Initia>Threat Model>Modules any.move and copyable_any.move

Modules any.move and copyable_any.move

These modules implement functions that can be used to wrap/unwrap any object into generic Any objects, which can be used to manipulate the value opaquely.

The two modules differ in that the copyable version defines an Any wrapper that has the copy ability (and in turn requires the wrapped value to have copy), while the noncopyable version cannot be copied, but relaxes the copy requirement for the wrapped value.

Internally, the object being wrapped is BCS serialized, and only the serialized representation is stored. The original instance of the object being wrapped is destroyed.

Function: pack

This function can be used to wrap an instance of an object. Importantly, the object to be wrapped is required to have store and drop. This prevents the caller from being able to — for example — dispose of an undroppable object and bypass the hot-potato pattern.

Inputs

  • Type T<drop + store>/T<drop + store + copy>

    • Validation: None required.

    • Impact: Type of the object to wrap.

  • x: T

    • Validation: None required.

    • Impact: Instance of the object to wrap.

Function: unpack

This function can be used to unwrap an Any instance to recover the original wrapped object.

Inputs

  • Type T

    • Validation: Must match the type of the wrapped object contained in the Any.

    • Impact: Type of the wrapped object.

  • x: Any

    • Validation: Must contain an object of type T.

    • Impact: Wrapped object to unwrap.

Zellic © 2024Back to top ↑