Skip to content

Commit

Permalink
add limit to name/symbol length
Browse files Browse the repository at this point in the history
  • Loading branch information
lightmark committed Apr 12, 2023
1 parent af43aab commit 0e28fad
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
46 changes: 46 additions & 0 deletions aptos-move/framework/aptos-framework/doc/fungible_asset.md
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,16 @@ The mint ref and the the store do not match.



<a name="0x1_fungible_asset_ENAME_TOO_LONG"></a>

Name of the fungible asset metadata is too long


<pre><code><b>const</b> <a href="fungible_asset.md#0x1_fungible_asset_ENAME_TOO_LONG">ENAME_TOO_LONG</a>: u64 = 15;
</code></pre>



<a name="0x1_fungible_asset_ENOT_STORE_OWNER"></a>

Account is not the store's owner.
Expand All @@ -562,6 +572,16 @@ More tokens than remaining supply are being burnt.



<a name="0x1_fungible_asset_ESYMBOL_TOO_LONG"></a>

Symbol of the fungible asset metadata is too long


<pre><code><b>const</b> <a href="fungible_asset.md#0x1_fungible_asset_ESYMBOL_TOO_LONG">ESYMBOL_TOO_LONG</a>: u64 = 16;
</code></pre>



<a name="0x1_fungible_asset_ETRANSFER_REF_AND_FUNGIBLE_ASSET_MISMATCH"></a>

The transfer ref and the fungible asset do not match.
Expand Down Expand Up @@ -592,6 +612,24 @@ Account cannot transfer or receive fungible assets.



<a name="0x1_fungible_asset_MAX_NAME_LENGTH"></a>



<pre><code><b>const</b> <a href="fungible_asset.md#0x1_fungible_asset_MAX_NAME_LENGTH">MAX_NAME_LENGTH</a>: u64 = 32;
</code></pre>



<a name="0x1_fungible_asset_MAX_SYMBOL_LENGTH"></a>



<pre><code><b>const</b> <a href="fungible_asset.md#0x1_fungible_asset_MAX_SYMBOL_LENGTH">MAX_SYMBOL_LENGTH</a>: u64 = 10;
</code></pre>



<a name="0x1_fungible_asset_add_fungibility"></a>

## Function `add_fungibility`
Expand Down Expand Up @@ -623,6 +661,14 @@ This returns the capabilities to mint, burn, and transfer.
maximum
}
});
<b>assert</b>!(
<a href="../../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_length">string::length</a>(&name) &lt;= <a href="fungible_asset.md#0x1_fungible_asset_MAX_NAME_LENGTH">MAX_NAME_LENGTH</a>,
<a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="fungible_asset.md#0x1_fungible_asset_ENAME_TOO_LONG">ENAME_TOO_LONG</a>)
);
<b>assert</b>!(
<a href="../../aptos-stdlib/../move-stdlib/doc/string.md#0x1_string_length">string::length</a>(&symbol) &lt;= <a href="fungible_asset.md#0x1_fungible_asset_MAX_SYMBOL_LENGTH">MAX_SYMBOL_LENGTH</a>,
<a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="fungible_asset.md#0x1_fungible_asset_ESYMBOL_TOO_LONG">ESYMBOL_TOO_LONG</a>)
);
<b>move_to</b>(metadata_object_signer,
<a href="fungible_asset.md#0x1_fungible_asset_Metadata">Metadata</a> {
supply,
Expand Down
25 changes: 21 additions & 4 deletions aptos-move/framework/aptos-framework/sources/fungible_asset.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module aptos_framework::fungible_asset {
use aptos_framework::event;
use aptos_framework::object::{Self, Object, ConstructorRef, DeleteRef};
use aptos_framework::optional_aggregator::{Self, OptionalAggregator};
use std::string;

use std::error;
use std::option::{Self, Option};
Expand Down Expand Up @@ -37,6 +39,17 @@ module aptos_framework::fungible_asset {
const EBURN_REF_AND_FUNGIBLE_ASSET_MISMATCH: u64 = 13;
/// Cannot destroy fungible stores with non-zero balance.
const EBALANCE_IS_NOT_ZERO: u64 = 14;
/// Name of the fungible asset metadata is too long
const ENAME_TOO_LONG: u64 = 15;
/// Symbol of the fungible asset metadata is too long
const ESYMBOL_TOO_LONG: u64 = 16;

//
// Constants
//

const MAX_NAME_LENGTH: u64 = 32;
const MAX_SYMBOL_LENGTH: u64 = 10;

/// Maximum possible coin supply.
const MAX_U128: u128 = 340282366920938463463374607431768211455;
Expand Down Expand Up @@ -134,6 +147,14 @@ module aptos_framework::fungible_asset {
maximum
}
});
assert!(
string::length(&name) <= MAX_NAME_LENGTH,
error::invalid_argument(ENAME_TOO_LONG)
);
assert!(
string::length(&symbol) <= MAX_SYMBOL_LENGTH,
error::invalid_argument(ESYMBOL_TOO_LONG)
);
move_to(metadata_object_signer,
Metadata {
supply,
Expand Down Expand Up @@ -533,12 +554,8 @@ module aptos_framework::fungible_asset {
borrow_global<FungibleStore>(object::object_address(store))
}

#[test_only]
use std::string;
#[test_only]
use aptos_framework::account;
use aptos_framework::optional_aggregator::OptionalAggregator;
use aptos_framework::optional_aggregator;

#[test_only]
#[resource_group_member(group = aptos_framework::object::ObjectGroup)]
Expand Down

0 comments on commit 0e28fad

Please sign in to comment.