Skip to content

Commit

Permalink
Do not allow shared object passed by value (MystenLabs#799)
Browse files Browse the repository at this point in the history
* Do not allow shared object passed by value

* fix tests
  • Loading branch information
lxfind authored Mar 12, 2022
1 parent 3b3b318 commit c623e0a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ fn test_freeze() {
assert!(err
.1
.to_string()
.contains("Argument 0 is expected to be mutable, immutable object found"));
.contains("Shared object cannot be passed by-value, found in argument 0"));
// Since it failed before VM execution, during type resolving,
// only minimum gas will be charged.
assert_eq!(err.0, gas::MIN_MOVE);
Expand Down
6 changes: 4 additions & 2 deletions sui_types/src/move_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,12 @@ pub fn resolve_and_type_check(
}
}
Type::Struct { .. } => {
if object.is_read_only() {
if object.is_shared() {
// Forbid passing shared (both mutable and immutable) object by value.
// This ensures that shared object cannot be transferred, deleted or wrapped.
return Err(SuiError::TypeError {
error: format!(
"Argument {} is expected to be mutable, immutable object found",
"Shared object cannot be passed by-value, found in argument {}",
idx
),
});
Expand Down

0 comments on commit c623e0a

Please sign in to comment.