Skip to content

Commit

Permalink
ensure ObjectCore exists before short-circuit
Browse files Browse the repository at this point in the history
(cherry picked from commit 1c4f6ed)
  • Loading branch information
GotenJBZ authored and sherry-x committed Dec 16, 2024
1 parent 45a3161 commit c0a4b90
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions aptos-move/framework/aptos-framework/doc/object.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>&lt;T: key&gt;(<a href="object.md#0x1_object">object</a>: <a href="object.md#0x1_object_Object">Object</a>&lt;T&gt;, 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>&lt;<a href="object.md#0x1_object_ObjectCore">ObjectCore</a>&gt;(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>&lt;<a href="object.md#0x1_object_ObjectCore">ObjectCore</a>&gt;(current_address);
<b>let</b> current_address = <a href="object.md#0x1_object">object</a>.owner;

Expand Down
7 changes: 4 additions & 3 deletions aptos-move/framework/aptos-framework/sources/object.move
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit c0a4b90

Please sign in to comment.