Conversation
fields() and into_fields() now return Option so an out-of-range or inconsistent RuntimeVariants query cannot collapse to an empty unit variant. Callers in move-vm-types treat None as an error. Completes the #411 serialize-path fix for delayed-field walks and as_move_value. Co-authored-by: Young Yang Liauw <sausagee@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Movement #411 made BCS serialize reject out-of-range
RuntimeVariantstags viatry_get_variant_field_layouts. The layout accessors themselves still returned an empty slice for a bad or missing tag (fields()/into_fields()), so other walkers could treat that tag as a unit variant.This is a clean-room completion of the fail-closed layout API (upstream intent only: aptos-labs#20304
fields() -> Option). No aptos-labs code was cherry-picked or copied.MoveStructLayout::fieldsandinto_fieldsnow returnOption:Runtimerequiresvariant == NoneRuntimeVariantsrequiresSome(idx)in rangefields()accessorInvariant: serialization must not emit an unknown variant tag. An empty field list is a valid unit variant (
Some(&[])). Callers must handleNoneand must not fall back to empty fields.Call sites updated in
move-vm-types: BCS serialize,as_move_value, delayed-field string/DerivedString layout walks, and the value proptest strategy. Feature flags 81/95 are not enabled.How Has This Been Tested?
Verified locally:
New coverage:
fields_returns_some_for_consistent_runtime_queries/fields_returns_none_for_unknown_or_inconsistent_tags/into_fields_is_fail_closed_like_fieldsenum_out_of_range_variant_tag_is_not_serializable(Reject out-of-range enum variant tags during value serialization #411)as_move_value_rejects_out_of_range_unit_tagKey Areas to Review
MoveStructLayout::fields/into_fieldscontract:Nonevs empty unit variantfields(None)error instead of empty-tuple serializeas_move_value: panics on unknown tag rather than emitting a unit variantis_string_layout/is_derived_string_struct_layouthandleNoneType of Change
Which Components or Systems Does This Change Impact?
Checklist
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.