From e63772f35c2fc658861ec6e2965d598a5946976e Mon Sep 17 00:00:00 2001 From: marco ilardi Date: Fri, 13 Dec 2024 19:40:31 +0100 Subject: [PATCH] ensure ObjectCore exists before short-circuit (cherry picked from commit 1c4f6ede1a396dbedab9d9ec1b85dba0192e015f) --- aptos-move/framework/aptos-framework/doc/object.md | 7 ++++--- aptos-move/framework/aptos-framework/sources/object.move | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/aptos-move/framework/aptos-framework/doc/object.md b/aptos-move/framework/aptos-framework/doc/object.md index cb633a173bf6c..7ae33a425ee25 100644 --- a/aptos-move/framework/aptos-framework/doc/object.md +++ b/aptos-move/framework/aptos-framework/doc/object.md @@ -2301,15 +2301,16 @@ Return true if the provided address has indirect or direct ownership of the prov
public fun owns<T: key>(object: Object<T>, owner: address): bool acquires ObjectCore {
     let current_address = object_address(&object);
-    if (current_address == owner) {
-        return true
-    };
 
     assert!(
         exists<ObjectCore>(current_address),
         error::not_found(EOBJECT_DOES_NOT_EXIST),
     );
 
+    if (current_address == owner) {
+        return true
+    };
+
     let object = borrow_global<ObjectCore>(current_address);
     let current_address = object.owner;
 
diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move
index abca67bb2451a..bb6684ff6f430 100644
--- a/aptos-move/framework/aptos-framework/sources/object.move
+++ b/aptos-move/framework/aptos-framework/sources/object.move
@@ -662,15 +662,16 @@ module aptos_framework::object {
     /// Return true if the provided address has indirect or direct ownership of the provided object.
     public fun owns(object: Object, owner: address): bool acquires ObjectCore {
         let current_address = object_address(&object);
-        if (current_address == owner) {
-            return true
-        };
 
         assert!(
             exists(current_address),
             error::not_found(EOBJECT_DOES_NOT_EXIST),
         );
 
+        if (current_address == owner) {
+            return true
+        };
+
         let object = borrow_global(current_address);
         let current_address = object.owner;