From 1c4f6ede1a396dbedab9d9ec1b85dba0192e015f Mon Sep 17 00:00:00 2001 From: marco ilardi <marco@freemaker.it> Date: Fri, 13 Dec 2024 19:40:31 +0100 Subject: [PATCH] ensure ObjectCore exists before short-circuit --- 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 <pre><code><b>public</b> <b>fun</b> <a href="object.md#0x1_object_owns">owns</a><T: key>(<a href="object.md#0x1_object">object</a>: <a href="object.md#0x1_object_Object">Object</a><T>, owner: <b>address</b>): bool <b>acquires</b> <a href="object.md#0x1_object_ObjectCore">ObjectCore</a> { <b>let</b> current_address = <a href="object.md#0x1_object_object_address">object_address</a>(&<a href="object.md#0x1_object">object</a>); - <b>if</b> (current_address == owner) { - <b>return</b> <b>true</b> - }; <b>assert</b>!( <b>exists</b><<a href="object.md#0x1_object_ObjectCore">ObjectCore</a>>(current_address), <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_not_found">error::not_found</a>(<a href="object.md#0x1_object_EOBJECT_DOES_NOT_EXIST">EOBJECT_DOES_NOT_EXIST</a>), ); + <b>if</b> (current_address == owner) { + <b>return</b> <b>true</b> + }; + <b>let</b> <a href="object.md#0x1_object">object</a> = <b>borrow_global</b><<a href="object.md#0x1_object_ObjectCore">ObjectCore</a>>(current_address); <b>let</b> current_address = <a href="object.md#0x1_object">object</a>.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<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;