Skip to content

feat(iota-types)!: update to MoveStruct with contents checked#11471

Merged
thibault-martinez merged 3 commits intodevelopfrom
sdk-replacement/29-MoveStruct
May 8, 2026
Merged

feat(iota-types)!: update to MoveStruct with contents checked#11471
thibault-martinez merged 3 commits intodevelopfrom
sdk-replacement/29-MoveStruct

Conversation

@Thoralf-M
Copy link
Copy Markdown
Member

This PR follows up on the MoveObjectType / MoveStruct migration in
iota-rust-sdk. The SDK's MoveStruct (re-exported in iota-types as
MoveObject) has been hardened: its fields are now private, construction
goes through a fallible MoveStruct::new constructor, and replacing the
contents goes through a fallible set_contents setter — both of which
validate that contents is at least ObjectId::LENGTH (32) bytes, since
every Move object must carry its ObjectId as the leading bytes of its
BCS payload. This PR adapts the iota-types and execution call sites to
the new API.

Description of change

  • iota-types::object (MoveObjectExt) no longer reaches into
    MoveObject fields directly. All self.object_type / self.version
    / self.contents accesses are replaced with the corresponding
    object_type() / version() / contents() getters; mutations go
    through set_version() and the fallible set_contents() (returning
    MoveStructContentsError, mapped to ExecutionError::invariant_violation
    on the production path).
  • MoveObjectExt::set_coin_value_unchecked and
    set_clock_timestamp_ms_unchecked no longer mutate the contents buffer
    in place via Vec::splice — they now copy the buffer
    (self.contents().to_vec()), patch the trailing 8 bytes, and pass it
    back through set_contents(...).unwrap() (the length is unchanged, so
    the length check cannot fail).
  • All MoveObject { object_type, version, contents } struct-literal
    constructions in Object::*_for_testing helpers and in
    MoveObjectExt::new_from_execution_with_limit are replaced with
    MoveObject::new(...). Test helpers .unwrap() the result; the
    execution path maps the error to ExecutionError::invariant_violation.
  • The associated helper MoveObject::id_opt(&bytes) (which extracted an
    ObjectId from the leading bytes of a raw payload) was removed in the
    SDK now that the same invariant is upheld by the constructor. The two
    call sites in iota-adapter::programmable_transactions::context are
    updated to call ObjectID::from_bytes(&bytes[..ObjectID::LENGTH])
    directly, with the missing-bytes case turning into an
    ExecutionError::invariant_violation.
  • iota-open-rpc::examples had a MoveObject::new_from_execution_with_limit
    call that built an example object with an empty contents: Vec::new()
    and an empty MoveStructLayout. Empty contents now fail the new
    length check, so the example is updated to construct a 32-byte payload
    via UID::new(parent_object_id).to_bcs_bytes() and a matching layout
    with a single id: UID field. Generated openrpc.json snapshots are
    regenerated to reflect the new example payload.

Release Notes

  • Protocol:
  • Nodes (Validators and Full nodes):
  • Indexer:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK: MoveStruct (re-exported as iota-types::object::MoveObject)
    now has private fields. Construction must go through
    MoveStruct::new(object_type, version, contents) and content updates
    through set_contents(...); both are fallible and reject contents
    shorter than ObjectId::LENGTH (32 bytes), since every Move object
    must carry its ObjectId as the leading bytes. The associated helper
    MoveObject::id_opt(&bytes) has been removed — call
    ObjectID::from_bytes(&bytes[..ObjectID::LENGTH]) directly. Direct
    field access (.object_type, .version, .contents) is replaced by
    the equivalent getter methods. Wire formats (BCS and JSON) are
    unchanged.
  • gRPC:

@Thoralf-M Thoralf-M requested review from a team as code owners May 8, 2026 07:24
@iota-ci iota-ci added dev-tools Issues related to the Developer Tools Team sc-platform Issues related to the Smart Contract Platform group. labels May 8, 2026
@Thoralf-M Thoralf-M force-pushed the sdk-replacement/28-TransactionData branch from 4bd1244 to 242e8e7 Compare May 8, 2026 07:35
@Thoralf-M Thoralf-M requested review from a team as code owners May 8, 2026 07:35
@Thoralf-M Thoralf-M force-pushed the sdk-replacement/29-MoveStruct branch from 42ac591 to 77e52fa Compare May 8, 2026 07:35
@Thoralf-M Thoralf-M force-pushed the sdk-replacement/28-TransactionData branch 4 times, most recently from 6966288 to 90176d8 Compare May 8, 2026 12:06
Base automatically changed from sdk-replacement/28-TransactionData to develop May 8, 2026 13:33
@Thoralf-M Thoralf-M force-pushed the sdk-replacement/29-MoveStruct branch from 77e52fa to ebfec8b Compare May 8, 2026 13:34
@alexsporn alexsporn added this to the v1.23.0 milestone May 8, 2026
Comment thread crates/iota-types/src/object.rs
@thibault-martinez thibault-martinez merged commit bb154cb into develop May 8, 2026
35 checks passed
@thibault-martinez thibault-martinez deleted the sdk-replacement/29-MoveStruct branch May 8, 2026 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dev-tools Issues related to the Developer Tools Team sc-platform Issues related to the Smart Contract Platform group.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants