You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The add_additional_metadata function in the CoinManager module enforces a redundant check to verify the non-existence of a value before adding additional metadata. However, the underlying df::add function already performs this check and aborts if the value with the same name exists.
Vulnerability Detail
In the CoinManager module, the add_additional_metadata function is defined as follows:
This function verifies that the additional_metadata field does not already exist before invoking df::add. However, the df::add function internally performs this exact check and aborts with EFieldAlreadyExists if a field with the same name already exists. The relevant portion of the df::add implementation is as follows:
publicfunadd<Name: copy + drop + store, Value: store>(
object: &mutUID,
name: Name,
value: Value,
) {
let object_addr = object.to_address();
let hash = hash_type_and_key(object_addr, name);
@>> assert!(!has_child_object(object_addr, hash), EFieldAlreadyExists);
let field = Field {
id: object::new_uid_from_hash(hash),
name,
value,
};
add_child_object(object_addr, field)
}
Since the existence check is already handled by df::add, the additional assertion in add_additional_metadata is redundant and unnecessarily duplicates logic.
Tool used
Manual Review
Recommendation
public fun add_additional_metadata<T, Value: store>(
_: &CoinManagerMetadataCap<T>,
manager: &mut CoinManager<T>,
value: Value
) {
- assert!(!df::exists_(&manager.id, b"additional_metadata"), EAdditionalMetadataAlreadyExists);
df::add(&mut manager.id, b"additional_metadata", value);
}
The text was updated successfully, but these errors were encountered:
FROM THE AUDIT:
The text was updated successfully, but these errors were encountered: